Subversion Repositories XServices

Rev

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

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