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