1
22
23 package com.liferay.portlet.tasks.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.util.StringPool;
28 import com.liferay.portal.model.ResourceConstants;
29 import com.liferay.portal.model.User;
30 import com.liferay.portal.util.PortalUtil;
31 import com.liferay.portlet.tasks.NoSuchProposalException;
32 import com.liferay.portlet.tasks.ProposalDueDateException;
33 import com.liferay.portlet.tasks.model.TasksProposal;
34 import com.liferay.portlet.tasks.service.base.TasksProposalLocalServiceBaseImpl;
35 import com.liferay.portlet.tasks.social.TasksActivityKeys;
36
37 import java.util.Date;
38 import java.util.List;
39
40
47 public class TasksProposalLocalServiceImpl
48 extends TasksProposalLocalServiceBaseImpl {
49
50 public TasksProposal addProposal(
51 long userId, long groupId, String className, String classPK,
52 String name, String description, long reviewUserId,
53 boolean addCommunityPermissions, boolean addGuestPermissions)
54 throws PortalException, SystemException {
55
56 return addProposal(
57 userId, groupId, className, classPK, name, description,
58 reviewUserId, Boolean.valueOf(addCommunityPermissions),
59 Boolean.valueOf(addGuestPermissions), null, null);
60 }
61
62 public TasksProposal addProposal(
63 long userId, long groupId, String className, String classPK,
64 String name, String description, long reviewUserId,
65 Boolean addCommunityPermissions, Boolean addGuestPermissions,
66 String[] communityPermissions, String[] guestPermissions)
67 throws PortalException, SystemException {
68
69
71 User user = userPersistence.findByPrimaryKey(userId);
72 long classNameId = PortalUtil.getClassNameId(className);
73 Date now = new Date();
74
75 long proposalId = counterLocalService.increment();
76
77 TasksProposal proposal = tasksProposalPersistence.create(proposalId);
78
79 proposal.setGroupId(groupId);
80 proposal.setCompanyId(user.getCompanyId());
81 proposal.setUserId(user.getUserId());
82 proposal.setUserName(user.getFullName());
83 proposal.setCreateDate(now);
84 proposal.setModifiedDate(now);
85 proposal.setClassNameId(classNameId);
86 proposal.setClassPK(classPK);
87 proposal.setName(name);
88 proposal.setDescription(description);
89
90 proposal = tasksProposalPersistence.update(proposal, false);
91
92
94 if ((addCommunityPermissions != null) &&
95 (addGuestPermissions != null)) {
96
97 addProposalResources(
98 proposal, addCommunityPermissions.booleanValue(),
99 addGuestPermissions.booleanValue());
100 }
101 else {
102 addProposalResources(
103 proposal, communityPermissions, guestPermissions);
104 }
105
106
108 long assignedByUserId = userId;
109 int stage = 1;
110
111 tasksReviewLocalService.addReview(
112 reviewUserId, proposal.getProposalId(), assignedByUserId, stage);
113
114
116 mbMessageLocalService.addDiscussionMessage(
117 userId, proposal.getUserName(), TasksProposal.class.getName(),
118 proposalId);
119
120
122 socialActivityLocalService.addActivity(
123 userId, groupId, TasksProposal.class.getName(), proposalId,
124 TasksActivityKeys.ADD_PROPOSAL, StringPool.BLANK, 0);
125
126 return proposal;
127 }
128
129 public TasksProposal addProposal(
130 long userId, long groupId, String className, String classPK,
131 String name, String description, long reviewUserId,
132 String[] communityPermissions, String[] guestPermissions)
133 throws PortalException, SystemException {
134
135 return addProposal(
136 userId, groupId, className, classPK, name, description,
137 reviewUserId, null, null, communityPermissions, guestPermissions);
138 }
139
140 public void addProposalResources(
141 long proposalId, boolean addCommunityPermissions,
142 boolean addGuestPermissions)
143 throws PortalException, SystemException {
144
145 TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
146 proposalId);
147
148 addProposalResources(
149 proposal, addCommunityPermissions, addGuestPermissions);
150 }
151
152 public void addProposalResources(
153 long proposalId, String[] communityPermissions,
154 String[] guestPermissions)
155 throws PortalException, SystemException {
156
157 TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
158 proposalId);
159
160 addProposalResources(proposal, communityPermissions, guestPermissions);
161 }
162
163 public void addProposalResources(
164 TasksProposal proposal, boolean addCommunityPermissions,
165 boolean addGuestPermissions)
166 throws PortalException, SystemException {
167
168 resourceLocalService.addResources(
169 proposal.getCompanyId(), proposal.getGroupId(),
170 proposal.getUserId(), TasksProposal.class.getName(),
171 proposal.getProposalId(), false, addCommunityPermissions,
172 addGuestPermissions);
173 }
174
175 public void addProposalResources(
176 TasksProposal proposal, String[] communityPermissions,
177 String[] guestPermissions)
178 throws PortalException, SystemException {
179
180 resourceLocalService.addModelResources(
181 proposal.getCompanyId(), proposal.getGroupId(),
182 proposal.getUserId(), TasksProposal.class.getName(),
183 proposal.getProposalId(), communityPermissions, guestPermissions);
184 }
185
186 public void deleteProposal(long proposalId)
187 throws PortalException, SystemException {
188
189 TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
190 proposalId);
191
192 deleteProposal(proposal);
193 }
194
195 public void deleteProposal(long classNameId, String classPK)
196 throws PortalException, SystemException {
197
198 try {
199 TasksProposal proposal = getProposal(classNameId, classPK);
200
201 deleteProposal(proposal);
202 }
203 catch (NoSuchProposalException nspe) {
204 }
205 }
206
207 public void deleteProposal(String className, String classPK)
208 throws PortalException, SystemException {
209
210 long classNameId = PortalUtil.getClassNameId(className);
211
212 deleteProposal(classNameId, classPK);
213 }
214
215 public void deleteProposal(TasksProposal proposal)
216 throws PortalException, SystemException {
217
218
220 tasksProposalPersistence.remove(proposal);
221
222
224 resourceLocalService.deleteResource(
225 proposal.getCompanyId(), TasksProposal.class.getName(),
226 ResourceConstants.SCOPE_INDIVIDUAL, proposal.getProposalId());
227
228
230 tasksReviewLocalService.deleteReviews(proposal.getProposalId());
231
232
234 mbMessageLocalService.deleteDiscussionMessages(
235 TasksProposal.class.getName(), proposal.getProposalId());
236
237
239 socialActivityLocalService.deleteActivities(
240 TasksProposal.class.getName(), proposal.getProposalId());
241 }
242
243 public void deleteProposals(long groupId)
244 throws PortalException, SystemException {
245
246 List<TasksProposal> proposals = tasksProposalPersistence.findByGroupId(
247 groupId);
248
249 for (TasksProposal proposal : proposals) {
250 deleteProposal(proposal);
251 }
252 }
253
254 public TasksProposal getProposal(long proposalId)
255 throws PortalException, SystemException {
256
257 return tasksProposalPersistence.findByPrimaryKey(proposalId);
258 }
259
260 public TasksProposal getProposal(long classNameId, String classPK)
261 throws PortalException, SystemException {
262
263 return tasksProposalPersistence.findByC_C(classNameId, classPK);
264 }
265
266 public TasksProposal getProposal(String className, String classPK)
267 throws PortalException, SystemException {
268
269 long classNameId = PortalUtil.getClassNameId(className);
270
271 return getProposal(classNameId, classPK);
272 }
273
274 public List<TasksProposal> getProposals(long groupId, int start, int end)
275 throws SystemException {
276
277 return tasksProposalPersistence.findByGroupId(groupId, start, end);
278 }
279
280 public int getProposalsCount(long groupId) throws SystemException {
281 return tasksProposalPersistence.countByGroupId(groupId);
282 }
283
284 public List<TasksProposal> getReviewProposals(
285 long groupId, long userId, int start, int end)
286 throws SystemException {
287
288 return tasksProposalFinder.findByG_U(groupId, userId, start, end);
289 }
290
291 public int getReviewProposalsCount(long groupId, long userId)
292 throws SystemException {
293
294 return tasksProposalFinder.countByG_U(groupId, userId);
295 }
296
297 public List<TasksProposal> getUserProposals(
298 long groupId, long userId, int start, int end)
299 throws SystemException {
300
301 return tasksProposalPersistence.findByG_U(groupId, userId, start, end);
302 }
303
304 public int getUserProposalsCount(long groupId, long userId)
305 throws SystemException {
306
307 return tasksProposalPersistence.countByG_U(groupId, userId);
308 }
309
310 public TasksProposal updateProposal(
311 long userId, long proposalId, String description, int dueDateMonth,
312 int dueDateDay, int dueDateYear, int dueDateHour, int dueDateMinute)
313 throws PortalException, SystemException {
314
315 User user = userPersistence.findByPrimaryKey(userId);
316
317 Date dueDate = PortalUtil.getDate(
318 dueDateMonth, dueDateDay, dueDateYear, dueDateHour, dueDateMinute,
319 user.getTimeZone(), new ProposalDueDateException());
320
321 TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
322 proposalId);
323
324 proposal.setModifiedDate(new Date());
325 proposal.setDescription(description);
326 proposal.setDueDate(dueDate);
327
328 tasksProposalPersistence.update(proposal, false);
329
330 return proposal;
331 }
332
333 }