Search in sources :

Example 1 with RepositoryResponse

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

the class OSIORestClient method postTaskData.

public RepositoryResponse postTaskData(TaskData taskData, Set<TaskAttribute> oldAttributes, TaskRepository repository, IOperationMonitor monitor) throws OSIORestException {
    Space space = null;
    if (taskData.isNew()) {
        TaskAttribute spaceAttribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE.getKey());
        Map<String, Space> spaces = getCachedSpaces(new NullOperationMonitor());
        space = spaces.get(spaceAttribute.getValue());
        String id = null;
        try {
            id = restRequestProvider.postNewTask(monitor, client, taskData, space, connector, repository);
        } catch (CoreException e1) {
            throw new OSIORestException(e1);
        }
        return new RepositoryResponse(ResponseKind.TASK_CREATED, id);
    } else {
        TaskAttribute spaceIdAttribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey());
        String spaceId = spaceIdAttribute.getValue();
        try {
            space = getSpaceById(spaceId, repository);
        } catch (CoreException e1) {
            throw new OSIORestException(e1);
        }
        TaskAttribute newComment = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().NEW_COMMENT.getKey());
        if (newComment != null) {
            String value = newComment.getValue();
            if (value != null && !value.isEmpty()) {
                restRequestProvider.postNewCommentTask(monitor, client, taskData, oldAttributes);
                newComment.setValue("");
            }
        }
        TaskAttribute removeLinks = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().REMOVE_LINKS.getKey());
        if (removeLinks != null) {
            List<String> links = removeLinks.getValues();
            TaskAttributeMetaData metadata = removeLinks.getMetaData();
            TaskAttribute widAttr = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().UUID.getKey());
            String wid = widAttr.getValue();
            for (String link : links) {
                try {
                    String id = metadata.getValue(link);
                    restRequestProvider.deleteLink(monitor, client, wid, id);
                } catch (Exception e) {
                    StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
                    NLS.bind(// $NON-NLS-1$
                    "Unexpected error during deletion of work item link: <{0}>", link), e));
                }
            }
        }
        TaskAttribute addLink = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().ADD_LINK.getKey());
        TaskAttributeMetaData metadata = addLink.getMetaData();
        // $NON-NLS-1$
        String linkid = metadata.getValue("linkid");
        String sourceid = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().UUID.getKey()).getValue();
        // $NON-NLS-1$
        String targetid = metadata.getValue("targetWid");
        // $NON-NLS-1$
        String direction = metadata.getValue("direction");
        boolean isForward = true;
        if (direction != null && !direction.isEmpty()) {
            // $NON-NLS-1$
            isForward = direction.equals("forward");
        }
        if (linkid != null && targetid != null) {
            restRequestProvider.postNewLink(monitor, client, linkid, sourceid, targetid, isForward);
        }
        restRequestProvider.patchUpdateTask(monitor, client, taskData, oldAttributes, space);
        return new RepositoryResponse(ResponseKind.TASK_UPDATED, taskData.getTaskId());
    }
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) CoreException(org.eclipse.core.runtime.CoreException) RepositoryResponse(org.eclipse.mylyn.tasks.core.RepositoryResponse) TaskAttributeMetaData(org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with RepositoryResponse

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

the class OSIORestHarness method submitNewTask.

public String submitNewTask(TaskData taskData) throws OSIORestException, CoreException {
    RepositoryResponse reposonse = connector().getClient(repository()).postTaskData(taskData, null, null, null);
    assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
    return reposonse.getTaskId();
}
Also used : RepositoryResponse(org.eclipse.mylyn.tasks.core.RepositoryResponse)

Aggregations

RepositoryResponse (org.eclipse.mylyn.tasks.core.RepositoryResponse)2 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)1 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)1 TaskAttributeMetaData (org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData)1