Subversion Repositories XServices

Compare Revisions

No changes between revisions

Ignore whitespace Rev 30 → Rev 31

/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/SBMClient.java
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);
}
break;
}
}
return table_names;
return fields;
}
/**
* Gets the field value for custom defined field.
* (those from &lt;extendedFieldList&gt;)
*
* @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 &lt;extendedFieldList&gt;)
*
* @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;
}
}
/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/model/SBMFieldValue.java
0,0 → 1,20
package net.brutex.mylyn.sbmconnector.core.model;
 
public class SBMFieldValue {
private String internalValue;
private String value;
public SBMFieldValue(String internalValue, String value) {
this.internalValue = internalValue;
this.value = value;
}
public String getInternalValue() {
return internalValue;
}
public String getValue() {
return value;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/model/SBMField.java
0,0 → 1,139
/*
* Mylyn Connector for Serena Business Mashups
* Copyright 2010 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Serena, TeamTrack and Serena Business Mashup are
* registered trademarks of SERENA Software Inc.
*/
 
package net.brutex.mylyn.sbmconnector.core.model;
 
// TODO: Auto-generated Javadoc
/**
* The Class SBMField.
* @author Brian Rosenberger, bru@brutex.de
*/
public class SBMField {
/** The type. */
private SBMFieldTypes type;
/** The value. */
private String value;
/** The internal value. */
private Object internalValue;
/** The parent table. */
private String parentTable;
/** The label. */
private String label;
/** The name. */
private String name;
/**
* Instantiates a new SBM field.
*
* @param type the type
* @param parentTable the parent table
* @param label the label
* @param name the name
*/
public SBMField(SBMFieldTypes type, String parentTable, String label,
String name) {
super();
this.type = type;
this.parentTable = parentTable;
this.label = label;
this.name = name;
}
 
/**
* Gets the value.
*
* @return the value
*/
public String getValue() {
return value;
}
 
/**
* Sets the value.
*
* @param value the new value
*/
public void setValue(String value) {
this.value = value;
}
 
/**
* Gets the internal value.
*
* @return the internal value
*/
public Object getInternalValue() {
return internalValue;
}
 
/**
* Sets the internal value.
*
* @param internalValue the new internal value
*/
public void setInternalValue(Object internalValue) {
this.internalValue = internalValue;
}
 
/**
* Gets the type.
*
* @return the type
*/
public SBMFieldTypes getType() {
return type;
}
 
/**
* Gets the parent table.
*
* @return the parent table
*/
public String getParentTable() {
return parentTable;
}
 
/**
* Gets the label.
*
* @return the label
*/
public String getLabel() {
return label;
}
 
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/model/SBMFieldTypes.java
21,25 → 21,25
 
public enum SBMFieldTypes {
UNKNOWN("UNKNOWN"),
NUMERIC("NUMERIC"),
TEXT("TEXT"),
DATETIME("DATETIME"),
SELECTION("SELECTION"),
BINARY("BINARY"),
STATE("STATE"),
USER("USER"),
PROJECT("PROJECT"),
SUMMATION("SUMMATION"),
MULTIPLE_SELECTION("MULTIPLE-SELECTION"),
CONTACT("CONTACT"),
INCIDENT("INCIDENT"),
FOLDER("FOLDER"),
RELATIONAL("RELATIONAL"),
SUBRELATIONAL("SUBRELATIONAL"),
SYSTEM("SYSTEM"),
MULTIPLE_RELATIONAL("MULTIPLE-RELATIONAL"),
MULTIPLE_GROUP("MULTIPLE-GROUP"),
MULTIPLE_USERGROUP("MULTIPLE-USERGROUP");
NUMERIC("FLDTYPE-NUMERIC"),
TEXT("FLDTYPE-TEXT"),
DATETIME("FLDTYPE-DATETIME"),
SELECTION("FLDTYPE-SELECTION"),
BINARY("FLDTYPE-BINARY"),
STATE("FLDTYPE-STATE"),
USER("FLDTYPE-USER"),
PROJECT("FLDTYPE-PROJECT"),
SUMMATION("FLDTYPE-SUMMATION"),
MULTIPLE_SELECTION("FLDTYPE-MULTIPLE-SELECTION"),
CONTACT("FLDTYPE-CONTACT"),
INCIDENT("FLDTYPE-INCIDENT"),
FOLDER("FLDTYPE-FOLDER"),
RELATIONAL("FLDTYPE-RELATIONAL"),
SUBRELATIONAL("FLDTYPE-SUBRELATIONAL"),
SYSTEM("FLDTYPE-SYSTEM"),
MULTIPLE_RELATIONAL("FLDTYPE-MULTIPLE-RELATIONAL"),
MULTIPLE_GROUP("FLDTYPE-MULTIPLE-GROUP"),
MULTIPLE_USERGROUP("FLDTYPE-MULTIPLE-USERGROUP");
 
private final String value;
 
/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/SBMTicketAttribute.java
160,7 → 160,7
return this.visible;
}
public static SBMTicketAttribute getSBMAttributeByName(String sbm_fieldname) {
public static SBMTicketAttribute getSBMAttributeBySBMName(String sbm_fieldname) {
for (SBMTicketAttribute attribute : values()) {
if (sbm_fieldname.equals(attribute.getSBMName())) {
return attribute;
/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/SBMRepositoryConnector.java
189,6 → 189,12
public boolean canDeleteTask(TaskRepository repository, ITask task) {
return false;
}
@Override
public boolean hasRepositoryDueDate(TaskRepository taskRepository,
ITask task, TaskData taskData) {
// TODO Auto-generated method stub
return false;
}
 
}
/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/SBMTicketDataHandler.java
19,9 → 19,14
*/
package net.brutex.mylyn.sbmconnector.core;
 
import java.util.List;
import java.util.Set;
 
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldAttributes;
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.TTItem;
121,6 → 126,7
*/
public TaskData convert(TaskRepository repository, TTItem ttitem, IProgressMonitor monitor)
throws CoreException {
SBMClient client = SBMRepositoryConnector.getClient(repository);
TaskData data = new TaskData(new SBMTicketAttributeMapper(repository),
SBMConnectorPlugin.CONNECTOR_KIND,
repository.getRepositoryUrl(),
141,24 → 147,48
attr.getMetaData().setReadOnly(false);
}
attr.getMetaData().setType(f.getTaskType());
attr.getMetaData().setLabel(SBMRepositoryConnector.getClient(repository).getFieldLabel(ttitem, f.getSBMName()));
attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName()));
if(f.isVisible()) {
attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
} else {
attr.getMetaData().setKind(null);
}
attr.setValue(SBMRepositoryConnector.getClient(repository).getFieldValue(ttitem, f.getSBMName()));
attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName()));
}
//Custom fields
TaskAttribute custom = data.getRoot().createAttribute("BLIBLABLUB");
custom.getMetaData().setType(TaskAttribute.TYPE_BOOLEAN);
custom.getMetaData().setLabel("BIILLALLLLLLLL");
custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
custom.setValue("roger");
//Custom fields
List<SBMField> customfields = client.getFields(client.getTableName(ttitem));
for(SBMField f : customfields) {
if(SBMTicketAttribute.getSBMAttributeBySBMName(f.getName())!=null) {
continue;
}
TaskAttribute custom = data.getRoot().createAttribute(f.getName());
custom.getMetaData().setType(
new SBMTicketAttributeMapper(repository).mapToTaskKey(f.getType()));
custom.getMetaData().setLabel(f.getLabel());
custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT);
custom.getMetaData().setReadOnly(true);
if(f.getType()==SBMFieldTypes.SELECTION &&
client.getFieldValue(ttitem, f.getName())!=null) {
String val = client.getFieldValue(ttitem, f.getName()).getValue();
custom.putOption(val, val);
custom.setValue(val);
} else if(f.getType()==SBMFieldTypes.MULTIPLE_SELECTION
|| f.getType()==SBMFieldTypes.MULTIPLE_RELATIONAL
|| f.getType()==SBMFieldTypes.MULTIPLE_GROUP
|| f.getType()==SBMFieldTypes.MULTIPLE_USERGROUP) {
List<SBMFieldValue> values = client.getFieldValues(ttitem, f.getName());
for(SBMFieldValue val : values) {
custom.putOption(val.getInternalValue(), val.getValue());
custom.addValue(val.getValue());
}
} else if(client.getFieldValue(ttitem, f.getName())!=null) {
custom.setValue(client.getFieldValue(ttitem, f.getName()).getValue());
}
}
//Notes
for(SBMNote n : SBMRepositoryConnector.getClient(repository).getNotes(ttitem)) {
for(SBMNote n : client.getNotes(ttitem)) {
TaskCommentMapper mapper = new TaskCommentMapper();
mapper.setCommentId(n.getId());
mapper.setNumber(Integer.valueOf(n.getId()));
/sbm4mylyn/trunk/src/net/brutex/mylyn/sbmconnector/core/SBMTicketAttributeMapper.java
19,6 → 19,8
*/
package net.brutex.mylyn.sbmconnector.core;
 
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldTypes;
 
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
40,7 → 42,40
@Override
public TaskAttribute getAssoctiatedAttribute(TaskAttribute taskAttribute) {
// TODO Auto-generated method stub
return super.getAssoctiatedAttribute(taskAttribute);
}
/**
* Map SBM field type to task field type. This mapping is a hint only because
* SBM allows fields to have a type and subtype, but the subtype is not returned
* by the SBM web service.
*
* @param sbmtype the SBM field type (unfortunately without field subtype)
* @return the mylyn task field type
*/
public String mapToTaskKey(SBMFieldTypes sbmtype) {
String tasktype = TaskAttribute.TYPE_SHORT_TEXT;
switch(sbmtype) {
case NUMERIC: tasktype = TaskAttribute.TYPE_LONG; break;
case TEXT: tasktype = TaskAttribute.TYPE_LONG_TEXT; break;
case DATETIME: tasktype = TaskAttribute.TYPE_DATETIME; break;
case SELECTION: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
case BINARY: tasktype = TaskAttribute.TYPE_BOOLEAN; break;
case STATE: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
case USER: tasktype = TaskAttribute.TYPE_PERSON; break;
case PROJECT: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
case SUMMATION: tasktype = TaskAttribute.TYPE_INTEGER; break;
case MULTIPLE_SELECTION: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
case CONTACT: tasktype = TaskAttribute.TYPE_PERSON; break;
case INCIDENT: tasktype = TaskAttribute.TYPE_TASK_DEPENDENCY; break;
case FOLDER: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
case RELATIONAL: tasktype = TaskAttribute.TYPE_SINGLE_SELECT; break;
case SUBRELATIONAL: tasktype = TaskAttribute.TYPE_SHORT_TEXT; break;
case SYSTEM: tasktype = TaskAttribute.TYPE_SHORT_TEXT; break;
case MULTIPLE_RELATIONAL: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
case MULTIPLE_GROUP: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
case MULTIPLE_USERGROUP: tasktype = TaskAttribute.TYPE_MULTI_SELECT; break;
}
return tasktype;
}
}