Subversion Repositories XServices

Rev

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

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