Subversion Repositories XServices

Rev

Rev 31 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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);
39 brianR 152
			int countItem = client.getResultCount(getQueryTable(repository),
153
					query.getAttribute("sql_where"));
154
			monitor.beginTask("", countItem);
155
			monitor.subTask("Loading "+countItem+" items ...");
156
			List<TTItem> list = client.getTTItemsByTable(
157
					getQueryTable(repository), query.getAttribute("sql_where"),
158
					true);
159
			monitor.worked(1);
30 brianR 160
			for (TTItem ttitem : list) {
39 brianR 161
				TaskData data = datahandler.convert(repository, ttitem,
162
						monitor, query);
30 brianR 163
				collector.accept(data);
39 brianR 164
				monitor.worked(1);
165
				if(monitor.isCanceled()) return Status.CANCEL_STATUS;
30 brianR 166
			}
167
		} catch (CoreException e) {
39 brianR 168
			IStatus status =  new Status(IStatus.ERROR, SBMConnectorPlugin.PLUGIN_ID,
169
					e.getMessage(), e);
170
			//StatusManager.getManager().handle(status, StatusManager.BLOCK);
171
			return status;
30 brianR 172
		} finally {
173
			monitor.done();
174
		}
175
		return Status.OK_STATUS;
176
	}
177
 
178
	@Override
179
	public void updateRepositoryConfiguration(TaskRepository taskRepository,
180
			IProgressMonitor monitor) throws CoreException {
181
		// TODO Auto-generated method stub
182
 
183
	}
184
 
185
	@Override
186
	public void updateTaskFromTaskData(TaskRepository taskRepository,
187
			ITask task, TaskData taskData) {
188
		getTaskMapping(taskData).applyTo(task);
189
	}
190
 
191
	@Override
192
	public TaskMapper getTaskMapping(TaskData taskData) {
193
		return new TaskMapper(taskData);
194
	}
39 brianR 195
 
30 brianR 196
	@Override
197
	public AbstractTaskDataHandler getTaskDataHandler() {
198
		return datahandler;
199
	}
200
 
201
	@Override
202
	public boolean canDeleteTask(TaskRepository repository, ITask task) {
203
		return false;
204
	}
39 brianR 205
 
31 brianR 206
	@Override
207
	public boolean hasRepositoryDueDate(TaskRepository taskRepository,
208
			ITask task, TaskData taskData) {
209
		// TODO Auto-generated method stub
39 brianR 210
		return false;
31 brianR 211
	}
30 brianR 212
 
39 brianR 213
	private String getQueryTable(TaskRepository repository) {
214
		return repository
215
				.getProperty(SBMRepositorySettingsPage.STRING_SOLUTIONTABLE);
216
	}
217
 
30 brianR 218
}