001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.announcements.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portlet.announcements.model.AnnouncementsFlag;
019    import com.liferay.portlet.announcements.service.base.AnnouncementsFlagLocalServiceBaseImpl;
020    
021    import java.util.Date;
022    import java.util.List;
023    
024    /**
025     * @author Thiago Moreira
026     * @author Raymond Aug??
027     */
028    public class AnnouncementsFlagLocalServiceImpl
029            extends AnnouncementsFlagLocalServiceBaseImpl {
030    
031            @Override
032            public AnnouncementsFlag addFlag(long userId, long entryId, int value) {
033                    long flagId = counterLocalService.increment();
034    
035                    AnnouncementsFlag flag = announcementsFlagPersistence.create(flagId);
036    
037                    flag.setUserId(userId);
038                    flag.setCreateDate(new Date());
039                    flag.setEntryId(entryId);
040                    flag.setValue(value);
041    
042                    announcementsFlagPersistence.update(flag);
043    
044                    return flag;
045            }
046    
047            @Override
048            public void deleteFlag(AnnouncementsFlag flag) {
049                    announcementsFlagPersistence.remove(flag);
050            }
051    
052            @Override
053            public void deleteFlag(long flagId) throws PortalException {
054                    AnnouncementsFlag flag = announcementsFlagPersistence.findByPrimaryKey(
055                            flagId);
056    
057                    deleteFlag(flag);
058            }
059    
060            @Override
061            public void deleteFlags(long entryId) {
062                    List<AnnouncementsFlag> flags =
063                            announcementsFlagPersistence.findByEntryId(entryId);
064    
065                    for (AnnouncementsFlag flag : flags) {
066                            deleteFlag(flag);
067                    }
068            }
069    
070            @Override
071            public AnnouncementsFlag getFlag(long userId, long entryId, int value)
072                    throws PortalException {
073    
074                    return announcementsFlagPersistence.findByU_E_V(userId, entryId, value);
075            }
076    
077    }