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