Subversion Repositories XServices

Rev

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

Rev 39 Rev 42
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.SBMRepositoryQueryPage;
29
import net.brutex.mylyn.sbmconnector.ui.SBMRepositoryQueryPage;
30
import net.brutex.mylyn.sbmconnector.ui.SBMRepositorySettingsPage;
30
import net.brutex.mylyn.sbmconnector.ui.SBMRepositorySettingsPage;
31
import net.brutex.sbm.wsclient.TTItem;
31
import net.brutex.sbm.wsclient.TTItem;
32
 
32
 
33
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.IStatus;
36
import org.eclipse.core.runtime.Status;
36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.core.runtime.jobs.Job;
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;
48
import org.eclipse.ui.statushandlers.StatusManager;
49
 
49
 
50
public class SBMRepositoryConnector extends AbstractRepositoryConnector {
50
public class SBMRepositoryConnector extends AbstractRepositoryConnector {
51
 
51
 
52
	private SBMTicketDataHandler datahandler;
52
	private SBMTicketDataHandler datahandler;
53
	private static Map<TaskRepository, SBMClient> clients = new HashMap<TaskRepository, SBMClient>();
53
	private static Map<TaskRepository, SBMClient> clients = new HashMap<TaskRepository, SBMClient>();
54
 
54
 
55
	public SBMRepositoryConnector() {
55
	public SBMRepositoryConnector() {
56
		this.datahandler = new SBMTicketDataHandler(this);
56
		this.datahandler = new SBMTicketDataHandler(this);
57
	}
57
	}
58
 
58
 
59
	public static synchronized SBMClient getClient(TaskRepository repository) {
59
	public static synchronized SBMClient getClient(TaskRepository repository) {
60
		SBMClient client = clients.get(repository);
60
		SBMClient client = clients.get(repository);
61
		if (client == null) {
61
		if (client == null) {
62
			client = new SBMClient(repository);
62
			client = new SBMClient(repository);
63
			clients.put(repository, client);
63
			clients.put(repository, client);
64
		}
64
		}
65
		return client;
65
		return client;
66
	}
66
	}
67
 
67
 
68
	@Override
68
	@Override
69
	public boolean canCreateNewTask(TaskRepository repository) {
69
	public boolean canCreateNewTask(TaskRepository repository) {
70
		return false;
70
		return false;
71
	}
71
	}
72
 
72
 
73
	@Override
73
	@Override
74
	public boolean canCreateTaskFromKey(TaskRepository repository) {
74
	public boolean canCreateTaskFromKey(TaskRepository repository) {
75
		return false;
75
		return false;
76
	}
76
	}
77
 
77
 
78
	@Override
78
	@Override
79
	public boolean canSynchronizeTask(TaskRepository taskRepository, ITask task) {
79
	public boolean canSynchronizeTask(TaskRepository taskRepository, ITask task) {
80
		return true;
80
		return true;
81
	}
81
	}
82
 
82
 
83
	@Override
83
	@Override
84
	public String getConnectorKind() {
84
	public String getConnectorKind() {
85
		return SBMConnectorPlugin.CONNECTOR_KIND;
85
		return SBMConnectorPlugin.CONNECTOR_KIND;
86
	}
86
	}
87
 
87
 
88
	@Override
88
	@Override
89
	public String getLabel() {
89
	public String getLabel() {
90
		return SBMConnectorPlugin.LABEL;
90
		return SBMConnectorPlugin.LABEL;
91
	}
91
	}
92
 
92
 
93
	@Override
93
	@Override
94
	public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
94
	public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
95
		// TODO Auto-generated method stub
95
		// TODO Auto-generated method stub
96
		return null;
96
		return null;
97
	}
97
	}
98
 
98
 
99
	@Override
99
	@Override
