diff options
author | megumi.telles | 2018-03-13 14:43:19 +0000 |
---|---|---|
committer | megumi.telles | 2018-03-19 21:57:24 +0000 |
commit | 52c07567e02cdb160ac0cd6dcb4f044126ebbdc9 (patch) | |
tree | d0b8a25b90e3f67d507098df4168d73b2392f3d0 /plugins | |
parent | e4a03f98fdea21e9ae8607448ee381192ba0e668 (diff) | |
download | org.eclipse.osee-52c07567e02cdb160ac0cd6dcb4f044126ebbdc9.tar.gz org.eclipse.osee-52c07567e02cdb160ac0cd6dcb4f044126ebbdc9.tar.xz org.eclipse.osee-52c07567e02cdb160ac0cd6dcb4f044126ebbdc9.zip |
feature[ats_TW7883]: Initial Rest Calls to support CI-Dispo Integration0.25.3.v201803192206-NR
Diffstat (limited to 'plugins')
8 files changed, 208 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java index 9698ee227b1..ba33e6f9104 100644 --- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java @@ -11,6 +11,7 @@ package org.eclipse.osee.disposition.rest; import java.util.Collection; +import java.util.HashMap; import java.util.List; import org.eclipse.osee.disposition.model.CopySetParams; import org.eclipse.osee.disposition.model.DispoAnnotationData; @@ -22,6 +23,7 @@ import org.eclipse.osee.disposition.model.DispoSetData; import org.eclipse.osee.disposition.model.DispoSetDescriptorData; import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.orcs.data.ArtifactReadable; /** * @author Angel Avila @@ -84,4 +86,11 @@ public interface DispoApi { Collection<DispoItem> getDispoItemByAnnotationText(BranchId branch, String setId, String keyword, boolean isDetailed); DispoApiConfiguration getConfig(); + + // CI + HashMap<ArtifactReadable, BranchId> getCiSet(String ciSet); + + String getDispoItemId(BranchId branch, String setId, String item); + + boolean isCiSetConfigured(String ciSet); } diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java index 42a670b2081..a899836d2a5 100644 --- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java @@ -665,4 +665,19 @@ public class DispoApiImpl implements DispoApi { return getDispoSetById(branch, String.valueOf(id)); } + @Override + public HashMap<ArtifactReadable, BranchId> getCiSet(String ciSet) { + return getQuery().getCiSet(ciSet); + } + + @Override + public String getDispoItemId(BranchId branch, String setId, String item) { + return getQuery().getDispoItemId(branch, setId, item); + } + + @Override + public boolean isCiSetConfigured(String ciSet) { + return !getCiSet(ciSet).isEmpty(); + } + } diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoQuery.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoQuery.java index ab4b554cb8e..1293ebddd4e 100644 --- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoQuery.java +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoQuery.java @@ -11,6 +11,7 @@ package org.eclipse.osee.disposition.rest.internal; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.osee.disposition.model.DispoConfig; @@ -55,4 +56,8 @@ public interface DispoQuery { Long getDispoItemParentSet(BranchId branch, String itemId); + HashMap<ArtifactReadable, BranchId> getCiSet(String ciSet); + + String getDispoItemId(BranchId branch, String setId, String item); + }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/OrcsStorageImpl.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/OrcsStorageImpl.java index 8ff81b7840b..49e953631af 100644 --- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/OrcsStorageImpl.java +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/OrcsStorageImpl.java @@ -15,6 +15,7 @@ import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.UriGenera import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -596,4 +597,38 @@ public class OrcsStorageImpl implements Storage { return artifact.getParent().getUuid(); } + @Override + public HashMap<ArtifactReadable, BranchId> getCiSet(String ciSet) { + HashMap<ArtifactReadable, BranchId> set = new HashMap<>(); + List<BranchReadable> dispoBranches = findDispoBranches(); + QueryFactory query = getQuery(); + for (BranchReadable branch : dispoBranches) { + List<ArtifactReadable> arts = + query.fromBranch(branch).andIsOfType(DispoConstants.DispoSet).and(DispoConstants.DispoCiSet, + Arrays.asList(ciSet)).getResults().getList(); + for (ArtifactReadable art : arts) { + set.put(art, branch); + } + } + return set; + } + + private List<BranchReadable> findDispoBranches() { + BranchReadable dispoParent = getQuery().branchQuery().andNameEquals("Dispo Parent").getResults().getOneOrNull(); + return getQuery().branchQuery().andIsChildOf( + dispoParent).excludeArchived().excludeDeleted().getResults().getList(); + } + + @Override + public String getDispoItemId(BranchId branch, String setId, String item) { + ArtifactReadable DispoSet = + getQuery().fromBranch(branch).andId(ArtifactId.valueOf(setId)).getResults().getOneOrNull(); + for (ArtifactReadable child : DispoSet.getChildren()) { + if (child.getName().equals(item)) { + return child.getIdString(); + } + } + return ""; + } + } diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/types/OseeTypes_Dispo.osee b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/types/OseeTypes_Dispo.osee index f241925de3d..9c7bef9c768 100644 --- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/types/OseeTypes_Dispo.osee +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/types/OseeTypes_Dispo.osee @@ -78,6 +78,7 @@ attributeType "dispo.Dispo Config" extends StringAttribute { dataProvider DefaultAttributeDataProvider min 0 max 1 + taggerId DefaultAttributeTaggerProvider fileExtension "txt" mediaType "text/plain" } @@ -297,6 +298,7 @@ attributeType "dispo.CI Set" extends StringAttribute { dataProvider DefaultAttributeDataProvider min 0 max 1 + taggerId DefaultAttributeTaggerProvider defaultValue "" mediaType "text/plain" } diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java new file mode 100644 index 00000000000..07adc5a3cb0 --- /dev/null +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2018 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.disposition.rest.resources; + +import java.util.HashMap; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.eclipse.osee.disposition.model.DispoAnnotationData; +import org.eclipse.osee.disposition.model.DispoItem; +import org.eclipse.osee.disposition.rest.DispoApi; +import org.eclipse.osee.disposition.rest.util.DispoUtil; +import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.orcs.data.ArtifactReadable; + +/** + * @author Megumi Telles + */ +@Path("ci") +public class ContinuousIntegrationResource { + private final DispoApi dispoApi; + + public ContinuousIntegrationResource(DispoApi dispoApi) { + this.dispoApi = dispoApi; + } + + @GET + @Path("{ciSet}/annotations") + @Produces(MediaType.APPLICATION_JSON) + public HashMap<String, List<DispoAnnotationData>> getAllDispoAnnotations(@PathParam("ciSet") String ciSet) { + HashMap<ArtifactReadable, BranchId> set = dispoApi.getCiSet(ciSet); + HashMap<String, List<DispoAnnotationData>> allDispoAnnotations = new HashMap<>(); + if (set != null && !set.isEmpty()) { + ArtifactReadable dispoSet = set.keySet().iterator().next(); + List<DispoItem> dispoItems = dispoApi.getDispoItems(set.get(dispoSet), dispoSet.getIdString(), false); + for (DispoItem item : dispoItems) { + allDispoAnnotations.put(item.getName(), item.getAnnotationsList()); + } + } + return allDispoAnnotations; + } + + @GET + @Path("{ciSet}/item/{item}/annotation") + @Produces(MediaType.APPLICATION_JSON) + public List<DispoAnnotationData> getAllDispoAnnotationsPerItem(@PathParam("ciSet") String ciSet, @PathParam("item") String item) { + HashMap<ArtifactReadable, BranchId> set = dispoApi.getCiSet(ciSet); + if (set != null && !set.isEmpty()) { + ArtifactReadable dispoSet = set.keySet().iterator().next(); + BranchId branchId = set.get(dispoSet); + String itemId = dispoApi.getDispoItemId(branchId, dispoSet.getIdString(), item); + return dispoApi.getDispoAnnotations(branchId, itemId); + } + return null; + } + + @GET + @Path("{ciSet}/configured") + @Produces(MediaType.APPLICATION_JSON) + public boolean isCiSetConfigured(@PathParam("ciSet") String ciSet) { + return dispoApi.isCiSetConfigured(ciSet); + } + + @Path("{ciSet}/item/{item}/annotate") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response createDispoAnnotation(@PathParam("ciSet") String ciSet, @PathParam("item") String item, DispoAnnotationData data, @QueryParam("userName") String userName) { + Response response; + HashMap<ArtifactReadable, BranchId> set = dispoApi.getCiSet(ciSet); + if (set != null && !set.isEmpty()) { + ArtifactReadable dispoSet = set.keySet().iterator().next(); + BranchId branchId = set.get(dispoSet); + String itemId = dispoApi.getDispoItemId(branchId, dispoSet.getIdString(), item); + String createdAnnotationId = dispoApi.createDispoAnnotation(branchId, itemId, data, userName); + if (!createdAnnotationId.isEmpty()) { + response = Response.status(Response.Status.OK).build(); + boolean wasEdited = dispoApi.editDispoAnnotation(branchId, itemId, createdAnnotationId, data, userName); + if (wasEdited) { + response = Response.status(Response.Status.OK).build(); + } else { + response = Response.status(Response.Status.NOT_MODIFIED).build(); + } + } else { + response = Response.status(Response.Status.NOT_ACCEPTABLE).build(); + } + } else { + response = Response.status(Response.Status.BAD_REQUEST).build(); + } + return response; + } + + @Path("{ciSet}/item/{item}/update") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response editDispoAnnotation(@PathParam("ciSet") String ciSet, @PathParam("item") String item, DispoAnnotationData data, @QueryParam("userName") String userName) { + Response response; + HashMap<ArtifactReadable, BranchId> set = dispoApi.getCiSet(ciSet); + if (set != null && !set.isEmpty()) { + ArtifactReadable dispoSet = set.keySet().iterator().next(); + BranchId branchId = set.get(dispoSet); + String itemId = dispoApi.getDispoItemId(branchId, dispoSet.getIdString(), item); + List<DispoItem> dispoItems = dispoApi.getDispoItems(branchId, dispoSet.getIdString(), false); + DispoItem dispoItem = DispoUtil.findDispoItem(dispoItems, item); + DispoAnnotationData id = DispoUtil.getById(dispoItem.getAnnotationsList(), data.getId()); + boolean wasEdited = dispoApi.editDispoAnnotation(branchId, itemId, id.getId(), data, userName); + if (wasEdited) { + response = Response.status(Response.Status.OK).build(); + } else { + response = Response.status(Response.Status.NOT_MODIFIED).build(); + } + } else { + response = Response.status(Response.Status.BAD_REQUEST).build(); + } + return response; + } + +} diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/DispoApplication.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/DispoApplication.java index a316142f52f..604668d7a9b 100644 --- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/DispoApplication.java +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/DispoApplication.java @@ -54,6 +54,7 @@ public final class DispoApplication extends Application { singletons.add(new DispoAnnotationMessageWriter()); singletons.add(new DispoProgramResource(dispoApi)); + singletons.add(new ContinuousIntegrationResource(dispoApi)); } public void stop() { diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java index 1ff9895da24..5aa7431a989 100644 --- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java +++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java @@ -558,4 +558,13 @@ public final class DispoUtil { return testScriptNameToPath; } + public static DispoItem findDispoItem(List<DispoItem> items, String itemName) { + for (DispoItem dItem : items) { + if (dItem.getName().equals(itemName)) { + return dItem; + } + } + return null; + } + } |