use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class TestOSIORestPostNewTask method testPostNewTask.
@Test
public void testPostNewTask() 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);
TaskAttribute root = taskData.getRoot();
OSIORestTaskSchema taskSchema = OSIORestTaskSchema.getDefault();
TaskAttribute summary = root.getAttribute(taskSchema.SUMMARY.getKey());
summary.setValue("Bug0001");
TaskAttribute description = root.getAttribute(taskSchema.DESCRIPTION.getKey());
description.setValue("This is a bug");
TaskAttribute workitemtype = root.getAttribute(taskSchema.WORKITEM_TYPE.getKey());
workitemtype.setValue("bug");
OSIORestPostNewTask data = new OSIORestPostNewTask(client.getClient(), taskData, testData.spaceMap.get("mywork"), connector, repository);
OSIORestPostNewTask.TaskAttributeTypeAdapter adapter = data.new TaskAttributeTypeAdapter(location);
StringWriter s = new StringWriter();
JsonWriter writer = new JsonWriter(s);
adapter.write(writer, taskData);
assertEquals("{\"data\":{\"attributes\":{\"system.state\":\"new\",\"system.title\":\"Bug0001\",\"version\":\"1\",\"system.description\":\"This is a bug\"},\"relationships\":{\"baseType\":{\"data\":{\"id\":\"WORKITEMTYPE-0001\",\"type\":\"workitemtypes\"}},\"space\":{\"data\":{\"id\":\"SPACE-0001\",\"type\":\"spaces\"}}},\"type\":\"workitems\"},\"included\":[true]}", s.toString());
}
use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class OSIORestHarness method createTaskData.
public TaskData createTaskData(ITaskMapping initializationData, ITaskMapping selectionData, IProgressMonitor monitor) throws CoreException {
AbstractTaskDataHandler taskDataHandler = connector().getTaskDataHandler();
TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository());
// $NON-NLS-1$
TaskData taskData = new TaskData(mapper, repository().getConnectorKind(), repository().getRepositoryUrl(), "");
boolean result = taskDataHandler.initializeTaskData(repository(), taskData, initializationData, monitor);
if (!result) {
throw new CoreException(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
"Initialization of task failed. The provided data is insufficient."));
}
if (selectionData != null) {
connector().getTaskMapping(taskData).merge(selectionData);
}
return taskData;
}
use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class OSIORestHarness method getTaskIdWithSummary.
private String getTaskIdWithSummary(String summary) throws OSIORestException, CoreException {
String taskID = null;
String queryUrlString = repository().getRepositoryUrl() + "/bug?" + "short_desc=" + summary;
RepositoryQuery query = new RepositoryQuery(repository().getConnectorKind(), "handle-testQueryViaConnector");
query.setUrl(queryUrlString);
final Map<Integer, TaskData> changedTaskData = new HashMap<Integer, TaskData>();
TaskDataCollector collector = new TaskDataCollector() {
@Override
public void accept(TaskData taskData) {
changedTaskData.put(Integer.valueOf(taskData.getTaskId()), taskData);
}
};
connector().performQuery(repository(), query, collector, null, new NullProgressMonitor());
if (changedTaskData.size() > 0) {
Set<Integer> ks = changedTaskData.keySet();
SortedSet<Integer> sks = new TreeSet<Integer>(ks);
taskID = sks.last().toString();
} else {
final TaskMapping taskMappingInit = new TaskMapping() {
@Override
public String getSummary() {
return summary;
}
@Override
public String getDescription() {
return "The Description";
}
@Override
public String getProduct() {
return "ManualTest";
}
@Override
public String getComponent() {
return "ManualC1";
}
@Override
public String getVersion() {
return "R1";
}
};
taskID = getNewTaksIdFromInitMapping(taskMappingInit, taskInitializationData);
}
return taskID;
}
use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class OSIORestHarness method getNewTaksIdFromInitMapping.
public String getNewTaksIdFromInitMapping(final ITaskMapping taskMappingInit, final ITaskMapping taskMappingSelection) throws CoreException, OSIORestException {
TaskData taskData = createTaskData(taskMappingInit, taskMappingSelection, null);
String taskId = submitNewTask(taskData);
return taskId;
}
use of org.eclipse.mylyn.tasks.core.data.TaskData in project linuxtools by eclipse.
the class OSIORestClient method getTaskData.
public void getTaskData(Set<String> taskIds, TaskRepository taskRepository, TaskDataCollector collector, IOperationMonitor monitor) throws OSIORestException {
OSIORestConfiguration config;
try {
config = connector.getRepositoryConfiguration(taskRepository);
} catch (CoreException e1) {
throw new OSIORestException(e1);
}
for (String taskId : taskIds) {
if (taskId.isEmpty()) {
continue;
}
String user = userName;
// $NON-NLS-1$
String[] tokens = taskId.split("#");
String spaceName = tokens[0];
// check for workitem in space not owned by this user
// in which case it is prefixed by username
// $NON-NLS-1$
String[] spaceTokens = spaceName.split("/");
if (spaceTokens.length > 1) {
spaceName = spaceTokens[1];
user = spaceTokens[0];
}
String wiNumber = tokens[1];
try {
// We need to translate from the space's workitem number to the real id
// The easiest way is to use a namedspaces request that we know will give
// us a "ResourceMovedPermanently" error which will contain the URL of the
// real location of the workitem which contains the workitem uuid.
user = URLQueryEncoder.transform(user);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String query = "/namedspaces/" + user + "/" + spaceName + "/workitems/" + wiNumber;
// $NON-NLS-1$
String wid = "";
try {
wid = restRequestProvider.getWID(monitor, client, query, taskRepository);
} catch (OSIORestResourceMovedPermanentlyException e) {
Header h = e.getHeader();
HeaderElement[] elements = h.getElements();
for (HeaderElement element : elements) {
if ("Location".equals(element.getName())) {
// $NON-NLS-1$
// $NON-NLS-1$
int index = element.getValue().indexOf("workitem/");
wid = element.getValue().substring(index + 9);
}
}
}
// $NON-NLS-1$
String workitemquery = "/workitems/" + wid;
TaskData taskData = restRequestProvider.getSingleTaskData(monitor, client, connector, workitemquery, taskRepository);
Space space = null;
String spaceId = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey()).getValue();
space = getSpaceById(spaceId, taskRepository);
restRequestProvider.getTaskComments(monitor, client, space, taskData);
restRequestProvider.getTaskCreator(monitor, client, taskData);
restRequestProvider.getTaskLabels(monitor, client, space, taskData);
restRequestProvider.getTaskLinks(monitor, client, this, space, taskData, config);
setTaskAssignees(taskData);
config.updateSpaceOptions(taskData);
config.addValidOperations(taskData);
collector.accept(taskData);
} catch (RuntimeException | CoreException e) {
// if the Throwable was wrapped in a RuntimeException in
// OSIORestGetTaskData.JSonTaskDataDeserializer.deserialize()
// we now remove the wrapper and throw an OSIORestException
e.printStackTrace();
Throwable cause = e.getCause();
if (cause instanceof CoreException) {
throw new OSIORestException(cause);
}
}
}
}
Aggregations