001    /**
002     * Copyright (c) 2000-2013 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            @Override
033            public AnnouncementsFlag addFlag(long userId, long entryId, int value)
034                    throws SystemException {
035    
036                    long flagId = counterLocalService.increment();
037    
038                    AnnouncementsFlag flag = announcementsFlagPersistence.create(flagId);
039    
040                    flag.setUserId(userId);
041                    flag.setCreateDate(new Date());
042                    flag.setEntryId(entryId);
043                    flag.setValue(value);
044    
045                    announcementsFlagPersistence.update(flag, false);
046    
047                    return flag;
048            }
049    
050            @Override
051            public void deleteFlag(AnnouncementsFlag flag) throws SystemException {
052                    announcementsFlagPersistence.remove(flag);
053            }
054    
055            @Override
056            public void deleteFlag(long flagId)
057                    throws PortalException, SystemException {
058    
059                    AnnouncementsFlag flag = announcementsFlagPersistence.findByPrimaryKey(
060                            flagId);
061    
062                    deleteFlag(flag);
063            }
064    
065            @Override
066            public void deleteFlags(long entryId) throws SystemException {
067                    List<AnnouncementsFlag> flags =
068                            announcementsFlagPersistence.findByEntryId(entryId);
069    
070                    for (AnnouncementsFlag flag : flags) {
071                            deleteFlag(flag);
072                    }
073            }
074    
075            @Override
076            public AnnouncementsFlag getFlag(long userId, long entryId, int value)
077                    throws PortalException, SystemException {
078    
079                    return announcementsFlagPersistence.findByU_E_V(userId, entryId, value);
080            }
081    
082    }