1 package com.germinus.merlin.util;
2
3 import java.util.Date;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.Set;
7
8 import javax.portlet.ActionRequest;
9 import javax.portlet.ActionResponse;
10 import javax.portlet.PortletRequest;
11 import javax.portlet.PortletResponse;
12 import javax.portlet.RenderRequest;
13 import javax.portlet.RenderResponse;
14 import javax.servlet.ServletContext;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17
18 import com.germinus.liferay.util.IUserUtil;
19 import com.germinus.merlin.manager.CourseManager;
20 import com.germinus.merlin.model.Course;
21 import com.germinus.merlin.model.Student;
22 import com.germinus.merlin.model.Teacher;
23 import com.liferay.portal.PortalException;
24 import com.liferay.portal.SystemException;
25 import com.liferay.portal.model.Layout;
26 import com.germinus.merlin.util.MerlinWebKeys;
27
28 public class MerlinUtil implements IMerlinUtil {
29 private IUserUtil userUtil;
30 private CourseManager courseManager;
31
32
33
34
35 public String getUserType(RenderRequest request,
36 RenderResponse response, long courseId) {
37
38 String username = userUtil.getUserName(request, response);
39 String userType = null;
40 if (username != null) {
41 Long id = Long.parseLong(username);
42
43 Course course = courseManager.getCourse(courseId);
44 Set<Teacher> courseTeachersSet = course.getTeachers();
45 Set<Student> courseStudentsSet = course.getStudents();
46
47 if (isTeacher(courseTeachersSet, id)) {
48 userType = MerlinWebKeys.TEACHER;
49 } else {
50 if (isStudent(courseStudentsSet, id)) {
51 userType = MerlinWebKeys.STUDENTS;
52
53 }
54 }
55 }
56 return userType;
57 }
58
59
60
61
62
63
64
65
66 private boolean isStudent(Set<Student> studentsSet, Long id) {
67 Student student = null;
68 Iterator<Student> studentsIterator = studentsSet.iterator();
69 while (studentsIterator.hasNext()) {
70 student = studentsIterator.next();
71 if (student.getId().getUserid() == id)
72 return true;
73 }
74 return false;
75 }
76
77
78
79
80
81
82
83
84 private boolean isTeacher(Set<Teacher> teachersSet, Long id) {
85 Teacher teacher = null;
86 Iterator<Teacher> teachersIterator = teachersSet.iterator();
87 while (teachersIterator.hasNext()) {
88 teacher = teachersIterator.next();
89 if (teacher.getId().getUserid() == id)
90 return true;
91 }
92
93 return false;
94 }
95
96
97
98
99 public IUserUtil getUserUtil() {
100 return userUtil;
101 }
102
103
104
105
106 public void setUserUtil(IUserUtil userUtil) {
107 this.userUtil = userUtil;
108 }
109
110
111
112
113 public CourseManager getCourseManager() {
114 return courseManager;
115 }
116
117
118
119
120 public void setCourseManager(CourseManager courseManager) {
121 this.courseManager = courseManager;
122 }
123
124 @SuppressWarnings("unchecked")
125 public List getUserList(RenderRequest request, RenderResponse response) {
126
127 return userUtil.getUserList(request, response);
128 }
129
130 public String getUserName(long arg0) {
131 return userUtil.getUserName(arg0);
132 }
133
134 public String getUserName(ActionRequest arg0, ActionResponse arg1) {
135 return userUtil.getUserName(arg0, arg1);
136 }
137
138 public String getUserName(RenderRequest arg0, RenderResponse arg1) {
139 return userUtil.getUserName(arg0, arg1);
140 }
141
142 public long getCompanyId(Layout arg0) {
143 return userUtil.getCompanyId(arg0);
144 }
145
146 public long getCompanyId(RenderRequest arg0) {
147 return userUtil.getCompanyId(arg0);
148 }
149
150 public long getComunityGroupId(ActionRequest arg0, ActionResponse arg1) {
151 return userUtil.getComunityGroupId(arg0, arg1);
152 }
153
154 public long getComunityGroupId(PortletRequest arg0, PortletResponse arg1) {
155 return userUtil.getComunityGroupId(arg0, arg1);
156 }
157
158 public long getComunityGroupId(RenderRequest arg0, RenderResponse arg1) {
159 return userUtil.getComunityGroupId(arg0, arg1);
160 }
161
162 public String getComunityName(RenderRequest arg0, RenderResponse arg1) {
163 return userUtil.getComunityName(arg0,arg1);
164 }
165
166 public HttpServletRequest getHttpServletRequest(RenderRequest arg0,
167 RenderResponse arg1) {
168 return userUtil.getHttpServletRequest(arg0, arg1);
169 }
170
171 public HttpServletResponse getHttpServletResponse(RenderRequest arg0,
172 RenderResponse arg1) {
173 return userUtil.getHttpServletResponse(arg0, arg1);
174 }
175
176 public Layout getLayout(Long arg0) throws PortalException, SystemException {
177 return userUtil.getLayout(arg0);
178 }
179
180 public Layout getLayout(RenderRequest arg0) {
181 return userUtil.getLayout(arg0);
182 }
183
184 public Layout getLayout(ActionRequest arg0, ActionResponse arg1) {
185 return userUtil.getLayout(arg0, arg1);
186 }
187
188 public Layout getLayout(PortletRequest arg0, PortletResponse arg1) {
189 return userUtil.getLayout(arg0, arg1);
190 }
191
192 public long getLayoutId(RenderRequest arg0) {
193 return userUtil.getLayoutId(arg0);
194 }
195
196 public long getParentLayoutId(RenderRequest arg0) {
197 return userUtil.getLayoutId(arg0);
198 }
199
200 public long getPlid(Layout arg0) {
201 return userUtil.getPlid(arg0);
202 }
203
204 public long getPlid(RenderRequest arg0) {
205 return userUtil.getPlid(arg0);
206 }
207
208 public ServletContext getServletContext(PortletRequest arg0,
209 PortletResponse arg1, String arg2) throws PortalException,
210 SystemException {
211 return userUtil.getServletContext(arg0, arg1, arg2);
212 }
213
214 public ServletContext getServletContext(RenderRequest arg0,
215 RenderResponse arg1, String arg2) throws PortalException,
216 SystemException {
217 return userUtil.getServletContext(arg0, arg1);
218 }
219
220 public Long getTabPlid(RenderRequest arg0, RenderResponse arg1) {
221 return userUtil.getTabPlid(arg0, arg1);
222 }
223
224 public ServletContext getServletContext(RenderRequest request,
225 RenderResponse response) throws PortalException, SystemException {
226
227 return userUtil.getServletContext(request, response);
228 }
229
230 public Void UpdateUser(long arg0, String arg1, String arg2, String arg3,
231 boolean arg4, String arg5, String arg6, String arg7, String arg8,
232 String arg9, String arg10, String arg11, String arg12,
233 String arg13, int arg14, int arg15, boolean arg16, int arg17,
234 int arg18, int arg19, String arg20, String arg21, String arg22,
235 String arg23, String arg24, String arg25, String arg26,
236 String arg27, long[] arg28) {
237
238 return null;
239 }
240
241 public String getAimSn(Long userId) {
242
243 return null;
244 }
245
246 public Date getBirthday(Long userId) {
247
248 return null;
249 }
250
251 public String getComments(Long userId) {
252
253 return null;
254 }
255
256 public String getGreeting(Long userId) {
257
258 return null;
259 }
260
261 public String getIcqSn(Long userId) {
262
263 return null;
264 }
265
266 public String getJabberSn(Long userId) {
267
268 return null;
269 }
270
271 public String getJobTitle(Long userId) {
272
273 return null;
274 }
275
276 public String getLanguageId(Long userId) {
277
278 return null;
279 }
280
281 public boolean getMale(Long userId) {
282
283 return false;
284 }
285
286 public String getMsnSn(Long userId) {
287
288 return null;
289 }
290
291 public Long[] getOrganizationIds(Long userId) {
292
293 return null;
294 }
295
296 public boolean getPasswordReset(Long userId) {
297
298 return false;
299 }
300
301 public String getSkypeSn(Long userId) {
302
303 return null;
304 }
305
306 public String getSmsSn(Long userId) {
307
308 return null;
309 }
310
311 public int getSuffixId(Long userId) {
312
313 return 0;
314 }
315
316 public String getTimeZoneId(Long userId) {
317
318 return null;
319 }
320
321 public String getUserEmail(Long userId) {
322
323 return null;
324 }
325
326 public String getUserFirstName(Long userId) {
327
328 return null;
329 }
330
331 public String getUserLastName(Long userId) {
332
333 return null;
334 }
335
336 public String getUserMidleName(Long userId) {
337
338 return null;
339 }
340
341 public String getUserName(Long userId) {
342
343 return null;
344 }
345
346 public String getUserPassword(Long userId) {
347
348 return null;
349 }
350
351 public Long getUserPhoto(Long userId) {
352
353 return null;
354 }
355
356 public int getUserPrefix(Long userId) {
357
358 return 0;
359 }
360
361 public String getUserScreenName(Long userId) {
362
363 return null;
364 }
365
366 public String getUserUuid(Long userId) {
367
368 return null;
369 }
370
371 public String getYmSn(Long userId) {
372
373 return null;
374 }
375
376 public void setAimSn(Long userId, String AimSn) {
377
378
379 }
380
381 public void setBirthday(Long userId, Date Birthday) {
382
383
384 }
385
386 public void setComments(Long userId, String Comments) {
387
388
389 }
390
391 public void setGreeting(Long userId, String Greeting) {
392
393
394 }
395
396 public void setIcqSn(Long userId, String IcqSn) {
397
398
399 }
400
401 public void setJabberSn(Long userId, String JabberSn) {
402
403
404 }
405
406 public void setJobTitle(Long userId, String JobTitle) {
407
408
409 }
410
411 public void setLanguageId(Long userId, String LanguageId) {
412
413
414 }
415
416 public void setMale(Long userId, boolean Male) {
417
418
419 }
420
421 public void setMsnSn(Long userId, String MsnSn) {
422
423
424 }
425
426 public void setOrganizationIds(Long userId, Long[] OrganizationIds) {
427
428
429 }
430
431 public void setPasswordReset(Long userId, boolean PasswordReset) {
432
433
434 }
435
436 public void setSkypeSn(Long userId, String SkypeSn) {
437
438
439 }
440
441 public void setSmsSn(Long userId, String SmsSn) {
442
443
444 }
445
446 public void setSuffixId(Long userId, int SuffixId) {
447
448
449 }
450
451 public void setTimeZoneId(Long userId, String TimeZoneId) {
452
453
454 }
455
456 public void setUserEmail(Long userId, String UserEmail) {
457
458
459 }
460
461 public void setUserFirstName(Long userId, String UserFirstName) {
462
463
464 }
465
466 public void setUserLastName(Long userIdv, String UserLastName) {
467
468
469 }
470
471 public void setUserMidleName(Long userId, String UserMidleName) {
472
473
474 }
475
476 public void setUserName(Long userId, String UserName) {
477
478
479 }
480
481 public void setUserPassword(Long userId, String UserPassword) {
482
483
484 }
485
486 public void setUserPhoto(Long userId, Long UserPhoto) {
487
488
489 }
490
491 public void setUserPrefix(Long userId, int UserPrefix) {
492
493
494 }
495
496 public void setUserScreenName(Long userId, String UserScreenName) {
497
498
499 }
500
501 public void setYmSn(Long userId, String YmSn) {
502
503
504 }
505
506 public void updateUser(Long userId, String oldPassword,
507 String newPassword1, String newPassword2, boolean passwordReset,
508 String screenName, String emailAddress, String firstName,
509 String middleName, String lastName, boolean male,
510 int birthdayMonth, int birthdayDay, int birthdayYear) {
511
512
513 }
514
515 public void updateUser(Long userId, String oldPassword,
516 String newPassword1, String newPassword2, boolean passwordReset,
517 String screenName, String emailAddress, String languageId,
518 String timeZoneId, String greeting, String comments,
519 String firstName, String middleName, String lastName, int prefixId,
520 int suffixId, boolean male, int birthdayMonth, int birthdayDay,
521 int birthdayYear, String smsSn, String aimSn, String icqSn,
522 String jabberSn, String msnSn, String skypeSn, String ymSn,
523 String jobTitle, Long[] organizationIds) {
524
525
526 }
527
528 public String getRealContext(ActionRequest request, ActionResponse response)
529 throws PortalException, SystemException {
530
531 return null;
532 }
533
534 }