001: /**
002: * $Id: APimTask.java,v 1.5 2003/10/23 00:02:49 rakeshn Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.ssoadapter.calendar.pim;
014:
015: import java.util.*;
016: import java.text.SimpleDateFormat;
017:
018: import com.sun.comclient.calendar.*;
019:
020: import com.aligo.pim.interfaces.*;
021: import com.aligo.pim.exceptions.*;
022: import com.aligo.pim.*;
023:
024: public class APimTask extends VTodo {
025:
026: private PimTaskItem taskItem;
027: private APimCalendar parentCal;
028:
029: private SimpleDateFormat isoFormatter;
030: private String isoFormat = "yyyyMMdd'T'HHmmss'Z'";
031: private boolean isNew = false;
032: private TimeZone tz = null;
033:
034: private String description = null;
035: private DateTime start = null;
036: private DateTime end = null;
037: private PimTaskStatusType status = PimTaskStatusType.NOT_COMPLETE;
038: private String summary = null;
039: private String id = null;
040:
041: private static boolean enableCache = true;
042:
043: public APimTask(APimCalendar cal, PimTaskItem item, boolean isNew) {
044: taskItem = item;
045: parentCal = cal;
046: this .isNew = isNew;
047:
048: isoFormatter = new SimpleDateFormat(isoFormat);
049: isoFormatter.setTimeZone(new SimpleTimeZone(0, "GMT"));
050: isoFormatter.setLenient(false);
051:
052: tz = cal.getTimeZone();
053: if (taskItem != null) {
054: try {
055: description = taskItem.getText();
056: status = taskItem.getStatus();
057: summary = taskItem.getSubject();
058: id = taskItem.getID();
059: end = toDateTime(taskItem.getDueDate());
060: start = toDateTime(taskItem.getStartDate());
061: if (enableCache) {
062: taskItem = null;
063: }
064: } catch (PimException pex) {
065: pex.printStackTrace();
066: } catch (Exception ex) {
067: ex.printStackTrace();
068: }
069: }
070: }
071:
072: public APimTask(APimCalendar cal, PimTaskItem item) {
073: this (cal, item, false);
074: }
075:
076: private DateTime toDateTime(Date date) throws Exception {
077: if (date != null) {
078: String tmp = isoFormatter.format(date);
079: return new DateTime(tmp, tz);
080: }
081: return null;
082: }
083:
084: public void addAlarmComponent(VAlarm alarm)
085: throws OperationNotSupportedException {
086: throw new OperationNotSupportedException("");
087: }
088:
089: public void addAttachment(Attach attachment)
090: throws OperationNotSupportedException {
091: throw new OperationNotSupportedException("");
092: }
093:
094: public void addCategory(java.lang.String category)
095: throws OperationNotSupportedException {
096: throw new OperationNotSupportedException("");
097: }
098:
099: public void addExceptionDate(DateTime exceptionDate)
100: throws OperationNotSupportedException {
101: throw new OperationNotSupportedException("");
102: }
103:
104: public void addExceptionRule(RecurrencePattern exceptionRule)
105: throws OperationNotSupportedException {
106: throw new OperationNotSupportedException("");
107: }
108:
109: public void addRecurrenceDate(DateTime recurrenceDate)
110: throws OperationNotSupportedException {
111: throw new OperationNotSupportedException("");
112: }
113:
114: public void addRecurrenceRule(RecurrencePattern recurrenceRule)
115: throws OperationNotSupportedException {
116: throw new OperationNotSupportedException("");
117: }
118:
119: public void addRelatedTo(java.lang.String relatedTo)
120: throws OperationNotSupportedException {
121: throw new OperationNotSupportedException("");
122: }
123:
124: public void addResource(java.lang.String resource)
125: throws OperationNotSupportedException {
126: throw new OperationNotSupportedException("");
127: }
128:
129: public VAlarm[] getAlarmComponents()
130: throws OperationNotSupportedException {
131: throw new OperationNotSupportedException("");
132: }
133:
134: public Attach[] getAttachments()
135: throws OperationNotSupportedException {
136: throw new OperationNotSupportedException("");
137: }
138:
139: public String[] getCategories()
140: throws OperationNotSupportedException {
141: throw new OperationNotSupportedException("");
142: }
143:
144: public String getClassification()
145: throws OperationNotSupportedException {
146: throw new OperationNotSupportedException("");
147: }
148:
149: public DateTime getCompletedTime()
150: throws OperationNotSupportedException {
151: throw new OperationNotSupportedException("");
152: }
153:
154: public DateTime getCreated() throws OperationNotSupportedException {
155: throw new OperationNotSupportedException("");
156: }
157:
158: public String getDescription() throws CalendarComponentException {
159: try {
160: if (taskItem == null) {
161: return description;
162: }
163: return taskItem.getText();
164: } catch (Exception pex) {
165: pex.printStackTrace();
166: throw new CalendarComponentException(pex.getMessage());
167: }
168: }
169:
170: public DateTime[] getExceptionDates()
171: throws OperationNotSupportedException {
172: throw new OperationNotSupportedException("");
173: }
174:
175: public RecurrencePattern[] getExceptionRules()
176: throws OperationNotSupportedException {
177: throw new OperationNotSupportedException("");
178: }
179:
180: public String getGeo() throws OperationNotSupportedException {
181: throw new OperationNotSupportedException("");
182: }
183:
184: public DateTime getLastModified()
185: throws OperationNotSupportedException {
186: throw new OperationNotSupportedException("");
187: }
188:
189: public String getLocation() throws OperationNotSupportedException {
190: throw new OperationNotSupportedException("");
191: }
192:
193: public int getPercent() throws OperationNotSupportedException {
194: throw new OperationNotSupportedException("");
195: }
196:
197: public int getPriority() throws OperationNotSupportedException {
198: throw new OperationNotSupportedException("");
199: }
200:
201: public DateTime[] getRecurrenceDates()
202: throws OperationNotSupportedException {
203: throw new OperationNotSupportedException("");
204: }
205:
206: public DateTime getRecurrenceID()
207: throws OperationNotSupportedException {
208: throw new OperationNotSupportedException("");
209: }
210:
211: public boolean isRecurring() throws OperationNotSupportedException {
212: throw new OperationNotSupportedException("");
213: // return false;
214: }
215:
216: public RecurrencePattern[] getRecurrenceRules()
217: throws OperationNotSupportedException {
218: throw new OperationNotSupportedException("");
219: }
220:
221: public String[] getRelatedTos()
222: throws OperationNotSupportedException {
223: throw new OperationNotSupportedException("");
224: }
225:
226: public String[] getResources()
227: throws OperationNotSupportedException {
228: throw new OperationNotSupportedException("");
229: }
230:
231: public int getSequence() throws OperationNotSupportedException {
232: throw new OperationNotSupportedException("");
233: }
234:
235: public DateTime getStart() throws CalendarComponentException {
236: try {
237: if (taskItem == null) {
238: return start;
239: }
240: return toDateTime(taskItem.getStartDate());
241: } catch (Exception pex) {
242: pex.printStackTrace();
243: throw new CalendarComponentException(pex.getMessage());
244: }
245: }
246:
247: public String getStatus() throws CalendarComponentException {
248: try {
249: if (taskItem == null) {
250: return status.toString();
251: }
252: PimTaskStatusType status = taskItem.getStatus();
253: return status.toString();
254: } catch (Exception ex) {
255: ex.printStackTrace();
256: throw new CalendarComponentException(ex.getMessage());
257: }
258: }
259:
260: public String getSummary() throws CalendarComponentException {
261: try {
262: if (taskItem == null) {
263: return summary;
264: }
265: return taskItem.getSubject();
266: } catch (Exception pex) {
267: pex.printStackTrace();
268: throw new CalendarComponentException(pex.getMessage());
269: }
270: }
271:
272: public boolean isAllDay() throws OperationNotSupportedException {
273: return true;
274: //outlook & LN client does not support time for Task
275: //If it is provided by pim dueDate, with time in it
276: //It uses the time, otherwise it is 00.00
277: }
278:
279: public void removeAlarmComponent(VAlarm alarm)
280: throws OperationNotSupportedException {
281: throw new OperationNotSupportedException("");
282: }
283:
284: public void removeAllAlarmComponents()
285: throws OperationNotSupportedException {
286: throw new OperationNotSupportedException("");
287: }
288:
289: public void removeAllAttachments()
290: throws OperationNotSupportedException {
291: throw new OperationNotSupportedException("");
292: }
293:
294: public void removeAllCategories()
295: throws OperationNotSupportedException {
296: throw new OperationNotSupportedException("");
297: }
298:
299: public void removeAllExceptionDates()
300: throws OperationNotSupportedException {
301: throw new OperationNotSupportedException("");
302: }
303:
304: public void removeAllExceptionRules()
305: throws OperationNotSupportedException {
306: throw new OperationNotSupportedException("");
307: }
308:
309: public void removeAllRecurrenceDates()
310: throws OperationNotSupportedException {
311: throw new OperationNotSupportedException("");
312: }
313:
314: public void removeAllRecurrenceRules()
315: throws OperationNotSupportedException {
316: throw new OperationNotSupportedException("");
317: }
318:
319: public void removeAllRelatedTos()
320: throws OperationNotSupportedException {
321: throw new OperationNotSupportedException("");
322: }
323:
324: public void removeAllResources()
325: throws OperationNotSupportedException {
326: throw new OperationNotSupportedException("");
327: }
328:
329: public void removeAttachment(Attach attachment)
330: throws OperationNotSupportedException {
331: throw new OperationNotSupportedException("");
332: }
333:
334: public void removeCategory(java.lang.String category)
335: throws OperationNotSupportedException {
336: throw new OperationNotSupportedException("");
337: }
338:
339: public void removeExceptionDate(DateTime exceptionDate)
340: throws OperationNotSupportedException {
341: throw new OperationNotSupportedException("");
342: }
343:
344: public void removeExceptionRule(RecurrencePattern exceptionRule)
345: throws OperationNotSupportedException {
346: throw new OperationNotSupportedException("");
347: }
348:
349: public void removeRecurrenceDate(DateTime recurrenceDate)
350: throws OperationNotSupportedException {
351: throw new OperationNotSupportedException("");
352: }
353:
354: public void removeRecurrenceRule(RecurrencePattern recurrenceRule)
355: throws OperationNotSupportedException {
356: throw new OperationNotSupportedException("");
357: }
358:
359: public void removeRelatedTo(String relatedTo)
360: throws OperationNotSupportedException {
361: throw new OperationNotSupportedException("");
362: }
363:
364: public void removeResource(String resource)
365: throws OperationNotSupportedException {
366: throw new OperationNotSupportedException("");
367: }
368:
369: public void setAllDay(boolean allday)
370: throws OperationNotSupportedException {
371: throw new OperationNotSupportedException("");
372: }
373:
374: public void setClassification(java.lang.String classification)
375: throws OperationNotSupportedException {
376: throw new OperationNotSupportedException("");
377: }
378:
379: public void setDescription(java.lang.String description)
380: throws CalendarComponentException {
381: try {
382: if (taskItem != null) {
383: taskItem.setText(description);
384: }
385: this .description = description;
386: } catch (Exception pex) {
387: pex.printStackTrace();
388: throw new CalendarComponentException(pex.getMessage());
389: }
390:
391: }
392:
393: public void setDuration(Duration duration)
394: throws OperationNotSupportedException {
395: throw new OperationNotSupportedException("");
396: }
397:
398: public void setGeo(java.lang.String geo)
399: throws OperationNotSupportedException {
400: throw new OperationNotSupportedException("");
401: }
402:
403: public void setLastModified(DateTime lastModified)
404: throws OperationNotSupportedException {
405: throw new OperationNotSupportedException("");
406: }
407:
408: public void setLocation(java.lang.String location)
409: throws OperationNotSupportedException {
410: throw new OperationNotSupportedException("");
411: }
412:
413: public void setPercent(int percent)
414: throws OperationNotSupportedException {
415: throw new OperationNotSupportedException("");
416: }
417:
418: public void setPriority(int priority)
419: throws OperationNotSupportedException {
420: throw new OperationNotSupportedException("");
421: }
422:
423: public void setSequence(int sequence)
424: throws OperationNotSupportedException {
425: throw new OperationNotSupportedException("");
426: }
427:
428: public void setStart(DateTime dtstart)
429: throws CalendarComponentException {
430: try {
431: if (taskItem != null) {
432: taskItem.setStartDate(dtstart.getTime());
433: }
434: start = dtstart;
435: } catch (PimException pex) {
436: pex.printStackTrace();
437: throw new CalendarComponentException(pex.getMessage());
438: }
439:
440: }
441:
442: public void setStatus(java.lang.String status)
443: throws CalendarComponentException {
444: try {
445: if (status.equalsIgnoreCase("completed")) {
446: this .status = PimTaskStatusType.COMPLETE;
447: } else {
448: this .status = PimTaskStatusType.NOT_COMPLETE;
449: }
450: if (taskItem != null) {
451: taskItem.setStatus(this .status);
452: }
453: } catch (Exception pex) {
454: pex.printStackTrace();
455: throw new CalendarComponentException(pex.getMessage());
456: }
457: }
458:
459: public void setSummary(java.lang.String summary)
460: throws CalendarComponentException {
461: try {
462: if (taskItem != null) {
463: taskItem.setSubject(summary);
464: }
465: this .summary = summary;
466: } catch (Exception pex) {
467: pex.printStackTrace();
468: throw new CalendarComponentException(pex.getMessage());
469: }
470: }
471:
472: public String toString() {
473: return null;
474: }
475:
476: //**************************************************
477:
478: public void setEnd(DateTime dtend)
479: throws CalendarComponentException {
480: try {
481: if (taskItem != null) {
482: taskItem.setDueDate(dtend.getTime());
483: }
484: end = dtend;
485: } catch (Exception pex) {
486: pex.printStackTrace();
487: throw new CalendarComponentException(pex.getMessage());
488: }
489: }
490:
491: public DateTime getEnd() throws CalendarComponentException {
492: try {
493: if (taskItem != null) {
494: return toDateTime(taskItem.getDueDate());
495: }
496: return end;
497: } catch (Exception pex) {
498: pex.printStackTrace();
499: throw new CalendarComponentException(pex.getMessage());
500: }
501:
502: }
503:
504: public void setCalID(String id)
505: throws OperationNotSupportedException {
506: throw new OperationNotSupportedException("");
507: }
508:
509: public String getCalID() throws CalendarComponentException {
510: return parentCal.getCalID();
511: }
512:
513: public String getUrl() throws OperationNotSupportedException {
514: throw new OperationNotSupportedException("");
515: }
516:
517: public void setUrl(String url)
518: throws OperationNotSupportedException {
519: throw new OperationNotSupportedException("");
520: }
521:
522: public String getID() throws CalendarComponentException {
523: try {
524: if (taskItem != null) {
525: return taskItem.getID();
526: } else
527: return id;
528: } catch (Exception ex) {
529: ex.printStackTrace();
530: throw new CalendarComponentException(ex.getMessage());
531: }
532: }
533:
534: public void setID(String uid) throws OperationNotSupportedException {
535: throw new OperationNotSupportedException("");
536: }
537:
538: public void removeAllRequestStatus()
539: throws OperationNotSupportedException {
540: throw new OperationNotSupportedException("");
541: }
542:
543: public void removeRequestStatus(String requeststatus)
544: throws OperationNotSupportedException,
545: CalendarComponentException {
546: throw new OperationNotSupportedException("");
547: }
548:
549: public void addRequestStatus(String requeststatus)
550: throws OperationNotSupportedException,
551: CalendarComponentException {
552: throw new OperationNotSupportedException("");
553: }
554:
555: public String[] getRequestStatus()
556: throws OperationNotSupportedException,
557: CalendarComponentException {
558: throw new OperationNotSupportedException("");
559: }
560:
561: public void setOrganizer(Organizer organizer)
562: throws OperationNotSupportedException,
563: CalendarComponentException {
564: throw new OperationNotSupportedException("");
565: }
566:
567: public Organizer getOrganizer()
568: throws OperationNotSupportedException,
569: CalendarComponentException {
570: throw new OperationNotSupportedException("");
571: }
572:
573: public Duration getDuration()
574: throws OperationNotSupportedException,
575: CalendarComponentException {
576: return null;
577: }
578:
579: public void setStamp(DateTime dtstamp)
580: throws OperationNotSupportedException,
581: CalendarComponentException {
582: throw new OperationNotSupportedException("");
583: }
584:
585: public DateTime getStamp() throws OperationNotSupportedException,
586: CalendarComponentException {
587: throw new OperationNotSupportedException("");
588: }
589:
590: public void removeAllComments()
591: throws OperationNotSupportedException,
592: CalendarComponentException {
593: throw new OperationNotSupportedException("");
594: }
595:
596: public void removeComment(String comment)
597: throws OperationNotSupportedException,
598: CalendarComponentException {
599: throw new OperationNotSupportedException("");
600: }
601:
602: public void addComment(String comment)
603: throws OperationNotSupportedException,
604: CalendarComponentException {
605: throw new OperationNotSupportedException("");
606: }
607:
608: public String[] getComments()
609: throws OperationNotSupportedException,
610: CalendarComponentException {
611: throw new OperationNotSupportedException("");
612: }
613:
614: public void removeAllContacts()
615: throws OperationNotSupportedException,
616: CalendarComponentException {
617: throw new OperationNotSupportedException("");
618: }
619:
620: public void removeContact(String contact)
621: throws OperationNotSupportedException,
622: CalendarComponentException {
623: throw new OperationNotSupportedException("");
624: }
625:
626: public void addContact(java.lang.String contact)
627: throws OperationNotSupportedException,
628: CalendarComponentException {
629: throw new OperationNotSupportedException("");
630: }
631:
632: public String[] getContacts()
633: throws OperationNotSupportedException,
634: CalendarComponentException {
635: throw new OperationNotSupportedException("");
636: }
637:
638: public void removeAllAttendees()
639: throws OperationNotSupportedException,
640: CalendarComponentException {
641: throw new OperationNotSupportedException("");
642: }
643:
644: public void removeAttendee(Attendee attendee)
645: throws OperationNotSupportedException,
646: CalendarComponentException {
647: throw new OperationNotSupportedException("");
648: }
649:
650: public void addAttendee(Attendee attendee)
651: throws OperationNotSupportedException,
652: CalendarComponentException {
653: throw new OperationNotSupportedException("");
654: }
655:
656: public Attendee[] getAttendees()
657: throws OperationNotSupportedException,
658: CalendarComponentException {
659: throw new OperationNotSupportedException("");
660: }
661:
662: public boolean hasAttendee() throws OperationNotSupportedException,
663: CalendarComponentException {
664: throw new OperationNotSupportedException("");
665: }
666:
667: public boolean isConfirmed() throws OperationNotSupportedException {
668: throw new OperationNotSupportedException("");
669: }
670:
671: public boolean isCompleted() throws CalendarComponentException {
672: try {
673: if (taskItem != null) {
674: status = taskItem.getStatus();
675: }
676: if (status == PimTaskStatusType.COMPLETE) {
677: return true;
678: }
679: return false;
680: } catch (Exception ex) {
681: throw new CalendarComponentException(ex.getMessage());
682: }
683: }
684:
685: public VAlarm createAlarm() throws OperationNotSupportedException {
686: throw new OperationNotSupportedException("");
687: }
688:
689: public boolean isCalIdTheOrganizer(String calId)
690: throws OperationNotSupportedException {
691: throw new OperationNotSupportedException("");
692: }
693:
694: public Attendee getAttendee(String calid)
695: throws OperationNotSupportedException {
696: throw new OperationNotSupportedException("");
697: }
698:
699: public void delete() throws PimException {
700: if (taskItem != null) {
701: taskItem.delete();
702: } else if (id != null) {
703: taskItem = parentCal.getTaskItems().getTaskItem(id);
704: taskItem.delete();
705: if (enableCache) {
706: taskItem = null;
707: }
708: }
709: }
710:
711: public void update() throws PimException {
712: if (taskItem == null) {
713: if (id == null) {
714: taskItem = parentCal.getTaskItems().addTaskItem();
715: } else {
716: taskItem = parentCal.getTaskItems().getTaskItem(id);
717: }
718: if (description != null) {
719: taskItem.setText(description);
720: }
721: if (status != null) {
722: taskItem.setStatus(status);
723: }
724: if (summary != null) {
725: taskItem.setSubject(summary);
726: }
727: if (end != null) {
728: taskItem.setDueDate(end.getTime());
729: }
730: if (start != null) {
731: taskItem.setStartDate(start.getTime());
732: }
733: }
734: taskItem.update();
735: isNew = false;
736: if (id == null) {
737: //As per Navin, the id allocation takes time for other backend servers
738: //other than Exchange & Notes
739: id = taskItem.getID();
740: }
741: if (enableCache) {
742: taskItem = null;
743: }
744: }
745:
746: // todo
747:
748: public boolean isPublic() throws OperationNotSupportedException,
749: CalendarComponentException {
750: throw new OperationNotSupportedException("");
751: }
752:
753: public int getPendingAttendeesCount()
754: throws OperationNotSupportedException,
755: CalendarComponentException {
756: throw new OperationNotSupportedException("");
757: }
758:
759: public int getTentativeAttendeesCount()
760: throws OperationNotSupportedException,
761: CalendarComponentException {
762: throw new OperationNotSupportedException("");
763: }
764:
765: public int getDeclinedAttendeesCount()
766: throws OperationNotSupportedException,
767: CalendarComponentException {
768: throw new OperationNotSupportedException("");
769: }
770:
771: public int getAcceptedAttendeesCount()
772: throws OperationNotSupportedException,
773: CalendarComponentException {
774: throw new OperationNotSupportedException("");
775: }
776:
777: public boolean hasAlarm() throws OperationNotSupportedException,
778: CalendarComponentException {
779: throw new OperationNotSupportedException("");
780: }
781:
782: }
|