001    /**
002     * Copyright (c) 2000-2013 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            @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    }