1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.calendar.model;
18
19 import org.exoplatform.calendar.service.Attachment;
20 import org.exoplatform.calendar.service.CalendarSetting;
21 import org.exoplatform.calendar.service.Invitation;
22 import org.exoplatform.calendar.service.Reminder;
23 import org.exoplatform.services.jcr.util.IdGenerator;
24
25 import java.util.*;
26
27
28
29
30
31 public class Event extends AbstractModel {
32
33 private static final long serialVersionUID = 908458203599863175L;
34
35 final public static String TYPE_EVENT = "Event".intern();
36
37 final public static String TYPE_TASK = "Task".intern();
38
39 final public static String TYPE_JOURNAL = "Journal".intern();
40
41 final public static String TENTATIVE = "tentative".intern();
42
43 final public static String CONFIRMED = "confirmed".intern();
44
45 final public static String CANCELLED = "canceled".intern();
46
47 final public static String NEEDS_ACTION = "needs-action".intern();
48
49 final public static String COMPLETED = "completed".intern();
50
51 final public static String IN_PROCESS = "in-process".intern();
52
53 final public static String PRIORITY_NONE = "none".intern();
54
55 final public static String PRIORITY_LOW = "low".intern();
56
57 final public static String PRIORITY_NORMAL = "normal".intern();
58
59 final public static String PRIORITY_HIGH = "high".intern();
60
61 final public static int PRI_UNDEFINED = 0;
62
63 final public static int PRI_HIGH = 1;
64
65 final public static int PRI_MEDIUM = 2;
66
67 final public static int PRI_LOW = 3;
68
69 final public static String[] PRIORITY = { PRIORITY_NONE, PRIORITY_HIGH, PRIORITY_NORMAL, PRIORITY_LOW };
70
71 final public static String DRAFT = "draft".intern();
72
73 final public static String FINAL = "final".intern();
74
75 final public static String[] EVENT_STATUS = { TENTATIVE, CONFIRMED, CANCELLED };
76
77 final public static String[] TASK_STATUS = { NEEDS_ACTION, IN_PROCESS, COMPLETED, CANCELLED };
78
79 final public static String[] JOURNAL_STATUS = { DRAFT, FINAL, CANCELLED };
80
81 final public static String IS_PUBLIC = "public".intern();
82
83 final public static String IS_PRIVATE = "private".intern();
84
85 final public static String ST_AVAILABLE = "available".intern();
86
87 final public static String ST_BUSY = "busy".intern();
88
89 final public static String ST_OUTSIDE = "outside".intern();
90
91 final public static String RP_NOREPEAT = "norepeat".intern();
92
93 final public static String RP_DAILY = "daily".intern();
94
95 final public static String RP_WEEKLY = "weekly".intern();
96
97 final public static String RP_MONTHLY = "monthly".intern();
98
99 final public static String RP_YEARLY = "yearly".intern();
100
101 final public static String RP_WEEKEND = "weekend".intern();
102
103 final public static String RP_WORKINGDAYS = "workingdays".intern();
104
105 final public static String[] RP_WEEKLY_BYDAY = { "MO", "TU", "WE", "TH", "FR", "SA", "SU" };
106
107 final public static String[] REPEATTYPES = { RP_NOREPEAT, RP_DAILY, RP_WEEKLY, RP_MONTHLY, RP_YEARLY };
108
109 private String summary;
110
111 private String location;
112
113 private String description;
114
115 private String eventCategoryId;
116
117 private String eventCategoryName;
118
119 private String calendarId;
120
121 private String repeatType;
122
123 private Date fromDateTime;
124
125 private Date toDateTime;
126
127 private Date completedDateTime;
128
129 private String taskDelegator;
130
131 private String sendOption = CalendarSetting.ACTION_BYSETTING;
132
133 private String message;
134
135 private String[] participantStatus;
136
137
138 private String recurrenceId;
139
140 private Boolean isExceptionOccurrence;
141
142 private Collection<String> exclusions;
143
144 private String originalReference;
145
146 private Date repeatUntilDate;
147
148 private long repeatCount;
149
150 private long repeatInterval;
151
152 private long[] repeatBySecond;
153
154 private long[] repeatByMinute;
155
156 private long[] repeatByHour;
157
158 private String[] repeatByDay;
159
160 private long[] repeatByMonthDay;
161
162 private long[] repeatByYearDay;
163
164 private long[] repeatByWeekNo;
165
166 private long[] repeatByMonth;
167
168 private long[] repeatBySetPos;
169
170 private String repeatWkst;
171
172
173
174
175 private String eventType = TYPE_EVENT;
176
177
178
179
180 private String priority = PRIORITY_NONE;
181
182 private boolean isPrivate = true;
183
184 private String eventState = ST_BUSY;
185
186
187
188
189
190
191
192
193
194
195 private String status = "";
196
197 private String[] invitation = new String[0];
198
199 private String[] participant = new String[0];
200
201 private List<Reminder> reminders = Collections.emptyList();
202
203 private List<Attachment> attachment = Collections.emptyList();
204
205 private String activityId ;
206 public Event() {
207 super("Event" + IdGenerator.generate());
208 }
209
210
211 public Event(Event event) {
212 super(event.getId());
213 this.summary = event.summary;
214 this.description = event.description;
215 this.fromDateTime = event.fromDateTime;
216 this.toDateTime = event.toDateTime;
217 this.eventCategoryId = event.eventCategoryId;
218 this.eventCategoryName = event.eventCategoryName;
219 this.message = event.message;
220 this.location = event.location;
221 this.repeatType = event.repeatType;
222 this.calendarId = event.calendarId;
223 this.sendOption = event.sendOption;
224 this.status = event.status;
225 List<Attachment> attachments = event.getAttachment();
226 setAttachment(attachments);
227 this.setInvitation(event.getInvitation());
228 this.setParticipant(event.getParticipant());
229 this.setParticipantStatus(event.getParticipantStatus());
230 this.setReminders(event.getReminders());
231 this.setPriority(event.getPriority());
232 this.setRepeatUntilDate(event.getRepeatUntilDate());
233 this.setRepeatCount(event.getRepeatCount());
234 this.setRepeatInterval(event.getRepeatInterval());
235 this.setRepeatByDay(event.getRepeatByDay());
236 this.setRepeatByMonthDay(event.getRepeatByMonthDay());
237 }
238
239 public String getSummary() {
240 return summary;
241 }
242
243 public void setSummary(String sum) {
244 this.summary = sum;
245 }
246
247 public String getDescription() {
248 return description;
249 }
250
251 public void setDescription(String description) {
252 this.description = description;
253 }
254
255 public boolean isPrivate() {
256 return isPrivate;
257 }
258
259 public void setPrivate(boolean isPrivate) {
260 this.isPrivate = isPrivate;
261 }
262
263 public String getEventCategoryId() {
264 return eventCategoryId;
265 }
266
267 public void setEventCategoryId(String eventCategoryId) {
268 this.eventCategoryId = eventCategoryId;
269 }
270
271 public String getCalendarId() {
272 return calendarId;
273 }
274
275 public void setCalendarId(String calendarId) {
276 this.calendarId = calendarId;
277 }
278
279 public Date getFromDateTime() {
280 return fromDateTime;
281 }
282
283 public void setFromDateTime(Date fromDateTime) {
284 this.fromDateTime = fromDateTime;
285 }
286
287 public Date getToDateTime() {
288 return toDateTime;
289 }
290
291 public void setToDateTime(Date toDateTime) {
292 this.toDateTime = toDateTime;
293 }
294
295 public Date getCompletedDateTime() {
296 return completedDateTime;
297 }
298
299 public void setCompletedDateTime(Date completedDateTime) {
300 this.completedDateTime = completedDateTime;
301 }
302
303 public String getLocation() {
304 return location;
305 }
306
307 public void setLocation(String location) {
308 this.location = location;
309 }
310
311 public String getEventState() {
312 return eventState;
313 }
314
315 public void setEventState(String eventState) {
316 this.eventState = eventState;
317 }
318
319
320
321
322
323 public String getStatus() {
324 return status;
325 }
326
327 public void setStatus(String status) {
328 this.status = status;
329 }
330
331 public String getEventType() {
332 return eventType;
333 }
334
335 public void setEventType(String eventType) {
336 this.eventType = eventType;
337 }
338
339 public String getPriority() {
340 return priority;
341 }
342
343 public void setPriority(String priority) {
344 this.priority = priority;
345 }
346
347 public String[] getInvitation() {
348 return invitation;
349 }
350
351 public void setInvitation(String[] invitation) {
352 this.invitation = invitation;
353 }
354
355 public List<Reminder> getReminders() {
356 return reminders;
357 }
358
359 public void setReminders(List<Reminder> rm) {
360 this.reminders = rm;
361 }
362
363 public void setRepeatType(String repeatType) {
364 this.repeatType = repeatType;
365 }
366
367 public String getRepeatType() {
368 return repeatType;
369 }
370
371 public List<Attachment> getAttachment() {
372 return attachment;
373 }
374
375 public void setAttachment(List<Attachment> list) {
376 attachment = list;
377 }
378
379 public void setParticipant(String[] participant) {
380 this.participant = participant;
381 }
382
383 public String[] getParticipant() {
384 return participant;
385 }
386
387 public String[] getParticipantStatus() {
388 return participantStatus;
389 }
390
391 public void setParticipantStatus(String[] participantStatus) {
392 this.participantStatus = participantStatus;
393 }
394
395 public void setTaskDelegator(String taskDelegator) {
396 this.taskDelegator = taskDelegator;
397 }
398
399 public String getTaskDelegator() {
400 return taskDelegator;
401 }
402
403 public void setEventCategoryName(String eventCategoryName) {
404 this.eventCategoryName = eventCategoryName;
405 }
406
407 public String getEventCategoryName() {
408 return eventCategoryName;
409 }
410
411 public void setSendOption(String sendOption) {
412 this.sendOption = sendOption;
413 }
414
415 public String getSendOption() {
416 return sendOption;
417 }
418
419 public String getMessage() {
420 return message;
421 }
422
423 public void setMessage(String message) {
424 if (message != null)
425 this.message = message;
426 else
427 this.message = new String();
428 }
429
430
431
432
433 public void setRecurrenceId(String recurrenceId) {
434 this.recurrenceId = recurrenceId;
435 }
436
437
438
439
440 public String getRecurrenceId() {
441 return recurrenceId;
442 }
443
444
445
446
447 public void setIsExceptionOccurrence(Boolean isExceptionOccurrence) {
448 this.isExceptionOccurrence = isExceptionOccurrence;
449 }
450
451
452
453
454 public Boolean getIsExceptionOccurrence() {
455 return isExceptionOccurrence;
456 }
457
458
459
460
461
462 public void setExclusions(Collection<String> ids){
463 if (ids != null) {
464 ids = new HashSet<String>(ids);
465 }
466 this.exclusions = ids;
467 }
468
469
470
471
472 public Collection<String> getExclusions(){
473 return this.exclusions;
474 }
475
476
477
478
479
480 public void addExclusion(String id){
481 if(this.exclusions == null){
482 this.exclusions = new HashSet<String>();
483
484 } else if (!(this.exclusions instanceof HashSet)) {
485
486 this.exclusions = new HashSet<String>(this.exclusions);
487 }
488 this.exclusions.add(id);
489 }
490
491 public void removeExclusion(String id){
492 if(this.exclusions != null){
493 this.exclusions.remove(id);
494 }
495 }
496
497
498
499
500 public void setRepeatUntilDate(Date repeatUntilDate) {
501 this.repeatUntilDate = repeatUntilDate;
502 }
503
504
505
506
507 public Date getRepeatUntilDate() {
508 return repeatUntilDate;
509 }
510
511
512
513
514 public void setOriginalReference(String originalReference) {
515 this.originalReference = originalReference;
516 }
517
518
519
520
521 public String getOriginalReference() {
522 return originalReference;
523 }
524
525
526
527
528 public void setRepeatCount(long repeatCount) {
529 this.repeatCount = repeatCount;
530 }
531
532
533
534
535 public long getRepeatCount() {
536 return repeatCount;
537 }
538
539
540
541
542 public void setRepeatInterval(long repeatInterval) {
543 this.repeatInterval = repeatInterval;
544 }
545
546
547
548
549 public long getRepeatInterval() {
550 return repeatInterval;
551 }
552
553
554
555
556 public void setRepeatBySecond(long[] repeatBySecond) {
557 this.repeatBySecond = repeatBySecond;
558 }
559
560
561
562
563 public long[] getRepeatBySecond() {
564 return repeatBySecond;
565 }
566
567
568
569
570 public long[] getRepeatByMinute() {
571 return repeatByMinute;
572 }
573
574
575
576
577 public void setRepeatByMinute(long[] repeatByMinute) {
578 this.repeatByMinute = repeatByMinute;
579 }
580
581
582
583
584 public long[] getRepeatByMonthDay() {
585 return repeatByMonthDay;
586 }
587
588
589
590
591 public void setRepeatByMonthDay(long[] repeatByMonthDay) {
592 this.repeatByMonthDay = repeatByMonthDay;
593 }
594
595
596
597
598 public long[] getRepeatByYearDay() {
599 return repeatByYearDay;
600 }
601
602
603
604
605 public void setRepeatByYearDay(long[] repeatByYearDay) {
606 this.repeatByYearDay = repeatByYearDay;
607 }
608
609
610
611
612 public long[] getRepeatByWeekNo() {
613 return repeatByWeekNo;
614 }
615
616
617
618
619 public void setRepeatByWeekNo(long[] repeatByWeekNo) {
620 this.repeatByWeekNo = repeatByWeekNo;
621 }
622
623
624
625
626 public long[] getRepeatByMonth() {
627 return repeatByMonth;
628 }
629
630
631
632
633 public void setRepeatByMonth(long[] repeatByMonth) {
634 this.repeatByMonth = repeatByMonth;
635 }
636
637
638
639
640 public long[] getRepeatBySetPos() {
641 return repeatBySetPos;
642 }
643
644
645
646
647 public void setRepeatBySetPos(long[] repeatBySetPos) {
648 this.repeatBySetPos = repeatBySetPos;
649 }
650
651
652
653
654 public String getRepeatWkst() {
655 return repeatWkst;
656 }
657
658
659
660
661 public void setRepeatWkst(String repeatWkst) {
662 this.repeatWkst = repeatWkst;
663 }
664
665
666
667
668 public void setRepeatByHour(long[] repeatByHour) {
669 this.repeatByHour = repeatByHour;
670 }
671
672
673
674
675 public long[] getRepeatByHour() {
676 return repeatByHour;
677 }
678
679
680
681
682 public void setRepeatByDay(String[] repeatByDay) {
683 this.repeatByDay = repeatByDay;
684 }
685
686
687
688
689 public String[] getRepeatByDay() {
690 return repeatByDay;
691 }
692
693
694
695
696
697
698 public boolean isEventDurationSmallerThanHalfHour()
699 {
700 long differenceInMin = ( getToDateTime().getTime() - getFromDateTime().getTime() ) / (1000 * 60);
701 return (differenceInMin <= 30);
702 }
703
704 public String getActivityId() {
705 return activityId;
706 }
707
708 public void setActivityId(String activityId) {
709 this.activityId = activityId;
710 }
711
712 public void addParticipant(String parName, String status) {
713 List<String> pars = new LinkedList<String>();
714 if (this.getParticipant() != null) {
715 pars.addAll(Arrays.asList(this.getParticipant()));
716 }
717
718 if (!pars.contains(parName)) {
719 pars.add(parName);
720 setParticipant(pars.toArray(new String[pars.size()]));
721
722 Map<String, String> statusMap = getStatusMap();
723 if (statusMap.isEmpty()) {
724 statusMap = new HashMap<String, String>();
725 }
726 statusMap.put(parName, status);
727 setStatusMap(statusMap);
728 }
729 }
730
731 public void removeParticipant(String parName) {
732 if (this.getParticipant() == null) {
733 return;
734 }
735
736 List<String> parList = new LinkedList<String>(Arrays.asList(this.getParticipant()));
737 parList.remove(parName);
738 this.setParticipant(parList.toArray(new String[parList.size()]));
739
740 Map<String, String> statusMap = getStatusMap();
741 statusMap.remove(parName);
742 this.setStatusMap(statusMap);
743 }
744
745 public Invitation[] getInvitations() {
746 if (this.getParticipant() == null) {
747 return new Invitation[0];
748 }
749 Invitation[] invitations = new Invitation[this.getParticipant().length];
750
751 int i = 0;
752 Map<String, String> parStatus = getStatusMap();
753 for (String par : this.getParticipant()) {
754 invitations[i++] = new Invitation(this.getId(), par, parStatus.get(par));
755 }
756 return invitations;
757 }
758
759 public void setStatusMap(Map<String, String> statusMap) {
760 String[] status = new String[statusMap.values().size()];
761 int i = 0;
762 for (String name : statusMap.keySet()) {
763 status[i++] = String.format("%s:%s", name, statusMap.get(name));
764 }
765 this.setParticipantStatus(status);
766 }
767
768 public Map<String, String> getStatusMap() {
769 if (getParticipantStatus() == null) {
770 return Collections.emptyMap();
771 }
772 Map<String, String> status = new HashMap<String, String>();
773
774 for (String s : getParticipantStatus()) {
775 String[] tmp = s.split(":");
776 if (tmp.length == 2) {
777 status.put(tmp[0], tmp[1]);
778 } else {
779 status.put(tmp[0], "");
780 }
781 }
782 return status;
783 }
784
785 @Override
786 public boolean equals(Object o) {
787 if (this == o) return true;
788 if (o == null || getClass() != o.getClass()) return false;
789 Event event = (Event) o;
790 return repeatCount == event.repeatCount &&
791 repeatInterval == event.repeatInterval &&
792 isPrivate == event.isPrivate &&
793 Objects.equals(summary, event.summary) &&
794 Objects.equals(location, event.location) &&
795 Objects.equals(description, event.description) &&
796 Objects.equals(eventCategoryId, event.eventCategoryId) &&
797 Objects.equals(eventCategoryName, event.eventCategoryName) &&
798 Objects.equals(calendarId, event.calendarId) &&
799 Objects.equals(repeatType, event.repeatType) &&
800 Objects.equals(fromDateTime, event.fromDateTime) &&
801 Objects.equals(toDateTime, event.toDateTime) &&
802 Objects.equals(completedDateTime, event.completedDateTime) &&
803 Objects.equals(taskDelegator, event.taskDelegator) &&
804 Objects.equals(sendOption, event.sendOption) &&
805 Objects.equals(message, event.message) &&
806 Arrays.equals(participantStatus, event.participantStatus) &&
807 Objects.equals(recurrenceId, event.recurrenceId) &&
808 Objects.equals(isExceptionOccurrence, event.isExceptionOccurrence) &&
809 Objects.equals(exclusions, event.exclusions) &&
810 Objects.equals(originalReference, event.originalReference) &&
811 Objects.equals(repeatUntilDate, event.repeatUntilDate) &&
812 Arrays.equals(repeatBySecond, event.repeatBySecond) &&
813 Arrays.equals(repeatByMinute, event.repeatByMinute) &&
814 Arrays.equals(repeatByHour, event.repeatByHour) &&
815 Arrays.equals(repeatByDay, event.repeatByDay) &&
816 Arrays.equals(repeatByMonthDay, event.repeatByMonthDay) &&
817 Arrays.equals(repeatByYearDay, event.repeatByYearDay) &&
818 Arrays.equals(repeatByWeekNo, event.repeatByWeekNo) &&
819 Arrays.equals(repeatByMonth, event.repeatByMonth) &&
820 Arrays.equals(repeatBySetPos, event.repeatBySetPos) &&
821 Objects.equals(repeatWkst, event.repeatWkst) &&
822 Objects.equals(eventType, event.eventType) &&
823 Objects.equals(priority, event.priority) &&
824 Objects.equals(eventState, event.eventState) &&
825 Objects.equals(status, event.status) &&
826 Arrays.equals(invitation, event.invitation) &&
827 Arrays.equals(participant, event.participant) &&
828 Objects.equals(reminders, event.reminders) &&
829 Objects.equals(attachment, event.attachment) &&
830 Objects.equals(activityId, event.activityId);
831 }
832
833 @Override
834 public int hashCode() {
835 return Objects.hash(summary, location, description, eventCategoryId, eventCategoryName, calendarId,
836 repeatType, fromDateTime, toDateTime, completedDateTime, taskDelegator, sendOption, message,
837 participantStatus, recurrenceId, isExceptionOccurrence, exclusions, originalReference, repeatUntilDate,
838 repeatCount, repeatInterval, repeatBySecond, repeatByMinute, repeatByHour, repeatByDay, repeatByMonthDay,
839 repeatByYearDay, repeatByWeekNo, repeatByMonth, repeatBySetPos, repeatWkst, eventType, priority, isPrivate,
840 eventState, status, invitation, participant, reminders, attachment, activityId);
841 }
842 }