Search in sources :

Example 11 with TaskData

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

the class TestOSIORestPostNewTask method testPostNewTask.

@Test
public void testPostNewTask() 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);
    TaskAttribute root = taskData.getRoot();
    OSIORestTaskSchema taskSchema = OSIORestTaskSchema.getDefault();
    TaskAttribute summary = root.getAttribute(taskSchema.SUMMARY.getKey());
    summary.setValue("Bug0001");
    TaskAttribute description = root.getAttribute(taskSchema.DESCRIPTION.getKey());
    description.setValue("This is a bug");
    TaskAttribute workitemtype = root.getAttribute(taskSchema.WORKITEM_TYPE.getKey());
    workitemtype.setValue("bug");
    OSIORestPostNewTask data = new OSIORestPostNewTask(client.getClient(), taskData, testData.spaceMap.get("mywork"), connector, repository);
    OSIORestPostNewTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter(location);
    StringWriter s = new StringWriter();
    JsonWriter writer = new JsonWriter(s);
    adapter.write(writer, taskData);
    assertEquals("{\"data\":{\"attributes\":{\"system.state\":\"new\",\"system.title\":\"Bug0001\",\"version\":\"1\",\"system.description\":\"This is a bug\"},\"relationships\":{\"baseType\":{\"data\":{\"id\":\"WORKITEMTYPE-0001\",\"type\":\"workitemtypes\"}},\"space\":{\"data\":{\"id\":\"SPACE-0001\",\"type\":\"spaces\"}}},\"type\":\"workitems\"},\"included\":[true]}", s.toString());
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestPostNewTask(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestPostNewTask) 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) OSIORestTaskSchema(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 12 with TaskData

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

the class OSIORestHarness method createTaskData.

public TaskData createTaskData(ITaskMapping initializationData, ITaskMapping selectionData, IProgressMonitor monitor) throws CoreException {
    AbstractTaskDataHandler taskDataHandler = connector().getTaskDataHandler();
    TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository());
    // $NON-NLS-1$
    TaskData taskData = new TaskData(mapper, repository().getConnectorKind(), repository().getRepositoryUrl(), "");
    boolean result = taskDataHandler.initializeTaskData(repository(), taskData, initializationData, monitor);
    if (!result) {
        throw new CoreException(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
        "Initialization of task failed. The provided data is insufficient."));
    }
    if (selectionData != null) {
        connector().getTaskMapping(taskData).merge(selectionData);
    }
    return taskData;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Example 13 with TaskData

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

the class OSIORestHarness method getTaskIdWithSummary.

private String getTaskIdWithSummary(String summary) throws OSIORestException, CoreException {
    String taskID = null;
    String queryUrlString = repository().getRepositoryUrl() + "/bug?" + "short_desc=" + summary;
    RepositoryQuery query = new RepositoryQuery(repository().getConnectorKind(), "handle-testQueryViaConnector");
    query.setUrl(queryUrlString);
    final Map<Integer, TaskData> changedTaskData = new HashMap<Integer, TaskData>();
    TaskDataCollector collector = new TaskDataCollector() {

        @Override
        public void accept(TaskData taskData) {
            changedTaskData.put(Integer.valueOf(taskData.getTaskId()), taskData);
        }
    };
    connector().performQuery(repository(), query, collector, null, new NullProgressMonitor());
    if (changedTaskData.size() > 0) {
        Set<Integer> ks = changedTaskData.keySet();
        SortedSet<Integer> sks = new TreeSet<Integer>(ks);
        taskID = sks.last().toString();
    } else {
        final TaskMapping taskMappingInit = new TaskMapping() {

            @Override
            public String getSummary() {
                return summary;
            }

            @Override
            public String getDescription() {
                return "The Description";
            }

            @Override
            public String getProduct() {
                return "ManualTest";
            }

            @Override
            public String getComponent() {
                return "ManualC1";
            }

            @Override
            public String getVersion() {
                return "R1";
            }
        };
        taskID = getNewTaksIdFromInitMapping(taskMappingInit, taskInitializationData);
    }
    return taskID;
}
Also used : SingleTaskDataCollector(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SingleTaskDataCollector) TaskDataCollector(org.eclipse.mylyn.tasks.core.data.TaskDataCollector) RepositoryQuery(org.eclipse.mylyn.internal.tasks.core.RepositoryQuery) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ITaskMapping(org.eclipse.mylyn.tasks.core.ITaskMapping) TaskMapping(org.eclipse.mylyn.tasks.core.TaskMapping) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Example 14 with TaskData

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

