Search in sources :

Example 1 with TaskAttributeMetaData

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

the class TestOSIORestClient method initWorkItems.

@SuppressWarnings("deprecation")
private void initWorkItems(TaskData task1, TaskData task2) throws Exception {
    OSIORestClient client = connector.getClient(repository, requestProvider);
    AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
    TaskData taskData = task1;
    OSIORestTaskSchema.getDefault().initialize(taskData);
    taskDataHandler.initializeTaskData(repository, taskData, null, null);
    OSIORestTaskSchema schema = OSIORestTaskSchema.getDefault();
    TaskAttribute root = taskData.getRoot();
    root.createAttribute(schema.UUID.getKey()).addValue("WORKITEM-0001");
    root.createAttribute(schema.SPACE.getKey()).addValue("mywork");
    root.createAttribute(schema.SPACE_ID.getKey()).addValue("SPACE-0001");
    root.createAttribute(schema.AREA.getKey()).addValue("otherarea");
    root.createAttribute(schema.ITERATION.getKey()).addValue("mywork");
    root.createAttribute(schema.DESCRIPTION.getKey()).addValue("This is Bug 1");
    root.createAttribute(schema.NUMBER.getKey()).addValue("1");
    root.createAttribute(schema.ORDER.getKey()).addValue("1000");
    root.createAttribute(schema.STATUS.getKey()).addValue("in progress");
    root.createAttribute(schema.SUMMARY.getKey()).addValue("Bug 0001");
    root.createAttribute(schema.TASK_URL.getKey()).addValue("https://api.openshift.io/api/workitems/WORKITEM-0001");
    root.createAttribute(schema.WORKITEM_TYPE.getKey()).addValue("bug");
    root.createAttribute(schema.ID.getKey()).addValue("user/mywork#1");
    root.createAttribute(schema.ASSIGNEE_IDS.getKey()).addValue("USER-0001");
    root.createAttribute(schema.CREATOR_ID.getKey()).addValue("USER-0001");
    TaskAttribute attribute = taskData.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + "0");
    TaskAttribute numComments = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().COMMENT_COUNT.getKey());
    numComments.setValue("1");
    TaskCommentMapper taskComment = TaskCommentMapper.createFrom(attribute);
    taskComment.setCommentId("COMMENT-0001");
    taskComment.setNumber(1);
    taskComment.setUrl("https://api.openshift.io/api/workitems/comments/COMMENT-0001");
    // $NON-NLS-1$
    String email = "user@user.org";
    // $NON-NLS-1$
    String fullName = "User 1";
    IRepositoryPerson author = taskData.getAttributeMapper().getTaskRepository().createPerson(// $NON-NLS-1$
    email);
    author.setName(fullName);
    taskComment.setAuthor(author);
    taskComment.setIsPrivate(null);
    taskComment.setCreationDate(new Date(2017, 01, 01));
    taskComment.setText("This is comment 1");
    taskComment.applyTo(attribute);
    TaskAttribute attribute2 = taskData.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + "1");
    taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().COMMENT_COUNT.getKey());
    numComments.setValue("2");
    taskComment = TaskCommentMapper.createFrom(attribute2);
    taskComment.setCommentId("COMMENT-0002");
    taskComment.setNumber(2);
    taskComment.setUrl("https://api.openshift.io/api/workitems/comments/COMMENT-0002");
    // $NON-NLS-1$
    email = "user2@user.org";
    // $NON-NLS-1$
    fullName = "User 2";
    author = taskData.getAttributeMapper().getTaskRepository().createPerson(// $NON-NLS-1$
    email);
    author.setName(fullName);
    taskComment.setAuthor(author);
    taskComment.setIsPrivate(null);
    taskComment.setCreationDate(new Date(2017, 01, 02));
    taskComment.setText("This is comment 2");
    taskComment.applyTo(attribute2);
    List<TaskAttribute> comments = new ArrayList<>();
    comments.add(attribute);
    comments.add(attribute2);
    requestProvider.addGetRequest("/workitems/WORKITEM-0001/comments", comments);
    TaskAttribute attribute5 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LABELS.getKey());
    attribute5.addValue("LabelA");
    attribute5.addValue("LabelB");
    requestProvider.addGetRequest("/workitems/WORKITEM-0001/labels", attribute5);
    TaskAttribute attribute6 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LINKS.getKey());
    attribute6.addValue("blocks Bug 3 [user/mywork#3]");
    requestProvider.addGetRequest("/workitems/WORKITEM-0001/relationships/links", attribute6);
    TaskAttribute creator = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().CREATOR.getKey());
    TaskAttributeMetaData creatorMeta = creator.getMetaData();
    creator.setValue("User 1");
    creatorMeta.putValue("email", "user@user.org");
    creatorMeta.putValue("username", "user");
    creatorMeta.putValue("id", "USER-0001");
    requestProvider.addGetRequest("/users/USER-0001", creator);
    TaskData taskData2 = task2;
    OSIORestTaskSchema.getDefault().initialize(taskData2);
    taskDataHandler.initializeTaskData(repository, taskData2, null, null);
    root = taskData2.getRoot();
    root.createAttribute(schema.UUID.getKey()).addValue("WORKITEM-0002");
    root.createAttribute(schema.SPACE.getKey()).addValue("mywork");
    root.createAttribute(schema.SPACE_ID.getKey()).addValue("SPACE-0003");
    root.createAttribute(schema.AREA.getKey()).addValue("mywork");
    root.createAttribute(schema.ITERATION.getKey()).addValue("mywork");
    root.createAttribute(schema.DESCRIPTION.getKey()).addValue("This is Feature 1");
    root.createAttribute(schema.NUMBER.getKey()).addValue("1");
    root.createAttribute(schema.ORDER.getKey()).addValue("1010");
    root.createAttribute(schema.STATUS.getKey()).addValue("open");
    root.createAttribute(schema.SUMMARY.getKey()).addValue("Feature 0001");
    root.createAttribute(schema.TASK_URL.getKey()).addValue("https://api.openshift.io/api/workitems/WORKITEM-0002");
    root.createAttribute(schema.WORKITEM_TYPE.getKey()).addValue("bug");
    root.createAttribute(schema.ID.getKey()).addValue("user3/mywork#1");
    root.createAttribute(schema.ASSIGNEE_IDS.getKey()).addValue("USER-0001");
    root.createAttribute(schema.CREATOR_ID.getKey()).addValue("USER-0003");
    TaskAttribute attribute3 = taskData.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + "0");
    TaskAttribute numComments3 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().COMMENT_COUNT.getKey());
    numComments.setValue("1");
    taskComment = TaskCommentMapper.createFrom(attribute);
    taskComment.setCommentId("COMMENT-0003");
    taskComment.setNumber(1);
    taskComment.setUrl("https://api.openshift.io/api/workitems/comments/COMMENT-0003");
    // $NON-NLS-1$
    String email3 = "user@user.org";
    // $NON-NLS-1$
    String fullName3 = "User 1";
    IRepositoryPerson author3 = taskData.getAttributeMapper().getTaskRepository().createPerson(// $NON-NLS-1$
    email3);
    author3.setName(fullName3);
    taskComment.setAuthor(author3);
    taskComment.setIsPrivate(null);
    taskComment.setCreationDate(new Date(2017, 01, 01));
    taskComment.setText("This is first comment");
    taskComment.applyTo(attribute3);
    List<TaskAttribute> comments2 = new ArrayList<>();
    comments2.add(attribute3);
    requestProvider.addGetRequest("/workitems/WORKITEM-0002/comments", comments2);
    TaskAttribute attribute4 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LABELS.getKey());
    attribute4.addValue("Label1");
    attribute4.addValue("Label2");
    requestProvider.addGetRequest("/workitems/WORKITEM-0002/labels", attribute4);
    TaskAttribute attribute7 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().LINKS.getKey());
    attribute7.clearValues();
    requestProvider.addGetRequest("/workitems/WORKITEM-0002/relationships/links", attribute7);
    TaskAttribute creator2 = taskData.getRoot().createAttribute(OSIORestTaskSchema.getDefault().CREATOR.getKey());
    TaskAttributeMetaData creatorMeta2 = creator.getMetaData();
    creator2.setValue("User 3");
    creatorMeta2.putValue("email", "user3@user.org");
    creatorMeta2.putValue("username", "user3");
    creatorMeta2.putValue("id", "USER-0003");
    requestProvider.addGetRequest("/users/USER-0003", creator2);
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) IRepositoryPerson(org.eclipse.mylyn.tasks.core.IRepositoryPerson) ArrayList(java.util.ArrayList) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) Date(java.sql.Date) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) TaskAttributeMetaData(org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TaskCommentMapper(org.eclipse.mylyn.tasks.core.data.TaskCommentMapper) OSIORestTaskSchema(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)

Example 2 with TaskAttributeMetaData

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

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

the class OSIOAddLinksAttributeEditor method createControl.

@Override
public void createControl(Composite parent, FormToolkit toolkit) {
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, true));
    attrAddLink = getModel().getTaskData().getRoot().getMappedAttribute(OSIORestTaskSchema.getDefault().ADD_LINK.getKey());
    typeCombo = new Combo(comp, SWT.READ_ONLY | SWT.DROP_DOWN);
    toolkit.adapt(typeCombo, true, true);
    typeCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    typeCombo.setFont(JFaceResources.getDefaultFont());
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(typeCombo);
    typeCombo.setToolTipText(getDescription());
    typeCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = typeCombo.getSelectionIndex();
            String linkType = typeCombo.getItem(index);
            TaskAttribute attr = getTaskAttribute();
            // $NON-NLS-1$
            attr.setValue(linkType + " " + workitemCombo.getText());
            TaskAttributeMetaData metadata = attr.getMetaData();
            // $NON-NLS-1$
            String linkid = linkTypes.containsKey(linkType) ? linkTypes.get(linkType) : "";
            metadata.putValue("linkid", linkid);
            if (index % 2 == 1) {
                // $NON-NLS-1$ //$NON-NLS-2$
                metadata.putValue("direction", "forward");
            } else {
                // $NON-NLS-1$ //$NON-NLS-2$
                metadata.putValue("direction", "reverse");
            }
            getModel().attributeChanged(attrAddLink);
        }
    });
    workitemCombo = new Combo(comp, SWT.READ_ONLY | SWT.DROP_DOWN);
    toolkit.adapt(workitemCombo, true, true);
    workitemCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    workitemCombo.setFont(JFaceResources.getDefaultFont());
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(workitemCombo);
    workitemCombo.setToolTipText(getDescription());
    workitemCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = workitemCombo.getSelectionIndex();
            String workitem = workitemCombo.getItem(index);
            TaskAttribute attr = getTaskAttribute();
            // $NON-NLS-1$
            attr.setValue(typeCombo.getText() + " " + workitem);
            TaskAttributeMetaData metadata = attr.getMetaData();
            metadata.putValue("targetWidName", workitem);
            // $NON-NLS-1$
            metadata.putValue("targetWid", workitems.get(workitem).getId());
            getModel().attributeChanged(attrAddLink);
        }
    });
    populateFromAttribute();
    setControl(comp);
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) GridLayout(org.eclipse.swt.layout.GridLayout) TaskAttributeMetaData(org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo)

