Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordonald.g.dunne2017-07-20 10:47:53 -0400
committerdonald.g.dunne2017-08-03 13:29:18 -0400
commitfefa2bb820b3a4dd11d59280dea1d329bc905630 (patch)
treeca953b6dadd760fdc9ca7d0a68b0d4ce88a8aac9
parent1ed589d90cdca3108d8f38a4fb95d59d91f2fc68 (diff)
downloadorg.eclipse.osee-fefa2bb820b3a4dd11d59280dea1d329bc905630.tar.gz
org.eclipse.osee-fefa2bb820b3a4dd11d59280dea1d329bc905630.tar.xz
org.eclipse.osee-fefa2bb820b3a4dd11d59280dea1d329bc905630.zip
feature[ats_TW1384]: Create ATS WorkItem attr Get/Update REST Calls
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/AtsActionEndpointApi.java22
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/Attribute.java60
-rw-r--r--plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/IAtsWorkItemService.java2
-rw-r--r--plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/AtsClientService.java10
-rw-r--r--plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsActionEndpointImplTest.java65
-rw-r--r--plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workflow/AtsWorkItemServiceImpl.java18
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java53
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Conditions.java7
8 files changed, 237 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/AtsActionEndpointApi.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/AtsActionEndpointApi.java
index 358fa319cd..707679d04d 100644
--- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/AtsActionEndpointApi.java
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/AtsActionEndpointApi.java
@@ -15,7 +15,9 @@ import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -26,6 +28,7 @@ import org.eclipse.osee.ats.api.IAtsWorkItem;
/**
* @author Donald G. Dunne
*/
+@Path("action")
public interface AtsActionEndpointApi {
@GET
@@ -71,4 +74,23 @@ public interface AtsActionEndpointApi {
@Consumes("application/x-www-form-urlencoded")
public abstract Response createAction(MultivaluedMap<String, String> form) throws Exception;
+ /**
+ * @param actionId (guid, atsId, long) of workItem
+ * @return html representation of the changed attribute
+ */
+ @Path("{actionId}/attributeType/{attrTypeId}")
+ @GET
+ @Produces({MediaType.APPLICATION_JSON})
+ public Attribute getActionAttributeByType(@PathParam("actionId") String actionId, @PathParam("attrTypeId") String attrTypeId);
+
+ /**
+ * @param actionId (guid, atsId, long) of workItem
+ * @return html representation of the changed attribute
+ */
+ @Path("{actionId}/attributeType/{attrTypeId}")
+ @PUT
+ @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({MediaType.APPLICATION_JSON})
+ public Attribute setActionAttributeByType(@PathParam("actionId") String actionId, @PathParam("attrTypeId") String attrTypeId, List<String> values);
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/Attribute.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/Attribute.java
new file mode 100644
index 0000000000..df517e6241
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/Attribute.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.api.workflow;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.osee.framework.core.data.ArtifactId;
+import org.eclipse.osee.framework.core.data.AttributeId;
+import org.eclipse.osee.framework.core.data.AttributeTypeId;
+import org.eclipse.osee.framework.core.data.IAttribute;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class Attribute {
+
+ private ArtifactId artId = ArtifactId.SENTINEL;
+ private AttributeTypeId attrTypeId = AttributeTypeId.SENTINEL;
+ private Map<AttributeId, String> values = new HashMap<>();
+
+ public Attribute() {
+ }
+
+ public ArtifactId getArtId() {
+ return artId;
+ }
+
+ public void setArtId(ArtifactId artId) {
+ this.artId = artId;
+ }
+
+ public AttributeTypeId getAttrTypeId() {
+ return attrTypeId;
+ }
+
+ public void setAttrTypeId(AttributeTypeId attrTypeId) {
+ this.attrTypeId = attrTypeId;
+ }
+
+ public void addAttribute(IAttribute<?> attr) {
+ values.put(AttributeId.valueOf(attr.getId()), attr.getValue().toString());
+ }
+
+ public Map<AttributeId, String> getValues() {
+ return values;
+ }
+
+ public void setValues(Map<AttributeId, String> values) {
+ this.values = values;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/IAtsWorkItemService.java b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/IAtsWorkItemService.java
index 0ad29d9274..172bc3c8fe 100644
--- a/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/IAtsWorkItemService.java
+++ b/plugins/org.eclipse.osee.ats.api/src/org/eclipse/osee/ats/api/workflow/IAtsWorkItemService.java
@@ -57,4 +57,6 @@ public interface IAtsWorkItemService {
IAtsWorkItemNotes getNotes(IAtsWorkItem workItem);
ITeamWorkflowProvidersLazy getTeamWorkflowProviders();
+
+ IAtsWorkItem getWorkItemByAnyId(String actionId);
}
diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/AtsClientService.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/AtsClientService.java
index 67b46d48e1..1271bbb728 100644
--- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/AtsClientService.java
+++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/AtsClientService.java
@@ -19,6 +19,7 @@ import org.eclipse.osee.ats.api.insertion.InsertionEndpointApi;
import org.eclipse.osee.ats.api.notify.AtsNotifyEndpointApi;
import org.eclipse.osee.ats.api.program.ProgramEndpointApi;
import org.eclipse.osee.ats.api.task.AtsTaskEndpointApi;
+import org.eclipse.osee.ats.api.workflow.AtsActionEndpointApi;
import org.eclipse.osee.ats.api.workflow.AtsRuleEndpointApi;
import org.eclipse.osee.ats.core.client.IAtsClient;
import org.eclipse.osee.ats.core.client.workflow.WorkItemJsonReader;
@@ -48,6 +49,7 @@ public class AtsClientService {
private static AtsConfigEndpointApi configEp;
private static AtsWorkPackageEndpointApi workPackageEp;
private static ClientEndpoint clientEp;
+ private static AtsActionEndpointApi actionEp;
public void setAtsClient(IAtsClient atsClient) {
AtsClientService.atsClient = atsClient;
@@ -158,4 +160,12 @@ public class AtsClientService {
return clientEp;
}
+ public static AtsActionEndpointApi getActionEndpoint() {
+ if (actionEp == null) {
+ actionEp = getAtsTarget().newProxy(AtsActionEndpointApi.class);
+ }
+ return actionEp;
+
+ }
+
}
diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsActionEndpointImplTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsActionEndpointImplTest.java
index 0f91e8ca78..a807e03ff4 100644
--- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsActionEndpointImplTest.java
+++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/AtsActionEndpointImplTest.java
@@ -19,6 +19,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.Arrays;
import java.util.Collection;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
@@ -26,12 +27,18 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
+import org.eclipse.osee.ats.api.IAtsObject;
import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
+import org.eclipse.osee.ats.api.util.IAtsChangeSet;
+import org.eclipse.osee.ats.api.workflow.AtsActionEndpointApi;
+import org.eclipse.osee.ats.api.workflow.Attribute;
import org.eclipse.osee.ats.client.demo.DemoUtil;
import org.eclipse.osee.ats.client.integration.tests.AtsClientService;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.core.util.AtsObjects;
import org.eclipse.osee.framework.core.client.OseeClientProperties;
+import org.eclipse.osee.framework.core.data.AttributeTypeId;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
@@ -188,6 +195,64 @@ public class AtsActionEndpointImplTest extends AbstractRestTest {
}
@Test
+ public void testGetActionAttributeByType() {
+ testAttributeTypeMatchesRestAttributes(AtsAttributeTypes.State);
+ }
+
+ @SuppressWarnings("deprecation")
+ private TeamWorkFlowArtifact testAttributeTypeMatchesRestAttributes(AttributeTypeId attrType) {
+ TeamWorkFlowArtifact teamWf = DemoUtil.getSawCodeCommittedWf();
+ AtsActionEndpointApi actionEp = AtsClientService.getActionEndpoint();
+ Attribute attribute = actionEp.getActionAttributeByType(teamWf.getIdString(), attrType.getIdString());
+ Assert.assertEquals(teamWf.getIdString(), attribute.getArtId().getIdString());
+ Assert.assertEquals(attrType.getIdString(), attribute.getAttrTypeId().getIdString());
+ Assert.assertEquals(teamWf.getAttributeCount(attrType), attribute.getValues().size());
+
+ for (org.eclipse.osee.framework.skynet.core.artifact.Attribute<Object> attr : teamWf.getAttributes(attrType)) {
+ Assert.assertTrue(attribute.getValues().values().contains(attr.getValue()));
+ }
+ return teamWf;
+ }
+
+ @Test
+ public void testSetActionAttributeByType() {
+ AtsActionEndpointApi actionEp = AtsClientService.getActionEndpoint();
+
+ TeamWorkFlowArtifact teamWf = testAttributeTypeMatchesRestAttributes(CoreAttributeTypes.StaticId);
+ Assert.assertEquals(0,
+ AtsClientService.get().getAttributeResolver().getAttributesToStringList((IAtsObject) teamWf,
+ CoreAttributeTypes.StaticId).size());
+
+ IAtsChangeSet changes = AtsClientService.get().createChangeSet(getClass().getSimpleName());
+ changes.addAttribute((IAtsObject) teamWf, CoreAttributeTypes.StaticId, "asdf");
+ changes.addAttribute((IAtsObject) teamWf, CoreAttributeTypes.StaticId, "qwer");
+ changes.addAttribute((IAtsObject) teamWf, CoreAttributeTypes.StaticId, "zxcv");
+ changes.execute();
+
+ teamWf = testAttributeTypeMatchesRestAttributes(CoreAttributeTypes.StaticId);
+ Assert.assertEquals(3,
+ AtsClientService.get().getAttributeResolver().getAttributesToStringList((IAtsObject) teamWf,
+ CoreAttributeTypes.StaticId).size());
+
+ actionEp.setActionAttributeByType(teamWf.getIdString(), CoreAttributeTypes.StaticId.getIdString(),
+ Arrays.asList("asdf", "zxcv"));
+
+ teamWf.reloadAttributesAndRelations();
+ teamWf = testAttributeTypeMatchesRestAttributes(CoreAttributeTypes.StaticId);
+ Assert.assertEquals(2,
+ AtsClientService.get().getAttributeResolver().getAttributesToStringList((IAtsObject) teamWf,
+ CoreAttributeTypes.StaticId).size());
+
+ // test that search by guid or atsId work as well
+ Attribute attribute =
+ actionEp.getActionAttributeByType(teamWf.getGuid(), CoreAttributeTypes.StaticId.getIdString());
+ Assert.assertEquals(2, attribute.getValues().size());
+ attribute = actionEp.getActionAttributeByType(teamWf.getAtsId(), CoreAttributeTypes.StaticId.getIdString());
+ Assert.assertEquals(2, attribute.getValues().size());
+
+ }
+
+ @Test
public void testCreateAction() throws Exception {
Form form = new Form();
diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workflow/AtsWorkItemServiceImpl.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workflow/AtsWorkItemServiceImpl.java
index baea7e15e8..0d8bbe1a11 100644
--- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workflow/AtsWorkItemServiceImpl.java
+++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/workflow/AtsWorkItemServiceImpl.java
@@ -42,6 +42,7 @@ import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.jdk.core.util.Strings;
/**
@@ -185,4 +186,21 @@ public class AtsWorkItemServiceImpl implements IAtsWorkItemService {
return teamWorkflowProvidersLazy;
}
+ @Override
+ public IAtsWorkItem getWorkItemByAnyId(String actionId) {
+ IAtsWorkItem workItem = null;
+ ArtifactToken artifact = null;
+ if (GUID.isValid(actionId)) {
+ artifact = services.getArtifactByGuid(actionId);
+ } else if (Strings.isNumeric(actionId)) {
+ artifact = services.getArtifact(Long.valueOf(actionId));
+ } else {
+ artifact = services.getArtifactByAtsId(actionId);
+ }
+ if (artifact != null) {
+ workItem = services.getWorkItemFactory().getWorkItem(artifact);
+ }
+ return workItem;
+ }
+
}
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java
index fa28133dff..14a6329d93 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/workitem/AtsActionEndpointImpl.java
@@ -21,6 +21,7 @@ import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@@ -43,11 +44,15 @@ import org.eclipse.osee.ats.api.version.IAtsVersion;
import org.eclipse.osee.ats.api.workdef.StateType;
import org.eclipse.osee.ats.api.workflow.ActionResult;
import org.eclipse.osee.ats.api.workflow.AtsActionEndpointApi;
+import org.eclipse.osee.ats.api.workflow.Attribute;
import org.eclipse.osee.ats.api.workflow.WorkItemType;
import org.eclipse.osee.ats.rest.IAtsServer;
import org.eclipse.osee.ats.rest.internal.util.RestUtil;
import org.eclipse.osee.framework.core.data.AttributeTypeId;
+import org.eclipse.osee.framework.core.data.IAttribute;
import org.eclipse.osee.framework.core.enums.QueryOption;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.jaxrs.mvc.IdentityView;
import org.eclipse.osee.orcs.OrcsApi;
@@ -102,6 +107,54 @@ public final class AtsActionEndpointImpl implements AtsActionEndpointApi {
}
/**
+ * @param ids (guid, atsId, long) of workItem
+ * @return html representation of the action
+ */
+ @Override
+ @Path("{actionId}/attributeType/{attrTypeId}")
+ @GET
+ @Produces({MediaType.APPLICATION_JSON})
+ public Attribute getActionAttributeByType(@PathParam("actionId") String actionId, @PathParam("attrTypeId") String attrTypeId) {
+ IAtsWorkItem workItem = services.getWorkItemService().getWorkItemByAnyId(actionId);
+ Attribute attribute = getActionAttributeValues(attrTypeId, workItem);
+ return attribute;
+ }
+
+ private Attribute getActionAttributeValues(String attrTypeId, IAtsWorkItem workItem) {
+ Attribute attribute = new Attribute();
+ if (workItem != null) {
+ attribute.setArtId(workItem.getStoreObject());
+ AttributeTypeId attrType = services.getStoreService().getAttributeType(Long.valueOf(attrTypeId));
+ attribute.setAttrTypeId(attrType);
+ for (IAttribute<?> attr : services.getAttributeResolver().getAttributes(workItem, attrType)) {
+ attribute.addAttribute(attr);
+ }
+ }
+ return attribute;
+ }
+
+ /**
+ * @param ids (guid, atsId, long) of workItem
+ * @return html representation of the action
+ */
+ @Override
+ @Path("{actionId}/attributeType/{attrTypeId}")
+ @PUT
+ @Consumes({MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_JSON})
+ public Attribute setActionAttributeByType(@PathParam("actionId") String actionId, @PathParam("attrTypeId") String attrTypeId, List<String> values) {
+ Conditions.assertNotNullOrEmpty(values, "values can not be null or empty");
+ IAtsWorkItem workItem = services.getWorkItemService().getWorkItemByAnyId(actionId);
+ IAtsChangeSet changes = services.createChangeSet("set attr by type");
+ AttributeTypeId attrType = services.getStoreService().getAttributeType(Long.valueOf(attrTypeId));
+ changes.setAttributeValues(workItem, attrType, Collections.castAll(values));
+ changes.executeIfNeeded();
+ // reload to get latest
+ workItem = services.getWorkItemService().getWorkItemByAnyId(actionId);
+ return getActionAttributeValues(attrTypeId, workItem);
+ }
+
+ /**
* @query_string <attr type name>=<value>, <attr type id>=<value>
* @return json representation of the matching workItem(s)
*/
diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Conditions.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Conditions.java
index e89461f3c1..042ff5ad7a 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Conditions.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Conditions.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.framework.jdk.core.util;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
@@ -191,4 +192,10 @@ public final class Conditions {
throw new OseeArgumentException(message, data);
}
}
+
+ public static void assertNotNullOrEmpty(List<String> values, String message, Object... data) {
+ if (values == null || values.isEmpty()) {
+ throw new OseeArgumentException(message, data);
+ }
+ }
}

Back to the top