Search in sources :

Example 31 with TaskAttribute

use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.

the class OSIORestConfiguration method updateInitialTaskData.

public void updateInitialTaskData(TaskData data) throws CoreException {
    setSpaceOptions(data, getSpaces());
    updateSpaceOptions(data);
    for (String key : data.getRoot().getAttributes().keySet()) {
        if (key.equals(OSIORestTaskSchema.getDefault().NEW_COMMENT.getKey()) || key.equals(TaskAttribute.OPERATION) || key.equals(OSIORestTaskSchema.getDefault().DATE_MODIFICATION.getKey())) {
            continue;
        }
        TaskAttribute attribute = data.getRoot().getAttribute(key);
        if (key.equals(OSIORestTaskSchema.getDefault().STATUS.getKey())) {
            if (attribute.getOptions().isEmpty()) {
                for (String status : statusValues) {
                    attribute.putOption(status, status);
                }
            }
        }
        if (key.equals(OSIORestTaskSchema.getDefault().ASSIGNEES.getKey())) {
            if (attribute.getOptions().isEmpty()) {
                attribute.putOption(userName, userName);
            }
            continue;
        }
        if (!key.equals(SCHEMA.SPACE.getKey())) {
            String configName = mapTaskAttributeKey2ConfigurationFields(key);
            if (configName.equals("baseType")) {
                if (attribute.getOptions().size() == 1 && attribute.getValue().isEmpty()) {
                    attribute.setValue((String) attribute.getOptions().values().toArray()[0]);
                }
            }
        }
    }
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute)

Example 32 with TaskAttribute

use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.

the class OSIORestConnector method updateTaskFromTaskData.

@Override
public void updateTaskFromTaskData(TaskRepository taskRepository, ITask task, TaskData taskData) {
    TaskMapper scheme = getTaskMapping(taskData);
    scheme.applyTo(task);
    task.setUrl(taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().TASK_URL.getKey()).getValue());
    boolean isComplete = false;
    TaskAttribute attributeStatus = taskData.getRoot().getMappedAttribute(TaskAttribute.STATUS);
    if (attributeStatus != null) {
        String statusValue = attributeStatus.getValue();
        isComplete = (statusValue.equals(IOSIORestConstants.RESOLVED) || statusValue.equals(IOSIORestConstants.CLOSED));
    }
    if (taskData.isPartial()) {
        if (isComplete) {
            if (task.getCompletionDate() == null) {
                task.setCompletionDate(new Date(0));
            }
        } else {
            task.setCompletionDate(null);
        }
    } else {
        inferCompletionDate(task, taskData, scheme, isComplete);
    }
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) Date(java.util.Date) TaskMapper(org.eclipse.mylyn.tasks.core.data.TaskMapper)

Example 33 with TaskAttribute

use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.

the class OSIORestConnector method hasTaskChanged.

@Override
public boolean hasTaskChanged(TaskRepository taskRepository, ITask task, TaskData taskData) {
    String lastKnownLocalModValue = task.getAttribute(OSIORestTaskSchema.getDefault().DATE_MODIFICATION.getKey());
    TaskAttribute latestRemoteModAttribute = taskData.getRoot().getMappedAttribute(TaskAttribute.DATE_MODIFICATION);
    String latestRemoteModValue = latestRemoteModAttribute != null ? latestRemoteModAttribute.getValue() : null;
    return !Objects.equal(latestRemoteModValue, lastKnownLocalModValue);
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute)

Example 34 with TaskAttribute

use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.

the class OSIORestTaskAttributeMapper method getOptions.

@Override
public Map<String, String> getOptions(@NonNull TaskAttribute attribute) {
    OSIORestTaskSchema taskSchema = OSIORestTaskSchema.getDefault();
    if (attribute.getId().equals(taskSchema.WORKITEM_TYPE.getKey()) || attribute.getId().equals(taskSchema.AREA.getKey()) || attribute.getId().equals(taskSchema.ASSIGNEES.getKey()) || attribute.getId().equals(taskSchema.STATUS.getKey()) || attribute.getId().equals(taskSchema.ITERATION.getKey())) {
        TaskAttribute spaceIdAttribute = attribute.getParentAttribute().getAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey());
        TaskAttribute spaceAttribute = attribute.getParentAttribute().getAttribute(OSIORestCreateTaskSchema.getDefault().SPACE.getKey());
        OSIORestConfiguration repositoryConfiguration;
        try {
            repositoryConfiguration = connector.getRepositoryConfiguration(this.getTaskRepository());
            // TODO: change this when we have offline cache for the repository configuration so we build the options in an temp var
            if (repositoryConfiguration != null) {
                if (spaceIdAttribute != null && !spaceIdAttribute.getValue().equals("")) {
                    // $NON-NLS-1$
                    attribute.clearOptions();
                    for (String spaceId : spaceIdAttribute.getValues()) {
                        Space actualSpace = connector.getClient(getTaskRepository()).getSpaceById(spaceId, getTaskRepository());
                        internalSetAttributeOptions4Space(attribute, actualSpace.getMapFor(attribute.getId()));
                    }
                } else {
                    attribute.clearOptions();
                    for (String spaceName : spaceAttribute.getValues()) {
                        Space actualSpace = repositoryConfiguration.getSpaceWithName(spaceName);
                        internalSetAttributeOptions4Space(attribute, actualSpace.getMapFor(attribute.getId()));
                    }
                    if (attribute.getOptions().size() == 0) {
                        if (attribute.getId().equals(taskSchema.ASSIGNEES.getKey())) {
                            String userName = repositoryConfiguration.getUserName();
                            attribute.putOption(userName, userName);
                        }
                    }
                }
            }
        } catch (CoreException e) {
            StatusHandler.log(new RepositoryStatus(getTaskRepository(), IStatus.ERROR, OSIORestCore.ID_PLUGIN, 0, "Failed to obtain repository configuration", // $NON-NLS-1$
            e));
        }
    }
    return super.getOptions(attribute);
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) CoreException(org.eclipse.core.runtime.CoreException) RepositoryStatus(org.eclipse.mylyn.tasks.core.RepositoryStatus)

Example 35 with TaskAttribute

use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.

the class OSIORestTaskEditorAttributePart method initialize.

private void initialize() {
    attributeEditors = new ArrayList<AbstractAttributeEditor>();
    hasIncoming = false;
    Collection<TaskAttribute> attributes = getAttributes();
    for (TaskAttribute attribute : attributes) {
        AbstractAttributeEditor attributeEditor = createAttributeEditor(attribute);
        if (attributeEditor != null) {
            attributeEditors.add(attributeEditor);
            if (getModel().hasIncomingChanges(attribute)) {
                hasIncoming = true;
            }
        }
    }
    Comparator<AbstractAttributeEditor> attributeSorter = createAttributeEditorSorter();
    if (attributeSorter != null) {
        Collections.sort(attributeEditors, attributeSorter);
    }
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) AbstractAttributeEditor(org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor)

Aggregations

TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)36 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)13 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)13 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)12 Test (org.junit.Test)12 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)11 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)11 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)10 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)10 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)10 FileReader (java.io.FileReader)7 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)5 TaskAttributeMetaData (org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData)5 JsonWriter (com.google.gson.stream.JsonWriter)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 TreeSet (java.util.TreeSet)3 Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)3 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)3