View Javadoc
1   /*
2    * Copyright (C) 2003-2014 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  
18  package org.exoplatform.calendar.ws.bean;
19  
20  import static org.exoplatform.calendar.ws.CalendarRestApi.CALENDAR_URI;
21  import static org.exoplatform.calendar.ws.CalendarRestApi.CATEGORY_URI;
22  import static org.exoplatform.calendar.ws.CalendarRestApi.TASK_URI;
23  
24  import java.io.Serializable;
25  import java.net.URLEncoder;
26  import java.util.Calendar;
27  import java.util.LinkedList;
28  import java.util.List;
29  
30  import org.exoplatform.calendar.service.Attachment;
31  import org.exoplatform.calendar.service.CalendarEvent;
32  import org.exoplatform.calendar.service.Reminder;
33  import org.exoplatform.calendar.service.Utils;
34  import org.exoplatform.calendar.ws.CalendarRestApi;
35  import org.exoplatform.calendar.ws.common.Resource;
36  import org.exoplatform.commons.utils.ISO8601;
37  
38  public class TaskResource extends Resource {
39    private static final long serialVersionUID = -5290204215375549320L;
40  
41    private String name;
42    private String note;
43    private String from;
44    private String to;
45    private Serializable calendar;
46    private Serializable[] categories;
47    private String[] delegation;
48    private String priority;
49    private Reminder[] reminder;
50    private Serializable[] attachments;
51    private String status;  
52    private String categoryId;
53  
54    public TaskResource() {
55      super(null);
56    }
57    
58    public TaskResource(CalendarEvent data, String basePath) throws Exception {
59     super(data.getId());
60     setHref(new StringBuilder(basePath).append(TASK_URI).append(data.getId()).toString());
61     name = data.getSummary();
62     note = data.getDescription();
63     
64     Calendar fromCal = Utils.getInstanceTempCalendar();
65     fromCal.setTime(data.getFromDateTime());
66     from = ISO8601.format(fromCal);
67     
68     Calendar toCal = Utils.getInstanceTempCalendar();
69     toCal.setTime(data.getToDateTime());
70     to = ISO8601.format(toCal);
71     
72     calendar = new StringBuilder(basePath).append(CALENDAR_URI).append(data.getCalendarId()).toString();
73     if (data.getEventCategoryId() != null) {
74       categories = new String[]{new StringBuilder(basePath).append(CATEGORY_URI).append(data.getEventCategoryId()).toString()};
75       categoryId = data.getEventCategoryId();
76     }
77     
78     if(data.getTaskDelegator() != null) delegation = data.getTaskDelegator().split(Utils.COLON);   
79     this.priority = data.getPriority(); 
80     if(data.getReminders() != null) reminder = data.getReminders().toArray(new Reminder[]{});
81     if(data.getAttachment() != null) {
82       List<String> atts = new LinkedList<String>();
83       
84       for (Attachment att : data.getAttachment()) {
85         AttachmentResource attRs = new AttachmentResource(att, basePath);
86         atts.add(attRs.getHref());
87       }
88       attachments = atts.toArray(new String[atts.size()]);
89     }
90      // Actually status is used in event state field
91     //status = data.getStatus();
92      status = data.getEventState();
93    }
94  
95    public String getName() {
96      return name;
97    }
98  
99    public void setName(String name) {
100     this.name = name;
101   }
102 
103   public String getNote() {
104     return note;
105   }
106 
107   public void setNote(String note) {
108     this.note = note;
109   }
110 
111   public String getFrom() {
112     return from;
113   }
114 
115   public void setFrom(String from) {
116     this.from = from;
117   }
118 
119   public String getTo() {
120     return to;
121   }
122 
123   public void setTo(String to) {
124     this.to = to;
125   }
126 
127   public Serializable getCalendar() {
128     return calendar;
129   }
130 
131   public TaskResource setCal(Serializable calendar) {
132     this.calendar = calendar;
133     return this;
134   }
135 
136   public Serializable[] getCategories() {
137     return categories;
138   }
139 
140   public void setCats(Serializable[] categories) {
141     this.categories = categories;
142   }
143 
144   public String[] getDelegation() {
145     return delegation;
146   }
147 
148   public void setDelegation(String[] delegation) {
149     this.delegation = delegation;
150   }
151 
152   public String getPriority() {
153     return priority;
154   }
155 
156   public void setPriority(String priority) {
157     this.priority = priority;
158   }
159 
160   public Reminder[] getReminder() {
161     return reminder;
162   }
163 
164   public void setReminder(Reminder[] reminder) {
165     this.reminder = reminder;
166   }
167 
168   public Serializable[] getAttachments() {
169     return attachments;
170   }
171 
172   public void setAtts(Serializable[] attachments) {
173     this.attachments = attachments;
174   }
175 
176   public String getStatus() {
177     return status;
178   }
179 
180   public void setStatus(String status) {
181     this.status = status;
182   }
183 
184   public String getCategoryId() {
185     return categoryId;
186   }
187 
188   public void setCategoryId(String categoryId) {
189     this.categoryId = categoryId;
190   }
191 }