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.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            @Override
032            public void deleteArticleResource(long groupId, String articleId)
033                    throws PortalException, SystemException {
034    
035                    journalArticleResourcePersistence.removeByG_A(groupId, articleId);
036            }
037    
038            @Override
039            public JournalArticleResource fetchArticleResource(
040                            long groupId, String articleId)
041                    throws SystemException {
042    
043                    return journalArticleResourcePersistence.fetchByG_A(groupId, articleId);
044            }
045    
046            @Override
047            public JournalArticleResource fetchArticleResource(
048                            String uuid, long groupId)
049                    throws SystemException {
050    
051                    return journalArticleResourcePersistence.fetchByUUID_G(uuid, groupId);
052            }
053    
054            @Override
055            public JournalArticleResource getArticleResource(
056                            long articleResourcePrimKey)
057                    throws PortalException, SystemException {
058    
059                    return journalArticleResourcePersistence.findByPrimaryKey(
060                            articleResourcePrimKey);
061            }
062    
063            @Override
064            public long getArticleResourcePrimKey(long groupId, String articleId)
065                    throws SystemException {
066    
067                    return getArticleResourcePrimKey(null, groupId, articleId);
068            }
069    
070            @Override
071            public long getArticleResourcePrimKey(
072                            String uuid, long groupId, String articleId)
073                    throws SystemException {
074    
075                    JournalArticleResource articleResource = null;
076    
077                    if (Validator.isNotNull(uuid)) {
078                            articleResource = journalArticleResourcePersistence.fetchByUUID_G(
079                                    uuid, groupId);
080                    }
081    
082                    if (articleResource == null) {
083                            articleResource = journalArticleResourcePersistence.fetchByG_A(
084                                    groupId, articleId);
085                    }
086    
087                    if (articleResource == null) {
088                            long articleResourcePrimKey = counterLocalService.increment();
089    
090                            articleResource = journalArticleResourcePersistence.create(
091                                    articleResourcePrimKey);
092    
093                            if (Validator.isNotNull(uuid)) {
094                                    articleResource.setUuid(uuid);
095                            }
096    
097                            articleResource.setGroupId(groupId);
098                            articleResource.setArticleId(articleId);
099    
100                            journalArticleResourcePersistence.update(articleResource);
101                    }
102    
103                    return articleResource.getResourcePrimKey();
104            }
105    
106            @Override
107            public List<JournalArticleResource> getArticleResources(long groupId)
108                    throws SystemException {
109    
110                    return journalArticleResourcePersistence.findByGroupId(groupId);
111            }
112    
113    }