Subversion Repositories XServices

Rev

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

Rev 30 Rev 31
Line 30... Line 30...
30
 
30
 
31
import javax.xml.namespace.QName;
31
import javax.xml.namespace.QName;
Line 32... Line 32...
32
import javax.xml.ws.BindingProvider;
32
import javax.xml.ws.BindingProvider;
-
 
33
 
-
 
34
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
-
 
35
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
33
 
36
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
34
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
37
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldValue;
35
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
38
import net.brutex.mylyn.sbmconnector.core.model.SBMNote;
36
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
39
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields;
37
import net.brutex.sbm.wsclient.AEWebservicesFaultFault;
40
import net.brutex.sbm.wsclient.AEWebservicesFaultFault;
Line 43... Line 46...
43
import net.brutex.sbm.wsclient.Note;
46
import net.brutex.sbm.wsclient.Note;
44
import net.brutex.sbm.wsclient.ObjectFactory;
47
import net.brutex.sbm.wsclient.ObjectFactory;
45
import net.brutex.sbm.wsclient.TTItem;
48
import net.brutex.sbm.wsclient.TTItem;
46
import net.brutex.sbm.wsclient.TableData;
49
import net.brutex.sbm.wsclient.TableData;
47
import net.brutex.sbm.wsclient.TableType;
50
import net.brutex.sbm.wsclient.TableType;
-
 
51
import net.brutex.sbm.wsclient.Value;
Line 48... Line 52...
48
 
52
 
49
import org.eclipse.core.runtime.CoreException;
53
import org.eclipse.core.runtime.CoreException;
50
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
54
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
51
import org.eclipse.mylyn.commons.net.AuthenticationType;
55
import org.eclipse.mylyn.commons.net.AuthenticationType;
Line 122... Line 126...
122
		auth.setUserId(of.createAuthUserId(credentials.getUserName()));
126
		auth.setUserId(of.createAuthUserId(credentials.getUserName()));
123
		auth.setPassword(of.createAuthPassword(credentials.getPassword()));	
127
		auth.setPassword(of.createAuthPassword(credentials.getPassword()));	
124
		return auth;
128
		return auth;
125
	}
129
	}
Line -... Line 130...
-
 
130
 
-
 
131
	/**
-
 
132
	 * Gets the field value for a system generic field.
-
 
133
	 *
-
 
134
	 * @param ttitem the ttitem
-
 
135
	 * @param fieldname the fieldname
-
 
136
	 * @return the static field value
126
 
137
	 */
127
	public String getFieldValue(TTItem ttitem, String fieldname) {
138
	public String getStaticFieldValue(TTItem ttitem, String fieldname) {
128
		if(fieldname.equals(SBMStaticFields.SUBMITDATE.getValue())) {
139
		if(fieldname.equals(SBMStaticFields.SUBMITDATE.getValue())) {
129
			Date date = ttitem.getCreateDate().getValue().toGregorianCalendar().getTime();
140
			Date date = ttitem.getCreateDate().getValue().toGregorianCalendar().getTime();
130
			return String.valueOf(date.getTime());
141
			return String.valueOf(date.getTime());
131
		}
142
		}
Line 229... Line 240...
229
		}
240
		}
Line 230... Line 241...
230
 
241
 
231
		return "UNKNOWN";
242
		return "UNKNOWN";
Line 232... Line -...
232
	}
-
 
233
	
243
	}
234
	//Todo caching
-
 
-
 
244
	
