Search in sources :

Example 11 with Space

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space in project linuxtools by eclipse.

the class OSIORestConfiguration method updateSpaceOptions.

public boolean updateSpaceOptions(@NonNull TaskData taskData) {
    if (taskData == null) {
        return false;
    }
    TaskAttribute attributeSpaceId = taskData.getRoot().getMappedAttribute(SCHEMA.SPACE_ID.getKey());
    TaskAttribute attributeSpace = taskData.getRoot().getMappedAttribute(SCHEMA.SPACE.getKey());
    if (attributeSpaceId != null && !attributeSpaceId.getValue().isEmpty()) {
        Space actualSpace = getSpaceById(attributeSpaceId.getValue());
        if (actualSpace == null) {
            return false;
        }
        TaskAttribute attributeWorkItemType = taskData.getRoot().getMappedAttribute(SCHEMA.WORKITEM_TYPE.getKey());
        if (attributeWorkItemType != null) {
            setAttributeOptionsForSpace(attributeWorkItemType, actualSpace);
        }
        TaskAttribute attributeArea = taskData.getRoot().getMappedAttribute(SCHEMA.AREA.getKey());
        if (attributeArea != null) {
            setAttributeOptionsForSpace(attributeArea, actualSpace);
        }
        TaskAttribute attributeIteration = taskData.getRoot().getMappedAttribute(SCHEMA.ITERATION.getKey());
        if (attributeIteration != null) {
            setAttributeOptionsForSpace(attributeIteration, actualSpace);
        }
        TaskAttribute attributeAddAssignee = taskData.getRoot().getMappedAttribute(SCHEMA.ADD_ASSIGNEE.getKey());
        if (attributeAddAssignee != null) {
            setAttributeOptionsForSpace(attributeAddAssignee, actualSpace);
        }
        TaskAttribute attributeAddLabel = taskData.getRoot().getMappedAttribute(SCHEMA.ADD_LABEL.getKey());
        if (attributeAddLabel != null) {
            setAttributeOptionsForSpace(attributeAddLabel, actualSpace);
        }
        TaskAttribute attributeState = taskData.getRoot().getMappedAttribute(SCHEMA.STATUS.getKey());
        if (attributeState != null) {
            setAttributeOptionsForSpace(attributeState, actualSpace);
        }
    } else {
        SortedSet<String> workItemTypes = new TreeSet<>();
        SortedSet<String> areas = new TreeSet<>();
        SortedSet<String> iterations = new TreeSet<>();
        SortedSet<String> users = new TreeSet<>();
        Set<String> states = new LinkedHashSet<>();
        for (Space space : getSpaces().values()) {
            if (attributeSpace != null) {
                attributeSpace.putOption(space.getName(), space.getName());
            }
            if (space.getWorkItemTypes() != null) {
                // assume first workItemType is representative of all with regards to states
                if (!space.getWorkItemTypes().isEmpty()) {
                    WorkItemTypeData data = space.getWorkItemTypes().values().iterator().next();
                    WorkItemTypeAttributes attributes = data.getWorkItemTypeAttributes();
                    Map<String, WorkItemTypeField> fields = attributes.getFields();
                    // $NON-NLS-1$
                    WorkItemTypeField state = fields.get("system.state");
                    WorkItemTypeFieldType stateType = state.getType();
                    String[] values = stateType.getValues();
                    if (values != null) {
                        for (String value : values) {
                            states.add(value);
                        }
                    }
                }
                for (Entry<String, WorkItemTypeData> entry : space.getWorkItemTypes().entrySet()) {
                    workItemTypes.add(entry.getKey());
                }
            }
            if (space.getAreas() != null) {
                for (String entry : space.getAreas().keySet()) {
                    areas.add(entry);
                }
            }
            if (space.getIterations() != null) {
                for (String entry : space.getIterations().keySet()) {
                    iterations.add(entry);
                }
            }
            if (space.getUsers() != null) {
                for (String entry : space.getUsers().keySet()) {
                    users.add(entry);
                }
            }
        }
        TaskAttribute attributeWorkItemType = taskData.getRoot().getMappedAttribute(SCHEMA.WORKITEM_TYPE.getKey());
        if (attributeWorkItemType != null) {
            setAllAttributeOptions(attributeWorkItemType, workItemTypes);
        }
        TaskAttribute attributeState = taskData.getRoot().getMappedAttribute(SCHEMA.STATUS.getKey());
        if (attributeState != null) {
            setAllAttributeOptions(attributeState, states);
        }
        TaskAttribute attributeAssignees = taskData.getRoot().getMappedAttribute(SCHEMA.ASSIGNEES.getKey());
        if (attributeAssignees != null && attributeAssignees.getOptions().size() == 0) {
            attributeAssignees.putOption(userName, userName);
        }
    }
    return true;
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) LinkedHashSet(java.util.LinkedHashSet) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) WorkItemTypeField(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeField) WorkItemTypeAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeAttributes) WorkItemTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData) TreeSet(java.util.TreeSet) WorkItemTypeFieldType(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeFieldType)

Example 12 with Space

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space 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

Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)12 CoreException (org.eclipse.core.runtime.CoreException)6 IStatus (org.eclipse.core.runtime.IStatus)5 WorkItemTypeData (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData)5 Status (org.eclipse.core.runtime.Status)4 Area (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area)4 Iteration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration)4 WorkItemLinkTypeData (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeData)4 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)3 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)3 Label (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label)3 User (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User)3 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)3 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)3 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2