30 |
brianR |
1 |
/*
|
|
|
2 |
* Mylyn Connector for Serena Business Mashups
|
|
|
3 |
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
|
|
4 |
*
|
|
|
5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
6 |
* you may not use this file except in compliance with the License.
|
|
|
7 |
* You may obtain a copy of the License at
|
|
|
8 |
*
|
|
|
9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
10 |
*
|
|
|
11 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
14 |
* See the License for the specific language governing permissions and
|
|
|
15 |
* limitations under the License.
|
|
|
16 |
*
|
|
|
17 |
* Serena, TeamTrack and Serena Business Mashup are
|
|
|
18 |
* registered trademarks of SERENA Software Inc.
|
|
|
19 |
*/
|
|
|
20 |
package net.brutex.mylyn.sbmconnector.core;
|
|
|
21 |
|
|
|
22 |
import java.util.Date;
|
|
|
23 |
import java.util.HashMap;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
import java.util.Map;
|
|
|
26 |
|
|
|
27 |
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
|
|
|
28 |
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
|
39 |
brianR |
29 |
import net.brutex.mylyn.sbmconnector.ui.SBMRepositoryQueryPage;
|
|
|
30 |
import net.brutex.mylyn.sbmconnector.ui.SBMRepositorySettingsPage;
|
30 |
brianR |
31 |
import net.brutex.sbm.wsclient.TTItem;
|
|
|
32 |
|
|
|
33 |
import org.eclipse.core.runtime.CoreException;
|
|
|
34 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
|
35 |
import org.eclipse.core.runtime.IStatus;
|
|
|
36 |
import org.eclipse.core.runtime.Status;
|
39 |
brianR |
37 |
import org.eclipse.core.runtime.jobs.Job;
|
30 |
brianR |
38 |
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
|
|
|
39 |
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
|
|
|
40 |
import org.eclipse.mylyn.tasks.core.ITask;
|
|
|
41 |
import org.eclipse.mylyn.tasks.core.TaskRepository;
|
|
|
42 |
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
|
|
|
43 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
|
|
|
44 |
import org.eclipse.mylyn.tasks.core.data.TaskData;
|
|
|
45 |
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
|
|
|
46 |
import org.eclipse.mylyn.tasks.core.data.TaskMapper;
|
|
|
47 |
import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
|
39 |
brianR |
48 |
import org.eclipse.ui.statushandlers.StatusManager;
|
30 |
brianR |
49 |
|
|
|
50 |
public class SBMRepositoryConnector extends AbstractRepositoryConnector {
|
|
|
51 |
|
|
|
52 |
private SBMTicketDataHandler datahandler;
|
|
|
53 |
private static Map<TaskRepository, SBMClient> clients = new HashMap<TaskRepository, SBMClient>();
|
|
|
54 |
|
|
|
55 |
public SBMRepositoryConnector() {
|
|
|
56 |
this.datahandler = new SBMTicketDataHandler(this);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public static synchronized SBMClient getClient(TaskRepository repository) {
|
|
|
60 |
SBMClient client = clients.get(repository);
|
|
|
61 |
if (client == null) {
|
|
|
62 |
client = new SBMClient(repository);
|
|
|
63 |
clients.put(repository, client);
|
|
|
64 |
}
|
|
|
65 |
return client;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
@Override
|
|
|
69 |
public boolean canCreateNewTask(TaskRepository repository) {
|
|
|
70 |
return false;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
@Override
|
|
|
74 |
public boolean canCreateTaskFromKey(TaskRepository repository) {
|
|
|
75 |
return false;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
public boolean canSynchronizeTask(TaskRepository taskRepository, ITask task) {
|
|
|
80 |
return true;
|
|
|
81 |
}
|
39 |
brianR |
82 |
|
30 |
brianR |
83 |
@Override
|
|
|
84 |
public String getConnectorKind() {
|
|
|
85 |
return SBMConnectorPlugin.CONNECTOR_KIND;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
@Override
|
|
|
89 |
public String getLabel() {
|
|
|
90 |
return SBMConnectorPlugin.LABEL;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
@Override
|
|
|
94 |
public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
|
|
|
95 |
// TODO Auto-generated method stub
|
|
|
96 |
return null;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
@Override
|
|
|
100 |
public TaskData getTaskData(TaskRepository taskRepository, String taskId,
|
|
|
101 |
IProgressMonitor monitor) throws CoreException {
|
|
|
102 |
monitor.beginTask("Loading SBM Ticket", IProgressMonitor.UNKNOWN);
|
|
|
103 |
TaskData data = null;
|
|
|
104 |
try {
|
|
|
105 |
SBMClient client = getClient(taskRepository);
|
|
|
106 |
TTItem item = client.getTTItem(taskId);
|
39 |
brianR |
107 |
data = datahandler.convert(taskRepository, item, monitor, null);
|
30 |
brianR |
108 |
|
|
|
109 |
} finally {
|
|
|
110 |
monitor.done();
|
|
|
111 |
}
|
|
|
112 |
return data;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
@Override
|
|
|
116 |
public String getTaskIdFromTaskUrl(String taskFullUrl) {
|
|
|
117 |
// TODO Auto-generated method stub
|
|
|
118 |
return null;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
@Override
|
|
|
122 |
public String getTaskUrl(String repositoryUrl, String taskId) {
|
|
|
123 |
// TODO Auto-generated method stub
|
|
|
124 |
return null;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
@Override
|
|
|
128 |
public boolean hasTaskChanged(TaskRepository taskRepository, ITask task,
|
|
|
129 |
TaskData taskData) {
|
|
|
130 |
TaskAttribute attribute = taskData.getRoot().getAttribute(
|
|
|
131 |
SBMStaticFields.LASTMODIFIEDDATE.getValue());
|
|
|
132 |
if (attribute != null) {
|
|
|
133 |
Date dataModificationDate = taskData.getAttributeMapper()
|
|
|
134 |
.getDateValue(attribute);
|
|
|
135 |
if (dataModificationDate != null) {
|
|
|
136 |
Date taskModificationDate = task.getModificationDate();
|
|
|
137 |
if (taskModificationDate != null) {
|
|
|
138 |
return !taskModificationDate.equals(dataModificationDate);
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
return true;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
@Override
|
|
|
146 |
public IStatus performQuery(TaskRepository repository,
|
|
|
147 |
IRepositoryQuery query, TaskDataCollector collector,
|
|
|
148 |
ISynchronizationSession session, IProgressMonitor monitor) {
|
39 |
brianR |
149 |
monitor.subTask("Calculating query result size ...");
|
30 |
brianR |
150 |
try {
|
|
|
151 |
SBMClient client = new SBMClient(repository);
|
42 |
brianR |
152 |
List<String> idlist = client.getResultCount(getQueryTable(repository),
|
39 |
brianR |
153 |
query.getAttribute("sql_where"));
|
42 |
brianR |
154 |
int countItem = idlist.size();
|
39 |
brianR |
155 |
monitor.beginTask("", countItem);
|
|
|
156 |
monitor.subTask("Loading "+countItem+" items ...");
|
42 |
brianR |
157 |
|
|
|
158 |
//List<TTItem> list = client.getTTItemsByTable(
|
|
|
159 |
// getQueryTable(repository), query.getAttribute("sql_where"),
|
|
|
160 |
// true);
|
39 |
brianR |
161 |
monitor.worked(1);
|
42 |
brianR |
162 |
int i = 1;
|
|
|
163 |
for (String id : idlist) {
|
|
|
164 |
if(id!=null) {
|
|
|
165 |
monitor.subTask("Loading item "+i+"/"+countItem+" ...");
|
|
|
166 |
TTItem ttitem = client.getTTItem("["+id+"]");
|
39 |
brianR |
167 |
TaskData data = datahandler.convert(repository, ttitem,
|
|
|
168 |
monitor, query);
|
30 |
brianR |
169 |
collector.accept(data);
|
42 |
brianR |
170 |
}
|
39 |
brianR |
171 |
monitor.worked(1);
|
|
|
172 |
if(monitor.isCanceled()) return Status.CANCEL_STATUS;
|
42 |
brianR |
173 |
i++;
|
30 |
brianR |
174 |
}
|
|
|
175 |
} catch (CoreException e) {
|
39 |
brianR |
176 |
IStatus status = new Status(IStatus.ERROR, SBMConnectorPlugin.PLUGIN_ID,
|
|
|
177 |
e.getMessage(), e);
|
|
|
178 |
//StatusManager.getManager().handle(status, StatusManager.BLOCK);
|
|
|
179 |
return status;
|
30 |
brianR |
180 |
} finally {
|
|
|
181 |
monitor.done();
|
|
|
182 |
}
|
|
|
183 |
return Status.OK_STATUS;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
@Override
|
|
|
187 |
public void updateRepositoryConfiguration(TaskRepository taskRepository,
|
|
|
188 |
IProgressMonitor monitor) throws CoreException {
|
|
|
189 |
// TODO Auto-generated method stub
|
|
|
190 |
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
@Override
|
|
|
194 |
public void updateTaskFromTaskData(TaskRepository taskRepository,
|
|
|
195 |
ITask task, TaskData taskData) {
|
|
|
196 |
getTaskMapping(taskData).applyTo(task);
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
@Override
|
|
|
200 |
public TaskMapper getTaskMapping(TaskData taskData) {
|
|
|
201 |
return new TaskMapper(taskData);
|
|
|
202 |
}
|
39 |
brianR |
203 |
|
30 |
brianR |
204 |
@Override
|
|
|
205 |
public AbstractTaskDataHandler getTaskDataHandler() {
|
|
|
206 |
return datahandler;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
@Override
|
|
|
210 |
public boolean canDeleteTask(TaskRepository repository, ITask task) {
|
|
|
211 |
return false;
|
|
|
212 |
}
|
39 |
brianR |
213 |
|
31 |
brianR |
214 |
@Override
|
|
|
215 |
public boolean hasRepositoryDueDate(TaskRepository taskRepository,
|
|
|
216 |
ITask task, TaskData taskData) {
|
|
|
217 |
// TODO Auto-generated method stub
|
39 |
brianR |
218 |
return false;
|
31 |
brianR |
219 |
}
|
30 |
brianR |
220 |
|
39 |
brianR |
221 |
private String getQueryTable(TaskRepository repository) {
|
|
|
222 |
return repository
|
|
|
223 |
.getProperty(SBMRepositorySettingsPage.STRING_SOLUTIONTABLE);
|
|
|
224 |
}
|
|
|
225 |
|
30 |
brianR |
226 |
}
|