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