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.portal.service.impl.ImageLocalUtil;
28  import com.liferay.portlet.journal.DuplicateArticleImageIdException;
29  import com.liferay.portlet.journal.NoSuchArticleImageException;
30  import com.liferay.portlet.journal.model.JournalArticleImage;
31  import com.liferay.portlet.journal.service.base.JournalArticleImageLocalServiceBaseImpl;
32  
33  import java.util.List;
34  
35  /**
36   * <a href="JournalArticleImageLocalServiceImpl.java.html"><b><i>View Source</i>
37   * </b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class JournalArticleImageLocalServiceImpl
43      extends JournalArticleImageLocalServiceBaseImpl {
44  
45      public void addArticleImageId(
46              long articleImageId, long groupId, String articleId, double version,
47              String elName, String languageId)
48          throws PortalException, SystemException {
49  
50          if (articleImageId <= 0) {
51              return;
52          }
53  
54          JournalArticleImage articleImage =
55              journalArticleImagePersistence.fetchByG_A_V_E_L(
56                  groupId, articleId, version, elName, languageId);
57  
58          if (articleImage == null) {
59              articleImage = journalArticleImagePersistence.create(
60                  articleImageId);
61  
62              articleImage.setGroupId(groupId);
63              articleImage.setArticleId(articleId);
64              articleImage.setVersion(version);
65              articleImage.setElName(elName);
66              articleImage.setLanguageId(languageId);
67              articleImage.setTempImage(false);
68  
69              journalArticleImagePersistence.update(articleImage, false);
70          }
71          else if (articleImage.getArticleImageId() == articleImageId) {
72          }
73          else {
74              throw new DuplicateArticleImageIdException();
75          }
76      }
77  
78      public void deleteArticleImage(long articleImageId) throws SystemException {
79          try {
80              journalArticleImagePersistence.remove(articleImageId);
81          }
82          catch (NoSuchArticleImageException nsaie) {
83          }
84      }
85  
86      public void deleteArticleImage(
87              long groupId, String articleId, double version, String elName,
88              String languageId)
89          throws SystemException {
90  
91          try {
92              journalArticleImagePersistence.removeByG_A_V_E_L(
93                  groupId, articleId, version, elName, languageId);
94          }
95          catch (NoSuchArticleImageException nsaie) {
96          }
97      }
98  
99      public void deleteImages(long groupId, String articleId, double version)
100         throws SystemException {
101 
102         for (JournalArticleImage articleImage :
103                 journalArticleImagePersistence.findByG_A_V(
104                     groupId, articleId, version)) {
105 
106             ImageLocalUtil.deleteImage(articleImage.getArticleImageId());
107 
108             journalArticleImagePersistence.remove(articleImage);
109         }
110     }
111 
112     public JournalArticleImage getArticleImage(long articleImageId)
113         throws PortalException, SystemException {
114 
115         return journalArticleImagePersistence.findByPrimaryKey(articleImageId);
116     }
117 
118     public long getArticleImageId(
119             long groupId, String articleId, double version, String elName,
120             String languageId)
121         throws SystemException {
122 
123         return getArticleImageId(
124             groupId, articleId, version, elName, languageId, false);
125     }
126 
127     public long getArticleImageId(
128             long groupId, String articleId, double version, String elName,
129             String languageId, boolean tempImage)
130         throws SystemException {
131 
132         JournalArticleImage articleImage =
133             journalArticleImagePersistence.fetchByG_A_V_E_L(
134                 groupId, articleId, version, elName, languageId);
135 
136         if (articleImage == null) {
137             long articleImageId = counterLocalService.increment();
138 
139             articleImage = journalArticleImagePersistence.create(
140                 articleImageId);
141 
142             articleImage.setGroupId(groupId);
143             articleImage.setArticleId(articleId);
144             articleImage.setVersion(version);
145             articleImage.setElName(elName);
146             articleImage.setLanguageId(languageId);
147             articleImage.setTempImage(tempImage);
148 
149             journalArticleImagePersistence.update(articleImage, false);
150         }
151 
152         return articleImage.getArticleImageId();
153     }
154 
155     public List<JournalArticleImage> getArticleImages(long groupId)
156         throws SystemException {
157 
158         return journalArticleImagePersistence.findByGroupId(groupId);
159     }
160 
161 }