Search in sources :

Example 1 with IRepositoryPerson

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

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

the class TestOSIORestGetTaskComments method testGetTaskComments.

@Test
public void testGetTaskComments() 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");
    OSIORestGetTaskComments data = new OSIORestGetTaskComments(client.getClient(), testData.spaceMap.get("mywork"), taskData);
    String bundleLocation = Activator.getContext().getBundle().getLocation();
    int index = bundleLocation.indexOf('/');
    String fileName = bundleLocation.substring(index) + "/testjson/comments.data";
    FileReader in = new FileReader(fileName);
    TaskAttribute original = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().ASSIGNEES.getKey());
    assertTrue(original == null || original.getValues().isEmpty());
    ArrayList<TaskAttribute> attributes = data.testParseFromJson(in);
    assertEquals(4, attributes.size());
    TaskAttribute attr1 = attributes.get(0);
    TaskCommentMapper commentMapper = TaskCommentMapper.createFrom(attr1);
    assertEquals("COMMENT-0004", commentMapper.getCommentId());
    assertEquals("This is the fourth comment.", commentMapper.getText());
    assertEquals(getDate("2017-11-21T20:46:47.383745Z"), commentMapper.getCreationDate());
    IRepositoryPerson person = commentMapper.getAuthor();
    assertEquals("User", person.getName());
    assertEquals("user@user.org", person.getPersonId());
    assertEquals(new Integer(4), commentMapper.getNumber());
    TaskAttribute attr2 = attributes.get(1);
    commentMapper = TaskCommentMapper.createFrom(attr2);
    assertEquals("COMMENT-0003", commentMapper.getCommentId());
    assertEquals("This is the third comment.", commentMapper.getText());
    assertEquals(getDate("2017-10-05T23:01:54.15784Z"), commentMapper.getCreationDate());
    IRepositoryPerson person2 = commentMapper.getAuthor();
    assertEquals("User", person2.getName());
    assertEquals("user@user.org", person2.getPersonId());
    assertEquals(new Integer(3), commentMapper.getNumber());
    TaskAttribute attr3 = attributes.get(2);
    commentMapper = TaskCommentMapper.createFrom(attr3);
    assertEquals("COMMENT-0002", commentMapper.getCommentId());
    assertEquals("This is the second comment.", commentMapper.getText());
    assertEquals(getDate("2017-10-05T21:09:19.673546Z"), commentMapper.getCreationDate());
    IRepositoryPerson person3 = commentMapper.getAuthor();
    assertEquals("User", person3.getName());
    assertEquals("user@user.org", person3.getPersonId());
    assertEquals(new Integer(2), commentMapper.getNumber());
    TaskAttribute attr4 = attributes.get(3);
    commentMapper = TaskCommentMapper.createFrom(attr4);
    assertEquals("COMMENT-0001", commentMapper.getCommentId());
    assertEquals("Comment on Task 1.", commentMapper.getText());
    assertEquals(getDate("2017-08-14T21:40:29.434379Z"), commentMapper.getCreationDate());
    IRepositoryPerson person4 = commentMapper.getAuthor();
    assertEquals("User", person4.getName());
    assertEquals("user@user.org", person4.getPersonId());
    assertEquals(new Integer(1), commentMapper.getNumber());
}
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) IRepositoryPerson(org.eclipse.mylyn.tasks.core.IRepositoryPerson) OSIORestGetTaskComments(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskComments) 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) TaskCommentMapper(org.eclipse.mylyn.tasks.core.data.TaskCommentMapper) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Aggregations

OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)2 IRepositoryPerson (org.eclipse.mylyn.tasks.core.IRepositoryPerson)2 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)2 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)2 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)2 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)2 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)2 FileReader (java.io.FileReader)1 Date (java.sql.Date)1 ArrayList (java.util.ArrayList)1 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)1 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)1 OSIORestGetTaskComments (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskComments)1 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)1 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)1 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)1 TaskAttributeMetaData (org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData)1 Test (org.junit.Test)1