001    /**
002     * Copyright (c) 2000-2010 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    
024    /**
025     * @author Thiago Moreira
026     * @author Raymond Augé
027     */
028    public class AnnouncementsFlagLocalServiceImpl
029            extends AnnouncementsFlagLocalServiceBaseImpl {
030    
031            public AnnouncementsFlag addFlag(long userId, long entryId, int value)
032                    throws SystemException {
033    
034                    long flagId = counterLocalService.increment();
035    
036                    AnnouncementsFlag flag = announcementsFlagPersistence.create(flagId);
037    
038                    flag.setUserId(userId);
039                    flag.setCreateDate(new Date());
040                    flag.setEntryId(entryId);
041                    flag.setValue(value);
042    
043                    announcementsFlagPersistence.update(flag, false);
044    
045                    return flag;
046            }
047    
048            public void deleteFlag(long flagId)
049                    throws PortalException, SystemException {
050    
051                    announcementsFlagPersistence.remove(flagId);
052            }
053    
054            public void deleteFlags(long entryId) throws SystemException {
055                    announcementsFlagPersistence.removeByEntryId(entryId);
056            }
057    
058            public AnnouncementsFlag getFlag(long userId, long entryId, int value)
059                    throws PortalException, SystemException {
060    
061                    return announcementsFlagPersistence.findByU_E_V(
062                            userId, entryId, value);
063            }
064    
065    }