Search in sources :

Example 26 with TaskAttribute

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

the class TestOSIORestGetTaskCreator method testGetTaskCreator.

@Test
public void testGetTaskCreator() throws Exception {
    TestData spaceData = new TestData();
    TestUtils.initSpaces(requestProvider, spaceData);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
    TaskData taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
    OSIORestTaskSchema.getDefault().initialize(taskData);
    OSIORestConfiguration config = client.getConfiguration(repository, new NullOperationMonitor());
    config.setSpaces(spaceData.spaceMap);
    connector.setConfiguration(config);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().CREATOR_ID.getKey()).setValue("USER-0001");
    OSIORestGetTaskCreator data = new OSIORestGetTaskCreator(client.getClient(), taskData);
    String bundleLocation = Activator.getContext().getBundle().getLocation();
    int index = bundleLocation.indexOf('/');
    String fileName = bundleLocation.substring(index) + "/testjson/user.data";
    FileReader in = new FileReader(fileName);
    TaskAttribute attr = data.testParseFromJson(in);
    assertEquals(OSIORestTaskSchema.getDefault().CREATOR.getKey(), attr.getId());
    assertEquals("User 1", attr.getValue());
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) OSIORestGetTaskCreator(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskCreator) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) FileReader(java.io.FileReader) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 27 with TaskAttribute

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

the class TestOSIORestGetTaskLabels method testGetTaskLabels.

@Test
public void testGetTaskLabels() throws Exception {
    TestData testData = new TestData();
    TestUtils.initSpaces(requestProvider, testData);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
    TaskData taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
    OSIORestTaskSchema.getDefault().initialize(taskData);
    OSIORestConfiguration config = client.getConfiguration(repository, new NullOperationMonitor());
    config.setSpaces(testData.spaceMap);
    connector.setConfiguration(config);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    OSIORestGetTaskLabels data = new OSIORestGetTaskLabels(client.getClient(), testData.spaceMap.get("mywork"), taskData);
    String bundleLocation = Activator.getContext().getBundle().getLocation();
    int index = bundleLocation.indexOf('/');
    String fileName = bundleLocation.substring(index) + "/testjson/labels.data";
    FileReader in = new FileReader(fileName);
    TaskAttribute original = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().LABELS.getKey());
    assertTrue(original == null || original.getValues().isEmpty());
    TaskAttribute attribute = data.testParseFromJson(in);
    assertEquals(2, attribute.getValues().size());
    List<String> values = attribute.getValues();
    assertEquals("Label1", values.get(0));
    assertEquals("Label2", values.get(1));
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestGetTaskLabels(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskLabels) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) FileReader(java.io.FileReader) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 28 with TaskAttribute

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

the class TestOSIORestPostNewComment method testPostNewComment.

@Test
public void testPostNewComment() throws Exception {
    TestData testData = new TestData();
    TestUtils.initSpaces(requestProvider, testData);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    OSIORestConfiguration config = client.getConfiguration(repository, new NullOperationMonitor());
    config.setSpaces(testData.spaceMap);
    connector.setConfiguration(config);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
    TaskData taskData = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
    OSIORestTaskSchema.getDefault().initialize(taskData);
    Set<TaskAttribute> attributes = new LinkedHashSet<>();
    TaskAttribute newComment = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().NEW_COMMENT.getKey());
    newComment.setValue("This is a test comment");
    attributes.add(newComment);
    OSIORestPostNewCommentTask data = new OSIORestPostNewCommentTask(client.getClient(), taskData, attributes);
    OSIORestPostNewCommentTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter(location);
    OSIORestPostNewCommentTask.OldAttributes oldAttributes = data.new OldAttributes(attributes);
    StringWriter s = new StringWriter();
    JsonWriter writer = new JsonWriter(s);
    adapter.write(writer, oldAttributes);
    assertEquals("{\"data\":{\"attributes\":{\"body\":\"This is a test comment\",\"markup\":\"Markdown\"},\"type\":\"comments\"},\"included\":[]}", s.getBuffer().toString());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestPostNewCommentTask(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewCommentTask) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) JsonWriter(com.google.gson.stream.JsonWriter) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) StringWriter(java.io.StringWriter) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 29 with TaskAttribute

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

the class OSIOTestRestRequestProvider method getTaskAssignee.

@Override
public TaskAttribute getTaskAssignee(IOperationMonitor monitor, CommonHttpClient client, String id, TaskData taskData) throws OSIORestException {
    TaskAttribute assignee = (TaskAttribute) requestMap.get("/users/" + id);
    TaskAttribute originalAttr = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().ASSIGNEES.getKey());
    originalAttr.addValue(assignee.getValue());
    return assignee;
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute)

Example 30 with TaskAttribute

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

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