19,9 → 19,15 |
*/ |
package net.brutex.mylyn.sbmconnector.core; |
|
import java.util.Date; |
import java.util.GregorianCalendar; |
import java.util.List; |
import java.util.Set; |
|
import javax.xml.datatype.DatatypeConfigurationException; |
import javax.xml.datatype.DatatypeFactory; |
import javax.xml.datatype.XMLGregorianCalendar; |
|
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin; |
import net.brutex.mylyn.sbmconnector.core.model.SBMField; |
import net.brutex.mylyn.sbmconnector.core.model.SBMFieldAttributes; |
29,10 → 35,13 |
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.mylyn.sbmconnector.core.model.SBMSystemFields; |
import net.brutex.mylyn.sbmconnector.ui.SBMRepositorySettingsPage; |
import net.brutex.sbm.wsclient.TTItem; |
|
import org.eclipse.core.runtime.CoreException; |
import org.eclipse.core.runtime.IProgressMonitor; |
import org.eclipse.mylyn.tasks.core.IRepositoryQuery; |
import org.eclipse.mylyn.tasks.core.ITaskMapping; |
import org.eclipse.mylyn.tasks.core.RepositoryResponse; |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
53,14 → 62,19 |
/** |
* Instantiates a new SBM ticket data handler. |
* |
* @param connector the connector |
* @param connector |
* the connector |
*/ |
public SBMTicketDataHandler(SBMRepositoryConnector connector) { |
this.connector = connector; |
} |
|
/* (non-Javadoc) |
* @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper(org.eclipse.mylyn.tasks.core.TaskRepository) |
/* |
* (non-Javadoc) |
* |
* @see |
* org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper |
* (org.eclipse.mylyn.tasks.core.TaskRepository) |
*/ |
@Override |
public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) { |
67,45 → 81,33 |
return new SBMTicketAttributeMapper(taskRepository); |
} |
|
/* (non-Javadoc) |
* @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) |
/* |
* (non-Javadoc) |
* |
* @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) |
*/ |
@Override |
public boolean initializeTaskData(TaskRepository repository, TaskData taskData, |
ITaskMapping initializationData, IProgressMonitor monitor) |
throws CoreException { |
|
/*TaskAttribute attribute = taskData.getRoot().createAttribute(SBMStaticFields.TITLE); |
attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_SHORT_TEXT).setLabel("Summary:"); |
|
/*attribute = taskData.getRoot().createAttribute(SBMStaticFields.DESCRIPTION); |
attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_LONG_TEXT).setLabel("Description:"); |
|
attribute = taskData.getRoot().createAttribute(SBMStaticFields.SUBMITDATE); |
attribute.getMetaData().setReadOnly(false).setType(TaskAttribute.TYPE_DATETIME).setLabel("Create Date:"); |
|
|
if (!taskData.isNew()) { |
attribute = taskData.getRoot().createAttribute(TaskAttribute.TASK_URL); |
attribute.getMetaData().setReadOnly(true).setKind(TaskAttribute.KIND_DEFAULT).setType( |
TaskAttribute.TYPE_URL).setLabel("Location:"); |
File file = client.getTask(taskData.getTaskId(), monitor); |
try { |
attribute.setValue(file.toURI().toURL().toString()); |
} catch (MalformedURLException e) { |
} |
} |
|
attribute = taskData.getRoot().createAttribute(TaskAttribute.PRODUCT); |
attribute.getMetaData().setReadOnly(false).setKind(TaskAttribute.KIND_DEFAULT).setType( |
TaskAttribute.TYPE_SINGLE_SELECT).setLabel("Project"); |
*/ |
public boolean initializeTaskData(TaskRepository repository, |
TaskData taskData, ITaskMapping initializationData, |
IProgressMonitor monitor) throws CoreException { |
monitor.subTask("Initialising task ..."); |
taskData.setPartial(true); |
return true; |
} |
|
/* (non-Javadoc) |
* @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) |
/* |
* (non-Javadoc) |
* |
* @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) |
*/ |
@Override |
public RepositoryResponse postTaskData(TaskRepository repository, |
118,91 → 120,165 |
/** |
* Convert. |
* |
* @param repository the repository |
* @param ttitem the ttitem |
* @param monitor the monitor |
* @param repository |
* the repository |
* @param ttitem |
* the ttitem |
* @param monitor |
* the monitor |
* @return the task data |
* @throws CoreException the core exception |
* @throws CoreException |
* the core exception |
*/ |
public TaskData convert(TaskRepository repository, TTItem ttitem, IProgressMonitor monitor) |
public TaskData convert(TaskRepository repository, TTItem ttitem, |
IProgressMonitor monitor, IRepositoryQuery query) |
throws CoreException { |
SBMClient client = SBMRepositoryConnector.getClient(repository); |
TaskData data = new TaskData(new SBMTicketAttributeMapper(repository), |
SBMConnectorPlugin.CONNECTOR_KIND, |
repository.getRepositoryUrl(), |
ttitem.getGenericItem().getValue().getItemName().getValue()+" ["+ |
ttitem.getGenericItem().getValue().getItemID().getValue()+"]"); |
SBMConnectorPlugin.CONNECTOR_KIND, repository |
.getRepositoryUrl(), ttitem.getGenericItem().getValue() |
.getItemName().getValue() |
+ " [" |
+ ttitem.getGenericItem().getValue().getItemID() |
.getValue() + "]"); |
initializeTaskData(repository, data, null, monitor); |
String fieldlist = ""; |
if (repository |
.hasProperty(SBMRepositorySettingsPage.STRING_TABLEFIELDLIST)) { |
fieldlist = repository |
.getProperty(SBMRepositorySettingsPage.STRING_TABLEFIELDLIST); |
} |
// Create Fields for all the generic SBM (system) fields |
for (SBMTicketAttribute f : SBMTicketAttribute.values()) { |
TaskAttribute attr; |
monitor.subTask("Creating generic SBM fields..."); |
for (SBMSystemFields sysfield : SBMSystemFields.values()) { |
if(!sysfield.hasTaskAttribute()) { |
// skip the field here, because we do not have a |
// matching task attribute to map. The field |
// will be processed in the custom field section |
continue; |
} |
if (!fieldlist.contains("," + sysfield.getValue() + ",")) { |
// do not process custom field when it has not |
// been selected by user in repository settings page |
continue; |
} |
// try to initialize the SBM attribute |
SBMTicketAttribute f = null; |
TaskAttribute attr = null; |
try { |
f = SBMTicketAttribute.valueOf(sysfield.getValue()); |
} catch (IllegalArgumentException e) { |
// the field is a valid sbm system field and is set up to |
// have an equivalent in the task attributes. It must have an |
// entry in the SBMTicketAttribute class ! |
continue; // we just skip the field |
} |
|
if(f.getTaskName()!=null) { |
attr = data.getRoot().createMappedAttribute(f.getTaskName()); |
} else { |
attr = data.getRoot().createAttribute(f.getSBMName()); |
// again the field is set up to have an task attribute |
// equivalent, but it is not set up in SBMAttributes correctly |
continue; |
} |
try { |
SBMStaticFields.valueOf(f.getSBMName()); //check if in static field list |
attr.getMetaData().setReadOnly(true); |
} catch (IllegalArgumentException e) { |
attr.getMetaData().setReadOnly(false); |
} |
attr.getMetaData().setType(f.getTaskType()); |
attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName())); |
|
attr.getMetaData().setReadOnly(true); //we do not support writing yet |
attr.getMetaData().setType(f.getTaskType()); // set the mapped field type |
attr.getMetaData().setLabel(client.getFieldLabel(ttitem, f.getSBMName())); // get and set the field label |
if(f.isVisible()) { |
// field is not hidden, display it by setting KIND_DEFAULT |
attr.getMetaData().setKind(TaskAttribute.KIND_DEFAULT); |
} else { |
// field is hidden |
attr.getMetaData().setKind(null); |
} |
/* |
if(f.getTaskType()==TaskAttribute.TYPE_SINGLE_SELECT) { |
List<SBMFieldValue> options = |
client.getValidSet(client.getTableName(ttitem), f.getSBMName()); |
for( SBMFieldValue optionvalue: options) { |
attr.putOption(optionvalue.getValue(), optionvalue.getValue()); |
} |
} |
*/ |
attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName())); |
|
attr.setValue(client.getStaticFieldValue(ttitem, f.getSBMName())); // get and set the field value |
} |
monitor.worked(1); |
|
//-------------- |
//Custom fields |
List<SBMField> customfields = client.getFields(client.getTableName(ttitem)); |
//-------------- |
List<SBMField> customfields = client.getFields(client |
.getTableName(ttitem)); |
for(SBMField f : customfields) { |
if(SBMTicketAttribute.getSBMAttributeBySBMName(f.getName())!=null) { |
if (!fieldlist.contains("," + f.getName() + ",")) { |
// do not process custom field when it has not |
// been selected by user in repository settings page |
continue; |
} |
try { |
SBMSystemFields sysfield = SBMSystemFields.valueOf(f.getName()); |
if( sysfield.hasTaskAttribute()) { |
// the field has an equivalent in the task attribute |
// mappings and therefore it can be skipped in the custom |
// fields section |
continue; |
} |
} catch (IllegalArgumentException e) { |
//field is not a system field, do nothing |
} |
monitor.subTask("Read custom field [" + f.getName() + "]"); |
TaskAttribute custom = data.getRoot().createAttribute(f.getName()); |
custom.getMetaData().setType( |
new SBMTicketAttributeMapper(repository).mapToTaskKey(f.getType())); |
new SBMTicketAttributeMapper(repository).mapToTaskKey(f |
.getType())); |
custom.getMetaData().setLabel(f.getLabel()); |
custom.getMetaData().setKind(TaskAttribute.KIND_DEFAULT); |
custom.getMetaData().setReadOnly(false); |
if(f.getType()==SBMFieldTypes.SELECTION && |
client.getFieldValue(ttitem, f.getName())!=null) { |
List<SBMFieldValue> options = |
client.getValidSet(client.getTableName(ttitem), f.getName()); |
custom.getMetaData().setReadOnly(true); |
|
//set value/ values depending on field type |
// single selection |
if (f.getType() == SBMFieldTypes.SELECTION |
&& client.getFieldValue(ttitem, f.getName()) != null) { |
List<SBMFieldValue> options = client.getValidSet(client |
.getTableName(ttitem), f.getName()); |
for( SBMFieldValue optionvalue: options) { |
custom.putOption(optionvalue.getInternalValue(), optionvalue.getValue()); |
custom.putOption(optionvalue.getInternalValue(), |
optionvalue.getValue()); |
} |
String val = client.getFieldValue(ttitem, f.getName()).getValue(); |
String val = client.getFieldValue(ttitem, f.getName()) |
.getValue(); |
custom.setValue(val); |
// Multi-Type fields |
} 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()); |
List<SBMFieldValue> values = client.getFieldValues(ttitem, f |
.getName()); |
for(SBMFieldValue val : values) { |
custom.putOption(val.getInternalValue(), val.getValue()); |
custom.addValue(val.getValue()); |
} |
//Date fields |
} else if (f.getType() == SBMFieldTypes.DATETIME) { |
String datestring = client.getFieldValue(ttitem, f.getName()).getValue(); |
long timestamp; |
try { |
timestamp = DatatypeFactory.newInstance().newXMLGregorianCalendar(datestring).toGregorianCalendar().getTimeInMillis(); |
custom.setValue(String.valueOf(timestamp)); |
} catch (DatatypeConfigurationException e) { |
// TODO Auto-generated catch block |
e.printStackTrace(); |
} catch (IllegalArgumentException e) { |
//date field is probably empty |
custom.setValue(""); |
} |
|
// any other field type |
} else if(client.getFieldValue(ttitem, f.getName())!=null) { |
custom.setValue(client.getFieldValue(ttitem, f.getName()).getValue()); |
custom.setValue(client.getFieldValue(ttitem, f.getName()) |
.getValue()); |
} |
} |
monitor.worked(1); |
|
// ---------- |
//Notes |
// ---------- |
monitor.subTask("Read notes."); |
for(SBMNote n : client.getNotes(ttitem)) { |
TaskCommentMapper mapper = new TaskCommentMapper(); |
mapper.setCommentId(n.getId()); |
210,9 → 286,11 |
mapper.setText(n.getText()); |
mapper.setCreationDate(n.getCreation()); |
|
TaskAttribute a = data.getRoot().createAttribute("NOTE"+n.getId()); |
TaskAttribute a = data.getRoot() |
.createAttribute("NOTE" + n.getId()); |
mapper.applyTo(a); |
} |
monitor.worked(1); |
|
data.setPartial(false); |
return data; |