001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.journal.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.service.impl.ImageLocalUtil;
026: import com.liferay.portlet.journal.DuplicateArticleImageIdException;
027: import com.liferay.portlet.journal.NoSuchArticleImageException;
028: import com.liferay.portlet.journal.model.JournalArticleImage;
029: import com.liferay.portlet.journal.service.base.JournalArticleImageLocalServiceBaseImpl;
030:
031: import java.util.Iterator;
032: import java.util.List;
033:
034: /**
035: * <a href="JournalArticleImageLocalServiceImpl.java.html"><b><i>View Source</i>
036: * </b></a>
037: *
038: * @author Brian Wing Shun Chan
039: *
040: */
041: public class JournalArticleImageLocalServiceImpl extends
042: JournalArticleImageLocalServiceBaseImpl {
043:
044: public void addArticleImageId(long articleImageId, long groupId,
045: String articleId, double version, String elName,
046: String languageId) throws PortalException, SystemException {
047:
048: if (articleImageId <= 0) {
049: return;
050: }
051:
052: JournalArticleImage articleImage = journalArticleImagePersistence
053: .fetchByG_A_V_E_L(groupId, articleId, version, elName,
054: languageId);
055:
056: if (articleImage == null) {
057: articleImage = journalArticleImagePersistence
058: .create(articleImageId);
059:
060: articleImage.setGroupId(groupId);
061: articleImage.setArticleId(articleId);
062: articleImage.setVersion(version);
063: articleImage.setElName(elName);
064: articleImage.setLanguageId(languageId);
065: articleImage.setTempImage(false);
066:
067: journalArticleImagePersistence.update(articleImage);
068: } else if (articleImage.getArticleImageId() == articleImageId) {
069: } else {
070: throw new DuplicateArticleImageIdException();
071: }
072: }
073:
074: public void deleteArticleImage(long articleImageId)
075: throws SystemException {
076: try {
077: journalArticleImagePersistence.remove(articleImageId);
078: } catch (NoSuchArticleImageException nsaie) {
079: }
080: }
081:
082: public void deleteArticleImage(long groupId, String articleId,
083: double version, String elName, String languageId)
084: throws SystemException {
085:
086: try {
087: journalArticleImagePersistence.removeByG_A_V_E_L(groupId,
088: articleId, version, elName, languageId);
089: } catch (NoSuchArticleImageException nsaie) {
090: }
091: }
092:
093: public void deleteImages(long groupId, String articleId,
094: double version) throws SystemException {
095:
096: Iterator itr = journalArticleImagePersistence.findByG_A_V(
097: groupId, articleId, version).iterator();
098:
099: while (itr.hasNext()) {
100: JournalArticleImage articleImage = (JournalArticleImage) itr
101: .next();
102:
103: ImageLocalUtil
104: .deleteImage(articleImage.getArticleImageId());
105:
106: journalArticleImagePersistence.remove(articleImage);
107: }
108: }
109:
110: public JournalArticleImage getArticleImage(long articleImageId)
111: throws PortalException, SystemException {
112:
113: return journalArticleImagePersistence
114: .findByPrimaryKey(articleImageId);
115: }
116:
117: public long getArticleImageId(long groupId, String articleId,
118: double version, String elName, String languageId)
119: throws SystemException {
120:
121: return getArticleImageId(groupId, articleId, version, elName,
122: languageId, false);
123: }
124:
125: public long getArticleImageId(long groupId, String articleId,
126: double version, String elName, String languageId,
127: boolean tempImage) throws SystemException {
128:
129: JournalArticleImage articleImage = journalArticleImagePersistence
130: .fetchByG_A_V_E_L(groupId, articleId, version, elName,
131: languageId);
132:
133: if (articleImage == null) {
134: long articleImageId = counterLocalService.increment();
135:
136: articleImage = journalArticleImagePersistence
137: .create(articleImageId);
138:
139: articleImage.setGroupId(groupId);
140: articleImage.setArticleId(articleId);
141: articleImage.setVersion(version);
142: articleImage.setElName(elName);
143: articleImage.setLanguageId(languageId);
144: articleImage.setTempImage(tempImage);
145:
146: journalArticleImagePersistence.update(articleImage);
147: }
148:
149: return articleImage.getArticleImageId();
150: }
151:
152: public List getArticleImages(long groupId) throws SystemException {
153: return journalArticleImagePersistence.findByGroupId(groupId);
154: }
155:
156: }
|