001    /**
002     * Copyright (c) 2000-2011 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.portal.kernel.util.Validator;
020    import com.liferay.portlet.journal.model.JournalArticleResource;
021    import com.liferay.portlet.journal.service.base.JournalArticleResourceLocalServiceBaseImpl;
022    
023    import java.util.List;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class JournalArticleResourceLocalServiceImpl
029            extends JournalArticleResourceLocalServiceBaseImpl {
030    
031            public void deleteArticleResource(long groupId, String articleId)
032                    throws PortalException, SystemException {
033    
034                    journalArticleResourcePersistence.removeByG_A(groupId, articleId);
035            }
036    
037            public JournalArticleResource getArticleResource(
038                            long articleResourcePrimKey)
039                    throws PortalException, SystemException {
040    
041                    return journalArticleResourcePersistence.findByPrimaryKey(
042                            articleResourcePrimKey);
043            }
044    
045            public long getArticleResourcePrimKey(long groupId, String articleId)
046                    throws SystemException {
047    
048                    return getArticleResourcePrimKey(null, groupId, articleId);
049            }
050    
051            public long getArticleResourcePrimKey(
052                            String uuid, long groupId, String articleId)
053                    throws SystemException {
054    
055                    JournalArticleResource articleResource = null;
056    
057                    if (Validator.isNotNull(uuid)) {
058                            articleResource = journalArticleResourcePersistence.fetchByUUID_G(
059                                    uuid, groupId);
060                    }
061    
062                    if (articleResource == null) {
063                            articleResource = journalArticleResourcePersistence.fetchByG_A(
064                                    groupId, articleId);
065                    }
066    
067                    if (articleResource == null) {
068                            long articleResourcePrimKey = counterLocalService.increment();
069    
070                            articleResource = journalArticleResourcePersistence.create(
071                                    articleResourcePrimKey);
072    
073                            if (Validator.isNotNull(uuid)) {
074                                    articleResource.setUuid(uuid);
075                            }
076    
077                            articleResource.setGroupId(groupId);
078                            articleResource.setArticleId(articleId);
079    
080                            journalArticleResourcePersistence.update(articleResource, false);
081                    }
082    
083                    return articleResource.getResourcePrimKey();
084            }
085    
086            public List<JournalArticleResource> getArticleResources(long groupId)
087                    throws SystemException {
088    
089                    return journalArticleResourcePersistence.findByGroupId(groupId);
090            }
091    
092    }