Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2013-01-18 19:31:46 +0000
committerRoberto E. Escobar2013-01-18 19:37:25 +0000
commit1be9de09381c28eebb3df604ae645f3210d9474c (patch)
tree7adb1584383fcb58a4fe6e45334056788b060227 /plugins/org.eclipse.osee.orcs.rest
parent020d9bb530a0f53cc18e2be4520c8bed49fb3dcc (diff)
downloadorg.eclipse.osee-1be9de09381c28eebb3df604ae645f3210d9474c.tar.gz
org.eclipse.osee-1be9de09381c28eebb3df604ae645f3210d9474c.tar.xz
org.eclipse.osee-1be9de09381c28eebb3df604ae645f3210d9474c.zip
feature[ats_L63H6]: Implement client rest search api
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.rest')
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/build.properties3
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch_V1.java78
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/Predicate.java101
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/PredicateHandler.java1
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchParameters.java67
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchResult.java83
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslFactory.java (renamed from plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/PredicateHandlerFactory.java)17
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslator.java24
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl_V1.java (renamed from plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl.java)36
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchFlag.java49
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchMethod.java46
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchOp.java47
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchQueryBuilder.java (renamed from plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDsl.java)42
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandler.java95
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandler.java27
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandler.java21
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandler.java11
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/PredicateHandlerUtil.java19
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/RelatedToPredicateHandler.java60
20 files changed, 256 insertions, 573 deletions
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 516a2f81e0..0c57b80a5b 100644
--- a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
@@ -17,5 +17,7 @@ Import-Package: javax.ws.rs,
org.eclipse.osee.framework.jdk.core.util,
org.eclipse.osee.orcs,
org.eclipse.osee.orcs.data,
+ org.eclipse.osee.orcs.rest.model,
+ org.eclipse.osee.orcs.rest.model.search,
org.eclipse.osee.orcs.search
Require-Bundle: org.eclipse.core.runtime
diff --git a/plugins/org.eclipse.osee.orcs.rest/build.properties b/plugins/org.eclipse.osee.orcs.rest/build.properties
index a3ef7214fa..52a96646f9 100644
--- a/plugins/org.eclipse.osee.orcs.rest/build.properties
+++ b/plugins/org.eclipse.osee.orcs.rest/build.properties
@@ -7,4 +7,5 @@ additional.bundles = org.eclipse.osee.orcs,\
javax.ws.rs,\
org.eclipse.osee.framework.core.model,\
org.eclipse.osee.framework.core,\
- org.eclipse.osee.framework.jdk.core
+ org.eclipse.osee.framework.jdk.core,\
+ org.eclipse.osee.orcs.rest.model
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch_V1.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch_V1.java
index 81afa7838a..00b4f41032 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch_V1.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch_V1.java
@@ -10,22 +10,24 @@
*******************************************************************************/
package org.eclipse.osee.orcs.rest.internal.search;
-import java.util.Map;
+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.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
-import org.eclipse.osee.framework.core.data.IOseeBranch;
-import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.data.HasLocalId;
import org.eclipse.osee.orcs.rest.internal.OrcsApplication;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.DslTranslatorImpl;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.PredicateHandlerFactory;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchDsl;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchDsl.DslTranslator;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.DslFactory;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.DslTranslator;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchQueryBuilder;
+import org.eclipse.osee.orcs.rest.model.search.SearchParameters;
+import org.eclipse.osee.orcs.rest.model.search.SearchResult;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
@@ -35,15 +37,11 @@ import org.eclipse.osee.orcs.search.QueryFactory;
*/
public class ArtifactSearch_V1 extends ArtifactSearch {
- private final SearchDsl dsl;
+ private final SearchQueryBuilder searchQueryBuilder;
public ArtifactSearch_V1(UriInfo uriInfo, Request request, String branchUuid) {
super(uriInfo, request, branchUuid);
-
- Map<SearchMethod, PredicateHandler> handlers = PredicateHandlerFactory.getHandlers();
- DslTranslator translator = new DslTranslatorImpl();
- // Can have a single instance of this
- dsl = new SearchDsl(handlers, translator);
+ searchQueryBuilder = DslFactory.createQueryBuilder();
}
/**
@@ -102,45 +100,53 @@ public class ArtifactSearch_V1 extends ArtifactSearch {
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public SearchResult getSearchWithQueryParams(@QueryParam("alt") String alt, @QueryParam("fields") String fields, @QueryParam("q") String rawQuery, @QueryParam("fromTx") int fromTransaction, @QueryParam("inherits") boolean includeTypeInheritance, @QueryParam("cached") boolean includeCache, @QueryParam("includeDeleted") boolean includeDeleted) throws OseeCoreException {
- return search(alt, fields, rawQuery, fromTransaction, includeTypeInheritance, includeCache, includeDeleted);
+ DslTranslator translator = DslFactory.createTranslator();
+ SearchParameters params =
+ new SearchParameters(getBranchUuid(), translator.translate(rawQuery), alt, fields, fromTransaction,
+ includeTypeInheritance, includeCache, includeDeleted);
+ return search(params);
}
- // @GET
- // @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
- // public SearchResult getSearchWithMatrixParams(@MatrixParam("alt") String alt, @MatrixParam("fields") String fields, @MatrixParam("q") String rawQuery, @MatrixParam("fromTx") int fromTransaction, @MatrixParam("inherits") boolean includeTypeInheritance, @MatrixParam("cached") boolean includeCache, @MatrixParam("includeDeleted") boolean includeDeleted) throws OseeCoreException {
- // return search(alt, fields, rawQuery, fromTransaction, includeTypeInheritance, includeCache, includeDeleted);
- // }
+ @POST
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public SearchResult getSearchWithMatrixParams(SearchParameters parameters) throws OseeCoreException {
+ return search(parameters);
+ }
- private SearchResult search(String alt, String fields, String rawQuery, int fromTransaction, boolean includeTypeInheritance, boolean includeCache, boolean includeDeleted) throws OseeCoreException {
+ private SearchResult search(SearchParameters params) throws OseeCoreException {
long startTime = System.currentTimeMillis();
- IOseeBranch branch = TokenFactory.createBranch(getBranchUuid(), "searchBranch");
-
QueryFactory qFactory = OrcsApplication.getOrcsApi().getQueryFactory(null); // Fix this
- QueryBuilder builder = dsl.build(qFactory, branch, rawQuery);
+ QueryBuilder builder = searchQueryBuilder.build(qFactory, params);
- builder.includeCache(includeCache);
- builder.includeTypeInheritance(includeTypeInheritance);
- builder.includeDeleted(includeDeleted);
+ builder.includeCache(params.isIncludeCache());
+ builder.includeTypeInheritance(params.isIncludeTypeInheritance());
+ builder.includeDeleted(params.isIncludeDeleted());
- if (fromTransaction > 0) {
- builder.fromTransaction(fromTransaction);
+ if (params.getFromTx() > 0) {
+ builder.fromTransaction(params.getFromTx());
}
- SearchResult result = new SearchResult();
- SearchParameters params = new SearchParameters(getBranchUuid(), rawQuery, alt, fields);
- result.setPredicates(dsl.getPredicates());
- result.setSearchParams(params);
- if (fields.equals("count")) {
+ SearchResult result;
+ if (params.getFields().equals("count")) {
+ result = new SearchResult();
int total = builder.getCount();
result.setTotal(total);
+ } else if (params.getFields().equals("ids")) {
+ List<Integer> localIds = new LinkedList<Integer>();
+ for (HasLocalId art : builder.getResultsAsLocalIds()) {
+ localIds.add(art.getLocalId());
+ }
+ result = new SearchResult();
+ result.setIds(localIds);
+ result.setTotal(localIds.size());
} else {
- // builder.createSearch();
- // builder.createSearchWithMatches();
throw new UnsupportedOperationException();
}
+ result.setSearchParams(params);
result.setSearchTime(System.currentTimeMillis() - startTime);
return result;
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/Predicate.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/Predicate.java
deleted file mode 100644
index cffbb3d841..0000000000
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/Predicate.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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;
-
-import java.util.List;
-import javax.xml.bind.annotation.XmlRootElement;
-import org.eclipse.osee.framework.jdk.core.util.Collections;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchFlag;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchOp;
-
-/**
- * @author John R. Misinco
- * @author Roberto E. Escobar
- */
-@XmlRootElement(name = "predicate")
-public class Predicate {
- private SearchMethod type;
- private List<String> typeParameters;
- private SearchOp op;
- private List<SearchFlag> flags;
- private List<String> values;
-
- public Predicate() {
- }
-
- public Predicate(SearchMethod type, List<String> typeParameters, SearchOp op, List<SearchFlag> flags, List<String> values) {
- this.type = type;
- this.typeParameters = typeParameters;
- this.op = op;
- this.flags = flags;
- this.values = values;
- }
-
- public void setType(SearchMethod type) {
- this.type = type;
- }
-
- public void setTypeParameters(List<String> typeParameters) {
- this.typeParameters = typeParameters;
- }
-
- public void setOp(SearchOp op) {
- this.op = op;
- }
-
- public void setFlags(List<SearchFlag> flags) {
- this.flags = flags;
- }
-
- public void setValues(List<String> values) {
- this.values = values;
- }
-
- public SearchMethod getType() {
- return type;
- }
-
- public List<String> getTypeParameters() {
- return typeParameters;
- }
-
- public SearchOp getOp() {
- return op;
- }
-
- public List<SearchFlag> getFlags() {
- return flags;
- }
-
- public List<String> getValues() {
- return values;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("type:[");
- sb.append(type);
- sb.append("],typeParameters:[");
- sb.append(Collections.toString(",", typeParameters));
- sb.append("],");
- sb.append("op:[");
- sb.append(op);
- sb.append("],flags:[");
- sb.append(Collections.toString(",", flags));
- sb.append("],values:[");
- sb.append(Collections.toString(",", values));
- sb.append("]");
- return sb.toString();
- }
-
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/PredicateHandler.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/PredicateHandler.java
index 6b25cdbb66..e807620bac 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/PredicateHandler.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/PredicateHandler.java
@@ -11,6 +11,7 @@
package org.eclipse.osee.orcs.rest.internal.search;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
import org.eclipse.osee.orcs.search.QueryBuilder;
/**
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchParameters.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchParameters.java
deleted file mode 100644
index cdbf24f8cc..0000000000
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchParameters.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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;
-
-/**
- * @author John R. Misinco
- * @author Roberto E. Escobar
- */
-public class SearchParameters {
-
- private String branchUuid;
- private String query;
- private String alt;
- private String fields;
-
- public SearchParameters() {
-
- }
-
- public SearchParameters(String uuid, String query, String alt, String fields) {
- this.branchUuid = uuid;
- this.query = query;
- this.alt = alt;
- this.fields = fields;
- }
-
- public String getBranchUuid() {
- return branchUuid;
- }
-
- public String getQuery() {
- return query;
- }
-
- public String getAlt() {
- return alt;
- }
-
- public String getFields() {
- return fields;
- }
-
- public void setBranchUuid(String uuid) {
- this.branchUuid = uuid;
- }
-
- public void setQuery(String query) {
- this.query = query;
- }
-
- public void setAlt(String alt) {
- this.alt = alt;
- }
-
- public void setFields(String fields) {
- this.fields = fields;
- }
-
-}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchResult.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchResult.java
deleted file mode 100644
index 4e05edefad..0000000000
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchResult.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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;
-
-import java.util.List;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
-/**
- * @author John R. Misinco
- * @author Roberto E. Escobar
- */
-@XmlRootElement
-public class SearchResult {
-
- // All else from out message
-
- private int total;
- private long searchTime;
- private String version;
-
- private SearchParameters searchParameters;
-
- @XmlTransient
- private List<Predicate> predicates;
-
- public SearchParameters getSearchParams() {
- return searchParameters;
- }
-
- public void setSearchParams(SearchParameters searchParams) {
- this.searchParameters = searchParams;
- }
-
- public void setPredicates(List<Predicate> predicates) {
- this.predicates = predicates;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public void setTotal(int total) {
- this.total = total;
- }
-
- public void setSearchTime(long searchTime) {
- this.searchTime = searchTime;
- }
-
- public int getTotal() {
- return total;
- }
-
- public long getSearchTime() {
- return searchTime;
- }
-
- public String getVersion() {
- return version;
- }
-
- @XmlElementWrapper(name = "predicates")
- @XmlElement(name = "predicate")
- public List<Predicate> getPredicates() {
- return predicates;
- }
-
- public SearchParameters getSearchParameters() {
- return searchParameters;
- }
-
-}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/PredicateHandlerFactory.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslFactory.java
index 40470116c1..d15fdb7305 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/PredicateHandlerFactory.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslFactory.java
@@ -17,12 +17,27 @@ import org.eclipse.osee.orcs.rest.internal.search.predicate.AttributeTypePredica
import org.eclipse.osee.orcs.rest.internal.search.predicate.ExistsTypePredicateHandler;
import org.eclipse.osee.orcs.rest.internal.search.predicate.IdsPredicateHandler;
import org.eclipse.osee.orcs.rest.internal.search.predicate.IsOfTypePredicateHandler;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
/**
* @author John R. Misinco
* @author Roberto E. Escobar
*/
-public class PredicateHandlerFactory {
+public class DslFactory {
+
+ private static SearchQueryBuilder builder;
+
+ public synchronized static SearchQueryBuilder createQueryBuilder() {
+ if (builder == null) {
+ Map<SearchMethod, PredicateHandler> handlers = DslFactory.getHandlers();
+ builder = new SearchQueryBuilder(handlers);
+ }
+ return builder;
+ }
+
+ public static DslTranslator createTranslator() {
+ return new DslTranslatorImpl_V1();
+ }
public static Map<SearchMethod, PredicateHandler> getHandlers() {
Map<SearchMethod, PredicateHandler> handlers = new HashMap<SearchMethod, PredicateHandler>();
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslator.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslator.java
new file mode 100644
index 0000000000..3232bd6750
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslator.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.dsl;
+
+import java.util.List;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+
+/**
+ * @author John R. Misinco
+ */
+public interface DslTranslator {
+
+ List<Predicate> translate(String rawString) throws OseeCoreException;
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl_V1.java
index 32a424023b..ae7984191d 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl_V1.java
@@ -13,62 +13,70 @@ package org.eclipse.osee.orcs.rest.internal.search.dsl;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
+import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
-import org.eclipse.osee.orcs.rest.internal.search.Predicate;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchDsl.DslTranslator;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+import org.eclipse.osee.orcs.rest.model.search.SearchFlag;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
+import org.eclipse.osee.orcs.rest.model.search.SearchOp;
/**
* @author John R. Misinco
* @author Roberto E. Escobar
*/
-public class DslTranslatorImpl implements DslTranslator {
+public class DslTranslatorImpl_V1 implements DslTranslator {
private static final String ARGUMENT_REGEX = ":([^&\\]]+)";
- private static final Pattern queryPattern = Pattern.compile("(\\[[^\\]]+\\])");
+ private static final Pattern queryPattern = Pattern.compile("\\]&\\[");
private static final Pattern typePattern = Pattern.compile("t" + ARGUMENT_REGEX);
private static final Pattern typeParametersPattern = Pattern.compile("tp" + ARGUMENT_REGEX);
private static final Pattern opPattern = Pattern.compile("op" + ARGUMENT_REGEX);
private static final Pattern flagsPattern = Pattern.compile("f" + ARGUMENT_REGEX);
private static final Pattern valuePattern = Pattern.compile("v" + ARGUMENT_REGEX);
+ private static final Pattern delimiterPattern = Pattern.compile("d:'(.+)'");
- private final Matcher queryMatcher, typeMatcher, opMatcher, flagsMatcher, valueMatcher, typeParametersMatcher;
+ private final Matcher typeMatcher, opMatcher, flagsMatcher, valueMatcher, typeParametersMatcher, delimiterMatcher;
+ private Scanner scanner;
- public DslTranslatorImpl() {
- queryMatcher = queryPattern.matcher("");
+ public DslTranslatorImpl_V1() {
typeMatcher = typePattern.matcher("");
opMatcher = opPattern.matcher("");
flagsMatcher = flagsPattern.matcher("");
valueMatcher = valuePattern.matcher("");
typeParametersMatcher = typeParametersPattern.matcher("");
+ delimiterMatcher = delimiterPattern.matcher("");
}
@Override
public List<Predicate> translate(String rawString) throws OseeCoreException {
List<Predicate> predicates = new LinkedList<Predicate>();
- queryMatcher.reset(rawString);
- while (queryMatcher.find()) {
- String queryBlock = queryMatcher.group(1);
+ scanner = new Scanner(rawString);
+ scanner.useDelimiter(queryPattern);
+ while (scanner.hasNext()) {
+ String queryBlock = scanner.next();
typeMatcher.reset(queryBlock);
typeParametersMatcher.reset(queryBlock);
opMatcher.reset(queryBlock);
flagsMatcher.reset(queryBlock);
valueMatcher.reset(queryBlock);
+ delimiterMatcher.reset(queryBlock);
String type = getMatch(typeMatcher);
String typeParams = getMatch(typeParametersMatcher);
String op = getMatch(opMatcher);
String flags = getMatch(flagsMatcher);
String value = getMatch(valueMatcher);
+ String delimiter = getMatch(delimiterMatcher);
- predicates.add(createPredicate(type, typeParams, op, flags, value));
+ predicates.add(createPredicate(type, typeParams, op, flags, delimiter, value));
}
return predicates;
}
- private Predicate createPredicate(String type, String typeParameters, String op, String flags, String value) throws OseeCoreException {
+ private Predicate createPredicate(String type, String typeParameters, String op, String flags, String delimiter, String value) throws OseeCoreException {
SearchMethod searchMethod = SearchMethod.fromString(type);
SearchOp searchOp = SearchOp.fromString(op);
@@ -81,14 +89,14 @@ public class DslTranslatorImpl implements DslTranslator {
List<String> values = Arrays.asList(value.split(",\\s*"));
List<String> typeParams = Arrays.asList(typeParameters.split(",\\s*"));
- return new Predicate(searchMethod, typeParams, searchOp, searchFlags, values);
+ return new Predicate(searchMethod, typeParams, searchOp, searchFlags, delimiter, values);
}
private String getMatch(Matcher m) {
if (m.find()) {
return m.group(1);
}
- return "";
+ return Strings.EMPTY_STRING;
}
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchFlag.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchFlag.java
deleted file mode 100644
index 9b9ebc8632..0000000000
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchFlag.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.dsl;
-
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.util.Conditions;
-
-/**
- * @author John R. Misinco
- * @author Roberto E. Escobar
- */
-public enum SearchFlag {
- TOKENIZED("t"),
- IGNORE_CASE("i"),
- MATCH_CASE("m"),
- TOKENIZED_ANY("t_any"),
- TOKENIZED_ORDERED("t_ordered"),
- INCLUDE_TYPE_INHERITANCE("iti");
-
- private final String token;
-
- private SearchFlag(String token) {
- this.token = token;
- }
-
- public String getToken() {
- return token;
- }
-
- public static SearchFlag fromString(String value) throws OseeCoreException {
- SearchFlag toReturn = null;
- for (SearchFlag op : SearchFlag.values()) {
- if (op.getToken().equals(value)) {
- toReturn = op;
- break;
- }
- }
- Conditions.checkNotNull(toReturn, "SearchFlag", "Invalid flag [%s]", value);
- return toReturn;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchMethod.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchMethod.java
deleted file mode 100644
index 9a516a9f7c..0000000000
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchMethod.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.dsl;
-
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.util.Conditions;
-
-/**
- * @author John R. Misinco
- * @author Roberto E. Escobar
- */
-public enum SearchMethod {
- IDS("ids"),
- IS_OF_TYPE("isOfType"),
- EXISTS_TYPE("exists"),
- ATTRIBUTE_TYPE("attrType");
-
- private final String token;
-
- private SearchMethod(String token) {
- this.token = token;
- }
-
- public String getToken() {
- return token;
- }
-
- public static SearchMethod fromString(String value) throws OseeCoreException {
- SearchMethod toReturn = null;
- for (SearchMethod op : SearchMethod.values()) {
- if (op.getToken().equals(value)) {
- toReturn = op;
- }
- }
- Conditions.checkNotNull(toReturn, "SearchMethod", "Invalid type [%s]", value);
- return toReturn;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchOp.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchOp.java
deleted file mode 100644
index 34d9f533bf..0000000000
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchOp.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.dsl;
-
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.util.Conditions;
-
-/**
- * @author John R. Misinco
- * @author Roberto E. Escobar
- */
-public enum SearchOp {
- EQUALS("=="),
- NOT_EQUALS("!="),
- LESS_THAN("<"),
- GREATER_THAN(">"),
- IN("in");
-
- private final String token;
-
- private SearchOp(String token) {
- this.token = token;
- }
-
- public String getToken() {
- return token;
- }
-
- public static SearchOp fromString(String value) throws OseeCoreException {
- SearchOp toReturn = null;
- for (SearchOp op : SearchOp.values()) {
- if (op.getToken().equals(value)) {
- toReturn = op;
- }
- }
- Conditions.checkNotNull(toReturn, "searchOp", "Invalid op [%s]", value);
- return toReturn;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDsl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchQueryBuilder.java
index 884a15a728..e97d74ed78 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDsl.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchQueryBuilder.java
@@ -13,10 +13,13 @@ package org.eclipse.osee.orcs.rest.internal.search.dsl;
import java.util.List;
import java.util.Map;
import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
-import org.eclipse.osee.orcs.rest.internal.search.Predicate;
import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
+import org.eclipse.osee.orcs.rest.model.search.SearchParameters;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
@@ -24,41 +27,30 @@ import org.eclipse.osee.orcs.search.QueryFactory;
* @author John R. Misinco
* @author Roberto E. Escobar
*/
-public class SearchDsl {
-
- public static interface DslTranslator {
-
- List<Predicate> translate(String rawString) throws OseeCoreException;
-
- }
+public class SearchQueryBuilder {
private final Map<SearchMethod, PredicateHandler> handlers;
- private final DslTranslator translator;
- private List<Predicate> predicates;
- public SearchDsl(Map<SearchMethod, PredicateHandler> handlers, DslTranslator translator) {
+ public SearchQueryBuilder(Map<SearchMethod, PredicateHandler> handlers) {
this.handlers = handlers;
- this.translator = translator;
}
- public QueryBuilder build(QueryFactory queryFactory, IOseeBranch branch, String rawQuery) throws OseeCoreException {
+ public QueryBuilder build(QueryFactory queryFactory, SearchParameters params) throws OseeCoreException {
Conditions.checkNotNull(queryFactory, "queryFactory");
- Conditions.checkNotNull(branch, "branch");
- Conditions.checkNotNull(rawQuery, "rawQuery");
- predicates = translator.translate(rawQuery);
- QueryBuilder builder = queryFactory.fromBranch(branch);
- for (Predicate predicate : predicates) {
- SearchMethod method = predicate.getType();
- if (handlers.containsKey(method)) {
+ Conditions.checkNotNull(params, "params");
+ IOseeBranch searchBranch = TokenFactory.createBranch(params.getBranchUuid(), "searchBranch");
+ QueryBuilder builder = queryFactory.fromBranch(searchBranch);
+ List<Predicate> predicates = params.getPredicates();
+ if (predicates != null) {
+ for (Predicate predicate : predicates) {
+ SearchMethod method = predicate.getType();
PredicateHandler handler = handlers.get(method);
- builder = handler.handle(builder, predicate);
+ if (handler != null) {
+ builder = handler.handle(builder, predicate);
+ }
}
}
return builder;
}
- public List<Predicate> getPredicates() {
- return predicates;
- }
-
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandler.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandler.java
index 87c4f8b0d8..9608d5b67e 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandler.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandler.java
@@ -14,18 +14,20 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.enums.CaseType;
+import org.eclipse.osee.framework.core.enums.MatchTokenCountType;
+import org.eclipse.osee.framework.core.enums.Operator;
+import org.eclipse.osee.framework.core.enums.TokenDelimiterMatch;
+import org.eclipse.osee.framework.core.enums.TokenOrderType;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
-import org.eclipse.osee.orcs.rest.internal.search.Predicate;
import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchFlag;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchOp;
-import org.eclipse.osee.orcs.search.CaseType;
-import org.eclipse.osee.orcs.search.Operator;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+import org.eclipse.osee.orcs.rest.model.search.SearchFlag;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
+import org.eclipse.osee.orcs.rest.model.search.SearchOp;
import org.eclipse.osee.orcs.search.QueryBuilder;
-import org.eclipse.osee.orcs.search.StringOperator;
/**
* @author John R. Misinco
@@ -42,40 +44,31 @@ public class AttributeTypePredicateHandler implements PredicateHandler {
List<String> typeParameters = predicate.getTypeParameters();
Collection<IAttributeType> attributeTypes = PredicateHandlerUtil.getIAttributeTypes(typeParameters);
SearchOp op = predicate.getOp();
- List<String> values = predicate.getValues();
+ Collection<String> values = predicate.getValues();
Conditions.checkNotNull(values, "values");
- if (isAttributeTokenSearch(op, flags) && !containsAny(Collections.singleton(op), SearchOp.GREATER_THAN,
- SearchOp.LESS_THAN)) {
- StringOperator operator = getStringOperator(op, flags);
- Conditions.checkNotNull(operator, "string operator",
- "Query error - cannot determine string operator from [%s]:[%s]", op, flags);
+ if (!containsAny(Collections.singleton(op), SearchOp.GREATER_THAN, SearchOp.LESS_THAN)) {
CaseType ct = getCaseType(flags);
- for (String value : values) {
- builder = and(builder, attributeTypes, operator, ct, value);
+ TokenOrderType orderType = getTokenOrderType(flags);
+ MatchTokenCountType countType = getMatchTokenCountType(flags);
+ if (values.size() == 1) {
+ builder =
+ builder.and(attributeTypes, values.iterator().next(),
+ TokenDelimiterMatch.custom(predicate.getDelimiter()), ct, orderType, countType);
+ } else {
+ for (IAttributeType type : attributeTypes) {
+ builder = builder.and(type, getOperator(op), values);
+ }
}
} else {
Operator operator = getOperator(op);
for (IAttributeType type : attributeTypes) {
- builder = and(builder, type, operator, values);
+ builder = builder.and(type, operator, values);
}
}
return builder;
}
- protected QueryBuilder and(QueryBuilder builder, Collection<IAttributeType> attributeTypes, StringOperator operator, CaseType ct, String value) throws OseeCoreException {
- return builder.and(attributeTypes, operator, ct, value);
- }
-
- protected QueryBuilder and(QueryBuilder builder, IAttributeType type, Operator operator, List<String> values) throws OseeCoreException {
- return builder.and(type, operator, values);
- }
-
- private boolean isAttributeTokenSearch(SearchOp op, List<SearchFlag> flags) {
- return containsAny(flags, SearchFlag.TOKENIZED, SearchFlag.TOKENIZED_ANY, SearchFlag.TOKENIZED_ORDERED,
- SearchFlag.IGNORE_CASE) || containsAny(Collections.singleton(op), SearchOp.IN);
- }
-
private boolean containsAny(Collection<?> data, Object... values) {
boolean result = false;
for (Object object : values) {
@@ -88,43 +81,24 @@ public class AttributeTypePredicateHandler implements PredicateHandler {
}
private CaseType getCaseType(List<SearchFlag> flags) {
- if (flags.contains(SearchFlag.MATCH_CASE)) {
+ if (flags != null && flags.contains(SearchFlag.MATCH_CASE)) {
return CaseType.MATCH_CASE;
}
return CaseType.IGNORE_CASE;
}
- // EQUALS(), // Exact Match as in Strings.equals
- // NOT_EQUALS(), // inverse of exact match - !Strings.equals
- // CONTAINS,
- // TOKENIZED_ANY_ORDER,
- // TOKENIZED_MATCH_ORDER
-
- private StringOperator getStringOperator(SearchOp op, List<SearchFlag> flags) {
- StringOperator toReturn;
-
- if (flags.contains(SearchFlag.TOKENIZED_ANY)) {
- toReturn = StringOperator.TOKENIZED_ANY_ORDER;
- } else if (flags.contains(SearchFlag.TOKENIZED_ORDERED)) {
- toReturn = StringOperator.TOKENIZED_MATCH_ORDER;
- } else {
- switch (op) {
- case EQUALS:
- toReturn = StringOperator.EQUALS;
- break;
- case NOT_EQUALS:
- toReturn = StringOperator.NOT_EQUALS;
- break;
- case IN:
- toReturn = StringOperator.CONTAINS;
- break;
- default:
- toReturn = null;
- break;
+ private TokenOrderType getTokenOrderType(List<SearchFlag> flags) {
+ if (flags != null && flags.contains(SearchFlag.MATCH_TOKEN_ORDER)) {
+ return TokenOrderType.MATCH_ORDER;
+ }
+ return TokenOrderType.ANY_ORDER;
+ }
- }
+ private MatchTokenCountType getMatchTokenCountType(List<SearchFlag> flags) {
+ if (flags != null && flags.contains(SearchFlag.MATCH_TOKEN_COUNT)) {
+ return MatchTokenCountType.MATCH_TOKEN_COUNT;
}
- return toReturn;
+ return MatchTokenCountType.IGNORE_TOKEN_COUNT;
}
// EQUAL("="), // Exact Match as in Strings.equals
@@ -138,9 +112,6 @@ public class AttributeTypePredicateHandler implements PredicateHandler {
if (op.equals(SearchOp.LESS_THAN)) {
return Operator.LESS_THAN;
}
- if (op.equals(SearchOp.NOT_EQUALS)) {
- return Operator.NOT_EQUAL;
- }
return Operator.EQUAL;
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandler.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandler.java
index 731d9f44c9..04c20b2cde 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandler.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandler.java
@@ -13,13 +13,13 @@ package org.eclipse.osee.orcs.rest.internal.search.predicate;
import java.util.Collection;
import java.util.List;
import org.eclipse.osee.framework.core.data.IAttributeType;
-import org.eclipse.osee.framework.core.data.IRelationTypeSide;
+import org.eclipse.osee.framework.core.data.IRelationType;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
-import org.eclipse.osee.orcs.rest.internal.search.Predicate;
import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
import org.eclipse.osee.orcs.search.QueryBuilder;
/**
@@ -34,7 +34,7 @@ public class ExistsTypePredicateHandler implements PredicateHandler {
throw new OseeArgumentException("This predicate handler only supports [%s]", SearchMethod.EXISTS_TYPE);
}
List<String> typeParameters = predicate.getTypeParameters();
- List<String> values = predicate.getValues();
+ Collection<String> values = predicate.getValues();
Conditions.checkNotNull(typeParameters, "typeParameters");
Conditions.checkNotNull(values, "values");
@@ -43,24 +43,17 @@ public class ExistsTypePredicateHandler implements PredicateHandler {
String existsType = typeParameters.get(0);
if ("attrType".equals(existsType)) {
Collection<IAttributeType> attributeTypes = PredicateHandlerUtil.getIAttributeTypes(values);
- builder = andAttrTypesExists(builder, attributeTypes);
+ if (!attributeTypes.isEmpty()) {
+ builder.andExists(attributeTypes);
+ }
} else if ("relType".equals(existsType)) {
- Collection<IRelationTypeSide> relations = PredicateHandlerUtil.getIRelationTypeSides(values);
- builder = andRelTypeSideExists(builder, relations);
+ for (IRelationType rt : PredicateHandlerUtil.getIRelationTypes(values)) {
+ builder.andExists(rt);
+ }
}
}
return builder;
}
- protected QueryBuilder andRelTypeSideExists(QueryBuilder builder, Collection<IRelationTypeSide> relations) throws OseeCoreException {
- for (IRelationTypeSide rts : relations) {
- builder = builder.andExists(rts);
- }
- return builder;
- }
-
- protected QueryBuilder andAttrTypesExists(QueryBuilder builder, Collection<IAttributeType> attributeTypes) throws OseeCoreException {
- return builder.andExists(attributeTypes);
- }
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandler.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandler.java
index 2794283563..e5b2001d19 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandler.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandler.java
@@ -12,13 +12,12 @@ package org.eclipse.osee.orcs.rest.internal.search.predicate;
import java.util.Collection;
import java.util.HashSet;
-import java.util.List;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
-import org.eclipse.osee.orcs.rest.internal.search.Predicate;
import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
import org.eclipse.osee.orcs.search.QueryBuilder;
/**
@@ -32,8 +31,7 @@ public class IdsPredicateHandler implements PredicateHandler {
if (predicate.getType() != SearchMethod.IDS) {
throw new OseeArgumentException("This predicate handler only supports [%s]", SearchMethod.IDS);
}
- QueryBuilder theBuilder = builder;
- List<String> values = predicate.getValues();
+ Collection<String> values = predicate.getValues();
Conditions.checkNotNull(values, "values");
@@ -48,20 +46,13 @@ public class IdsPredicateHandler implements PredicateHandler {
}
if (!guids.isEmpty()) {
- theBuilder = addGuids(builder, guids);
+ builder.andGuidsOrHrids(guids);
}
if (!rawIds.isEmpty()) {
- theBuilder = addIds(builder, rawIds);
+ builder.andLocalIds(rawIds);
}
- return theBuilder;
+ return builder;
}
- protected QueryBuilder addGuids(QueryBuilder builder, Collection<String> guids) throws OseeCoreException {
- return builder.andGuidsOrHrids(guids);
- }
-
- protected QueryBuilder addIds(QueryBuilder builder, Collection<Integer> rawIds) throws OseeCoreException {
- return builder.andLocalIds(rawIds);
- }
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandler.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandler.java
index 13b96179be..2d04869ed4 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandler.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandler.java
@@ -11,14 +11,13 @@
package org.eclipse.osee.orcs.rest.internal.search.predicate;
import java.util.Collection;
-import java.util.List;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
-import org.eclipse.osee.orcs.rest.internal.search.Predicate;
import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler;
-import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
import org.eclipse.osee.orcs.search.QueryBuilder;
/**
@@ -32,10 +31,12 @@ public class IsOfTypePredicateHandler implements PredicateHandler {
if (predicate.getType() != SearchMethod.IS_OF_TYPE) {
throw new OseeArgumentException("This predicate handler only supports [%s]", SearchMethod.IS_OF_TYPE);
}
- List<String> values = predicate.getValues();
+ Collection<String> values = predicate.getValues();
Conditions.checkNotNull(values, "values");
Collection<IArtifactType> artTypes = PredicateHandlerUtil.getIArtifactTypes(values);
- builder = andIsOfType(builder, artTypes);
+ if (!artTypes.isEmpty()) {
+ builder.andIsOfType(artTypes);
+ }
return builder;
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/PredicateHandlerUtil.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/PredicateHandlerUtil.java
index 289f4d58d4..7baab311f5 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/PredicateHandlerUtil.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/PredicateHandlerUtil.java
@@ -12,9 +12,9 @@ package org.eclipse.osee.orcs.rest.internal.search.predicate;
import java.util.Collection;
import java.util.HashSet;
-import java.util.List;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IRelationType;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.enums.RelationSide;
@@ -27,7 +27,7 @@ import org.eclipse.osee.framework.core.util.HexUtil;
*/
public class PredicateHandlerUtil {
- public static Collection<IAttributeType> getIAttributeTypes(List<String> types) throws OseeCoreException {
+ public static Collection<IAttributeType> getIAttributeTypes(Collection<String> types) throws OseeCoreException {
Collection<IAttributeType> attrTypes = new HashSet<IAttributeType>();
for (String value : types) {
long uuid = parseUuid(value);
@@ -38,7 +38,7 @@ public class PredicateHandlerUtil {
return attrTypes;
}
- public static Collection<IArtifactType> getIArtifactTypes(List<String> types) throws OseeCoreException {
+ public static Collection<IArtifactType> getIArtifactTypes(Collection<String> types) throws OseeCoreException {
Collection<IArtifactType> artTypes = new HashSet<IArtifactType>();
for (String value : types) {
long uuid = parseUuid(value);
@@ -49,7 +49,18 @@ public class PredicateHandlerUtil {
return artTypes;
}
- public static Collection<IRelationTypeSide> getIRelationTypeSides(List<String> rels) throws OseeCoreException {
+ public static Collection<IRelationType> getIRelationTypes(Collection<String> rels) throws OseeCoreException {
+ Collection<IRelationType> types = new HashSet<IRelationType>();
+ for (String value : rels) {
+ long longUuid = parseUuid(value);
+ if (longUuid != -1L) {
+ types.add(TokenFactory.createRelationType(longUuid, "SearchRelationType"));
+ }
+ }
+ return types;
+ }
+
+ public static Collection<IRelationTypeSide> getIRelationTypeSides(Collection<String> rels) throws OseeCoreException {
Collection<IRelationTypeSide> relSides = new HashSet<IRelationTypeSide>();
for (String value : rels) {
char sideChar = value.charAt(0);
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/RelatedToPredicateHandler.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/RelatedToPredicateHandler.java
new file mode 100644
index 0000000000..67113005ef
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/RelatedToPredicateHandler.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.predicate;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import org.eclipse.osee.framework.core.data.IRelationTypeSide;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler;
+import org.eclipse.osee.orcs.rest.model.search.Predicate;
+import org.eclipse.osee.orcs.rest.model.search.SearchMethod;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+
+/**
+ * @author John Misinco
+ */
+public class RelatedToPredicateHandler implements PredicateHandler {
+
+ @Override
+ public QueryBuilder handle(QueryBuilder builder, Predicate predicate) throws OseeCoreException {
+ if (predicate.getType() != SearchMethod.RELATED_TO) {
+ throw new OseeArgumentException("This predicate handler only supports [%s]", SearchMethod.EXISTS_TYPE);
+ }
+ List<String> typeParameters = predicate.getTypeParameters();
+ Collection<String> values = predicate.getValues();
+
+ Conditions.checkNotNull(typeParameters, "typeParameters");
+ Conditions.checkNotNull(values, "values");
+
+ Collection<IRelationTypeSide> types = PredicateHandlerUtil.getIRelationTypeSides(typeParameters);
+ Collection<Integer> localIds = new LinkedList<Integer>();
+
+ for (String value : values) {
+ if (GUID.isValid(value)) {
+ throw new UnsupportedOperationException();
+ } else {
+ localIds.add(Integer.parseInt(value));
+ }
+ }
+
+ if (!localIds.isEmpty()) {
+ for (IRelationTypeSide rts : types) {
+ builder.andRelatedToLocalIds(rts, localIds);
+ }
+ }
+ return builder;
+ }
+}

Back to the top