Subversion Repositories XServices

Rev

Rev 34 | Rev 42 | Go to most recent revision | Show entire file | Regard 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 51... Line 60...
51
	private final SBMRepositoryConnector connector;
60
	private final SBMRepositoryConnector connector;
Line 52... Line 61...
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;
Line -... Line 70...
-
 
70
	}
60
	}
71
 
-
 
72
	/*
-
 
73
	 * (non-Javadoc)
61
	
74
	 * 
-
 
75
	 * @see
62
	/* (non-Javadoc)
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) {
Line -... Line 81...
-
 
81
		return new SBMTicketAttributeMapper(taskRepository);
67
		return new SBMTicketAttributeMapper(taskRepository);
82
	}
-
 
83
 
-
 
84
	/*
-
 
85
	 * (non-Javadoc)
-
 
86
	 * 
68
	}
87
	 * @see
-
 
88
	 * org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#initializeTaskData
-
 
89
	 * (org.eclipse.mylyn.tasks.core.TaskRepository,
69
 
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,
-
 
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()) {
95
	public boolean initializeTaskData(TaskRepository repository,
89
			attribute = taskData.getRoot().createAttribute(TaskAttribute.TASK_URL);
-
 
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(
96
			TaskData taskData, ITaskMapping initializationData,
101
				TaskAttribute.TYPE_SINGLE_SELECT).setLabel("Project");
97
			IProgressMonitor monitor) throws CoreException {
102
				*/
98
		monitor.subTask("Initialising task ...");
Line -... Line 99...
-
 
99
		taskData.setPartial(true);
103
		taskData.setPartial(true);
100
		return true;
-
 
101
	}
-
 
102
 
104
		return true;
103
	/*
-
 
104
	 * (non-Javadoc)
-
 
105
	 * 
-
 
106
	 * @see
105
	}
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
	 */
Line 116... Line 118...
116
	}
118
	}
Line 117... Line 119...
117
	
119
 
118
	/**
120
	/**
119
	 * Convert.
121
	 * Convert.
-
 
122
	 * 
120
	 *
123
	 * @param repository
-
 
124
	 *            the repository
121
	 * @param repository the repository
125
	 * @param ttitem
-
 
126
	 *            the ttitem
122
	 * @param ttitem the ttitem
127
	 * @param monitor
123
	 * @param monitor the monitor
128
	 *            the monitor
-
 
129
	 * @return the task data
124
	 * @return the task data
130
	 * @throws CoreException
125
	 * @throws CoreException the core exception
131
	 *             the core exception
126
	 */
132
	 */
-
 
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),
131
				SBMConnectorPlugin.CONNECTOR_KIND, 
138
				SBMConnectorPlugin.CONNECTOR_KIND, repository
132
				repository.getRepositoryUrl(), 
139
						.getRepositoryUrl(), ttitem.getGenericItem().getValue()
-
 
140
						.getItemName().getValue()
133
				ttitem.getGenericItem().getValue().getItemName().getValue()+" ["+
141
						+ " ["
-
 
142
						+ ttitem.getGenericItem().getValue().getItemID()
134
				ttitem.getGenericItem().getValue().getItemID().getValue()+"]");
143
								.getValue() + "]");
-
 
144
		initializeTaskData(repository, data, null, monitor);
-
 
145
		String fieldlist = "";
-
 
146
		if (repository
-
 
147
				.hasProperty(SBMRepositorySettingsPage.STRING_TABLEFIELDLIST)) {
-
 
148
			fieldlist = repository
-
 
149
					.getProperty(SBMRepositorySettingsPage.STRING_TABLEFIELDLIST);
135
		initializeTaskData(repository, data, null, monitor);
150
		}
-
 
151
		// Create Fields for all the generic SBM (system) fields
136
		// Create Fields for all the generic SBM (system) fields
152
		monitor.subTask("Creating generic SBM fields...");
137
		for (SBMTicketAttribute f : SBMTicketAttribute.values()) {
153
		for (SBMSystemFields sysfield : SBMSystemFields.values()) {
-
 
154
			if(!sysfield.hasTaskAttribute()) {
138
			TaskAttribute attr;
155
				// skip the field here, because we do not have a
139
			if(f.getTaskName()!=null) {
156
				// matching task attribute to map. The field
140
				attr = data.getRoot().createMappedAttribute(f.getTaskName());
157
				// will be processed in the custom field section
141
			} else {
-
 
142
				attr = data.getRoot().createAttribute(f.getSBMName());
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
			}
-
 
165
			// try to initialize the SBM attribute
-
 
166
			SBMTicketAttribute f = null;
143
			}
167
			TaskAttribute attr = null;
144
			try {
-
 
145
				SBMStaticFields.valueOf(f.getSBMName()); //check if in static field list
168
			try {
146
				attr.getMetaData().setReadOnly(true);
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 
-
 
175
			}
-
 
176
			
147
			} catch (IllegalArgumentException e) {
177
			if (f.getTaskName() != null) {
-
 
178
				attr = data.getRoot().createMappedAttribute(f.getTaskName());
-
 
179
			} else {
-
 
180
				// again the field is set up to have an task attribute
-
 
181
				// equivalent, but it is not set up in SBMAttributes correctly
148
				attr.getMetaData().setReadOnly(false);	
182
				continue;
-
 
183
			}
-
 
184
			
149
			}			
185
			attr.getMetaData().setReadOnly(true); //we do not support writing yet 
150
			attr.getMetaData().setType(f.getTaskType());
186
			attr.getMetaData().setType(f.getTaskType()); // set the mapped field type
151
			attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName()));
