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.softwarecatalog.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.Validator;
026: import com.liferay.portal.model.User;
027: import com.liferay.portal.util.PortalUtil;
028: import com.liferay.portlet.softwarecatalog.FrameworkVersionNameException;
029: import com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion;
030: import com.liferay.portlet.softwarecatalog.service.base.SCFrameworkVersionLocalServiceBaseImpl;
031:
032: import java.util.Date;
033: import java.util.Iterator;
034: import java.util.List;
035:
036: /**
037: * <a href="SCFrameworkVersionLocalServiceImpl.java.html"><b><i>View Source</i>
038: * </b></a>
039: *
040: * @author Jorge Ferrer
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class SCFrameworkVersionLocalServiceImpl extends
045: SCFrameworkVersionLocalServiceBaseImpl {
046:
047: public SCFrameworkVersion addFrameworkVersion(long userId,
048: long plid, String name, String url, boolean active,
049: int priority, boolean addCommunityPermissions,
050: boolean addGuestPermissions) throws PortalException,
051: SystemException {
052:
053: return addFrameworkVersion(userId, plid, name, url, active,
054: priority, Boolean.valueOf(addCommunityPermissions),
055: Boolean.valueOf(addGuestPermissions), null, null);
056: }
057:
058: public SCFrameworkVersion addFrameworkVersion(long userId,
059: long plid, String name, String url, boolean active,
060: int priority, String[] communityPermissions,
061: String[] guestPermissions) throws PortalException,
062: SystemException {
063:
064: return addFrameworkVersion(userId, plid, name, url, active,
065: priority, null, null, communityPermissions,
066: guestPermissions);
067: }
068:
069: public SCFrameworkVersion addFrameworkVersion(long userId,
070: long plid, String name, String url, boolean active,
071: int priority, Boolean addCommunityPermissions,
072: Boolean addGuestPermissions, String[] communityPermissions,
073: String[] guestPermissions) throws PortalException,
074: SystemException {
075:
076: // Framework version
077:
078: User user = userPersistence.findByPrimaryKey(userId);
079: long groupId = PortalUtil.getPortletGroupId(plid);
080: Date now = new Date();
081:
082: validate(name);
083:
084: long frameworkVersionId = counterLocalService.increment();
085:
086: SCFrameworkVersion frameworkVersion = scFrameworkVersionPersistence
087: .create(frameworkVersionId);
088:
089: frameworkVersion.setGroupId(groupId);
090: frameworkVersion.setCompanyId(user.getCompanyId());
091: frameworkVersion.setUserId(user.getUserId());
092: frameworkVersion.setUserName(user.getFullName());
093: frameworkVersion.setCreateDate(now);
094: frameworkVersion.setModifiedDate(now);
095: frameworkVersion.setName(name);
096: frameworkVersion.setUrl(url);
097: frameworkVersion.setActive(active);
098: frameworkVersion.setPriority(priority);
099:
100: scFrameworkVersionPersistence.update(frameworkVersion);
101:
102: // Resources
103:
104: if ((addCommunityPermissions != null)
105: && (addGuestPermissions != null)) {
106:
107: addFrameworkVersionResources(frameworkVersion,
108: addCommunityPermissions.booleanValue(),
109: addGuestPermissions.booleanValue());
110: } else {
111: addFrameworkVersionResources(frameworkVersion,
112: communityPermissions, guestPermissions);
113: }
114:
115: return frameworkVersion;
116: }
117:
118: public void addFrameworkVersionResources(long frameworkVersionId,
119: boolean addCommunityPermissions, boolean addGuestPermissions)
120: throws PortalException, SystemException {
121:
122: SCFrameworkVersion frameworkVersion = scFrameworkVersionPersistence
123: .findByPrimaryKey(frameworkVersionId);
124:
125: addFrameworkVersionResources(frameworkVersion,
126: addCommunityPermissions, addGuestPermissions);
127: }
128:
129: public void addFrameworkVersionResources(
130: SCFrameworkVersion frameworkVersion,
131: boolean addCommunityPermissions, boolean addGuestPermissions)
132: throws PortalException, SystemException {
133:
134: resourceLocalService.addResources(frameworkVersion
135: .getCompanyId(), frameworkVersion.getGroupId(),
136: frameworkVersion.getUserId(), SCFrameworkVersion.class
137: .getName(), frameworkVersion
138: .getFrameworkVersionId(), false,
139: addCommunityPermissions, addGuestPermissions);
140: }
141:
142: public void addFrameworkVersionResources(long frameworkVersionId,
143: String[] communityPermissions, String[] guestPermissions)
144: throws PortalException, SystemException {
145:
146: SCFrameworkVersion frameworkVersion = scFrameworkVersionPersistence
147: .findByPrimaryKey(frameworkVersionId);
148:
149: addFrameworkVersionResources(frameworkVersion,
150: communityPermissions, guestPermissions);
151: }
152:
153: public void addFrameworkVersionResources(
154: SCFrameworkVersion frameworkVersion,
155: String[] communityPermissions, String[] guestPermissions)
156: throws PortalException, SystemException {
157:
158: resourceLocalService.addModelResources(frameworkVersion
159: .getCompanyId(), frameworkVersion.getGroupId(),
160: frameworkVersion.getUserId(), SCFrameworkVersion.class
161: .getName(), frameworkVersion
162: .getFrameworkVersionId(), communityPermissions,
163: guestPermissions);
164: }
165:
166: public void deleteFrameworkVersion(long frameworkVersionId)
167: throws PortalException, SystemException {
168:
169: scFrameworkVersionPersistence.remove(frameworkVersionId);
170: }
171:
172: public void deleteFrameworkVersion(
173: SCFrameworkVersion frameworkVersion)
174: throws PortalException, SystemException {
175:
176: scFrameworkVersionPersistence.remove(frameworkVersion);
177: }
178:
179: public void deleteFrameworkVersions(long groupId)
180: throws PortalException, SystemException {
181:
182: Iterator itr = scFrameworkVersionPersistence.findByGroupId(
183: groupId).iterator();
184:
185: while (itr.hasNext()) {
186: SCFrameworkVersion frameworkVersion = (SCFrameworkVersion) itr
187: .next();
188:
189: deleteFrameworkVersion(frameworkVersion);
190: }
191: }
192:
193: public SCFrameworkVersion getFrameworkVersion(
194: long frameworkVersionId) throws PortalException,
195: SystemException {
196:
197: return scFrameworkVersionPersistence
198: .findByPrimaryKey(frameworkVersionId);
199: }
200:
201: public List getFrameworkVersions(long groupId, int begin, int end)
202: throws SystemException {
203:
204: return scFrameworkVersionPersistence.findByGroupId(groupId,
205: begin, end);
206: }
207:
208: public List getFrameworkVersions(long groupId, boolean active)
209: throws SystemException {
210:
211: return scFrameworkVersionPersistence.findByG_A(groupId, active);
212: }
213:
214: public List getFrameworkVersions(long groupId, boolean active,
215: int begin, int end) throws SystemException {
216:
217: return scFrameworkVersionPersistence.findByG_A(groupId, active,
218: begin, end);
219: }
220:
221: public int getFrameworkVersionsCount(long groupId)
222: throws SystemException {
223:
224: return scFrameworkVersionPersistence.countByGroupId(groupId);
225: }
226:
227: public int getFrameworkVersionsCount(long groupId, boolean active)
228: throws SystemException {
229:
230: return scFrameworkVersionPersistence
231: .countByG_A(groupId, active);
232: }
233:
234: public List getProductVersionFrameworkVersions(long productVersionId)
235: throws PortalException, SystemException {
236:
237: return scProductVersionPersistence
238: .getSCFrameworkVersions(productVersionId);
239: }
240:
241: public SCFrameworkVersion updateFrameworkVersion(
242: long frameworkVersionId, String name, String url,
243: boolean active, int priority) throws PortalException,
244: SystemException {
245:
246: validate(name);
247:
248: SCFrameworkVersion frameworkVersion = scFrameworkVersionPersistence
249: .findByPrimaryKey(frameworkVersionId);
250:
251: frameworkVersion.setName(name);
252: frameworkVersion.setUrl(url);
253: frameworkVersion.setActive(active);
254: frameworkVersion.setPriority(priority);
255:
256: scFrameworkVersionPersistence.update(frameworkVersion);
257:
258: return frameworkVersion;
259: }
260:
261: protected void validate(String name) throws PortalException {
262: if (Validator.isNull(name)) {
263: throw new FrameworkVersionNameException();
264: }
265: }
266:
267: }
|