Subversion Repositories XServices

Rev

Rev 42 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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