100
	public TaskData getTaskData(TaskRepository taskRepository, String taskId,
100
	public TaskData getTaskData(TaskRepository taskRepository, String taskId,
101
			IProgressMonitor monitor) throws CoreException {
101
			IProgressMonitor monitor) throws CoreException {
102
		monitor.beginTask("Loading SBM Ticket", IProgressMonitor.UNKNOWN);
102
		monitor.beginTask("Loading SBM Ticket", IProgressMonitor.UNKNOWN);
103
		TaskData data = null;
103
		TaskData data = null;
104
		try {
104
		try {
105
			SBMClient client = getClient(taskRepository);
105
			SBMClient client = getClient(taskRepository);
106
			TTItem item = client.getTTItem(taskId);
106
			TTItem item = client.getTTItem(taskId);
107
			data = datahandler.convert(taskRepository, item, monitor, null);
107
			data = datahandler.convert(taskRepository, item, monitor, null);
108
 
108
 
109
		} finally {
109
		} finally {
110
			monitor.done();
110
			monitor.done();
111
		}
111
		}
112
		return data;
112
		return data;
113
	}
113
	}
114
 
114
 
115
	@Override
115
	@Override
116
	public String getTaskIdFromTaskUrl(String taskFullUrl) {
116
	public String getTaskIdFromTaskUrl(String taskFullUrl) {
117
		// TODO Auto-generated method stub
117
		// TODO Auto-generated method stub
118
		return null;
118
		return null;
119
	}
119
	}
120
 
120
 
121
	@Override
121
	@Override
122
	public String getTaskUrl(String repositoryUrl, String taskId) {
122
	public String getTaskUrl(String repositoryUrl, String taskId) {
123
		// TODO Auto-generated method stub
123
		// TODO Auto-generated method stub
124
		return null;
124
		return null;
125
	}
125
	}
126
 
126
 
127
	@Override
127
	@Override
128
	public boolean hasTaskChanged(TaskRepository taskRepository, ITask task,
128
	public boolean hasTaskChanged(TaskRepository taskRepository, ITask task,
129
			TaskData taskData) {
129
			TaskData taskData) {
130
		TaskAttribute attribute = taskData.getRoot().getAttribute(
130
		TaskAttribute attribute = taskData.getRoot().getAttribute(
131
				SBMStaticFields.LASTMODIFIEDDATE.getValue());
131
				SBMStaticFields.LASTMODIFIEDDATE.getValue());
132
		if (attribute != null) {
132
		if (attribute != null) {
133
			Date dataModificationDate = taskData.getAttributeMapper()
133
			Date dataModificationDate = taskData.getAttributeMapper()
134
					.getDateValue(attribute);
134
					.getDateValue(attribute);
135
			if (dataModificationDate != null) {
135
			if (dataModificationDate != null) {
136
				Date taskModificationDate = task.getModificationDate();
136
				Date taskModificationDate = task.getModificationDate();
137
				if (taskModificationDate != null) {
137
				if (taskModificationDate != null) {
138
					return !taskModificationDate.equals(dataModificationDate);
138
					return !taskModificationDate.equals(dataModificationDate);
139
				}
139
				}
140
			}
140
			}
141
		}
141
		}
142
		return true;
142
		return true;
143
	}
143
	}
144
 
144
 
145
	@Override
145
	@Override
