Subversion Repositories XServices

Rev

Rev 34 | Rev 42 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 39
Line 17... Line 17...
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;
Line -... Line 21...
-
 
21
 
-
 
22
import java.util.Date;
21
 
23
import java.util.GregorianCalendar;
22
import java.util.List;
24
import java.util.List;
Line -... Line 25...
-
 
25
import java.util.Set;
-
 
26
 
-
 
27
import javax.xml.datatype.DatatypeConfigurationException;
-
 
28
import javax.xml.datatype.DatatypeFactory;
23
import java.util.Set;
29
import javax.xml.datatype.XMLGregorianCalendar;
24
 
30
 
25
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
31
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
26
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
32
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
27
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldAttributes;
33
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldAttributes;
28
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
34
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
29
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldValue;
35
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldValue;
-
 
36
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
-
 
37
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
30
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
38
import net.brutex.mylyn.sbmconnector.core.model.SBMSystemFields;
Line 31... Line 39...
31
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
39
import net.brutex.mylyn.sbmconnector.ui.SBMRepositorySettingsPage;
32
import net.brutex.sbm.wsclient.TTItem;
40
import net.brutex.sbm.wsclient.TTItem;
-
 
41
 
33
 
42
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.CoreException;
43
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IProgressMonitor;
44
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
36
import org.eclipse.mylyn.tasks.core.ITaskMapping;
45
import org.eclipse.mylyn.tasks.core.ITaskMapping;
37
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
46
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
Line 47... Line 56...
47
 */
56
 */
48
public class SBMTicketDataHandler extends AbstractTaskDataHandler {
57
public class SBMTicketDataHandler extends AbstractTaskDataHandler {
Line 49... Line 58...
49
 
58
 
50
	/** The connector. */
59
	/** The connector. */
51
	private final SBMRepositoryConnector connector;
60
	private final SBMRepositoryConnector connector;
52
	
61
 
53
	/**
62
	/**
54
	 * Instantiates a new SBM ticket data handler.
63
	 * Instantiates a new SBM ticket data handler.
-
 
64
	 * 
55
	 *
65
	 * @param connector
56
	 * @param connector the connector
66
	 *            the connector
57
	 */
67
	 */
58
	public SBMTicketDataHandler(SBMRepositoryConnector connector) {
68
	public SBMTicketDataHandler(SBMRepositoryConnector connector) {
59
		this.connector = connector;
69
		this.connector = connector;
60
	}
70
	}
-
 
71
 
61
	
72
	/*
-
 
73
	 * (non-Javadoc)
-
 
74
	 * 
62
	/* (non-Javadoc)
75
	 * @see
-
 
76
	 * org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper
63
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper(org.eclipse.mylyn.tasks.core.TaskRepository)
77
	 * (org.eclipse.mylyn.tasks.core.TaskRepository)
64
	 */
78
	 */
65
	@Override
79
	@Override
66
	public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) {
80
	public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) {
67
		return new SBMTicketAttributeMapper(taskRepository);
81
		return new SBMTicketAttributeMapper(taskRepository);
Line -... Line 82...
-
 
82
	}
68
	}
83
 
-
 
84
	/*
-
 
85
	 * (non-Javadoc)
-
 
86
	 * 
-
 
87
	 * @see
69
 
88
	 * org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#initializeTaskData
-
 
89
	 * (org.eclipse.mylyn.tasks.core.TaskRepository,
-
 
90
	 * org.eclipse.mylyn.tasks.core.data.TaskData,
70
	/* (non-Javadoc)
91
	 * org.eclipse.mylyn.tasks.core.ITaskMapping,
71
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#initializeTaskData(org.eclipse.mylyn.tasks.core.TaskRepository, org.eclipse.mylyn.tasks.core.data.TaskData, org.eclipse.mylyn.tasks.core.ITaskMapping, org.eclipse.core.runtime.IProgressMonitor)
92
	 * org.eclipse.core.runtime.IProgressMonitor)
72
	 */
93
	 */
73
	@Override
94
	@Override
