KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > exchange > items > task > manager > TaskManager


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 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 General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.exchange.items.task.manager;
20
21 import java.io.IOException JavaDoc;
22
23 import sync4j.exchange.items.task.dao.TaskDAO;
24 import sync4j.exchange.items.task.model.Task;
25 import sync4j.exchange.DataAccessException;
26 import sync4j.exchange.xml.XmlParser;
27 import java.util.Date JavaDoc;
28
29 /*
30  * This class defines methods to access task data
31  * in exchange server datastore
32  *
33  * @author Fabio Maggi @ Funambol
34  * @version $Id: TaskManager.java,v 1.7 2005/07/22 13:21:26 nichele Exp $
35  *
36  **/

37 public class TaskManager {
38
39     //------------------------------------------------------------- Constants
40

41     //------------------------------------------------------------- Private Data
42

43     TaskDAO td = null ;
44
45     //------------------------------------------------------------- Costructor
46

47     public TaskManager(String JavaDoc exchangeServerHost ,
48                        int exchangeServerPort)
49         throws DataAccessException {
50
51         this.td = new TaskDAO (exchangeServerHost ,
52                                exchangeServerPort);
53
54     }
55
56     //------------------------------------------------------------- Public methods
57

58     /**
59      * get all tasks
60      *
61      * @param username
62      * @param credentials
63      * @param exchangeFolder
64      *
65      * @return array of find tasks
66      *
67      * @throws sync4j.exchange.util.DataAccessException
68      **/

69     public Task[] getAllTasks(String JavaDoc username ,
70                               String JavaDoc credentials ,
71                               String JavaDoc exchangeFolder )
72         throws DataAccessException {
73
74         return this.td.getTasks(username ,
75                                 credentials ,
76                                 new String JavaDoc[0] ,
77                                 exchangeFolder );
78     }
79
80     /**
81      * get tasks
82      *
83      * @param username
84      * @param credentials
85      * @param ids
86      * @param exchangeFolder
87      *
88      * @return array of find tasks
89      *
90      * @throws sync4j.exchange.util.DataAccessException
91      **/

92     public Task[] getTasks(String JavaDoc username ,
93                            String JavaDoc credentials ,
94                            String JavaDoc[] ids ,
95                            String JavaDoc exchangeFolder )
96         throws DataAccessException {
97
98          return this.td.getTasks(username ,
99                                  credentials ,
100                                  ids ,
101                                  exchangeFolder );
102
103     }
104
105     /**
106      * get task by id
107      *
108      * @param id
109      * @param username
110      * @param credentials
111      *
112      * @return find task
113      *
114      * @throws sync4j.exchange.util.DataAccessException
115      **/

116     public Task getTaskById(String JavaDoc username ,
117                             String JavaDoc credentials ,
118                             String JavaDoc id ,
119                             String JavaDoc exchangeFolder )
120         throws DataAccessException {
121
122         Task[] tasks = null;
123
124         tasks = this.td.getTasks(username ,
125                                  credentials ,
126                                  new String JavaDoc[] {id} ,
127                                  exchangeFolder );
128
129         if (tasks == null || !(tasks.length > 0)) {
130             return null;
131         }
132
133         return tasks[0];
134
135     }
136
137
138     /**
139      * get task twin
140      *
141      * @param task the task object
142      * @param username
143      * @param credentials
144      * @param exchangeFolder
145      *
146      * @return find contact
147      *
148      * @throws sync4j.exchange.util.DataAccessException
149      **/

150     public Task getTaskTwin(Task task,
151                             String JavaDoc username,
152                             String JavaDoc credentials,
153                             String JavaDoc exchangeFolder)
154     throws DataAccessException {
155
156         Task[] tasks = null;
157
158         String JavaDoc subject = null;
159         Date JavaDoc date = null;
160         Date JavaDoc dueDate = null;
161
162         try {
163
164             subject = task.getSubject();
165             date = task.getDate();
166             dueDate = task.getDueDate();
167
168         } catch (Exception JavaDoc e) {
169             throw new DataAccessException(e.getMessage());
170         }
171
172         String JavaDoc[] fields = {
173                           TaskDAO.TAG_SUBJECT,
174                           TaskDAO.TAG_DATE,
175                           TaskDAO.TAG_DUE_DATE
176         };
177
178         Object JavaDoc[] values = {
179                           subject,
180                           date,
181                           dueDate
182         };
183
184         tasks = this.td.getTasks(username,
185                                 credentials,
186                                 fields,
187                                 values,
188                                 exchangeFolder);
189
190         if (tasks == null || !(tasks.length > 0)) {
191             return null;
192         }
193
194         return tasks[0];
195     }
196
197     /**
198      * add / update task
199      *
200      * @param task
201      * @param username
202      * @param credentials
203      * @param exchangeFolder
204      *
205      * @return new tsk
206      *
207      * @throws sync4j.exchange.util.DataAccessException
208      **/

209     public Task setTask(Task task ,
210                         String JavaDoc username ,
211                         String JavaDoc credentials ,
212                         String JavaDoc exchangeFolder )
213         throws DataAccessException {
214
215         return this.td.setTask(task ,
216                                username ,
217                                credentials ,
218                                exchangeFolder );
219
220     }
221
222     /**
223      * remove task
224      *
225      * @param task
226      * @param username
227      * @param principal
228      * @param exchangeFolder
229      *
230      * @throws sync4j.exchange.util.DataAccessException
231      **/

232     public void removeTask(Task task ,
233                            String JavaDoc username ,
234                            String JavaDoc principal ,
235                            String JavaDoc exchangeFolder )
236         throws DataAccessException {
237
238         this.td.removeTask(task, username, principal, exchangeFolder);
239
240     }
241
242
243 }
244
Popular Tags