001: /**
002: * $Id: TaskBean.java,v 1.22 2005/09/21 10:51:11 dg154973 Exp $
003: * Copyright 2003 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.portal.wireless.taglibs.cal;
014:
015: import com.sun.comclient.calendar.VTodo;
016: import com.sun.comclient.calendar.DateTime;
017: import com.sun.portal.wireless.taglibs.base.Util;
018: import com.sun.portal.log.common.PortalLogger;
019:
020: import java.util.logging.Logger;
021: import java.util.logging.Level;
022:
023: public class TaskBean extends SchedulingBean implements Comparable {
024:
025: private VTodo theTask;
026: private boolean isDueTime = false;
027:
028: // Create a logger for this class
029: private static Logger debugLogger = PortalLogger
030: .getLogger(TaskBean.class);
031:
032: public TaskBean(VTodo task) {
033: super (task);
034: this .theTask = task;
035: }
036:
037: public VTodo getTask() {
038: return theTask;
039: }
040:
041: /**
042: * Returns the Todo due date.
043: * This method returns same value as getStart() in Component
044: * <br><br>
045: * @return DateTime object of the task due date
046: * @see com.sun.portal.wireless.taglibs.cal.DateTimeTag
047: */
048:
049: public DateTime getDueDate() throws Exception {
050: return theTask.getDueTime();
051: }
052:
053: /**
054: * Does this task have a due date
055: * <br><br>
056: * @return true if it has a due date
057: */
058: public boolean isValidDueDate() throws Exception {
059: if (theTask.getDueTime() != null) {
060: return true;
061: } else {
062: this .setDueTimeField("false");
063: return false;
064: }
065: }
066:
067: /**
068: * Does this task have a due completion time
069: * <br><br>
070: * @return true if the task has a due completion time
071: */
072:
073: public boolean isDueTime() {
074: return isDueTime;
075: }
076:
077: /**
078: * specifies the due time status for a task
079: * @param String "true" if this task has a due completion time
080: * <br><br>
081: */
082:
083: public void setDueTimeField(String isdue) {
084: if (isdue.equalsIgnoreCase("true")) {
085: isDueTime = true;
086: } else {
087: isDueTime = false;
088: }
089: }
090:
091: /**
092: * Sets the status of the task
093: * @param status status of this task
094: */
095:
096: public void setStatus(String status) throws Exception {
097: if (status != null) {
098: theTask.setStatus(status.trim());
099: }
100: }
101:
102: /**
103: * Returns a DateTime object indicating due time,
104: * if duetime exists
105: * <br><br>
106: * @return true if due time exists
107: * @throws Exception indicating processing error
108: * @see com.sun.comclient.calendar.DateTime
109: */
110:
111: public String getDueTimeField() throws Exception {
112: return theTask.getDueTime().toString();
113: }
114:
115: /**
116: * Sets the due date of the todo with the
117: * supplied DateTime object
118: * <br><br>
119: * @param dtDue due time of the todo
120: * @throws Exception indicating processing error
121: */
122:
123: public void setDueDate(DateTime dtDue) throws Exception {
124: theTask.setStart(dtDue);
125: theTask.setDueTime(dtDue);
126: }
127:
128: /**
129: * Returns true is todo status is comleted
130: * <br><br>
131: * @return true when todo status is complete
132: */
133:
134: public boolean isCompleted() {
135: try {
136: return theTask.isCompleted();
137: } catch (Exception e) {
138: return false;
139: }
140: }
141:
142: /**
143: * @returns the task as a string.
144: * <br><br>
145: */
146:
147: public String toString() {
148: return theTask.toString();
149: }
150:
151: /**
152: * Get the id of the todo
153: * <br><br>
154: * @return unique id for this todo
155: * @throws Exception indicating processing error
156: */
157:
158: public Object getID() throws Exception {
159: return theTask.getID();
160: }
161:
162: /**
163: * Checks if the todo is overdue
164: * @return true if the todo is overdue. default is false.
165: */
166:
167: public boolean isOverDue() {
168: boolean taskOverdue = false;
169: DateTime dt = new DateTime();
170: try {
171: DateTime taskDT = theTask.getDueTime();
172: if (taskDT == null) {
173: return taskOverdue;
174: }
175: if ((taskDT.before(dt)) && (!isCompleted())) {
176: taskOverdue = true;
177: }
178: } catch (Exception e) {
179: debugLogger.log(Level.INFO, "PSMA_CSPWTC0001", e);
180: }
181:
182: return taskOverdue;
183: }
184:
185: /**
186: * This is requied for comparable
187: */
188:
189: public int compareTo(Object o) {
190: int result = -1;
191: try {
192: if (o instanceof TaskBean) {
193: TaskBean taskObj = (TaskBean) o;
194: if (isValidDueDate() && taskObj.isValidDueDate()) {
195: if (getDueDate().before(taskObj.getDueDate())) {
196: result = -1;
197: //When returns 0 , TreeSet does not add to the Collection
198: } else {
199: result = 1;
200: }
201: }
202: }
203: } catch (Exception ex) {
204: ex.printStackTrace();
205: }
206: return result;
207: }
208:
209: }
|