Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2017-11-14 22:57:40 +0000
committerJeff Johnston2017-11-14 23:40:42 +0000
commitc62266fed70fb1c9a6edbdca7994b6d89414748b (patch)
tree403e1993cefe3915de8f2e6842008c457766fe25
parent0603e18be867fc70acb9263e77fc4170af2f7748 (diff)
downloadorg.eclipse.linuxtools-c62266fed70fb1c9a6edbdca7994b6d89414748b.tar.gz
org.eclipse.linuxtools-c62266fed70fb1c9a6edbdca7994b6d89414748b.tar.xz
org.eclipse.linuxtools-c62266fed70fb1c9a6edbdca7994b6d89414748b.zip
Add OSIO Label support to OSIO Rest Connector
- add new Labelxxxx classes to support Label data - modify OSIORestGetTaskData and OSIORestGetSingleTaskData classes to read "labels" relationship - add new OSIOLabelAttributeEditor for showing labels in the Task editor and allowing a user to add a label to a work item and to select labels for removal similar to how assignees works - add new OSIORestPostNewLabelTask to create a new label for a space (there is no corresponding delete function defined by the fabric-8 design at present) - add support in OSIORestPatchUpdateTask to handle new and removed labels; for new labels check to see if the label exists in the space and if not, create it first - add labels to space relationships and also add a Map of all labels for the space - add support in OSIORestClient to load all labels for a space and use these values as suggestions for the Add Label field in the Task editor Change-Id: I4b71b62454904acf99ee054dd34730bfa46eab02 Reviewed-on: https://git.eclipse.org/r/111598 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/IOSIORestConstants.java2
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestClient.java10
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestConfiguration.java6
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetSingleTaskData.java10
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskData.java13
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskLabels.java73
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestMessages.properties5
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPatchUpdateTask.java79
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPostNewLabelTask.java144
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestTaskSchema.java17
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Label.java49
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelAttributes.java82
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelListResponse.java34
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelRelationships.java21
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelResponse.java22
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Space.java14
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIOLabelAttributeEditor.java122
-rw-r--r--mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIORestTaskEditorPage.java6
18 files changed, 698 insertions, 11 deletions
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/IOSIORestConstants.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/IOSIORestConstants.java
index e57ad21a14..4309f1ba8b 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/IOSIORestConstants.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/IOSIORestConstants.java
@@ -14,6 +14,8 @@ package org.eclipse.linuxtools.internal.mylyn.osio.rest.core;
public interface IOSIORestConstants {
public static final String EDITOR_TYPE_ASSIGNEES = "osio.editor.assignees"; //$NON-NLS-1$
+
+ public static final String EDITOR_TYPE_LABELS = "osio.editor.labels"; //$NON-NLS-1$
public static final String EDITOR_TYPE_KEYWORD = "osio.editor.keyword"; //$NON-NLS-1$
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestClient.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestClient.java
index 8c8da85fd0..3d77cd6dd3 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestClient.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestClient.java
@@ -31,6 +31,8 @@ import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.AreaLi
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.IdNamed;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.IterationListResponse;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.LabelListResponse;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Named;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.RestResponse;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space;
@@ -117,6 +119,8 @@ public class OSIORestClient {
space.setAreas(areas);
Map<String, Iteration> iterations = getSpaceIterations(new NullOperationMonitor(), space);
space.setIterations(iterations);
+ Map<String, Label> labels = getSpaceLabels(new NullOperationMonitor(), space);
+ space.setLabels(labels);
Map<String, User> users = getUsers(new NullOperationMonitor(), space);
space.setUsers(users);
}
@@ -209,6 +213,11 @@ public class OSIORestClient {
});
}
+ public Map<String, Label> getSpaceLabels(IOperationMonitor monitor, Space space) throws OSIORestException {
+ return retrieveItems(monitor, "/spaces/" + space.getId() + "/labels", new TypeToken<LabelListResponse>() { //$NON-NLS-1$ //$NON-NLS-2$
+ });
+ }
+
public RepositoryResponse postTaskData(TaskData taskData, Set<TaskAttribute> oldAttributes,
TaskRepository repository, IOperationMonitor monitor) throws OSIORestException {
TaskAttribute spaceAttribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE.getKey());
@@ -316,6 +325,7 @@ public class OSIORestClient {
new OSIORestGetTaskComments(getClient(), space,taskData).run(monitor);
new OSIORestGetTaskCreator(getClient(), taskData).run(monitor);
new OSIORestGetTaskLinks(getClient(), space, taskData).run(monitor);
+ new OSIORestGetTaskLabels(getClient(), space, taskData).run(monitor);
setTaskAssignees(taskData);
config.updateSpaceOptions(taskData);
config.addValidOperations(taskData);
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestConfiguration.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestConfiguration.java
index 39b1111380..36cb67d3f4 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestConfiguration.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestConfiguration.java
@@ -178,6 +178,8 @@ public class OSIORestConfiguration implements Serializable {
internalSetAttributeOptions(taskAttribute, actualSpace.getIterations());
} else if (taskAttribute.getId().equals(SCHEMA.ADD_ASSIGNEE.getKey())) {
internalSetAttributeOptions(taskAttribute, actualSpace.getUsers());
+ } else if (taskAttribute.getId().equals(SCHEMA.ADD_LABEL.getKey())) {
+ internalSetAttributeOptions(taskAttribute, actualSpace.getLabels());
} else if (taskAttribute.getId().equals(SCHEMA.STATUS.getKey())) {
Map<String, String> stateMap = new LinkedHashMap<>();
Map<String, WorkItemTypeData> workItemTypes = actualSpace.getWorkItemTypes();
@@ -264,6 +266,10 @@ public class OSIORestConfiguration implements Serializable {
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);
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetSingleTaskData.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetSingleTaskData.java
index 33217e0459..ad089ef18a 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetSingleTaskData.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetSingleTaskData.java
@@ -31,6 +31,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.IdNamed;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceSingleResponse;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User;
@@ -157,6 +158,8 @@ public class OSIORestGetSingleTaskData extends OSIORestGetRequest<TaskData> {
actualSpace.setAreas(areas);
Map<String, Iteration> iterations = restClient.getSpaceIterations(new NullOperationMonitor(), actualSpace);
actualSpace.setIterations(iterations);
+ Map<String, Label> labels = restClient.getSpaceLabels(new NullOperationMonitor(), actualSpace);
+ actualSpace.setLabels(labels);
Map<String, User> users = restClient.getUsers(new NullOperationMonitor(), actualSpace);
actualSpace.setUsers(users);
} catch (OSIORestException e) {
@@ -258,6 +261,7 @@ public class OSIORestGetSingleTaskData extends OSIORestGetRequest<TaskData> {
if (attributeId.equals("space") //$NON-NLS-1$
|| attributeId.equals("assignees") //$NON-NLS-1$
|| attributeId.equals("creator") //$NON-NLS-1$
+ || attributeId.equals("labels") //$NON-NLS-1$
|| attributeId.equals("children")) { //$NON-NLS-1$
continue;
}
@@ -298,6 +302,12 @@ public class OSIORestGetSingleTaskData extends OSIORestGetRequest<TaskData> {
JsonObject creatorData = creatorObject.get("data").getAsJsonObject(); //$NON-NLS-1$
creatorID.setValue(creatorData.get("id").getAsString());
+ // add labels link (will resolve later)
+ TaskAttribute labelsLink = taskData.getRoot().getAttribute(taskSchema.LABELS_LINK.getKey());
+ JsonObject labelsObject = relationships.get("labels").getAsJsonObject(); //$NON-NLS-1$
+ JsonObject labelsData = labelsObject.get("links").getAsJsonObject(); //$NON-NLS-1$
+ labelsLink.setValue(labelsData.get("related").getAsString());
+
// add workitem url
TaskAttribute workitemURL = taskData.getRoot().getAttribute(taskSchema.TASK_URL.getKey());
JsonObject linksObject = workitemdata.get("links").getAsJsonObject(); //$NON-NLS-1$
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskData.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskData.java
index 3fb523a6c0..d8976e478c 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskData.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskData.java
@@ -33,6 +33,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.IdNamed;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceSingleResponse;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User;
@@ -164,13 +165,12 @@ public class OSIORestGetTaskData extends OSIORestGetRequest<List<TaskData>> {
actualSpace.setAreas(areas);
Map<String, Iteration> iterations = restClient.getSpaceIterations(new NullOperationMonitor(), actualSpace);
actualSpace.setIterations(iterations);
+ Map<String, Label> labels = restClient.getSpaceLabels(new NullOperationMonitor(), actualSpace);
+ actualSpace.setLabels(labels);
Map<String, User> users = restClient.getUsers(new NullOperationMonitor(), actualSpace);
actualSpace.setUsers(users);
} catch (OSIORestException e) {
continue;
-// com.google.common.base.Throwables.propagate(
-// new CoreException(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN,
-// "Can not find Space (" + spaceId + ")"))); //$NON-NLS-1$ //$NON-NLS-2$
}
externalSpaces.put(actualSpace.getName(), actualSpace);
}
@@ -267,6 +267,7 @@ public class OSIORestGetTaskData extends OSIORestGetRequest<List<TaskData>> {
if (attributeId.equals("space") //$NON-NLS-1$
|| attributeId.equals("assignees") //$NON-NLS-1$
|| attributeId.equals("creator") //$NON-NLS-1$
+ || attributeId.equals("labels") //$NON-NLS-1$
|| attributeId.equals("children")) { //$NON-NLS-1$
continue;
}
@@ -307,6 +308,12 @@ public class OSIORestGetTaskData extends OSIORestGetRequest<List<TaskData>> {
JsonObject creatorData = creatorObject.get("data").getAsJsonObject(); //$NON-NLS-1$
creatorID.setValue(creatorData.get("id").getAsString()); //$NON-NLS-1$
+ // add labels link (will resolve later)
+ TaskAttribute labelsLink = taskData.getRoot().getAttribute(taskSchema.LABELS_LINK.getKey());
+ JsonObject labelsObject = relationships.get("labels").getAsJsonObject(); //$NON-NLS-1$
+ JsonObject labelsData = labelsObject.get("links").getAsJsonObject(); //$NON-NLS-1$
+ labelsLink.setValue(labelsData.get("related").getAsString());
+
// add workitem url
TaskAttribute workitemURL = taskData.getRoot().getAttribute(taskSchema.TASK_URL.getKey());
JsonObject linksObject = workitemdata.get("links").getAsJsonObject(); //$NON-NLS-1$
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskLabels.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskLabels.java
new file mode 100644
index 0000000000..6a32df2e3c
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestGetTaskLabels.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2015, 2017 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ * Red Hat Inc. - modified for use with OpenShift.io
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.core;
+
+import java.io.InputStreamReader;
+import java.lang.reflect.Type;
+
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space;
+import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpClient;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.reflect.TypeToken;
+
+@SuppressWarnings("restriction")
+public class OSIORestGetTaskLabels extends OSIORestGetRequest<TaskAttribute> {
+
+ private final TaskData taskData;
+ public OSIORestGetTaskLabels(CommonHttpClient client, Space space, TaskData taskData) {
+ super(client, "/workitems/" + taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().UUID.getKey()).getValue() + "/labels", null); //$NON-NLS-1$ //$NON-NLS-2$
+ this.taskData = taskData;
+ taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().UUID.getKey()).getValue();
+ }
+
+ @Override
+ protected TaskAttribute parseFromJson(InputStreamReader in) {
+ TypeToken<TaskAttribute> type = new TypeToken<TaskAttribute>() {
+ };
+ return new GsonBuilder().registerTypeAdapter(type.getType(), new JSonTaskDataDeserializer())
+ .create()
+ .fromJson(in, type.getType());
+ }
+
+ OSIORestTaskSchema taskSchema = OSIORestTaskSchema.getDefault();
+
+ private class JSonTaskDataDeserializer implements JsonDeserializer<TaskAttribute> {
+
+ @Override
+ public TaskAttribute deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
+ throws JsonParseException {
+ TaskAttribute response = taskData.getRoot().getAttribute(taskSchema.LABELS.getKey());
+ response.clearValues();
+ if (json.getAsJsonObject().get("data") != null) {
+ for (JsonElement entry : json.getAsJsonObject().get("data") //$NON-NLS-1$
+ .getAsJsonArray()) {
+ JsonObject entryObject = (JsonObject) entry.getAsJsonObject();
+ JsonObject attributes = (JsonObject) entryObject.get("attributes").getAsJsonObject();
+ String name = attributes.getAsJsonObject().get("name").getAsString(); //$NON-NLS-1$
+ response.addValue(name);
+ }
+ }
+ return response;
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestMessages.properties b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestMessages.properties
index abdeae6a42..477b59249e 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestMessages.properties
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestMessages.properties
@@ -15,9 +15,13 @@ SchemaUUID.label=UUID
SchemaWorkitemType.label=Workitem Type
SchemaWorkitemURL.label=Workitem URL
SchemaAddAssignee.label=Add Assignee
+SchemaLabelAdd.label=Add Label
SchemaRemoveAssignee.label=Remove Assignee
+SchemaRemoveLabel.label=Remove Label
SchemaArea.label=Area
SchemaAssignees.label=Assignees\n(Select to remove)
+SchemaLabels.label=Labels\n(Select to remove)
+SchemaLabelsLink.label=Labels Link
SchemaAssigneeIDs.label=Assignee IDs
SchemaCreator.label=Creator
SchemaCreatorID.label=Creator ID
@@ -30,6 +34,7 @@ SchemaLinks.label=Links
SchemaNumber.label=#
UnknownAssignee.msg=Assignee: {0} not valid for space
+UnknownLabel.msg=Label: {0} not valid for space
StateChangeOperation=Change state to "{0}"
KeepStateOperation=Keep state as "{0}" \ No newline at end of file
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPatchUpdateTask.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPatchUpdateTask.java
index 7be93a1d98..e27cc7fac9 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPatchUpdateTask.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPatchUpdateTask.java
@@ -35,6 +35,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.LabelResponse;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
@@ -192,19 +194,80 @@ public class OSIORestPatchUpdateTask extends OSIORestPatchRequest<TaskData> {
out.name("data"); //$NON-NLS-1$
out.beginArray();
for (String assignee : assignees) {
- String userid = users.get(assignee).getId();
- if (userid == null) {
- throw new UnsupportedOperationException(
- OSIORestMessages.getFormattedString("UnknownAssignee.msg", assignee)); //$NON-NLS-1$
+ if (assignee != null && !assignee.isEmpty()) {
+ User user = users.get(assignee);
+ if (user == null) {
+ throw new UnsupportedOperationException(
+ OSIORestMessages.getFormattedString("UnknownAssignee.msg", assignee)); //$NON-NLS-1$
+ }
+ String userid = user.getId();
+ out.beginObject();
+ out.name("id").value(userid); //$NON-NLS-1$
+ out.name("type").value("users"); //$NON-NLS-1$ //$NON-NLS-2$
+ out.endObject();
}
- out.beginObject();
- out.name("id").value(userid); //$NON-NLS-1$
- out.name("type").value("users"); //$NON-NLS-1$ //$NON-NLS-2$
- out.endObject();
}
out.endArray();
}
out.endObject(); // assignees
+ // labels
+ attribute = taskData.getRoot().getAttribute(taskSchema.LABELS.getKey());
+ List<String> labels = attribute.getValues();
+ if (labels == null) {
+ labels = new ArrayList<String>();
+ } else {
+ labels = new ArrayList<>(labels);
+ }
+ attribute = taskData.getRoot().getAttribute(taskSchema.REMOVE_LABEL.getKey());
+ List<String> labelRemovals = attribute.getValues();
+ if (labelRemovals != null) {
+ for (String removal : labelRemovals) {
+ int index = labels.indexOf(removal);
+ if (index >= 0) {
+ labels.remove(index);
+ }
+ }
+ }
+ attribute = taskData.getRoot().getAttribute(taskSchema.ADD_LABEL.getKey());
+ String labelAddString = attribute.getValue();
+ String[] labelAdditions = labelAddString.split(",");
+ if (labelAdditions != null) {
+ for (String addition : labelAdditions) {
+ int index = labels.indexOf(addition);
+ if (index < 0) {
+ labels.add(addition);
+ }
+ }
+ }
+ out.name("labels"); //$NON-NLS-1$
+ out.beginObject();
+ out.name("data"); //$NON-NLS-1$
+ out.beginArray();
+ if (labels.size() > 0 && !labels.get(0).isEmpty()) {
+ Map<String, Label> spaceLabels = space.getLabels();
+ for (String label : labels) {
+ Label l = spaceLabels.get(label);
+ if (l == null) {
+ try {
+ LabelResponse response = new OSIORestPostNewLabelTask(client, space, label).run(new NullOperationMonitor());
+ Label newLabel = response.getData();
+ spaceLabels.put(label, newLabel);
+ } catch (OSIORestException e) {
+ e.printStackTrace();
+ }
+ }
+ l = spaceLabels.get(label);
+ if (l != null) {
+ String labelid = l.getId();
+ out.beginObject();
+ out.name("id").value(labelid); //$NON-NLS-1$
+ out.name("type").value("labels"); //$NON-NLS-1$ //$NON-NLS-2$
+ out.endObject();
+ }
+ }
+ }
+ out.endArray();
+ out.endObject(); // labels
out.endObject(); // relationships
out.name("type").value("workitems"); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPostNewLabelTask.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPostNewLabelTask.java
new file mode 100644
index 0000000000..c3365c6205
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestPostNewLabelTask.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2015, 2017 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ * Red Hat Inc. - modified for use with OpenShift.io
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.core;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.http.HttpStatus;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.StringEntity;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.LabelResponse;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space;
+import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
+import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpClient;
+import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpResponse;
+
+import com.google.common.base.Function;
+import com.google.common.base.Throwables;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.TypeAdapter;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+
+public class OSIORestPostNewLabelTask extends OSIORestPostRequest<LabelResponse> {
+
+ private final CommonHttpClient client;
+ private final String newLabel;
+
+ class TaskAttributeTypeAdapter extends TypeAdapter<String> {
+
+ public TaskAttributeTypeAdapter() {
+ super();
+ }
+
+ private final Function<String, String> function = new Function<String, String>() {
+
+ @Override
+ public String apply(String input) {
+ return OSIORestGsonUtil.convertString2GSonString(input);
+ }
+ };
+
+ @Override
+ public void write(JsonWriter out, String newLabel) throws IOException {
+ out.beginObject();
+ out.name("data"); //$NON-NLS-1$
+ out.beginObject();
+ out.name("attributes"); //$NON-NLS-1$
+ out.beginObject();
+ out.name("name").value(newLabel);
+ out.name("background-color").value("#f9d67a"); //$NON-NLS-1$
+ out.name("border-color").value("#f39d3c"); //$NON-NLS-1$
+ out.endObject(); // end attributes
+ out.name("type").value("labels"); //$NON-NLS-1$
+ out.endObject(); // end data
+ out.name("included").beginArray(); //$NON-NLS-1$
+ out.endArray();
+ out.endObject();
+ }
+
+ @Override
+ public String read(JsonReader in) throws IOException {
+ throw new UnsupportedOperationException(
+ "TaskAttributeTypeAdapter in OSIORestNewLabelTask only supports write"); //$NON-NLS-1$
+ }
+
+ }
+
+ public OSIORestPostNewLabelTask(CommonHttpClient client, Space space, String newLabel) {
+ super(client, "/spaces/" + //$NON-NLS-1$
+ space.getId() +
+ "/labels", true); //$NON-NLS-1$
+ this.client = client;
+ this.newLabel = newLabel;
+ }
+
+ List<NameValuePair> requestParameters;
+
+ @Override
+ protected void addHttpRequestEntities(HttpRequestBase request) throws OSIORestException {
+ super.addHttpRequestEntities(request);
+ try {
+ Gson gson = new GsonBuilder()
+ .registerTypeAdapter(String.class, new TaskAttributeTypeAdapter())
+ .create();
+ StringEntity requestEntity = new StringEntity(gson.toJson(newLabel));
+ ((HttpPost) request).setEntity(requestEntity);
+ } catch (UnsupportedEncodingException e) {
+ Throwables.propagate(new CoreException(
+ new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, "Can not build HttpRequest", e))); //$NON-NLS-1$
+ }
+ }
+
+ public static String convert(String str) {
+ str = str.replace("\"", "\\\"").replace("\n", "\\\n"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
+ StringBuffer ostr = new StringBuffer();
+ for (int i = 0; i < str.length(); i++) {
+ char ch = str.charAt(i);
+ if ((ch >= 0x0020) && (ch <= 0x007e)) {
+ ostr.append(ch);
+ } else {
+ ostr.append("\\u"); //$NON-NLS-1$
+ String hex = Integer.toHexString(str.charAt(i) & 0xFFFF);
+ for (int j = 0; j < 4 - hex.length(); j++) {
+ ostr.append("0"); //$NON-NLS-1$
+ }
+ ostr.append(hex.toLowerCase());
+ }
+ }
+ return (new String(ostr));
+ }
+
+ @Override
+ protected void doValidate(CommonHttpResponse response, IOperationMonitor monitor)
+ throws IOException, OSIORestException {
+ validate(response, HttpStatus.SC_CREATED, monitor);
+ }
+
+ @Override
+ protected LabelResponse parseFromJson(InputStreamReader in) throws OSIORestException {
+ return new Gson().fromJson(in, new TypeToken<LabelResponse>() {}.getType());
+ }
+
+
+} \ No newline at end of file
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestTaskSchema.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestTaskSchema.java
index 28cab2b985..d670d4cb94 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestTaskSchema.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/OSIORestTaskSchema.java
@@ -122,6 +122,19 @@ public class OSIORestTaskSchema extends AbstractTaskSchema {
OSIORestMessages.getString("SchemaRemoveAssignee.label"), //$NON-NLS-1$
IOSIORestConstants.EDITOR_TYPE_ASSIGNEES);
+ public final Field LABELS = createField("labels", //$NON-NLS-1$
+ OSIORestMessages.getString("SchemaLabels.label"), //$NON-NLS-1$
+ IOSIORestConstants.EDITOR_TYPE_LABELS, Flag.ATTRIBUTE);
+
+
+ public final Field REMOVE_LABEL = createField("removeLabel", //$NON-NLS-1$
+ OSIORestMessages.getString("SchemaRemoveLabel.label"), //$NON-NLS-1$
+ IOSIORestConstants.EDITOR_TYPE_LABELS);
+
+ public final Field LABELS_LINK = createField("labelsLink", //$NON-NLS-1$
+ OSIORestMessages.getString("SchemaLabelsLink.label"), //$NON-NLS-1$
+ TaskAttribute.TYPE_URL);
+
public final Field ASSIGNEE_IDS = createField("assigneeIDs", //$NON-NLS-1$
OSIORestMessages.getString("SchemaAssigneeIDs.label"), //$NON-NLS-1$
TaskAttribute.TYPE_SHORT_TEXT, Flag.READ_ONLY);
@@ -146,6 +159,10 @@ public class OSIORestTaskSchema extends AbstractTaskSchema {
OSIORestMessages.getString("SchemaLinks.label"),
TaskAttribute.TYPE_SHORT_TEXT, Flag.ATTRIBUTE);
+ public final Field ADD_LABEL = createField("addLabel", //$NON-NLS-1$
+ OSIORestMessages.getString("SchemaLabelAdd.label"), //$NON-NLS-1$
+ TaskAttribute.TYPE_MULTI_LABEL, Flag.ATTRIBUTE);
+
public final Field COMMENT_COUNT = createField("commentCount", //$NON-NLS-1$
OSIORestMessages.getString("SchemaCommentCount.label"), //$NON-NLS-1$
TaskAttribute.TYPE_INTEGER, Flag.READ_ONLY);
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Label.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Label.java
new file mode 100644
index 0000000000..f467920e61
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Label.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data;
+
+public class Label implements IdNamed {
+
+ private String type;
+
+ private String id;
+
+ private LabelAttributes attributes;
+
+ private LabelRelationships relationships;
+
+ private GenericLinks links;
+
+ public String getType() {
+ return type;
+ }
+
+ public String getName() {
+ return attributes.getName();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public LabelAttributes getAttributes() {
+ return attributes;
+ }
+
+ public LabelRelationships getRelationships() {
+ return relationships;
+ }
+
+ public GenericLinks getLinks() {
+ return links;
+ }
+
+}
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelAttributes.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelAttributes.java
new file mode 100644
index 0000000000..ab4c9a7184
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelAttributes.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.google.gson.annotations.SerializedName;
+
+public class LabelAttributes implements Named {
+
+ private String name;
+
+ @SerializedName("created-at")
+ private String created_at;
+
+ @SerializedName("updated-at")
+ private String updated_at;
+
+ private String version;
+
+ @SerializedName("text-color")
+ private String text_color;
+
+ @SerializedName("background-color")
+ private String background_color;
+
+ @SerializedName("border-color")
+ private String border_color;
+
+ public String getName() {
+ return name;
+ }
+
+ public Date getCreatedAt() {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss"); //$NON-NLS-1$
+ Date d = null;
+ try {
+ d = sdf.parse(created_at.replace("Z", "").replace("T", "-")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return d;
+ }
+
+ public Date getUpdatedAt() {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss"); //$NON-NLS-1$
+ Date d = null;
+ try {
+ d = sdf.parse(updated_at.replace("Z", "").replace("T", "-")); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return d;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getBackgroundColor() {
+ return background_color;
+ }
+
+ public String getTextColor() {
+ return text_color;
+ }
+
+ public String getBorderColor() {
+ return border_color;
+ }
+
+}
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelListResponse.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelListResponse.java
new file mode 100644
index 0000000000..49ae435ae8
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelListResponse.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2017 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ * Red Hat Inc. - modified for use in OSIO Rest Connector
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data;
+
+public class LabelListResponse implements RestResponse<Label> {
+ private Label[] data;
+
+ private PagingLinks links;
+
+ private SpaceListMeta meta;
+
+ @Override
+ public Label[] getArray() {
+ return data;
+ }
+
+ public PagingLinks getLinks() {
+ return links;
+ }
+
+ public SpaceListMeta getMeta() {
+ return meta;
+ }
+}
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelRelationships.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelRelationships.java
new file mode 100644
index 0000000000..b412def6ac
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelRelationships.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data;
+
+public class LabelRelationships {
+
+ private RelationGeneric space;
+
+ public RelationGeneric getSpace() {
+ return space;
+ }
+
+}
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelResponse.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelResponse.java
new file mode 100644
index 0000000000..7b8638c1dd
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/LabelResponse.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data;
+
+public class LabelResponse implements SingleRestResponse<Label> {
+ private Label data;
+
+ @Override
+ public Label getData() {
+ return data;
+ }
+
+}
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Space.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Space.java
index 3f7cf46cca..31bd1f3dbd 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Space.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.core/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/core/response/data/Space.java
@@ -39,6 +39,10 @@ public class Space implements IdNamed {
private Map<String, IdNamed> iterationsIdNamed;
+ private Map<String, Label> labels;
+
+ private Map<String, IdNamed> labelsIdNamed;
+
private Map<String, User> users;
private Map<String, IdNamed> usersIdNamed;
@@ -115,6 +119,16 @@ public class Space implements IdNamed {
return iterations;
}
+ public void setLabels(Map<String, Label> labels) {
+ this.labels = labels;
+ this.labelsIdNamed = labels.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> (IdNamed)e.getValue()));
+ }
+
+ public Map<String, Label> getLabels() {
+ return labels;
+ }
+
public Map<String, IdNamed> getMapFor(String member) {
if ("area".equals(member)) {
return areasIdNamed;
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIOLabelAttributeEditor.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIOLabelAttributeEditor.java
new file mode 100644
index 0000000000..f1681191de
--- /dev/null
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIOLabelAttributeEditor.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2015, 2017 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ * Red Hat Inc - modified for use with OpenShift.io
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.mylyn.osio.rest.ui;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+public class OSIOLabelAttributeEditor extends AbstractAttributeEditor {
+
+ private List list;
+
+ private TaskAttribute attrRemoveLabel;
+
+ protected boolean suppressRefresh;
+
+ public OSIOLabelAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
+ super(manager, taskAttribute);
+ setLayoutHint(new LayoutHint(RowSpan.MULTIPLE, ColumnSpan.SINGLE));
+ }
+
+ @Override
+ public void createControl(Composite parent, FormToolkit toolkit) {
+ list = new List(parent, SWT.FLAT | SWT.MULTI | SWT.V_SCROLL);
+ toolkit.adapt(list, true, true);
+ list.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
+ list.setFont(JFaceResources.getDefaultFont());
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(list);
+ list.setToolTipText(getDescription());
+
+ populateFromAttribute();
+
+ attrRemoveLabel = getModel().getTaskData()
+ .getRoot()
+ .getMappedAttribute(OSIORestTaskSchema.getDefault().REMOVE_LABEL.getKey());
+
+ selectValuesToRemove();
+
+ list.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ suppressRefresh = true;
+ for (String cc : list.getItems()) {
+ int index = list.indexOf(cc);
+ if (list.isSelected(index)) {
+ java.util.List<String> remove = attrRemoveLabel.getValues();
+ if (!remove.contains(cc)) {
+ attrRemoveLabel.addValue(cc);
+ }
+ } else {
+ attrRemoveLabel.removeValue(cc);
+ }
+ }
+ getModel().attributeChanged(attrRemoveLabel);
+ } finally {
+ suppressRefresh = false;
+ }
+ }
+ });
+
+ list.showSelection();
+
+ setControl(list);
+ }
+
+ private void populateFromAttribute() {
+ TaskAttribute attrLabel = getTaskAttribute();
+ if (attrLabel != null) {
+ for (String value : attrLabel.getValues()) {
+ list.add(value);
+ }
+ }
+ }
+
+ private void selectValuesToRemove() {
+ for (String item : attrRemoveLabel.getValues()) {
+ int i = list.indexOf(item);
+ if (i != -1) {
+ list.select(i);
+ }
+ }
+ }
+
+ @Override
+ public void refresh() {
+ if (list != null && !list.isDisposed()) {
+ list.removeAll();
+ populateFromAttribute();
+ selectValuesToRemove();
+ }
+ }
+
+ @Override
+ public boolean shouldAutoRefresh() {
+ return !suppressRefresh;
+ }
+
+}
diff --git a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIORestTaskEditorPage.java b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIORestTaskEditorPage.java
index d6762f0629..328135b951 100644
--- a/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIORestTaskEditorPage.java
+++ b/mylyn/org.eclipse.linuxtools.mylyn.osio.rest.ui/src/org/eclipse/linuxtools/internal/mylyn/osio/rest/ui/OSIORestTaskEditorPage.java
@@ -50,6 +50,8 @@ public class OSIORestTaskEditorPage extends AbstractTaskEditorPage {
AbstractAttributeEditor editor;
if (IOSIORestConstants.EDITOR_TYPE_ASSIGNEES.equals(type)) {
editor = new OSIOAssigneeAttributeEditor(getModel(), taskAttribute);
+ } else if (IOSIORestConstants.EDITOR_TYPE_LABELS.equals(type)) {
+ editor = new OSIOLabelAttributeEditor(getModel(), taskAttribute);
} else if (IOSIORestConstants.EDITOR_TYPE_KEYWORD.equals(type)) {
editor = new OSIOKeywordAttributeEditor(getModel(), taskAttribute);
} else {
@@ -59,6 +61,10 @@ public class OSIORestTaskEditorPage extends AbstractTaskEditorPage {
&& OSIORestTaskSchema.getDefault().ADD_ASSIGNEE.getKey().equals(taskAttribute.getId())) {
editor.setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
}
+ if (editor != null
+ && OSIORestTaskSchema.getDefault().ADD_LABEL.getKey().equals(taskAttribute.getId())) {
+ editor.setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
+ }
return editor;
}

Back to the top