235
	public String getFieldLabel(TTItem ttitem, String fieldname) {
245
	public String getFieldLabel(TTItem ttitem, String fieldname) {
236
		
246
		refreshTables();
237
		String itemid = ttitem.getGenericItem().getValue().getItemID().getValue();
-
 
238
		String tableid = new StringTokenizer(itemid, ":").nextToken();
-
 
239
		if (tables.isEmpty()) {
-
 
240
			try {
-
 
241
				tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE);
-
 
242
			} catch (AEWebservicesFaultFault e) {
-
 
243
				new CoreException(
-
 
244
						RepositoryStatus.createInternalError(
-
 
245
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
-
 
246
			}
247
		String itemid = ttitem.getGenericItem().getValue().getItemID().getValue();
247
		}
248
		String tableid = new StringTokenizer(itemid, ":").nextToken();
248
		for (TableData table : tables) {
249
		for (TableData table : tables) {
249
			if (String.valueOf(table.getTableID().intValue()).equals(tableid)) {
250
			if (String.valueOf(table.getTableID().intValue()).equals(tableid)) {
250
				Iterator<Field> iter = table.getFieldList().iterator();
251
				Iterator<Field> iter = table.getFieldList().iterator();
Line 258... Line 259...
258
			}
259
			}
259
		}
260
		}
260
	return "label_UNKNOWN";
261
	return "label_UNKNOWN";
261
	}
262
	}
Line -... Line 263...
-
 
263
	
-
 
264
	/**
-
 
265
	 * Gets the table database name.
-
 
266
	 *
-
 
267
	 * @param ttitem the ttitem
-
 
268
	 * @return the table name or null in case table is not found
-
 
269
	 */
-
 
270
	public String getTableName(TTItem ttitem) {
-
 
271
		refreshTables();
-
 
272
		String itemid = ttitem.getGenericItem().getValue().getItemID().getValue();
-
 
273
		String tableid = new StringTokenizer(itemid, ":").nextToken();
-
 
274
		for (TableData table : tables) {
-
 
275
			if (String.valueOf(table.getTableID().intValue()).equals(tableid)) {
-
 
276
				return table.getName().getValue();
-
 
277
			}
-
 
278
		}
-
 
279
		return null;
-
 
280
	}
262
	
281
	
263
	public List<SBMNote> getNotes(TTItem ttitem) {
282
	public List<SBMNote> getNotes(TTItem ttitem) {
264
		List<SBMNote> notes = new ArrayList<SBMNote>();
283
		List<SBMNote> notes = new ArrayList<SBMNote>();
265
		Iterator<Note> iter = ttitem.getNoteList().iterator();
284
		Iterator<Note> iter = ttitem.getNoteList().iterator();
266
		while(iter.hasNext()) {
285
		while(iter.hasNext()) {
Line 272... Line 291...
272
			notes.add(note);
291
			notes.add(note);
273
		}
292
		}
274
		return notes;
293
		return notes;
275
	}
294
	}
Line -... Line 295...
-
 
295
 
-
 
296
	
-
 
297
	/**
-
 
298
	 * Gets the names of all available primary tables.
-
 
299
	 * A table name is a unique reference within one SBM environment, thus can be
-
 
300
	 * used as a key.
-
 
301
	 *
-
 
302
	 * @return the primary table names as a list
276
 
303
	 */
-
 
304
	public List<String> getPrimaryTables() {
277
	public List<String> getPrimaryTables() {
305
		refreshTables();
-
 
306
		List<String> table_names = new ArrayList<String>();
-
 
307
		for (TableData table : tables) {
-
 
308
			table_names.add(table.getName().getValue());
-
 
309
		}
-
 
310
		return table_names;
-
 
311
	}
-
 
312
	
-
 
313
	/**
-
 
314
	 * Refresh table specifications from SBM web service. This
-
 
315
	 * is only done once per SBMClient instance.
-
 
316
	 */
278
		List<String> table_names = new ArrayList<String>();
317
	private void refreshTables() {
279
		if (tables.isEmpty()) {
318
		if (tables.isEmpty()) {
-
 
319
			try {
280
			try {
320
				//currently we limit this to primary tables
281
				tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE);
321
				tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE);
282
			} catch (AEWebservicesFaultFault e) {
322
			} catch (AEWebservicesFaultFault e) {
283
				new CoreException(
323
				new CoreException(
284
						RepositoryStatus.createInternalError(
324
						RepositoryStatus.createInternalError(
285
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
325
								SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e));
286
			}
326
			}
-
 
327
		}
-
 
328
	}
-
 
329
	
-
 
330
	/**
-
 
331
	 * Gets the fields for a primary table
-
 
332
	 *
-
 
333
	 * @param tablename the table database name
-
 
334
	 * @return the fields, empty when table does not exist
-
 
335
	 */
-
 
336
	public List<SBMField> getFields(String tablename) {
-
 
337
		refreshTables();
287
		}
338
		List<SBMField> fields = new ArrayList<SBMField>();
-
 
339
		for (TableData table : tables) {
-
 
340
			if(table.getName().getValue().equals(tablename)) {
-
 
341
				Iterator<Field> iter = table.getFieldList().iterator();
-
 
342
				while(iter.hasNext()) {
-
 
343
					Field f = iter.next();
-
 
344
					SBMField nf = new SBMField(
-
 
345
							SBMFieldTypes.fromValue(f.getFieldType().value()),
-
 
346
							tablename,
288
		for (TableData table : tables) {
347
							f.getDisplayName().getValue(),
-
 
348
							f.getName().getValue());
-
 
349
					fields.add(nf);
-
 
350
				}
-
 
351
				break;
289
			table_names.add(table.getName().getValue());
352
			}
-
 
353
		}
-
 
354
		return fields;
-
 
355
	}
-
 
356
	
-
 
357
	/**
-
 
358
	 * Gets the field value for custom defined field.
-
 
359
	 * (those from &lt;extendedFieldList&gt;)
-
 
360
	 *
-
 
361
	 * @param ttitem the ttitem
-
 
362
	 * @param fieldname the fieldname
-
 
363
	 * @return the field value or null if the field is not found
-
 
364
	 */
-
 
365
	public SBMFieldValue getFieldValue(TTItem ttitem, String fieldname) {
-
 
366
		SBMFieldValue value;
-
 
367
		Iterator<NameValue> fs = ttitem.getExtendedFieldList().iterator();
-
 
368
		while(fs.hasNext()) {
-
 
369
			NameValue nv = fs.next();
-
 
370
			if(nv.getName().getValue().equals(fieldname)) {
-
 
371
				if (nv.getValue()!=null && !nv.getValue().isNil()) {
-
 
372
					value = new SBMFieldValue(
-
 
373
							nv.getValue().getValue().getInternalValue().getValue(),
-
 
374
							nv.getValue().getValue().getDisplayValue().getValue());
-
 
375
					return value;
-
 
376
				}
-
 
377
			}
-
 
378
		}
-
 
379
		return null;
-
 
380
	}
-
 
381
	
-
 
382
	/**
-
 
383
	 * Gets the field values for custom defined, multi type field.
-
 
384
	 * (those from &lt;extendedFieldList&gt;)
-
 
385
	 *
-
 
386
	 * @param ttitem the ttitem
-
 
387
	 * @param fieldname the fieldname
-
 
388
	 * @return the list of field values
-
 
389
	 */
-
 
390
	public List<SBMFieldValue> getFieldValues(TTItem ttitem, String fieldname) {
-
 
391
		List<SBMFieldValue> values = new ArrayList<SBMFieldValue>();
-
 
392
		Iterator<NameValue> fs = ttitem.getExtendedFieldList().iterator();
-
 
393
		while(fs.hasNext()) {
-
 
394
			NameValue nv = fs.next();
-
 
395
			if(nv.getName().getValue().equals(fieldname)) {
-
 
396
				if (nv.getValues()!=null && !nv.getValues().isEmpty()) {
-
 
397
					Iterator<Value> nvv = nv.getValues().iterator();
-
 
398
					while(nvv.hasNext()) {
-
 
399
						Value nvv_value = nvv.next();			
-
 
400
						SBMFieldValue value = new SBMFieldValue(
-
 
401
							nvv_value.getInternalValue().getValue(),
-
 
402
							nvv_value.getDisplayValue().getValue());
-
 
403
						values.add(value);
-
 
404
					}
-
 
405
					return values;
-
 
406
				}
-
 
407
			}
290
		}
408
		}
291
		return table_names;
409
		return values;
292
	}
410
	}