001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.announcements.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portlet.announcements.model.AnnouncementsFlag;
020    import com.liferay.portlet.announcements.service.base.AnnouncementsFlagLocalServiceBaseImpl;
021    
022    import java.util.Date;
023    import java.util.List;
024    
025    /**
026     * @author Thiago Moreira
027     * @author Raymond Augé
028     */
029    public class AnnouncementsFlagLocalServiceImpl
030            extends AnnouncementsFlagLocalServiceBaseImpl {
031    
032            public AnnouncementsFlag addFlag(long userId, long entryId, int value)
033                    throws SystemException {
034    
035                    long flagId = counterLocalService.increment();
036    
037                    AnnouncementsFlag flag = announcementsFlagPersistence.create(flagId);
038    
039                    flag.setUserId(userId);
040                    flag.setCreateDate(new Date());
041                    flag.setEntryId(entryId);
042                    flag.setValue(value);
043    
044                    announcementsFlagPersistence.update(flag, false);
045    
046                    return flag;
047            }
048    
049            public void deleteFlag(AnnouncementsFlag flag) throws SystemException {
050                    announcementsFlagPersistence.remove(flag);
051            }
052    
053            public void deleteFlag(long flagId)
054                    throws PortalException, SystemException {
055    
056                    AnnouncementsFlag flag = announcementsFlagPersistence.findByPrimaryKey(
057                            flagId);
058    
059                    deleteFlag(flag);
060            }
061    
062            public void deleteFlags(long entryId) throws SystemException {
063                    List<AnnouncementsFlag> flags =
064                            announcementsFlagPersistence.findByEntryId(entryId);
065    
066                    for (AnnouncementsFlag flag : flags) {
067                            deleteFlag(flag);
068                    }
069            }
070    
071            public AnnouncementsFlag getFlag(long userId, long entryId, int value)
072                    throws PortalException, SystemException {
073    
074                    return announcementsFlagPersistence.findByU_E_V(
075                            userId, entryId, value);
076            }
077    
078    }