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 getArticleResource(
040                            long articleResourcePrimKey)
041                    throws PortalException, SystemException {
042    
043                    return journalArticleResourcePersistence.findByPrimaryKey(
044                            articleResourcePrimKey);
045            }
046    
047            @Override
048            public long getArticleResourcePrimKey(long groupId, String articleId)
049                    throws SystemException {
050    
051                    return getArticleResourcePrimKey(null, groupId, articleId);
052            }
053    
054            @Override
055            public long getArticleResourcePrimKey(
056                            String uuid, long groupId, String articleId)
057                    throws SystemException {
058    
059                    JournalArticleResource articleResource = null;
060    
061                    if (Validator.isNotNull(uuid)) {
062                            articleResource = journalArticleResourcePersistence.fetchByUUID_G(
063                                    uuid, groupId);
064                    }
065    
066                    if (articleResource == null) {
067                            articleResource = journalArticleResourcePersistence.fetchByG_A(
068                                    groupId, articleId);
069                    }
070    
071                    if (articleResource == null) {
072                            long articleResourcePrimKey = counterLocalService.increment();
073    
074                            articleResource = journalArticleResourcePersistence.create(
075                                    articleResourcePrimKey);
076    
077                            if (Validator.isNotNull(uuid)) {
078                                    articleResource.setUuid(uuid);
079                            }
080    
081                            articleResource.setGroupId(groupId);
082                            articleResource.setArticleId(articleId);
083    
084                            journalArticleResourcePersistence.update(articleResource, false);
085                    }
086    
087                    return articleResource.getResourcePrimKey();
088            }
089    
090            @Override
091            public List<JournalArticleResource> getArticleResources(long groupId)
092                    throws SystemException {
093    
094                    return journalArticleResourcePersistence.findByGroupId(groupId);
095            }
096    
097    }