Search in sources :

Example 16 with TaskData

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

the class OSIORestPostNewTask method addHttpRequestEntities.

@SuppressWarnings("deprecation")
@Override
protected void addHttpRequestEntities(HttpRequestBase request) throws OSIORestException {
    super.addHttpRequestEntities(request);
    try {
        Gson gson = new GsonBuilder().registerTypeAdapter(TaskData.class, new TaskAttributeTypeAdapter(getClient().getLocation())).create();
        StringEntity requestEntity = new StringEntity(gson.toJson(taskData));
        ((HttpPost) request).setEntity(requestEntity);
    } catch (UnsupportedEncodingException e) {
        Throwables.propagate(new CoreException(// $NON-NLS-1$
        new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, "Can not build HttpRequest", e)));
    }
}
Also used : HttpStatus(org.apache.http.HttpStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) StringEntity(org.apache.http.entity.StringEntity) HttpPost(org.apache.http.client.methods.HttpPost) CoreException(org.eclipse.core.runtime.CoreException) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Example 17 with TaskData

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

the class OSIORestRepositoryConnectorUI method getQueryWizard.

@Override
public IWizard getQueryWizard(TaskRepository repository, IRepositoryQuery query) {
    RepositoryQueryWizard wizard = new RepositoryQueryWizard(repository);
    AbstractRepositoryConnector connector = getConnector();
    OSIORestConnector connectorREST = (OSIORestConnector) connector;
    TaskData taskData = new TaskData(new OSIORestTaskAttributeMapper(repository, connectorREST), repository.getConnectorKind(), "Query", // $NON-NLS-1$ //$NON-NLS-2$
    "Query");
    if (query == null) {
        wizard.addPage(new OSIORestQueryTypeWizardPage(repository, connector));
    } else {
        if (isCustomQuery(query)) {
            wizard.addPage(OSIORestUIUtil.createOSIORestSearchPage(true, true, taskData, connectorREST, repository, query));
        } else {
            wizard.addPage(OSIORestUIUtil.createOSIORestSearchPage(false, true, taskData, connectorREST, repository, query));
        }
    }
    return wizard;
}
Also used : RepositoryQueryWizard(org.eclipse.mylyn.tasks.ui.wizards.RepositoryQueryWizard) AbstractRepositoryConnector(org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector) OSIORestQueryTypeWizardPage(org.eclipse.linuxtools.internal.mylyn.osio.rest.ui.provisional.OSIORestQueryTypeWizardPage) OSIORestConnector(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConnector) OSIORestTaskAttributeMapper(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskAttributeMapper) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Example 18 with TaskData

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

the class TestOSIORestClient method testFormSearchURL.

@Test
public void testFormSearchURL() throws Exception {
    TestData testData = new TestData();
    TestUtils.initSpaces(requestProvider, testData);
    requestProvider.addGetRequest("/namedspaces/user", testData.spaces);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
    TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository);
    TaskData taskData1 = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
    assertTrue(taskDataHandler.initializeTaskData(repository, taskData1, null, null));
    taskData1.getRoot().createAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey()).addValue("SPACE-0001");
    taskData1.getRoot().createAttribute(OSIORestTaskSchema.getDefault().WORKITEM_TYPE.getKey()).addValue("bug");
    TaskData taskData2 = new TaskData(mapper, repository.getConnectorKind(), repository.getRepositoryUrl(), "");
    assertTrue(taskDataHandler.initializeTaskData(repository, taskData2, null, null));
    taskData2.getRoot().createAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey()).addValue("SPACE-0002");
    taskData2.getRoot().createAttribute(OSIORestTaskSchema.getDefault().WORKITEM_TYPE.getKey()).addValue("bug");
    List<TaskData> taskList = new ArrayList<>();
    taskList.add(taskData1);
    taskList.add(taskData2);
    String query = "filter[expression]={\"$AND\":[{\"$OR\":[{\"space\":\"SPACE-0001\"},{\"space\":\"SPACE-0002\"}]},{\"$OR\":[{\"workitemtype\":\"WORKITEMTYPE-0001\"}]}]}";
    String transformedQuery = URLQueryEncoder.transform(query);
    requestProvider.addGetRequest("/search?" + transformedQuery, taskList);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    location.setUrl("https://api.openshift.io/api");
    OSIORestConfiguration configuration = client.getConfiguration(repository, new NullOperationMonitor());
    Map<String, Space> spaces = configuration.getSpaces();
    TestTaskDataCollector collector = new TestTaskDataCollector();
    RepositoryQuery repoQuery = new RepositoryQuery("https://api.openshift.io/api/query?space=mywork&space=mywork2&baseType=bug");
    IStatus status = client.performQuery(repository, repoQuery, collector, new NullOperationMonitor());
    assertTrue(status.isOK());
    List<TaskData> dataList = collector.getTaskData();
    assertTrue(dataList != null);
    assertEquals(dataList.size(), 2);
    assertEquals(dataList.get(0), taskData1);
    assertEquals(dataList.get(1), taskData2);
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) IStatus(org.eclipse.core.runtime.IStatus) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) ArrayList(java.util.ArrayList) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) IRepositoryQuery(org.eclipse.mylyn.tasks.core.IRepositoryQuery) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor) Test(org.junit.Test)

Example 19 with TaskData

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

the class TestOSIORestGetTaskCreator method testGetTaskCreator.

@Test
public void testGetTaskCreator() throws Exception {
    TestData spaceData = new TestData();
    TestUtils.initSpaces(requestProvider, spaceData);
    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(spaceData.spaceMap);
    connector.setConfiguration(config);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().CREATOR_ID.getKey()).setValue("USER-0001");
    OSIORestGetTaskCreator data = new OSIORestGetTaskCreator(client.getClient(), taskData);
    String bundleLocation = Activator.getContext().getBundle().getLocation();
    int index = bundleLocation.indexOf('/');
    String fileName = bundleLocation.substring(index) + "/testjson/user.data";
    FileReader in = new FileReader(fileName);
    TaskAttribute attr = data.testParseFromJson(in);
    assertEquals(OSIORestTaskSchema.getDefault().CREATOR.getKey(), attr.getId());
    assertEquals("User 1", attr.getValue());
}
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) AbstractTaskDataHandler(org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) OSIORestGetTaskCreator(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskCreator) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) FileReader(java.io.FileReader) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

Example 20 with TaskData

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

the class TestOSIORestGetTaskLabels method testGetTaskLabels.

@Test
public void testGetTaskLabels() 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");
    OSIORestGetTaskLabels data = new OSIORestGetTaskLabels(client.getClient(), testData.spaceMap.get("mywork"), taskData);
    String bundleLocation = Activator.getContext().getBundle().getLocation();
    int index = bundleLocation.indexOf('/');
    String fileName = bundleLocation.substring(index) + "/testjson/labels.data";
    FileReader in = new FileReader(fileName);
    TaskAttribute original = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().LABELS.getKey());
    assertTrue(original == null || original.getValues().isEmpty());
    TaskAttribute attribute = data.testParseFromJson(in);
    assertEquals(2, attribute.getValues().size());
    List<String> values = attribute.getValues();
    assertEquals("Label1", values.get(0));
    assertEquals("Label2", values.get(1));
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestGetTaskLabels(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestGetTaskLabels) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) 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) TaskAttributeMapper(org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper) NullOperationMonitor(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor) Test(org.junit.Test)

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