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            public void deleteArticleResource(long groupId, String articleId)
032                    throws PortalException, SystemException {
033    
034                    journalArticleResourcePersistence.removeByG_A(groupId, articleId);
035            }
036    
037            public JournalArticleResource fetchArticleResource(
038                            long groupId, String articleId)
039                    throws SystemException {
040    
041                    return journalArticleResourcePersistence.fetchByG_A(groupId, articleId);
042            }
043    
044            public JournalArticleResource fetchArticleResource(
045                            String uuid, long groupId)
046                    throws SystemException {
047    
048                    return journalArticleResourcePersistence.fetchByUUID_G(uuid, groupId);
049            }
050    
051            public JournalArticleResource getArticleResource(
052                            long articleResourcePrimKey)
053                    throws PortalException, SystemException {
054    
055                    return journalArticleResourcePersistence.findByPrimaryKey(
056                            articleResourcePrimKey);
057            }
058    
059            public long getArticleResourcePrimKey(long groupId, String articleId)
060                    throws SystemException {
061    
062                    return getArticleResourcePrimKey(null, groupId, articleId);
063            }
064    
065            public long getArticleResourcePrimKey(
066                            String uuid, long groupId, String articleId)
067                    throws SystemException {
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            public List<JournalArticleResource> getArticleResources(long groupId)
101                    throws SystemException {
102    
103                    return journalArticleResourcePersistence.findByGroupId(groupId);
104            }
105    
106    }