001    /**
002     * Copyright (c) 2000-2012 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.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(userId, entryId, value);
075            }
076    
077    }