the class OSIORestHarness method getNewTaksIdFromInitMapping.

public String getNewTaksIdFromInitMapping(final ITaskMapping taskMappingInit, final ITaskMapping taskMappingSelection) throws CoreException, OSIORestException {
    TaskData taskData = createTaskData(taskMappingInit, taskMappingSelection, null);
    String taskId = submitNewTask(taskData);
    return taskId;
}
Also used : TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Example 15 with TaskData

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

the class OSIORestClient method getTaskData.

public void getTaskData(Set<String> taskIds, TaskRepository taskRepository, TaskDataCollector collector, IOperationMonitor monitor) throws OSIORestException {
    OSIORestConfiguration config;
    try {
        config = connector.getRepositoryConfiguration(taskRepository);
    } catch (CoreException e1) {
        throw new OSIORestException(e1);
    }
    for (String taskId : taskIds) {
        if (taskId.isEmpty()) {
            continue;
        }
        String user = userName;
        // $NON-NLS-1$
        String[] tokens = taskId.split("#");
        String spaceName = tokens[0];
        // check for workitem in space not owned by this user
        // in which case it is prefixed by username
        // $NON-NLS-1$
        String[] spaceTokens = spaceName.split("/");
        if (spaceTokens.length > 1) {
            spaceName = spaceTokens[1];
            user = spaceTokens[0];
        }
        String wiNumber = tokens[1];
        try {
            // We need to translate from the space's workitem number to the real id
            // The easiest way is to use a namedspaces request that we know will give
            // us a "ResourceMovedPermanently" error which will contain the URL of the
            // real location of the workitem which contains the workitem uuid.
            user = URLQueryEncoder.transform(user);
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String query = "/namedspaces/" + user + "/" + spaceName + "/workitems/" + wiNumber;
            // $NON-NLS-1$
            String wid = "";
            try {
                wid = restRequestProvider.getWID(monitor, client, query, taskRepository);
            } catch (OSIORestResourceMovedPermanentlyException e) {
                Header h = e.getHeader();
                HeaderElement[] elements = h.getElements();
                for (HeaderElement element : elements) {
                    if ("Location".equals(element.getName())) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        int index = element.getValue().indexOf("workitem/");
                        wid = element.getValue().substring(index + 9);
                    }
                }
            }
            // $NON-NLS-1$
            String workitemquery = "/workitems/" + wid;
            TaskData taskData = restRequestProvider.getSingleTaskData(monitor, client, connector, workitemquery, taskRepository);
            Space space = null;
            String spaceId = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey()).getValue();
            space = getSpaceById(spaceId, taskRepository);
            restRequestProvider.getTaskComments(monitor, client, space, taskData);
            restRequestProvider.getTaskCreator(monitor, client, taskData);
            restRequestProvider.getTaskLabels(monitor, client, space, taskData);
            restRequestProvider.getTaskLinks(monitor, client, this, space, taskData, config);
            setTaskAssignees(taskData);
            config.updateSpaceOptions(taskData);
            config.addValidOperations(taskData);
            collector.accept(taskData);
        } catch (RuntimeException | CoreException e) {
            // if the Throwable was wrapped in a RuntimeException in
            // OSIORestGetTaskData.JSonTaskDataDeserializer.deserialize()
            // we now remove the wrapper and throw an OSIORestException
            e.printStackTrace();
            Throwable cause = e.getCause();
            if (cause instanceof CoreException) {
                throw new OSIORestException(cause);
            }
        }
    }
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) HeaderElement(org.apache.http.HeaderElement) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) CoreException(org.eclipse.core.runtime.CoreException) Header(org.apache.http.Header)

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