Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2014-04-03 13:17:06 -0400
committerJohn Misinco2014-04-07 15:24:48 -0400
commit9189cc5fa25bce7053fc004a7a1069f1a20ab545 (patch)
tree3c2cec3bd71738cd65e0a70353b48ec8fb9ba98a
parent042e50f7f7bcacdb092cc8ee562fc03ad4ed0027 (diff)
downloadorg.eclipse.osee-9189cc5fa25bce7053fc004a7a1069f1a20ab545.tar.gz
org.eclipse.osee-9189cc5fa25bce7053fc004a7a1069f1a20ab545.tar.xz
org.eclipse.osee-9189cc5fa25bce7053fc004a7a1069f1a20ab545.zip
feature[ats_ATS29067]: Create BranchQuery REST API
-rw-r--r--features/org.eclipse.osee.x.server.external.feature/feature.xml8
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/search/branch/BranchQueryOptions.java104
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/branch/BranchQueryResource.java226
6 files changed, 344 insertions, 1 deletions
diff --git a/features/org.eclipse.osee.x.server.external.feature/feature.xml b/features/org.eclipse.osee.x.server.external.feature/feature.xml
index 3bcef246d3..4978680235 100644
--- a/features/org.eclipse.osee.x.server.external.feature/feature.xml
+++ b/features/org.eclipse.osee.x.server.external.feature/feature.xml
@@ -41,6 +41,7 @@
<import plugin="org.eclipse.jetty.servlet" version="8.1.10" match="compatible"/>
<import plugin="org.eclipse.jetty.util" version="8.1.10" match="compatible"/>
<import plugin="com.google.guava" version="11.0.0" match="greaterOrEqual"/>
+ <import plugin="com.google.gson" version="2.1.0" match="greaterOrEqual"/>
<import plugin="org.apache.commons.dbcp" version="1.4.0" match="compatible"/>
<import plugin="org.apache.commons.pool" version="1.6.0" match="compatible"/>
<import feature="org.eclipse.emf" version="2.9.0" match="greaterOrEqual"/>
@@ -169,6 +170,13 @@
install-size="0"
version="0.0.0"
unpack="false"/>
+
+ <plugin
+ id="com.google.gson"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
<plugin
id="com.google.inject"
diff --git a/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF
index fcc3738494..df06c40df7 100644
--- a/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.rest.model/META-INF/MANIFEST.MF
@@ -6,7 +6,8 @@ Bundle-Version: 0.17.0.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.eclipse.osee.orcs.rest.model,
- org.eclipse.osee.orcs.rest.model.search.artifact
+ org.eclipse.osee.orcs.rest.model.search.artifact,
+ org.eclipse.osee.orcs.rest.model.search.branch
Import-Package: javax.xml.bind.annotation,
org.eclipse.osee.framework.core.enums,
org.eclipse.osee.framework.core.exception,
diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/search/branch/BranchQueryOptions.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/search/branch/BranchQueryOptions.java
new file mode 100644
index 0000000000..97d45aceff
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/search/branch/BranchQueryOptions.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.orcs.rest.model.search.branch;
+
+import java.util.List;
+import org.eclipse.osee.framework.core.enums.BranchState;
+import org.eclipse.osee.framework.core.enums.BranchType;
+
+/**
+ * @author John Misinco
+ */
+public class BranchQueryOptions {
+
+ private List<Integer> branchIds;
+ private List<BranchType> branchTypes;
+ private List<BranchState> branchStates;
+ private boolean includeDeleted;
+ private boolean includeArchived;
+ private String nameEquals;
+ private String namePattern;
+ private Long isChildOf = -1L;
+ private Long isAncestorOf = -1L;
+
+ public List<Integer> getBranchIds() {
+ return branchIds;
+ }
+
+ public void setBranchIds(List<Integer> branchIds) {
+ this.branchIds = branchIds;
+ }
+
+ public List<BranchType> getBranchTypes() {
+ return branchTypes;
+ }
+
+ public void setBranchTypes(List<BranchType> branchTypes) {
+ this.branchTypes = branchTypes;
+ }
+
+ public List<BranchState> getBranchStates() {
+ return branchStates;
+ }
+
+ public void setBranchStates(List<BranchState> branchStates) {
+ this.branchStates = branchStates;
+ }
+
+ public boolean isIncludeDeleted() {
+ return includeDeleted;
+ }
+
+ public void setIncludeDeleted(boolean includeDeleted) {
+ this.includeDeleted = includeDeleted;
+ }
+
+ public boolean isIncludeArchived() {
+ return includeArchived;
+ }
+
+ public void setIncludeArchived(boolean includeArchived) {
+ this.includeArchived = includeArchived;
+ }
+
+ public String getNameEquals() {
+ return nameEquals;
+ }
+
+ public void setNameEquals(String nameEquals) {
+ this.nameEquals = nameEquals;
+ }
+
+ public String getNamePattern() {
+ return namePattern;
+ }
+
+ public void setNamePattern(String namePattern) {
+ this.namePattern = namePattern;
+ }
+
+ public void setIsChildOf(Long isChildOf) {
+ this.isChildOf = isChildOf;
+ }
+
+ public Long getIsChildOf() {
+ return isChildOf;
+ }
+
+ public void setIsAncestorOf(Long isAncestorOf) {
+ this.isAncestorOf = isAncestorOf;
+ }
+
+ public Long getIsAncestorOf() {
+ return isAncestorOf;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
index 7d9f566553..d800467964 100644
--- a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Service-Component: OSGI-INF/*.xml
Import-Package: com.google.common.base,
com.google.common.collect,
+ com.google.gson,
javax.ws.rs,
javax.ws.rs.core,
javax.ws.rs.ext,
@@ -23,4 +24,5 @@ Import-Package: com.google.common.base,
org.eclipse.osee.orcs.data,
org.eclipse.osee.orcs.rest.model,
org.eclipse.osee.orcs.rest.model.search.artifact,
+ org.eclipse.osee.orcs.rest.model.search.branch,
org.eclipse.osee.orcs.search
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
index f9b844508c..74fd0fc991 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java
@@ -14,6 +14,7 @@ import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import org.eclipse.osee.orcs.OrcsApi;
+import org.eclipse.osee.orcs.rest.internal.search.branch.BranchQueryResource;
/**
* Get application.wadl at this context to get rest documentation
@@ -36,6 +37,7 @@ public class OrcsApplication extends Application {
public void start() {
classes.add(BranchesResource.class);
+ resources.add(new BranchQueryResource(orcsApi));
}
public void stop() {
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/branch/BranchQueryResource.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/branch/BranchQueryResource.java
new file mode 100644
index 0000000000..98886b18a9
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/branch/BranchQueryResource.java
@@ -0,0 +1,226 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.orcs.rest.internal.search.branch;
+
+import java.util.Collections;
+import java.util.LinkedList;
+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.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.data.TokenFactory;
+import org.eclipse.osee.framework.core.enums.BranchState;
+import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.orcs.OrcsApi;
+import org.eclipse.osee.orcs.data.BranchReadable;
+import org.eclipse.osee.orcs.rest.model.search.branch.BranchQueryOptions;
+import org.eclipse.osee.orcs.search.BranchQuery;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * @author John Misinco
+ */
+@Path("branchQuery")
+public class BranchQueryResource {
+
+ private final Gson plainG = new Gson();
+ private final Gson prettyG = new GsonBuilder().setPrettyPrinting().create();
+ private final OrcsApi orcsApi;
+
+ public BranchQueryResource(OrcsApi orcsApi) {
+ this.orcsApi = orcsApi;
+ }
+
+ /**
+ * Perform a branch query based on a JSON input
+ *
+ * @param branchQueryJson JSON of {@link org.eclipse.osee.orcs.rest.model.search.branch.BranchQueryOptions
+ * BranchQueryOptions} class
+ * @return JSON representation of the branch query results
+ */
+ @Path("/")
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response searchBranches(String branchQueryJson) {
+ BranchQueryOptions options = plainG.fromJson(branchQueryJson, BranchQueryOptions.class);
+ List<BranchReadable> results = getResultsFromOptions(options);
+ return Response.ok(plainG.toJson(results)).build();
+ }
+
+ /**
+ * Perform a branch query based on the input query parameters
+ *
+ * @param branchIds comma separated list of branch ids
+ * @param branchTypes comma separated list of {@link org.eclipse.osee.framework.core.enums.BranchType BranchType}
+ * @param branchStates comma separated list of {@link org.eclipse.osee.framework.core.enums.BranchState BranchState}
+ * @param deleted to include deleted branches in the search
+ * @param archived to include archived branches in the search
+ * @param childOf branch id of the parent to search children of
+ * @param ancestorOf branch id of ancestor to search decendents of
+ * @param pretty if the returned JSON should be pretty printed
+ * @return JSON representation of the branch query results
+ */
+ @Path("/")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response searchBranchesFromQuery(@QueryParam("branchIds") String branchIds, @QueryParam("branchTypes") String branchTypes, @QueryParam("branchStates") String branchStates, @QueryParam("deleted") boolean deleted, @QueryParam("archived") boolean archived, @QueryParam("nameEquals") String nameEquals, @QueryParam("namePattern") String namePattern, @QueryParam("childOf") Long childOf, @QueryParam("ancestorOf") Long ancestorOf, @QueryParam("pretty") boolean pretty) {
+ BranchQueryOptions options = new BranchQueryOptions();
+ if (Strings.isValid(branchIds)) {
+ List<Integer> branchIdVals = new LinkedList<Integer>();
+ for (String branchId : branchIds.split(",")) {
+ branchIdVals.add(Integer.parseInt(branchId));
+ }
+ options.setBranchIds(branchIdVals);
+ }
+
+ if (Strings.isValid(branchTypes)) {
+ List<BranchType> branchTypeVals = new LinkedList<BranchType>();
+ for (String branchType : branchTypes.split(",")) {
+ branchTypeVals.add(BranchType.valueOf(branchType.toUpperCase()));
+ }
+ options.setBranchTypes(branchTypeVals);
+ }
+
+ if (Strings.isValid(branchStates)) {
+ List<BranchState> branchStateVals = new LinkedList<BranchState>();
+ for (String branchState : branchStates.split(",")) {
+ branchStateVals.add(BranchState.valueOf(branchState.toUpperCase()));
+ }
+ options.setBranchStates(branchStateVals);
+ }
+
+ options.setIncludeDeleted(deleted);
+ options.setIncludeArchived(archived);
+
+ if (Strings.isValid(nameEquals)) {
+ options.setNameEquals(nameEquals);
+ }
+
+ if (Strings.isValid(namePattern)) {
+ options.setNamePattern(namePattern);
+ }
+
+ if (childOf != null) {
+ options.setIsChildOf(childOf);
+ }
+
+ if (ancestorOf != null) {
+ options.setIsAncestorOf(ancestorOf);
+ }
+
+ List<BranchReadable> results = getResultsFromOptions(options);
+ Gson gson = pretty ? prettyG : plainG;
+ return Response.ok(gson.toJson(results)).build();
+ }
+
+ /**
+ * Perform a branch query for all working branches
+ *
+ * @param pretty if the returned JSON should be pretty printed
+ * @return JSON representation of the branch query results
+ */
+ @Path("/working")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getWorkingBranches(@QueryParam("pretty") boolean pretty) {
+ BranchQueryOptions options = new BranchQueryOptions();
+ options.setBranchTypes(Collections.singletonList(BranchType.WORKING));
+ List<BranchReadable> results = getResultsFromOptions(options);
+ Gson gson = pretty ? prettyG : plainG;
+ return Response.ok(gson.toJson(results)).build();
+ }
+
+ /**
+ * Perform a branch query for all baseline branches
+ *
+ * @param pretty if the returned JSON should be pretty printed
+ * @return JSON representation of the branch query results
+ */
+ @Path("/baseline")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getBaselineBranches(@QueryParam("pretty") boolean pretty) throws OseeCoreException {
+ BranchQueryOptions options = new BranchQueryOptions();
+ options.setBranchTypes(Collections.singletonList(BranchType.BASELINE));
+ List<BranchReadable> results = getResultsFromOptions(options);
+ Gson gson = pretty ? prettyG : plainG;
+ return Response.ok(gson.toJson(results)).build();
+ }
+
+ private List<BranchReadable> getResultsFromOptions(BranchQueryOptions options) {
+ BranchQuery query = orcsApi.getQueryFactory(null).branchQuery();
+ if (Conditions.hasValues(options.getBranchIds())) {
+ query.andLocalIds(options.getBranchIds());
+ }
+
+ List<BranchState> branchStates = options.getBranchStates();
+ if (Conditions.hasValues(branchStates)) {
+ query.andStateIs(branchStates.toArray(new BranchState[branchStates.size()]));
+ }
+
+ List<BranchType> branchTypes = options.getBranchTypes();
+ if (Conditions.hasValues(branchTypes)) {
+ query.andIsOfType(branchTypes.toArray(new BranchType[branchTypes.size()]));
+ }
+
+ List<Integer> branchIds = options.getBranchIds();
+ if (Conditions.hasValues(branchIds)) {
+ query.andLocalIds(branchIds);
+ }
+
+ if (options.isIncludeArchived()) {
+ query.includeArchived();
+ }
+
+ if (options.isIncludeDeleted()) {
+ query.includeDeleted();
+ }
+
+ String nameEquals = options.getNameEquals();
+ if (Strings.isValid(nameEquals)) {
+ query.andNameEquals(nameEquals);
+ }
+
+ String namePattern = options.getNamePattern();
+ if (Strings.isValid(namePattern)) {
+ query.andNamePattern(namePattern);
+ }
+
+ Long ancestorOf = options.getIsAncestorOf();
+ if (ancestorOf > 0) {
+ IOseeBranch ancestorOfToken = TokenFactory.createBranch(ancestorOf, "queryAncestorOf");
+ query.andIsAncestorOf(ancestorOfToken);
+ }
+
+ Long childOf = options.getIsChildOf();
+ if (childOf > 0) {
+ IOseeBranch childOfToken = TokenFactory.createBranch(ancestorOf, "queryChildOf");
+ query.andIsAncestorOf(childOfToken);
+ }
+
+ List<BranchReadable> toReturn = new LinkedList<BranchReadable>();
+ for (BranchReadable branch : query.getResults()) {
+ toReturn.add(branch);
+ }
+ return toReturn;
+ }
+}

Back to the top