use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class TestOSIORestPostNewComment method testPostNewComment.
@Test
public void testPostNewComment() 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);
Set<TaskAttribute> attributes = new LinkedHashSet<>();
TaskAttribute newComment = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().NEW_COMMENT.getKey());
newComment.setValue("This is a test comment");
attributes.add(newComment);
OSIORestPostNewCommentTask data = new OSIORestPostNewCommentTask(client.getClient(), taskData, attributes);
OSIORestPostNewCommentTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter(location);
OSIORestPostNewCommentTask.OldAttributes oldAttributes = data.new OldAttributes(attributes);
StringWriter s = new StringWriter();
JsonWriter writer = new JsonWriter(s);
adapter.write(writer, oldAttributes);
assertEquals("{\"data\":{\"attributes\":{\"body\":\"This is a test comment\",\"markup\":\"Markdown\"},\"type\":\"comments\"},\"included\":[]}", s.getBuffer().toString());
}
use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class TestOSIORestPostNewLabel method testPostNewLabel.
@Test
public void testPostNewLabel() 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);
OSIORestPostNewLabelTask data = new OSIORestPostNewLabelTask(client.getClient(), testData.spaceMap.get("mywork"), "NewLabel");
OSIORestPostNewLabelTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter();
StringWriter s = new StringWriter();
JsonWriter writer = new JsonWriter(s);
adapter.write(writer, "NewLabel");
assertEquals("{\"data\":{\"attributes\":{\"name\":\"NewLabel\",\"background-color\":\"#f9d67a\",\"border-color\":\"#f39d3c\"},\"type\":\"labels\"},\"included\":[]}", s.getBuffer().toString());
}
use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class OSIORestHarness method getTaskFromServer.
public TaskData getTaskFromServer(String taskId) throws OSIORestException, CoreException {
Set<String> taskIds = new HashSet<String>();
taskIds.add(taskId);
SingleTaskDataCollector singleTaskDataCollector = new SingleTaskDataCollector();
connector().getClient(repository()).getTaskData(taskIds, repository(), singleTaskDataCollector, null);
TaskData taskDataGet = singleTaskDataCollector.getTaskData();
assertNotNull(taskDataGet);
assertNotNull(taskDataGet.getRoot());
return taskDataGet;
}
use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class OSIORestClient method performQuery.
public IStatus performQuery(TaskRepository taskRepository, final IRepositoryQuery query, final TaskDataCollector resultCollector, IOperationMonitor monitor) throws OSIORestException {
String queryUrl = query.getUrl();
// $NON-NLS-1$
int index = queryUrl.indexOf("?");
if (index > 0) {
String queryParams = queryUrl.substring(index + 1);
if (!queryParams.startsWith("filter")) {
// $NON-NLS-1$
queryUrl = formSearchUrl(queryUrl);
}
}
String queryUrlSuffix = connector.getURLSuffix(queryUrl);
try {
List<TaskData> taskDataArray = restRequestProvider.getTaskData(monitor, client, connector, queryUrlSuffix, taskRepository);
for (final TaskData taskData : taskDataArray) {
taskData.setPartial(true);
SafeRunner.run(new ISafeRunnable() {
@Override
public void run() throws Exception {
resultCollector.accept(taskData);
}
@Override
public void handleException(Throwable exception) {
StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
"Unexpected error during result collection. TaskID {0} in repository {1}", taskData.getTaskId(), taskData.getRepositoryUrl()), exception));
}
});
}
} catch (CoreException e) {
StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
"Unexpected error during result collection in repository {0}", taskRepository.getRepositoryUrl()), e));
}
return Status.OK_STATUS;
}
Aggregations