001    /**
002     * Copyright (c) 2000-2010 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.portlet.journal.DuplicateArticleImageIdException;
020    import com.liferay.portlet.journal.NoSuchArticleImageException;
021    import com.liferay.portlet.journal.model.JournalArticleImage;
022    import com.liferay.portlet.journal.service.base.JournalArticleImageLocalServiceBaseImpl;
023    
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class JournalArticleImageLocalServiceImpl
030            extends JournalArticleImageLocalServiceBaseImpl {
031    
032            public void addArticleImageId(
033                            long articleImageId, long groupId, String articleId, double version,
034                            String elInstanceId, String elName, String languageId)
035                    throws PortalException, SystemException {
036    
037                    if (articleImageId <= 0) {
038                            return;
039                    }
040    
041                    JournalArticleImage articleImage =
042                            journalArticleImagePersistence.fetchByG_A_V_E_E_L(
043                                    groupId, articleId, version, elInstanceId, elName, languageId);
044    
045                    if (articleImage == null) {
046                            articleImage = journalArticleImagePersistence.create(
047                                    articleImageId);
048    
049                            articleImage.setGroupId(groupId);
050                            articleImage.setArticleId(articleId);
051                            articleImage.setVersion(version);
052                            articleImage.setElInstanceId(elInstanceId);
053                            articleImage.setElName(elName);
054                            articleImage.setLanguageId(languageId);
055                            articleImage.setTempImage(false);
056    
057                            journalArticleImagePersistence.update(articleImage, false);
058                    }
059                    else if (articleImage.getArticleImageId() == articleImageId) {
060                    }
061                    else {
062                            throw new DuplicateArticleImageIdException();
063                    }
064            }
065    
066            public void deleteArticleImage(long articleImageId) throws SystemException {
067                    try {
068                            JournalArticleImage articleImage =
069                                    journalArticleImagePersistence.findByPrimaryKey(
070                                            articleImageId);
071    
072                            deleteArticleImage(articleImage);
073                    }
074                    catch (NoSuchArticleImageException nsaie) {
075                    }
076            }
077    
078            public void deleteArticleImage(JournalArticleImage articleImage)
079                    throws SystemException {
080    
081                    try {
082                            imageLocalService.deleteImage(articleImage.getArticleImageId());
083                    }
084                    catch (PortalException pe) {
085                    }
086    
087                    journalArticleImagePersistence.remove(articleImage);
088            }
089    
090            public void deleteArticleImage(
091                            long groupId, String articleId, double version, String elInstanceId,
092                            String elName, String languageId)
093                    throws SystemException {
094    
095                    try {
096                            JournalArticleImage articleImage =
097                                    journalArticleImagePersistence.findByG_A_V_E_E_L(
098                                    groupId, articleId, version, elInstanceId, elName, languageId);
099    
100                            deleteArticleImage(articleImage);
101                    }
102                    catch (NoSuchArticleImageException nsaie) {
103                    }
104            }
105    
106            public void deleteImages(long groupId, String articleId, double version)
107                    throws SystemException {
108    
109                    for (JournalArticleImage articleImage :
110                                    journalArticleImagePersistence.findByG_A_V(
111                                            groupId, articleId, version)) {
112    
113                            deleteArticleImage(articleImage);
114                    }
115            }
116    
117            public JournalArticleImage getArticleImage(long articleImageId)
118                    throws PortalException, SystemException {
119    
120                    return journalArticleImagePersistence.findByPrimaryKey(articleImageId);
121            }
122    
123            public long getArticleImageId(
124                            long groupId, String articleId, double version, String elInstanceId,
125                            String elName, String languageId)
126                    throws SystemException {
127    
128                    return getArticleImageId(
129                            groupId, articleId, version, elInstanceId, elName, languageId,
130                            false);
131            }
132    
133            public long getArticleImageId(
134                            long groupId, String articleId, double version, String elInstanceId,
135                            String elName, String languageId, boolean tempImage)
136                    throws SystemException {
137    
138                    JournalArticleImage articleImage =
139                            journalArticleImagePersistence.fetchByG_A_V_E_E_L(
140                                    groupId, articleId, version, elInstanceId, elName, languageId);
141    
142                    if (articleImage == null) {
143                            long articleImageId = counterLocalService.increment();
144    
145                            articleImage = journalArticleImagePersistence.create(
146                                    articleImageId);
147    
148                            articleImage.setGroupId(groupId);
149                            articleImage.setArticleId(articleId);
150                            articleImage.setVersion(version);
151                            articleImage.setElInstanceId(elInstanceId);
152                            articleImage.setElName(elName);
153                            articleImage.setLanguageId(languageId);
154                            articleImage.setTempImage(tempImage);
155    
156                            journalArticleImagePersistence.update(articleImage, false);
157                    }
158    
159                    return articleImage.getArticleImageId();
160            }
161    
162            public List<JournalArticleImage> getArticleImages(long groupId)
163                    throws SystemException {
164    
165                    return journalArticleImagePersistence.findByGroupId(groupId);
166            }
167    
168    }