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