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.journal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portlet.journal.model.JournalArticleResource;
020    import com.liferay.portlet.journal.service.base.JournalArticleResourceLocalServiceBaseImpl;
021    
022    import java.util.List;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class JournalArticleResourceLocalServiceImpl
028            extends JournalArticleResourceLocalServiceBaseImpl {
029    
030            public void deleteArticleResource(long groupId, String articleId)
031                    throws PortalException, SystemException {
032    
033                    journalArticleResourcePersistence.removeByG_A(groupId, articleId);
034            }
035    
036            public JournalArticleResource getArticleResource(
037                            long articleResourcePrimKey)
038                    throws PortalException, SystemException {
039    
040                    return journalArticleResourcePersistence.findByPrimaryKey(
041                            articleResourcePrimKey);
042            }
043    
044            public long getArticleResourcePrimKey(long groupId, String articleId)
045                    throws SystemException {
046    
047                    JournalArticleResource articleResource =
048                            journalArticleResourcePersistence.fetchByG_A(groupId, articleId);
049    
050                    if (articleResource == null) {
051                            long articleResourcePrimKey = counterLocalService.increment();
052    
053                            articleResource = journalArticleResourcePersistence.create(
054                                    articleResourcePrimKey);
055    
056                            articleResource.setGroupId(groupId);
057                            articleResource.setArticleId(articleId);
058    
059                            journalArticleResourcePersistence.update(articleResource, false);
060                    }
061    
062                    return articleResource.getResourcePrimKey();
063            }
064    
065            public List<JournalArticleResource> getArticleResources(long groupId)
066                    throws SystemException {
067    
068                    return journalArticleResourcePersistence.findByGroupId(groupId);
069            }
070    
071    }