use of org.eclipse.mylyn.tasks.core.data.TaskAttribute 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());
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute 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));
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute 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.TaskAttribute in project linuxtools by eclipse.
the class OSIOTestRestRequestProvider method getTaskAssignee.
@Override
public TaskAttribute getTaskAssignee(IOperationMonitor monitor, CommonHttpClient client, String id, TaskData taskData) throws OSIORestException {
TaskAttribute assignee = (TaskAttribute) requestMap.get("/users/" + id);
TaskAttribute originalAttr = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().ASSIGNEES.getKey());
originalAttr.addValue(assignee.getValue());
return assignee;
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class OSIORestConfiguration method updateSpaceOptions.
public boolean updateSpaceOptions(@NonNull TaskData taskData) {
if (taskData == null) {
return false;
}
TaskAttribute attributeSpaceId = taskData.getRoot().getMappedAttribute(SCHEMA.SPACE_ID.getKey());
TaskAttribute attributeSpace = taskData.getRoot().getMappedAttribute(SCHEMA.SPACE.getKey());
if (attributeSpaceId != null && !attributeSpaceId.getValue().isEmpty()) {
Space actualSpace = getSpaceById(attributeSpaceId.getValue());
if (actualSpace == null) {
return false;
}
TaskAttribute attributeWorkItemType = taskData.getRoot().getMappedAttribute(SCHEMA.WORKITEM_TYPE.getKey());
if (attributeWorkItemType != null) {
setAttributeOptionsForSpace(attributeWorkItemType, actualSpace);
}
TaskAttribute attributeArea = taskData.getRoot().getMappedAttribute(SCHEMA.AREA.getKey());
if (attributeArea != null) {
setAttributeOptionsForSpace(attributeArea, actualSpace);
}
TaskAttribute attributeIteration = taskData.getRoot().getMappedAttribute(SCHEMA.ITERATION.getKey());
if (attributeIteration != null) {
setAttributeOptionsForSpace(attributeIteration, actualSpace);
}
TaskAttribute attributeAddAssignee = taskData.getRoot().getMappedAttribute(SCHEMA.ADD_ASSIGNEE.getKey());
if (attributeAddAssignee != null) {
setAttributeOptionsForSpace(attributeAddAssignee, actualSpace);
}
TaskAttribute attributeAddLabel = taskData.getRoot().getMappedAttribute(SCHEMA.ADD_LABEL.getKey());
if (attributeAddLabel != null) {
setAttributeOptionsForSpace(attributeAddLabel, actualSpace);
}
TaskAttribute attributeState = taskData.getRoot().getMappedAttribute(SCHEMA.STATUS.getKey());
if (attributeState != null) {
setAttributeOptionsForSpace(attributeState, actualSpace);
}
} else {
SortedSet<String> workItemTypes = new TreeSet<>();
SortedSet<String> areas = new TreeSet<>();
SortedSet<String> iterations = new TreeSet<>();
SortedSet<String> users = new TreeSet<>();
Set<String> states = new LinkedHashSet<>();
for (Space space : getSpaces().values()) {
if (attributeSpace != null) {
attributeSpace.putOption(space.getName(), space.getName());
}
if (space.getWorkItemTypes() != null) {
// assume first workItemType is representative of all with regards to states
if (!space.getWorkItemTypes().isEmpty()) {
WorkItemTypeData data = space.getWorkItemTypes().values().iterator().next();
WorkItemTypeAttributes attributes = data.getWorkItemTypeAttributes();
Map<String, WorkItemTypeField> fields = attributes.getFields();
// $NON-NLS-1$
WorkItemTypeField state = fields.get("system.state");
WorkItemTypeFieldType stateType = state.getType();
String[] values = stateType.getValues();
if (values != null) {
for (String value : values) {
states.add(value);
}
}
}
for (Entry<String, WorkItemTypeData> entry : space.getWorkItemTypes().entrySet()) {
workItemTypes.add(entry.getKey());
}
}
if (space.getAreas() != null) {
for (String entry : space.getAreas().keySet()) {
areas.add(entry);
}
}
if (space.getIterations() != null) {
for (String entry : space.getIterations().keySet()) {
iterations.add(entry);
}
}
if (space.getUsers() != null) {
for (String entry : space.getUsers().keySet()) {
users.add(entry);
}
}
}
TaskAttribute attributeWorkItemType = taskData.getRoot().getMappedAttribute(SCHEMA.WORKITEM_TYPE.getKey());
if (attributeWorkItemType != null) {
setAllAttributeOptions(attributeWorkItemType, workItemTypes);
}
TaskAttribute attributeState = taskData.getRoot().getMappedAttribute(SCHEMA.STATUS.getKey());
if (attributeState != null) {
setAllAttributeOptions(attributeState, states);
}
TaskAttribute attributeAssignees = taskData.getRoot().getMappedAttribute(SCHEMA.ASSIGNEES.getKey());
if (attributeAssignees != null && attributeAssignees.getOptions().size() == 0) {
attributeAssignees.putOption(userName, userName);
}
}
return true;
}
Aggregations