Search in sources :

Example 21 with TaskData

use of org.eclipse.mylyn.tasks.core.data.TaskData 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 22 with TaskData

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

the class TestOSIORestPostNewLabel method testPostNewLabel.

@Test
public void testPostNewLabel() 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);
    OSIORestPostNewLabelTask data = new OSIORestPostNewLabelTask(client.getClient(), testData.spaceMap.get("mywork"), "NewLabel");
    OSIORestPostNewLabelTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter();
    StringWriter s = new StringWriter();
    JsonWriter writer = new JsonWriter(s);
    adapter.write(writer, "NewLabel");
    assertEquals("{\"data\":{\"attributes\":{\"name\":\"NewLabel\",\"background-color\":\"#f9d67a\",\"border-color\":\"#f39d3c\"},\"type\":\"labels\"},\"included\":[]}", s.getBuffer().toString());
}
Also used : 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) JsonWriter(com.google.gson.stream.JsonWriter) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) OSIORestPostNewLabelTask(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewLabelTask) 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 23 with TaskData

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

the class OSIORestHarness method getTaskFromServer.

public TaskData getTaskFromServer(String taskId) throws OSIORestException, CoreException {
    Set<String> taskIds = new HashSet<String>();
    taskIds.add(taskId);
    SingleTaskDataCollector singleTaskDataCollector = new SingleTaskDataCollector();
    connector().getClient(repository()).getTaskData(taskIds, repository(), singleTaskDataCollector, null);
    TaskData taskDataGet = singleTaskDataCollector.getTaskData();
    assertNotNull(taskDataGet);
    assertNotNull(taskDataGet.getRoot());
    return taskDataGet;
}
Also used : SingleTaskDataCollector(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SingleTaskDataCollector) HashSet(java.util.HashSet) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Example 24 with TaskData

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

the class OSIORestClient method performQuery.

public IStatus performQuery(TaskRepository taskRepository, final IRepositoryQuery query, final TaskDataCollector resultCollector, IOperationMonitor monitor) throws OSIORestException {
    String queryUrl = query.getUrl();
    // $NON-NLS-1$
    int index = queryUrl.indexOf("?");
    if (index > 0) {
        String queryParams = queryUrl.substring(index + 1);
        if (!queryParams.startsWith("filter")) {
            // $NON-NLS-1$
            queryUrl = formSearchUrl(queryUrl);
        }
    }
    String queryUrlSuffix = connector.getURLSuffix(queryUrl);
    try {
        List<TaskData> taskDataArray = restRequestProvider.getTaskData(monitor, client, connector, queryUrlSuffix, taskRepository);
        for (final TaskData taskData : taskDataArray) {
            taskData.setPartial(true);
            SafeRunner.run(new ISafeRunnable() {

                @Override
                public void run() throws Exception {
                    resultCollector.accept(taskData);
                }

                @Override
                public void handleException(Throwable exception) {
                    StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
                    NLS.bind(// $NON-NLS-1$
                    "Unexpected error during result collection. TaskID {0} in repository {1}", taskData.getTaskId(), taskData.getRepositoryUrl()), exception));
                }
            });
        }
    } catch (CoreException e) {
        StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
        NLS.bind(// $NON-NLS-1$
        "Unexpected error during result collection in repository {0}", taskRepository.getRepositoryUrl()), e));
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Aggregations

TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)24 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)16 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)15 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)15 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)15 Test (org.junit.Test)15 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)13 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)13 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)13 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)12 FileReader (java.io.FileReader)7 JsonWriter (com.google.gson.stream.JsonWriter)5 StringWriter (java.io.StringWriter)5 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)5 CoreException (org.eclipse.core.runtime.CoreException)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)3 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2