74
	public boolean initializeTaskData(TaskRepository repository, TaskData taskData,
95
	public boolean initializeTaskData(TaskRepository repository,
75
			ITaskMapping initializationData, IProgressMonitor monitor)
-
 
76
			throws CoreException {
-
 
77
		
-
 
78
		/*TaskAttribute attribute = taskData.getRoot().createAttribute(SBMStaticFields.TITLE);
-
 
79
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_SHORT_TEXT).setLabel("Summary:");
-
 
80
 
-
 
81
		/*attribute = taskData.getRoot().createAttribute(SBMStaticFields.DESCRIPTION);
-
 
82
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_LONG_TEXT).setLabel("Description:");
-
 
83
 
-
 
84
		attribute = taskData.getRoot().createAttribute(SBMStaticFields.SUBMITDATE);
-
 
85
		attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_DATETIME).setLabel("Create Date:");
-
 
86
 
-
 
87
 
-
 
88
		  if (!taskData.isNew()) {
-
 
89
			attribute = taskData.getRoot().createAttribute(TaskAttribute.TASK_URL);
96
			TaskData taskData, ITaskMapping initializationData,
90
			attribute.getMetaData().setReadOnly(true).setKind(TaskAttribute.KIND_DEFAULT).setType(
-
 
91
					TaskAttribute.TYPE_URL).setLabel("Location:");
-
 
92
			File file = client.getTask(taskData.getTaskId(), monitor);
-
 
93
			try {
-
 
94
				attribute.setValue(file.toURI().toURL().toString());
-
 
95
			} catch (MalformedURLException e) {
-
 
96
			}
-
 
97
		}
-
 
98
 
-
 
99
		attribute = taskData.getRoot().createAttribute(TaskAttribute.PRODUCT);
-
 
100
		attribute.getMetaData().setReadOnly(false).setKind(TaskAttribute.KIND_DEFAULT).setType(
-
 
101
				TaskAttribute.TYPE_SINGLE_SELECT).setLabel("Project");
97
			IProgressMonitor monitor) throws CoreException {
102
				*/
98
		monitor.subTask("Initialising task ...");
103
		taskData.setPartial(true);
99
		taskData.setPartial(true);
Line -... Line 100...
-
 
100
		return true;
104
		return true;
101
	}
-
 
102
 
-
 
103
	/*
105
	}
104
	 * (non-Javadoc)
-
 
105
	 * 
-
 
106
	 * @see
-
 
107
	 * org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#postTaskData
106
 
108
	 * (org.eclipse.mylyn.tasks.core.TaskRepository,
107
	/* (non-Javadoc)
109
	 * org.eclipse.mylyn.tasks.core.data.TaskData, java.util.Set,
108
	 * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#postTaskData(org.eclipse.mylyn.tasks.core.TaskRepository, org.eclipse.mylyn.tasks.core.data.TaskData, java.util.Set, org.eclipse.core.runtime.IProgressMonitor)
110
	 * org.eclipse.core.runtime.IProgressMonitor)
109
	 */
111
	 */
110
	@Override
112
	@Override
111
	public RepositoryResponse postTaskData(TaskRepository repository,
113
	public RepositoryResponse postTaskData(TaskRepository repository,
112
			TaskData taskData, Set<TaskAttribute> oldAttributes,
114
			TaskData taskData, Set<TaskAttribute> oldAttributes,
113
			IProgressMonitor monitor) throws CoreException {
115
			IProgressMonitor monitor) throws CoreException {
114
		// TODO Auto-generated method stub
116
		// TODO Auto-generated method stub
115
		return null;
117
		return null;
116
	}
118
	}
117
	
119
 
-
 
120
	/**
118
	/**
121
	 * Convert.
-
 
122
	 * 
119
	 * Convert.
123
	 * @param repository
-
 
124
	 *            the repository
120
	 *
125
	 * @param ttitem
121
	 * @param repository the repository
126
	 *            the ttitem
-
 
127
	 * @param monitor
122
	 * @param ttitem the ttitem
128
	 *            the monitor
123
	 * @param monitor the monitor
129
	 * @return the task data
124
	 * @return the task data
130
	 * @throws CoreException
-
 
131
	 *             the core exception
125
	 * @throws CoreException the core exception
132
	 */
126
	 */
133
	public TaskData convert(TaskRepository repository, TTItem ttitem,
127
	public TaskData convert(TaskRepository repository, TTItem ttitem, IProgressMonitor monitor) 
134
			IProgressMonitor monitor, IRepositoryQuery query)
128
		throws CoreException {
135
			throws CoreException {
129
		SBMClient client = SBMRepositoryConnector.getClient(repository);
136
		SBMClient client = SBMRepositoryConnector.getClient(repository);
130
		TaskData data = new TaskData(new SBMTicketAttributeMapper(repository),
137
		TaskData data = new TaskData(new SBMTicketAttributeMapper(repository),
-
 
138
				SBMConnectorPlugin.CONNECTOR_KIND, repository
131
				SBMConnectorPlugin.CONNECTOR_KIND, 
139
						.getRepositoryUrl(), ttitem.getGenericItem().getValue()
-
 
140
						.getItemName().getValue()
132
				repository.getRepositoryUrl(), 
141
						+ " ["
-
 
142
						+ ttitem.getGenericItem().getValue().getItemID()
-
 
143
								.getValue() + "]");
-
 
144
		initializeTaskData(repository, data, null, monitor);
-
 
145
		String fieldlist = "";
-
 
146
		if (repository
-
 
147
				.hasProperty(SBMRepositorySettingsPage.STRING_TABLEFIELDLIST)) {
133
				ttitem.getGenericItem().getValue().getItemName().getValue()+" ["+
148
			fieldlist = repository
-
 
149
					.getProperty(SBMRepositorySettingsPage.STRING_TABLEFIELDLIST);
134
				ttitem.getGenericItem().getValue().getItemID().getValue()+"]");
150
		}
135
		initializeTaskData(repository, data, null, monitor);
151
		// Create Fields for all the generic SBM (system) fields
-
 
152
		monitor.subTask("Creating generic SBM fields...");
136
		// Create Fields for all the generic SBM (system) fields
153
		for (SBMSystemFields sysfield : SBMSystemFields.values()) {
137
		for (SBMTicketAttribute f : SBMTicketAttribute.values()) {
154
			if(!sysfield.hasTaskAttribute()) {
138
			TaskAttribute attr;
155
				// skip the field here, because we do not have a
139
			if(f.getTaskName()!=null) {
-
 
140
				attr = data.getRoot().createMappedAttribute(f.getTaskName());
156
				// matching task attribute to map. The field
-
 
157
				// will be processed in the custom field section
-
 
158
				continue;
-
 
159
			}
-
 
160
			if (!fieldlist.contains("," + sysfield.getValue() + ",")) {
-
 
161
				// do not process custom field when it has not
-
 
162
				// been selected by user in repository settings page
-
 
163
				continue;
-
 
164
			}
141
			} else {
165
			// try to initialize the SBM attribute
142
				attr = data.getRoot().createAttribute(f.getSBMName());
-
 
143
			}
166
			SBMTicketAttribute f = null;
144
			try {
167
			TaskAttribute attr = null;
-
 
168
			try {
-
 
169
				f = SBMTicketAttribute.valueOf(sysfield.getValue());
-
 
170
			} catch (IllegalArgumentException e) {
-
 
171
				// the field is a valid sbm system field and is set up to
-
 
172
				// have an equivalent in the task attributes. It must have an
-
 
173
				// entry in the SBMTicketAttribute class !
-
 
174
				continue; // we just skip the field 
145
				SBMStaticFields.valueOf(f.getSBMName()); //check if in static field list
175
			}
-
 
176
			
-
 
177
			if (f.getTaskName() != null) {
-
 
178
				attr = data.getRoot().createMappedAttribute(f.getTaskName());
-
 
179
			} else {
146
				attr.getMetaData().setReadOnly(true);
180
				// again the field is set up to have an task attribute
-
 
181
				// equivalent, but it is not set up in SBMAttributes correctly
-
 
182
				continue;
147
			} catch (IllegalArgumentException e) {
183
			}
148
				attr.getMetaData().setReadOnly(false);	
184
			
149
			}			
185
			attr.getMetaData().setReadOnly(true); //we do not support writing yet 
-
 
186
			attr.getMetaData().setType(f.getTaskType()); // set the mapped field type
150
			attr.getMetaData().setType(f.getTaskType());
187
			attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName())); // get and set the field label
151
			attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName()));
188
			if (f.isVisible()) {
-
 
189
				// field is not hidden, display it by setting KIND_DEFAULT
152
			if(f.isVisible()) {
190
				attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
153
				attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
191
			} else {
154
			} else {
-
 
155
				attr.getMetaData().setKind(null);
-
 
156
			}
-
 
157
			/*
-
 
158
			if(f.getTaskType()==TaskAttribute.TYPE_SINGLE_SELECT) {
-
 
159
				List<SBMFieldValue> options = 
-
 
160
					client.getValidSet(client.getTableName(ttitem), f.getSBMName());
-
 
161
				for( SBMFieldValue optionvalue: options) {
-
 
162
					attr.putOption(optionvalue.getValue(), optionvalue.getValue());
-
 
163
				}
-
 
Line -... Line 192...
-
 
192
				// field is hidden
164
			}
193
				attr.getMetaData().setKind(null);
-
 
194
			}
Line -... Line 195...
-
 
195
			
165
			*/
196
			attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName())); // get and set the field value