187
			attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName())); // get and set the field label
-
 
188
			if (f.isVisible()) {
152
			if(f.isVisible()) {
189
				// field is not hidden, display it by setting KIND_DEFAULT
153
				attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
190
				attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
-
 
191
			} else {
154
			} else {
192
				// field is hidden
155
				attr.getMetaData().setKind(null);
193
				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
				}
-
 
164
			}
-
 
165
			*/
-
 
Line -... Line 194...
-
 
194
			}
166
			attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName()));
195
			
-
 
196
			attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName())); // get and set the field value
Line -... Line 197...
-
 
197
		}
167
			
198
		monitor.worked(1);
-
 
199
		
168
		}
200
		//--------------
-
 
201
		// Custom fields
169
		
202
		//--------------
170
		//Custom fields		
203
		List<SBMField> customfields = client.getFields(client
-
 
204
				.getTableName(ttitem));
-
 
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()) {
171
		List<SBMField> customfields = client.getFields(client.getTableName(ttitem));
214
					// the field has an equivalent in the task attribute
172
		for(SBMField f : customfields) {
215
					// mappings and therefore it can be skipped in the custom
-
 
216
					// fields section
-
 
217
					continue;
-
 
218
				}
-
 
219
			} catch (IllegalArgumentException e) {
173
			if(SBMTicketAttribute.getSBMAttributeBySBMName(f.getName())!=null) {
220
				//field is not a system field, do nothing
174
				continue;
221
			}
175
			}
222
			monitor.subTask("Read custom field [" + f.getName() + "]");
-
 
223
			TaskAttribute custom = data.getRoot().createAttribute(f.getName());
176
			TaskAttribute custom = data.getRoot().createAttribute(f.getName());
224
			custom.getMetaData().setType(
177
			custom.getMetaData().setType(
225
					new SBMTicketAttributeMapper(repository).mapToTaskKey(f
178
					new SBMTicketAttributeMapper(repository).mapToTaskKey(f.getType()));
226
							.getType()));
-
 
227
			custom.getMetaData().setLabel(f.getLabel());
-
 
228
			custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
-
 
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
183
					client.getFieldValue(ttitem, f.getName())!=null) {
234
					&& client.getFieldValue(ttitem, f.getName()) != null) {
184
				List<SBMFieldValue> options = 
235
				List<SBMFieldValue> options = client.getValidSet(client
-
 
236
						.getTableName(ttitem), f.getName());
185
					client.getValidSet(client.getTableName(ttitem), f.getName());
237
				for (SBMFieldValue optionvalue : options) {
186
				for( SBMFieldValue optionvalue: options) {
238
					custom.putOption(optionvalue.getInternalValue(),
-
 
239
							optionvalue.getValue());
187
					custom.putOption(optionvalue.getInternalValue(), optionvalue.getValue());
240
				}
-
 
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
191
			} else if(f.getType()==SBMFieldTypes.MULTIPLE_SELECTION 
245
			} else if (f.getType() == SBMFieldTypes.MULTIPLE_SELECTION
192
					|| f.getType()==SBMFieldTypes.MULTIPLE_RELATIONAL
246
					|| 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
195
				List<SBMFieldValue> values = client.getFieldValues(ttitem, f.getName());
250
						.getName());
196
				for(SBMFieldValue val : values) {
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) {
-
 
266
					//date field is probably empty
-
 
267
					custom.setValue("");
197
					custom.putOption(val.getInternalValue(), val.getValue());
268
				}
198
					custom.addValue(val.getValue());
269
				
-
 
270
			// any other field type
199
				}				
271
			} else if (client.getFieldValue(ttitem, f.getName()) != null) {
200
			} else if(client.getFieldValue(ttitem, f.getName())!=null) {
272
				custom.setValue(client.getFieldValue(ttitem, f.getName())
-
 
273
						.getValue());
Line -... Line 274...
-
 
274
			}
201
					custom.setValue(client.getFieldValue(ttitem, f.getName()).getValue());
275
		}
-
 
276
		monitor.worked(1);
-
 
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();
Line -... Line 284...
-
 
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
 
Line 211... Line 289...
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
		}