Example 4 with TaskAttributeMetaData

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

the class OSIOLinksAttributeEditor method copyLinkMetaData.

// Copy link meta data from Links attribute to RemoveLinks attribute
// (a map of link strings to their link uuids which is needed to delete them)
private void copyLinkMetaData() {
    TaskAttribute attrLinks = getTaskAttribute();
    if (attrLinks != null) {
        TaskAttributeMetaData metadata = attrLinks.getMetaData();
        TaskAttributeMetaData removeMetaData = attrRemoveLinks.getMetaData();
        if (metadata != null) {
            for (String link : attrLinks.getValues()) {
                String metaValue = metadata.getValue(link);
                removeMetaData.putValue(link, metaValue);
            }
        }
    }
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TaskAttributeMetaData(org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData)

Example 5 with TaskAttributeMetaData

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

the class OSIORestTaskEditorPeoplePart method getAttributes.

@Override
protected Collection<TaskAttribute> getAttributes() {
    Map<String, TaskAttribute> allAttributes = getTaskData().getRoot().getAttributes();
    List<TaskAttribute> attributes = new ArrayList<TaskAttribute>(allAttributes.size());
    attributes.add(getTaskData().getRoot().getMappedAttribute(OSIORestTaskSchema.getDefault().ASSIGNEES.getKey()));
    for (TaskAttribute attribute : allAttributes.values()) {
        TaskAttributeMetaData properties = attribute.getMetaData();
        if (TaskAttribute.KIND_PEOPLE.equals(properties.getKind())) {
            if (!attributes.contains(attribute)) {
                attributes.add(attribute);
            }
        }
    }
    return attributes;
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TaskAttributeMetaData(org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData) ArrayList(java.util.ArrayList)

Aggregations

TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)5 TaskAttributeMetaData (org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData)5 ArrayList (java.util.ArrayList)2 Date (java.sql.Date)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)1 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)1 Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)1 IRepositoryPerson (org.eclipse.mylyn.tasks.core.IRepositoryPerson)1 RepositoryResponse (org.eclipse.mylyn.tasks.core.RepositoryResponse)1 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)1 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)1 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)1 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Combo (org.eclipse.swt.widgets.Combo)1