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(frameworkVersionId);
053
054 frameworkVersion.setGroupId(groupId);
055 frameworkVersion.setCompanyId(user.getCompanyId());
056 frameworkVersion.setUserId(user.getUserId());
057 frameworkVersion.setUserName(user.getFullName());
058 frameworkVersion.setCreateDate(now);
059 frameworkVersion.setModifiedDate(now);
060 frameworkVersion.setName(name);
061 frameworkVersion.setUrl(url);
062 frameworkVersion.setActive(active);
063 frameworkVersion.setPriority(priority);
064
065 scFrameworkVersionPersistence.update(frameworkVersion, false);
066
067
068
069 if (serviceContext.isAddGroupPermissions() ||
070 serviceContext.isAddGuestPermissions()) {
071
072 addFrameworkVersionResources(
073 frameworkVersion, serviceContext.isAddGroupPermissions(),
074 serviceContext.isAddGuestPermissions());
075 }
076 else {
077 addFrameworkVersionResources(
078 frameworkVersion, serviceContext.getGroupPermissions(),
079 serviceContext.getGuestPermissions());
080 }
081
082 return frameworkVersion;
083 }
084
085 public void addFrameworkVersionResources(
086 long frameworkVersionId, boolean addGroupPermissions,
087 boolean addGuestPermissions)
088 throws PortalException, SystemException {
089
090 SCFrameworkVersion frameworkVersion =
091 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
092
093 addFrameworkVersionResources(
094 frameworkVersion, addGroupPermissions, addGuestPermissions);
095 }
096
097 public void addFrameworkVersionResources(
098 long frameworkVersionId, String[] groupPermissions,
099 String[] guestPermissions)
100 throws PortalException, SystemException {
101
102 SCFrameworkVersion frameworkVersion =
103 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
104
105 addFrameworkVersionResources(
106 frameworkVersion, groupPermissions, guestPermissions);
107 }
108
109 public void addFrameworkVersionResources(
110 SCFrameworkVersion frameworkVersion, boolean addGroupPermissions,
111 boolean addGuestPermissions)
112 throws PortalException, SystemException {
113
114 resourceLocalService.addResources(
115 frameworkVersion.getCompanyId(), frameworkVersion.getGroupId(),
116 frameworkVersion.getUserId(), SCFrameworkVersion.class.getName(),
117 frameworkVersion.getFrameworkVersionId(), false,
118 addGroupPermissions, addGuestPermissions);
119 }
120
121 public void addFrameworkVersionResources(
122 SCFrameworkVersion frameworkVersion, String[] groupPermissions,
123 String[] guestPermissions)
124 throws PortalException, SystemException {
125
126 resourceLocalService.addModelResources(
127 frameworkVersion.getCompanyId(), frameworkVersion.getGroupId(),
128 frameworkVersion.getUserId(), SCFrameworkVersion.class.getName(),
129 frameworkVersion.getFrameworkVersionId(), groupPermissions,
130 guestPermissions);
131 }
132
133 public void deleteFrameworkVersion(long frameworkVersionId)
134 throws PortalException, SystemException {
135
136 SCFrameworkVersion frameworkVersion =
137 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
138
139 deleteFrameworkVersion(frameworkVersion);
140 }
141
142 public void deleteFrameworkVersion(SCFrameworkVersion frameworkVersion)
143 throws SystemException {
144
145 scFrameworkVersionPersistence.remove(frameworkVersion);
146 }
147
148 public void deleteFrameworkVersions(long groupId) throws SystemException {
149 List<SCFrameworkVersion> frameworkVersions =
150 scFrameworkVersionPersistence.findByGroupId(groupId);
151
152 for (SCFrameworkVersion frameworkVersion : frameworkVersions) {
153 deleteFrameworkVersion(frameworkVersion);
154 }
155 }
156
157 public SCFrameworkVersion getFrameworkVersion(long frameworkVersionId)
158 throws PortalException, SystemException {
159
160 return scFrameworkVersionPersistence.findByPrimaryKey(
161 frameworkVersionId);
162 }
163
164 public List<SCFrameworkVersion> getFrameworkVersions(
165 long groupId, boolean active)
166 throws SystemException {
167
168 return scFrameworkVersionPersistence.findByG_A(groupId, active);
169 }
170
171 public List<SCFrameworkVersion> getFrameworkVersions(
172 long groupId, boolean active, int start, int end)
173 throws SystemException {
174
175 return scFrameworkVersionPersistence.findByG_A(
176 groupId, active, start, end);
177 }
178
179 public List<SCFrameworkVersion> getFrameworkVersions(
180 long groupId, int start, int end)
181 throws SystemException {
182
183 return scFrameworkVersionPersistence.findByGroupId(groupId, start, end);
184 }
185
186 public int getFrameworkVersionsCount(long groupId)
187 throws SystemException {
188
189 return scFrameworkVersionPersistence.countByGroupId(groupId);
190 }
191
192 public int getFrameworkVersionsCount(long groupId, boolean active)
193 throws SystemException {
194
195 return scFrameworkVersionPersistence.countByG_A(groupId, active);
196 }
197
198 public List<SCFrameworkVersion> getProductVersionFrameworkVersions(
199 long productVersionId)
200 throws SystemException {
201
202 return scProductVersionPersistence.getSCFrameworkVersions(
203 productVersionId);
204 }
205
206 public SCFrameworkVersion updateFrameworkVersion(
207 long frameworkVersionId, String name, String url, boolean active,
208 int priority)
209 throws PortalException, SystemException {
210
211 validate(name);
212
213 SCFrameworkVersion frameworkVersion =
214 scFrameworkVersionPersistence.findByPrimaryKey(frameworkVersionId);
215
216 frameworkVersion.setName(name);
217 frameworkVersion.setUrl(url);
218 frameworkVersion.setActive(active);
219 frameworkVersion.setPriority(priority);
220
221 scFrameworkVersionPersistence.update(frameworkVersion, false);
222
223 return frameworkVersion;
224 }
225
226 protected void validate(String name) throws PortalException {
227 if (Validator.isNull(name)) {
228 throw new FrameworkVersionNameException();
229 }
230 }
231
232 }