32,6 → 32,9 |
import javax.xml.ws.BindingProvider; |
|
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin; |
import net.brutex.mylyn.sbmconnector.core.model.SBMField; |
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes; |
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldValue; |
import net.brutex.mylyn.sbmconnector.core.model.SBMNote; |
import net.brutex.mylyn.sbmconnector.core.model.SBMStaticFields; |
import net.brutex.sbm.wsclient.AEWebservicesFaultFault; |
45,6 → 48,7 |
import net.brutex.sbm.wsclient.TTItem; |
import net.brutex.sbm.wsclient.TableData; |
import net.brutex.sbm.wsclient.TableType; |
import net.brutex.sbm.wsclient.Value; |
|
import org.eclipse.core.runtime.CoreException; |
import org.eclipse.mylyn.commons.net.AuthenticationCredentials; |
124,7 → 128,14 |
return auth; |
} |
|
public String getFieldValue(TTItem ttitem, String fieldname) { |
/** |
* Gets the field value for a system generic field. |
* |
* @param ttitem the ttitem |
* @param fieldname the fieldname |
* @return the static field value |
*/ |
public String getStaticFieldValue(TTItem ttitem, String fieldname) { |
if(fieldname.equals(SBMStaticFields.SUBMITDATE.getValue())) { |
Date date = ttitem.getCreateDate().getValue().toGregorianCalendar().getTime(); |
return String.valueOf(date.getTime()); |
231,20 → 242,10 |
return "UNKNOWN"; |
} |
|
//Todo caching |
public String getFieldLabel(TTItem ttitem, String fieldname) { |
|
refreshTables(); |
String itemid = ttitem.getGenericItem().getValue().getItemID().getValue(); |
String tableid = new StringTokenizer(itemid, ":").nextToken(); |
if (tables.isEmpty()) { |
try { |
tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE); |
} catch (AEWebservicesFaultFault e) { |
new CoreException( |
RepositoryStatus.createInternalError( |
SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e)); |
} |
} |
for (TableData table : tables) { |
if (String.valueOf(table.getTableID().intValue()).equals(tableid)) { |
Iterator<Field> iter = table.getFieldList().iterator(); |
260,6 → 261,24 |
return "label_UNKNOWN"; |
} |
|
/** |
* Gets the table database name. |
* |
* @param ttitem the ttitem |
* @return the table name or null in case table is not found |
*/ |
public String getTableName(TTItem ttitem) { |
refreshTables(); |
String itemid = ttitem.getGenericItem().getValue().getItemID().getValue(); |
String tableid = new StringTokenizer(itemid, ":").nextToken(); |
for (TableData table : tables) { |
if (String.valueOf(table.getTableID().intValue()).equals(tableid)) { |
return table.getName().getValue(); |
} |
} |
return null; |
} |
|
public List<SBMNote> getNotes(TTItem ttitem) { |
List<SBMNote> notes = new ArrayList<SBMNote>(); |
Iterator<Note> iter = ttitem.getNoteList().iterator(); |
274,10 → 293,31 |
return notes; |
} |
|
|
/** |
* Gets the names of all available primary tables. |
* A table name is a unique reference within one SBM environment, thus can be |
* used as a key. |
* |
* @return the primary table names as a list |
*/ |
public List<String> getPrimaryTables() { |
refreshTables(); |
List<String> table_names = new ArrayList<String>(); |
for (TableData table : tables) { |
table_names.add(table.getName().getValue()); |
} |
return table_names; |
} |
|
/** |
* Refresh table specifications from SBM web service. This |
* is only done once per SBMClient instance. |
*/ |
private void refreshTables() { |
if (tables.isEmpty()) { |
try { |
//currently we limit this to primary tables |
tables = port.getTables(getAuth(), null, TableType.PRIMARY_TABLE); |
} catch (AEWebservicesFaultFault e) { |
new CoreException( |
285,9 → 325,87 |
SBMConnectorPlugin.PLUGIN_ID, e.getFaultInfo(), e)); |
} |
} |
} |
|
/** |
* Gets the fields for a primary table |
* |
* @param tablename the table database name |
* @return the fields, empty when table does not exist |
*/ |
public List<SBMField> getFields(String tablename) { |
refreshTables(); |
List<SBMField> fields = new ArrayList<SBMField>(); |
for (TableData table : tables) { |
table_names.add(table.getName().getValue()); |
if(table.getName().getValue().equals(tablename)) { |
Iterator<Field> iter = table.getFieldList().iterator(); |
while(iter.hasNext()) { |
Field f = iter.next(); |
SBMField nf = new SBMField( |
SBMFieldTypes.fromValue(f.getFieldType().value()), |
tablename, |
f.getDisplayName().getValue(), |
f.getName().getValue()); |
fields.add(nf); |
} |
return table_names; |
break; |
} |
} |
return fields; |
} |
|
/** |
* Gets the field value for custom defined field. |
* (those from <extendedFieldList>) |
* |
* @param ttitem the ttitem |
* @param fieldname the fieldname |
* @return the field value or null if the field is not found |
*/ |
public SBMFieldValue getFieldValue(TTItem ttitem, String fieldname) { |
SBMFieldValue value; |
Iterator<NameValue> fs = ttitem.getExtendedFieldList().iterator(); |
while(fs.hasNext()) { |
NameValue nv = fs.next(); |
if(nv.getName().getValue().equals(fieldname)) { |
if (nv.getValue()!=null && !nv.getValue().isNil()) { |
value = new SBMFieldValue( |
nv.getValue().getValue().getInternalValue().getValue(), |
nv.getValue().getValue().getDisplayValue().getValue()); |
return value; |
} |
} |
} |
return null; |
} |
|
/** |
* Gets the field values for custom defined, multi type field. |
* (those from <extendedFieldList>) |
* |
* @param ttitem the ttitem |
* @param fieldname the fieldname |
* @return the list of field values |
*/ |
public List<SBMFieldValue> getFieldValues(TTItem ttitem, String fieldname) { |
List<SBMFieldValue> values = new ArrayList<SBMFieldValue>(); |
Iterator<NameValue> fs = ttitem.getExtendedFieldList().iterator(); |
while(fs.hasNext()) { |
NameValue nv = fs.next(); |
if(nv.getName().getValue().equals(fieldname)) { |
if (nv.getValues()!=null && !nv.getValues().isEmpty()) { |
Iterator<Value> nvv = nv.getValues().iterator(); |
while(nvv.hasNext()) { |
Value nvv_value = nvv.next(); |
SBMFieldValue value = new SBMFieldValue( |
nvv_value.getInternalValue().getValue(), |
nvv_value.getDisplayValue().getValue()); |
values.add(value); |
} |
return values; |
} |
} |
} |
return values; |
} |
} |