146
	public IStatus performQuery(TaskRepository repository,
146
	public IStatus performQuery(TaskRepository repository,
147
			IRepositoryQuery query, TaskDataCollector collector,
147
			IRepositoryQuery query, TaskDataCollector collector,
148
			ISynchronizationSession session, IProgressMonitor monitor) {
148
			ISynchronizationSession session, IProgressMonitor monitor) {
149
			monitor.subTask("Calculating query result size ...");
149
			monitor.subTask("Calculating query result size ...");
150
		try {
150
		try {
151
			SBMClient client = new SBMClient(repository);
151
			SBMClient client = new SBMClient(repository);
152
			int countItem = client.getResultCount(getQueryTable(repository), 
152
			List<String> idlist = client.getResultCount(getQueryTable(repository), 
153
					query.getAttribute("sql_where"));
153
					query.getAttribute("sql_where"));
-
 
154
			int countItem = idlist.size();
154
			monitor.beginTask("", countItem);
155
			monitor.beginTask("", countItem);
155
			monitor.subTask("Loading "+countItem+" items ...");
156
			monitor.subTask("Loading "+countItem+" items ...");
-
 
157
			
156
			List<TTItem> list = client.getTTItemsByTable(
158
			//List<TTItem> list = client.getTTItemsByTable(
157
					getQueryTable(repository), query.getAttribute("sql_where"),
159
			//		getQueryTable(repository), query.getAttribute("sql_where"),
158
					true);
160
			//		true);
159
			monitor.worked(1);
161
			monitor.worked(1);
-
 
162
			int i = 1;
160
			for (TTItem ttitem : list) {
163
			for (String id : idlist) {
-
 
164
				if(id!=null) {
-
 
165
				monitor.subTask("Loading item "+i+"/"+countItem+" ...");
-
 
166
				TTItem ttitem = client.getTTItem("["+id+"]");
161
				TaskData data = datahandler.convert(repository, ttitem,
167
				TaskData data = datahandler.convert(repository, ttitem,
162
						monitor, query);
168
						monitor, query);
163
				collector.accept(data);
169
				collector.accept(data);
-
 
170
				}
164
				monitor.worked(1);
171
				monitor.worked(1);
165
				if(monitor.isCanceled()) return Status.CANCEL_STATUS;
172
				if(monitor.isCanceled()) return Status.CANCEL_STATUS;
-
 
173
				i++;
166
			}
174
			}
167
		} catch (CoreException e) {
175
		} catch (CoreException e) {
168
			IStatus status =  new Status(IStatus.ERROR, SBMConnectorPlugin.PLUGIN_ID,
176
			IStatus status =  new Status(IStatus.ERROR, SBMConnectorPlugin.PLUGIN_ID,
169
					e.getMessage(), e);
177
					e.getMessage(), e);
170
			//StatusManager.getManager().handle(status, StatusManager.BLOCK);
178
			//StatusManager.getManager().handle(status, StatusManager.BLOCK);
171
			return status;
179
			return status;
172
		} finally {
180
		} finally {
173
			monitor.done();
181
			monitor.done();
174
		}
182
		}
175
		return Status.OK_STATUS;
183
		return Status.OK_STATUS;
176
	}
184
	}
177
 
185
 
178
	@Override
186
	@Override
179
	public void updateRepositoryConfiguration(TaskRepository taskRepository,
187
	public void updateRepositoryConfiguration(TaskRepository taskRepository,
180
			IProgressMonitor monitor) throws CoreException {
188
			IProgressMonitor monitor) throws CoreException {
181
		// TODO Auto-generated method stub
189
		// TODO Auto-generated method stub
182
 
190
 
183
	}
191
	}
184
 
192
 
185
	@Override
193
	@Override
186
	public void updateTaskFromTaskData(TaskRepository taskRepository,
194
	public void updateTaskFromTaskData(TaskRepository taskRepository,
187
			ITask task, TaskData taskData) {
195
			ITask task, TaskData taskData) {
188
		getTaskMapping(taskData).applyTo(task);
196
		getTaskMapping(taskData).applyTo(task);
189
	}
197
	}
190
 
198
 
191
	@Override
199
	@Override
192
	public TaskMapper getTaskMapping(TaskData taskData) {
200
	public TaskMapper getTaskMapping(TaskData taskData) {
193
		return new TaskMapper(taskData);
201
		return new TaskMapper(taskData);
194
	}
202
	}
195
 
203
 
196
	@Override
204
	@Override
197
	public AbstractTaskDataHandler getTaskDataHandler() {
205
	public AbstractTaskDataHandler getTaskDataHandler() {
198
		return datahandler;
206
		return datahandler;
199
	}
207
	}
200
 
208
 
201
	@Override
209
	@Override
202
	public boolean canDeleteTask(TaskRepository repository, ITask task) {
210
	public boolean canDeleteTask(TaskRepository repository, ITask task) {
203
		return false;
211
		return false;
204
	}
212
	}
205
 
213
 
206
	@Override
214
	@Override
207
	public boolean hasRepositoryDueDate(TaskRepository taskRepository,
215
	public boolean hasRepositoryDueDate(TaskRepository taskRepository,
208
			ITask task, TaskData taskData) {
216
			ITask task, TaskData taskData) {
209
		// TODO Auto-generated method stub
217
		// TODO Auto-generated method stub
210
		return false;
218
		return false;
211
	}
219
	}
212
 
220
 
213
	private String getQueryTable(TaskRepository repository) {
221
	private String getQueryTable(TaskRepository repository) {
214
		return repository
222
		return repository
215
				.getProperty(SBMRepositorySettingsPage.STRING_SOLUTIONTABLE);
223
				.getProperty(SBMRepositorySettingsPage.STRING_SOLUTIONTABLE);
216
	}
224
	}
217
 
225
 
218
}
226
}