1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portlet.journal.DuplicateArticleImageIdException;
28  import com.liferay.portlet.journal.NoSuchArticleImageException;
29  import com.liferay.portlet.journal.model.JournalArticleImage;
30  import com.liferay.portlet.journal.service.base.JournalArticleImageLocalServiceBaseImpl;
31  
32  import java.util.List;
33  
34  /**
35   * <a href="JournalArticleImageLocalServiceImpl.java.html"><b><i>View Source</i>
36   * </b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class JournalArticleImageLocalServiceImpl
42      extends JournalArticleImageLocalServiceBaseImpl {
43  
44      public void addArticleImageId(
45              long articleImageId, long groupId, String articleId, double version,
46              String elName, String languageId)
47          throws PortalException, SystemException {
48  
49          if (articleImageId <= 0) {
50              return;
51          }
52  
53          JournalArticleImage articleImage =
54              journalArticleImagePersistence.fetchByG_A_V_E_L(
55                  groupId, articleId, version, elName, languageId);
56  
57          if (articleImage == null) {
58              articleImage = journalArticleImagePersistence.create(
59                  articleImageId);
60  
61              articleImage.setGroupId(groupId);
62              articleImage.setArticleId(articleId);
63              articleImage.setVersion(version);
64              articleImage.setElName(elName);
65              articleImage.setLanguageId(languageId);
66              articleImage.setTempImage(false);
67  
68              journalArticleImagePersistence.update(articleImage, false);
69          }
70          else if (articleImage.getArticleImageId() == articleImageId) {
71          }
72          else {
73              throw new DuplicateArticleImageIdException();
74          }
75      }
76  
77      public void deleteArticleImage(long articleImageId) throws SystemException {
78          try {
79              journalArticleImagePersistence.remove(articleImageId);
80          }
81          catch (NoSuchArticleImageException nsaie) {
82          }
83      }
84  
85      public void deleteArticleImage(
86              long groupId, String articleId, double version, String elName,
87              String languageId)
88          throws SystemException {
89  
90          try {
91              journalArticleImagePersistence.removeByG_A_V_E_L(
92                  groupId, articleId, version, elName, languageId);
93          }
94          catch (NoSuchArticleImageException nsaie) {
95          }
96      }
97  
98      public void deleteImages(long groupId, String articleId, double version)
99          throws PortalException, SystemException {
100 
101         for (JournalArticleImage articleImage :
102                 journalArticleImagePersistence.findByG_A_V(
103                     groupId, articleId, version)) {
104 
105             imageLocalService.deleteImage(articleImage.getArticleImageId());
106 
107             journalArticleImagePersistence.remove(articleImage);
108         }
109     }
110 
111     public JournalArticleImage getArticleImage(long articleImageId)
112         throws PortalException, SystemException {
113 
114         return journalArticleImagePersistence.findByPrimaryKey(articleImageId);
115     }
116 
117     public long getArticleImageId(
118             long groupId, String articleId, double version, String elName,
119             String languageId)
120         throws SystemException {
121 
122         return getArticleImageId(
123             groupId, articleId, version, elName, languageId, false);
124     }
125 
126     public long getArticleImageId(
127             long groupId, String articleId, double version, String elName,
128             String languageId, boolean tempImage)
129         throws SystemException {
130 
131         JournalArticleImage articleImage =
132             journalArticleImagePersistence.fetchByG_A_V_E_L(
133                 groupId, articleId, version, elName, languageId);
134 
135         if (articleImage == null) {
136             long articleImageId = counterLocalService.increment();
137 
138             articleImage = journalArticleImagePersistence.create(
139                 articleImageId);
140 
141             articleImage.setGroupId(groupId);
142             articleImage.setArticleId(articleId);
143             articleImage.setVersion(version);
144             articleImage.setElName(elName);
145             articleImage.setLanguageId(languageId);
146             articleImage.setTempImage(tempImage);
147 
148             journalArticleImagePersistence.update(articleImage, false);
149         }
150 
151         return articleImage.getArticleImageId();
152     }
153 
154     public List<JournalArticleImage> getArticleImages(long groupId)
155         throws SystemException {
156 
157         return journalArticleImagePersistence.findByGroupId(groupId);
158     }
159 
160 }