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