-
 
197
		}
166
			attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName()));
198
		monitor.worked(1);
-
 
199
		
167
			
200
		//--------------
168
		}
201
		// Custom fields
-
 
202
		//--------------
-
 
203
		List<SBMField> customfields = client.getFields(client
169
		
204
				.getTableName(ttitem));
170
		//Custom fields		
205
		for (SBMField f : customfields) {
-
 
206
			if (!fieldlist.contains("," + f.getName() + ",")) {
-
 
207
				// do not process custom field when it has not
-
 
208
				// been selected by user in repository settings page
-
 
209
				continue;
-
 
210
			}
-
 
211
			try {
-
 
212
				SBMSystemFields sysfield = SBMSystemFields.valueOf(f.getName());
-
 
213
				if( sysfield.hasTaskAttribute()) {
-
 
214
					// the field has an equivalent in the task attribute
-
 
215
					// mappings and therefore it can be skipped in the custom
-
 
216
					// fields section
-
 
217
					continue;
171
		List<SBMField> customfields = client.getFields(client.getTableName(ttitem));
218
				}
172
		for(SBMField f : customfields) {
219
			} catch (IllegalArgumentException e) {
173
			if(SBMTicketAttribute.getSBMAttributeBySBMName(f.getName())!=null) {
220
				//field is not a system field, do nothing
-
 
221
			}
174
				continue;
222
			monitor.subTask("Read custom field [" + f.getName() + "]");
175
			}
223
			TaskAttribute custom = data.getRoot().createAttribute(f.getName());
176
			TaskAttribute custom = data.getRoot().createAttribute(f.getName());
224
			custom.getMetaData().setType(
-
 
225
					new SBMTicketAttributeMapper(repository).mapToTaskKey(f
-
 
226
							.getType()));
-
 
227
			custom.getMetaData().setLabel(f.getLabel());
177
			custom.getMetaData().setType(
228
			custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
178
					new SBMTicketAttributeMapper(repository).mapToTaskKey(f.getType()));
229
			custom.getMetaData().setReadOnly(true);
179
			custom.getMetaData().setLabel(f.getLabel());
230
			
180
			custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
231
			//set value/ values depending on field type
181
			custom.getMetaData().setReadOnly(false);
232
			// single selection
182
			if(f.getType()==SBMFieldTypes.SELECTION &&
233
			if (f.getType() == SBMFieldTypes.SELECTION
-
 
234
					&& client.getFieldValue(ttitem, f.getName()) != null) {
183
					client.getFieldValue(ttitem, f.getName())!=null) {
235
				List<SBMFieldValue> options = client.getValidSet(client
184
				List<SBMFieldValue> options = 
236
						.getTableName(ttitem), f.getName());
-
 
237
				for (SBMFieldValue optionvalue : options) {
185
					client.getValidSet(client.getTableName(ttitem), f.getName());
238
					custom.putOption(optionvalue.getInternalValue(),
-
 
239
							optionvalue.getValue());
186
				for( SBMFieldValue optionvalue: options) {
240
				}
187
					custom.putOption(optionvalue.getInternalValue(), optionvalue.getValue());
241
				String val = client.getFieldValue(ttitem, f.getName())
188
				}
242
						.getValue();
189
				String val = client.getFieldValue(ttitem, f.getName()).getValue();
243
				custom.setValue(val);
190
				custom.setValue(val);
244
			// Multi-Type fields
-
 
245
			} else if (f.getType() == SBMFieldTypes.MULTIPLE_SELECTION
191
			} else if(f.getType()==SBMFieldTypes.MULTIPLE_SELECTION 
246
					|| f.getType() == SBMFieldTypes.MULTIPLE_RELATIONAL
192
					|| f.getType()==SBMFieldTypes.MULTIPLE_RELATIONAL
247
					|| f.getType() == SBMFieldTypes.MULTIPLE_GROUP
193
					|| f.getType()==SBMFieldTypes.MULTIPLE_GROUP
248
					|| f.getType() == SBMFieldTypes.MULTIPLE_USERGROUP) {
194
					|| f.getType()==SBMFieldTypes.MULTIPLE_USERGROUP) {
249
				List<SBMFieldValue> values = client.getFieldValues(ttitem, f
-
 
250
						.getName());
-
 
251
				for (SBMFieldValue val : values) {
-
 
252
					custom.putOption(val.getInternalValue(), val.getValue());
-
 
253
					custom.addValue(val.getValue());
-
 
254
				}
-
 
255
			//Date fields
-
 
256
			} else if (f.getType() == SBMFieldTypes.DATETIME) {
-
 
257
				String datestring = client.getFieldValue(ttitem, f.getName()).getValue();
-
 
258
				long timestamp;
-
 
259
				try {
-
 
260
					timestamp = DatatypeFactory.newInstance().newXMLGregorianCalendar(datestring).toGregorianCalendar().getTimeInMillis();
-
 
261
					custom.setValue(String.valueOf(timestamp));
-
 
262
				} catch (DatatypeConfigurationException e) {
-
 
263
					// TODO Auto-generated catch block
-
 
264
					e.printStackTrace();
-
 
265
				} catch (IllegalArgumentException e) {
195
				List<SBMFieldValue> values = client.getFieldValues(ttitem, f.getName());
266
					//date field is probably empty
196
				for(SBMFieldValue val : values) {
267
					custom.setValue("");
-
 
268
				}
197
					custom.putOption(val.getInternalValue(), val.getValue());
269
				
198
					custom.addValue(val.getValue());
270
			// any other field type
-
 
271
			} else if (client.getFieldValue(ttitem, f.getName()) != null) {
199
				}				
272
				custom.setValue(client.getFieldValue(ttitem, f.getName())
-
 
273
						.getValue());
200
			} else if(client.getFieldValue(ttitem, f.getName())!=null) {
274
			}
-
 
275
		}
-
 
276
		monitor.worked(1);
201
					custom.setValue(client.getFieldValue(ttitem, f.getName()).getValue());
277
 
202
			}
278
		// ----------
203
		}
279
		// Notes
204
		
280
		// ----------
205
		//Notes
281
		monitor.subTask("Read notes.");
206
		for(SBMNote n : client.getNotes(ttitem)) {
282
		for (SBMNote n : client.getNotes(ttitem)) {
207
			TaskCommentMapper mapper = new TaskCommentMapper();
283
			TaskCommentMapper mapper = new TaskCommentMapper();
-
 
284
			mapper.setCommentId(n.getId());
208
			mapper.setCommentId(n.getId());
285
			mapper.setNumber(Integer.valueOf(n.getId()));
209
			mapper.setNumber(Integer.valueOf(n.getId()));
286
			mapper.setText(n.getText());
210
			mapper.setText(n.getText());
287
			mapper.setCreationDate(n.getCreation());
-
 
288
 
211
			mapper.setCreationDate(n.getCreation());
289
			TaskAttribute a = data.getRoot()
212
			
290
					.createAttribute("NOTE" + n.getId());
213
			TaskAttribute a = data.getRoot().createAttribute("NOTE"+n.getId());
291
			mapper.applyTo(a);
214
			mapper.applyTo(a);
292
		}
215
		}
293
		monitor.worked(1);