Search in sources :

Example 1 with RepositoryStatus

use of org.eclipse.mylyn.tasks.core.RepositoryStatus 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)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)1 Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)1 RepositoryStatus (org.eclipse.mylyn.tasks.core.RepositoryStatus)1 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)1