001
014
015 package com.liferay.portlet.softwarecatalog.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.model.User;
021 import com.liferay.portal.service.ServiceContext;
022 import com.liferay.portlet.softwarecatalog.FrameworkVersionNameException;
023 import com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion;
024 import com.liferay.portlet.softwarecatalog.service.base.SCFrameworkVersionLocalServiceBaseImpl;
025
026 import java.util.Date;
027 import java.util.List;
028
029
033 public class SCFrameworkVersionLocalServiceImpl
034 extends SCFrameworkVersionLocalServiceBaseImpl {
035
036 public SCFrameworkVersion addFrameworkVersion(
037 long userId, String name, String url, boolean active, int priority,
038 ServiceContext serviceContext)
039 throws PortalException, SystemException {
040
041
042
043 User user = userPersistence.findByPrimaryKey(userId);
044 long groupId = serviceContext.getScopeGroupId();
045 Date now = new Date();
046
047 validate(name);
048
049 long frameworkVersionId = counterLocalService.increment();
050
051 SCFrameworkVersion frameworkVersion =
052 scFrameworkVersionPersistence.create(
053 frameworkVersionId);
054
055 frameworkVersion.setGroupId(groupId);
056 frameworkVersion.setCompanyId(user.getCompanyId());
057 frameworkVersion.setUserId(user.getUserId());
058 frameworkVersion.setUserName(user.getFullName());
059 frameworkVersion.setCreateDate(now);
060 frameworkVersion.setModifiedDate(now);
061 frameworkVersion.setName(name);
062 frameworkVersion.setUrl(url);
063 frameworkVersion.setActive(active);
064 frameworkVersion.setPriority(priority);
065
066 scFrameworkVersionPersistence.update(frameworkVersion, false);
067
068
069
070 if (serviceContext.getAddGroupPermissions() ||
071 serviceContext.getAddGuestPermissions()) {
072
073 addFrameworkVersionResources(
074 frameworkVersion, serviceContext.getAddGroupPermissions(),
075 serviceContext.getAddGuestPermissions());
076 }
077 else {
078 addFrameworkVersionResources(
079 frameworkVersion, serviceContext.getGroupPermissions(),
080 serviceContext.getGuestPermissions());
081 }
082
083 return frameworkVersion;
084 }
085
086 public void addFrameworkVersionResources(
087 long frameworkVersionId, boolean addGroupPermissions,
088 boolean addGuestPermissions)
089 throws PortalException, SystemException {
090
091 SCFrameworkVersion frameworkVersion =
092 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
093
094 addFrameworkVersionResources(
095 frameworkVersion, addGroupPermissions, addGuestPermissions);
096 }
097
098 public void addFrameworkVersionResources(
099 long frameworkVersionId, String[] groupPermissions,
100 String[] guestPermissions)
101 throws PortalException, SystemException {
102
103 SCFrameworkVersion frameworkVersion =
104 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
105
106 addFrameworkVersionResources(
107 frameworkVersion, groupPermissions, guestPermissions);
108 }
109
110 public void addFrameworkVersionResources(
111 SCFrameworkVersion frameworkVersion,
112 boolean addGroupPermissions, boolean addGuestPermissions)
113 throws PortalException, SystemException {
114
115 resourceLocalService.addResources(
116 frameworkVersion.getCompanyId(), frameworkVersion.getGroupId(),
117 frameworkVersion.getUserId(), SCFrameworkVersion.class.getName(),
118 frameworkVersion.getFrameworkVersionId(), false,
119 addGroupPermissions, addGuestPermissions);
120 }
121
122 public void addFrameworkVersionResources(
123 SCFrameworkVersion frameworkVersion, String[] groupPermissions,
124 String[] guestPermissions)
125 throws PortalException, SystemException {
126
127 resourceLocalService.addModelResources(
128 frameworkVersion.getCompanyId(), frameworkVersion.getGroupId(),
129 frameworkVersion.getUserId(), SCFrameworkVersion.class.getName(),
130 frameworkVersion.getFrameworkVersionId(), groupPermissions,
131 guestPermissions);
132 }
133
134 public void deleteFrameworkVersion(long frameworkVersionId)
135 throws PortalException, SystemException {
136
137 SCFrameworkVersion frameworkVersion =
138 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
139
140 deleteFrameworkVersion(frameworkVersion);
141 }
142
143 public void deleteFrameworkVersion(SCFrameworkVersion frameworkVersion)
144 throws SystemException {
145
146 scFrameworkVersionPersistence.remove(frameworkVersion);
147 }
148
149 public void deleteFrameworkVersions(long groupId) throws SystemException {
150 List<SCFrameworkVersion> frameworkVersions =
151 scFrameworkVersionPersistence.findByGroupId(groupId);
152
153 for (SCFrameworkVersion frameworkVersion : frameworkVersions) {
154 deleteFrameworkVersion(frameworkVersion);
155 }
156 }
157
158 public SCFrameworkVersion getFrameworkVersion(long frameworkVersionId)
159 throws PortalException, SystemException {
160
161 return scFrameworkVersionPersistence.findByPrimaryKey(
162 frameworkVersionId);
163 }
164
165 public List<SCFrameworkVersion> getFrameworkVersions(
166 long groupId, boolean active)
167 throws SystemException {
168
169 return scFrameworkVersionPersistence.findByG_A(groupId, active);
170 }
171
172 public List<SCFrameworkVersion> getFrameworkVersions(
173 long groupId, boolean active, int start, int end)
174 throws SystemException {
175
176 return scFrameworkVersionPersistence.findByG_A(
177 groupId, active, start, end);
178 }
179
180 public List<SCFrameworkVersion> getFrameworkVersions(
181 long groupId, int start, int end)
182 throws SystemException {
183
184 return scFrameworkVersionPersistence.findByGroupId(groupId, start, end);
185 }
186
187 public int getFrameworkVersionsCount(long groupId)
188 throws SystemException {
189
190 return scFrameworkVersionPersistence.countByGroupId(groupId);
191 }
192
193 public int getFrameworkVersionsCount(long groupId, boolean active)
194 throws SystemException {
195
196 return scFrameworkVersionPersistence.countByG_A(groupId, active);
197 }
198
199 public List<SCFrameworkVersion> getProductVersionFrameworkVersions(
200 long productVersionId)
201 throws SystemException {
202
203 return scProductVersionPersistence.getSCFrameworkVersions(
204 productVersionId);
205 }
206
207 public SCFrameworkVersion updateFrameworkVersion(
208 long frameworkVersionId, String name, String url, boolean active,
209 int priority)
210 throws PortalException, SystemException {
211
212 validate(name);
213
214 SCFrameworkVersion frameworkVersion =
215 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
216
217 frameworkVersion.setName(name);
218 frameworkVersion.setUrl(url);
219 frameworkVersion.setActive(active);
220 frameworkVersion.setPriority(priority);
221
222 scFrameworkVersionPersistence.update(frameworkVersion, false);
223
224 return frameworkVersion;
225 }
226
227 protected void validate(String name) throws PortalException {
228 if (Validator.isNull(name)) {
229 throw new FrameworkVersionNameException();
230 }
231 }
232
233 }