Subversion Repositories XServices

Rev

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