diff options
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.rest')
21 files changed, 1209 insertions, 2 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 debc22a54bf..90138fb40c5 100644 --- a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF @@ -13,6 +13,8 @@ Import-Package: javax.ws.rs, org.eclipse.osee.framework.core.exception, org.eclipse.osee.framework.core.model, org.eclipse.osee.framework.core.model.cache, + org.eclipse.osee.framework.core.util, + org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.orcs, org.eclipse.osee.orcs.data, org.eclipse.osee.orcs.search diff --git a/plugins/org.eclipse.osee.orcs.rest/build.properties b/plugins/org.eclipse.osee.orcs.rest/build.properties index 730445b64ff..a3ef7214fa9 100644 --- a/plugins/org.eclipse.osee.orcs.rest/build.properties +++ b/plugins/org.eclipse.osee.orcs.rest/build.properties @@ -6,4 +6,5 @@ bin.includes = META-INF/,\ additional.bundles = org.eclipse.osee.orcs,\ javax.ws.rs,\ org.eclipse.osee.framework.core.model,\ - org.eclipse.osee.framework.core + org.eclipse.osee.framework.core,\ + org.eclipse.osee.framework.jdk.core diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactSearchResource.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactSearchResource.java new file mode 100644 index 00000000000..02e10544894 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactSearchResource.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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; + +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.UriInfo; +import org.eclipse.osee.orcs.rest.internal.search.ArtifactSearch; +import org.eclipse.osee.orcs.rest.internal.search.ArtifactSearch_V1; + +/** + * @author Roberto E. Escobar + */ +public class ArtifactSearchResource { + + @Context + UriInfo uriInfo; + @Context + Request request; + + String branchUuid; + + public ArtifactSearchResource(UriInfo uriInfo, Request request, String branchUuid) { + this.uriInfo = uriInfo; + this.request = request; + this.branchUuid = branchUuid; + } + + @Path("{version}") + public ArtifactSearch getArtifact(@PathParam("version") String version) { + String versionToMatch = version.toUpperCase(); + + ArtifactSearch toReturn = null; + if ("V1".equals(versionToMatch)) { + toReturn = new ArtifactSearch_V1(uriInfo, request, branchUuid); + } + return toReturn; + } +} diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactsResource.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactsResource.java index 9505ab9fab7..91192674187 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactsResource.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactsResource.java @@ -48,6 +48,11 @@ public class ArtifactsResource { this.branchUuid = branchUuid; } + @Path("search") + public ArtifactSearchResource getSearch() { + return new ArtifactSearchResource(uriInfo, request, branchUuid); + } + @Path("{uuid}") public ArtifactResource getArtifact(@PathParam("uuid") String artifactUuid) { return new ArtifactResource(uriInfo, request, branchUuid, artifactUuid); @@ -58,7 +63,8 @@ public class ArtifactsResource { public String getAsHtml() throws OseeCoreException { IOseeBranch branch = TokenFactory.createBranch(branchUuid, ""); QueryFactory factory = OrcsApplication.getOrcsApi().getQueryFactory(null); - ResultSet<ReadableArtifact> results = factory.fromBranch(branch).andNameEquals(DEFAULT_HIERARCHY_ROOT_NAME).getResults(); + ResultSet<ReadableArtifact> results = + factory.fromBranch(branch).andNameEquals(DEFAULT_HIERARCHY_ROOT_NAME).getResults(); ReadableArtifact rootArtifact = results.getExactlyOne(); Graph graph = OrcsApplication.getOrcsApi().getGraph(null); diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch.java new file mode 100644 index 00000000000..5fa8453f3cb --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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 javax.ws.rs.core.Request; +import javax.ws.rs.core.UriInfo; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public abstract class ArtifactSearch { + + private final UriInfo uriInfo; + private final Request request; + private final String branchUuid; + + public ArtifactSearch(UriInfo uriInfo, Request request, String branchUuid) { + this.uriInfo = uriInfo; + this.request = request; + this.branchUuid = branchUuid; + } + + public UriInfo getUriInfo() { + return uriInfo; + } + + public Request getRequest() { + return request; + } + + public String getBranchUuid() { + return branchUuid; + } + +} 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 new file mode 100644 index 00000000000..9884489902b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch_V1.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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.Map; +import javax.ws.rs.GET; +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.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.search.QueryBuilder; +import org.eclipse.osee.orcs.search.QueryFactory; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class ArtifactSearch_V1 extends ArtifactSearch { + + private final SearchDsl dsl; + + 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); + } + + @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); + } + + // @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); + // } + + private SearchResult search(String alt, String fields, String rawQuery, int fromTransaction, boolean includeTypeInheritance, boolean includeCache, boolean includeDeleted) 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); + + builder.includeCache(includeCache); + builder.includeTypeInheritance(includeTypeInheritance); + builder.includeDeleted(includeDeleted); + + if (fromTransaction > 0) { + builder.fromTransaction(fromTransaction); + } + + SearchResult result = new SearchResult(); + SearchParameters params = new SearchParameters(getBranchUuid(), rawQuery, alt, fields); + result.setPredicates(dsl.getPredicates()); + result.setSearchParams(params); + if (fields.equals("count")) { + int total = builder.getCount(); + result.setTotal(total); + + } else { + // builder.createSearch(); + // builder.createSearchWithMatches(); + throw new UnsupportedOperationException(); + } + 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 new file mode 100644 index 00000000000..2e429174d99 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/Predicate.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * 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 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 new file mode 100644 index 00000000000..77d4e836bfe --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/PredicateHandler.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * 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 org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.search.QueryBuilder; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public interface PredicateHandler { + QueryBuilder handle(QueryBuilder builder, Predicate predicate) throws OseeCoreException; +}
\ No newline at end of file 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 new file mode 100644 index 00000000000..3e53359b459 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchParameters.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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 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 new file mode 100644 index 00000000000..2da7ebd74e1 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/SearchResult.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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 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/DslTranslatorImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl.java new file mode 100644 index 00000000000..33128abed5d --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImpl.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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.Arrays; +import java.util.LinkedList; +import java.util.List; +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; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class DslTranslatorImpl implements DslTranslator { + + private static final String ARGUMENT_REGEX = ":([^&\\]]+)"; + 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 final Matcher queryMatcher, typeMatcher, opMatcher, flagsMatcher, valueMatcher, typeParametersMatcher; + + public DslTranslatorImpl() { + queryMatcher = queryPattern.matcher(""); + typeMatcher = typePattern.matcher(""); + opMatcher = opPattern.matcher(""); + flagsMatcher = flagsPattern.matcher(""); + valueMatcher = valuePattern.matcher(""); + typeParametersMatcher = typeParametersPattern.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); + typeMatcher.reset(queryBlock); + typeParametersMatcher.reset(queryBlock); + opMatcher.reset(queryBlock); + flagsMatcher.reset(queryBlock); + valueMatcher.reset(queryBlock); + + String type = getMatch(typeMatcher); + String typeParams = getMatch(typeParametersMatcher); + String op = getMatch(opMatcher); + String flags = getMatch(flagsMatcher); + String value = getMatch(valueMatcher); + + predicates.add(createPredicate(type, typeParams, op, flags, value)); + } + return predicates; + } + + private Predicate createPredicate(String type, String typeParameters, String op, String flags, String value) throws OseeCoreException { + SearchMethod searchMethod = SearchMethod.fromString(type); + SearchOp searchOp = SearchOp.fromString(op); + + List<SearchFlag> searchFlags = new LinkedList<SearchFlag>(); + for (String flag : flags.split(",")) { + if (Strings.isValid(flag)) { + searchFlags.add(SearchFlag.fromString(flag)); + } + } + + List<String> values = Arrays.asList(value.split(",\\s*")); + List<String> typeParams = Arrays.asList(typeParameters.split(",\\s*")); + return new Predicate(searchMethod, typeParams, searchOp, searchFlags, values); + } + + private String getMatch(Matcher m) { + if (m.find()) { + return m.group(1); + } + return ""; + } + +} 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/PredicateHandlerFactory.java new file mode 100644 index 00000000000..4b7c25b4d96 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/PredicateHandlerFactory.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * 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.HashMap; +import java.util.Map; +import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler; +import org.eclipse.osee.orcs.rest.internal.search.predicate.AttributeTypePredicateHandler; +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; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class PredicateHandlerFactory { + + public static Map<SearchMethod, PredicateHandler> getHandlers() { + Map<SearchMethod, PredicateHandler> handlers = new HashMap<SearchMethod, PredicateHandler>(); + handlers.put(SearchMethod.IDS, new IdsPredicateHandler()); + handlers.put(SearchMethod.IS_OF_TYPE, new IsOfTypePredicateHandler()); + handlers.put(SearchMethod.EXISTS_TYPE, new ExistsTypePredicateHandler()); + handlers.put(SearchMethod.ATTRIBUTE_TYPE, new AttributeTypePredicateHandler()); + return handlers; + } +}
\ 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/SearchDsl.java new file mode 100644 index 00000000000..f51589d3001 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDsl.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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 java.util.Map; +import org.eclipse.osee.framework.core.data.IOseeBranch; +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.search.QueryBuilder; +import org.eclipse.osee.orcs.search.QueryFactory; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class SearchDsl { + + public static interface DslTranslator { + + List<Predicate> translate(String rawString) throws OseeCoreException; + + } + + private final Map<SearchMethod, PredicateHandler> handlers; + private final DslTranslator translator; + private List<Predicate> predicates; + + public SearchDsl(Map<SearchMethod, PredicateHandler> handlers, DslTranslator translator) { + this.handlers = handlers; + this.translator = translator; + } + + public QueryBuilder build(QueryFactory queryFactory, IOseeBranch branch, String rawQuery) 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)) { + PredicateHandler handler = handlers.get(method); + 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/dsl/SearchFlag.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchFlag.java new file mode 100644 index 00000000000..e5d15369cfe --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchFlag.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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 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 new file mode 100644 index 00000000000..0f18bcdd1db --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchMethod.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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 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 new file mode 100644 index 00000000000..e796cc8f36b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchOp.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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 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/predicate/AttributeTypePredicateHandler.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandler.java new file mode 100644 index 00000000000..afad0ccc623 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandler.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * 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.Collections; +import java.util.List; +import org.eclipse.osee.framework.core.data.IAttributeType; +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.search.QueryBuilder; +import org.eclipse.osee.orcs.search.StringOperator; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class AttributeTypePredicateHandler implements PredicateHandler { + + @Override + public QueryBuilder handle(QueryBuilder builder, Predicate predicate) throws OseeCoreException { + if (predicate.getType() != SearchMethod.ATTRIBUTE_TYPE) { + throw new OseeArgumentException("This predicate handler only supports [%s]", SearchMethod.ATTRIBUTE_TYPE); + } + List<SearchFlag> flags = predicate.getFlags(); + List<String> typeParameters = predicate.getTypeParameters(); + Collection<IAttributeType> attributeTypes = PredicateHandlerUtil.getIAttributeTypes(typeParameters); + SearchOp op = predicate.getOp(); + List<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); + CaseType ct = getCaseType(flags); + for (String value : values) { + builder = and(builder, attributeTypes, operator, ct, value); + } + } else { + Operator operator = getOperator(op); + for (IAttributeType type : attributeTypes) { + builder = and(builder, 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) { + if (data.contains(object)) { + result = true; + break; + } + } + return result; + } + + private CaseType getCaseType(List<SearchFlag> flags) { + if (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; + + } + } + return toReturn; + } + + // EQUAL("="), // Exact Match as in Strings.equals + // NOT_EQUAL("<>"), // inverse of exact match - !Strings.equals + // LESS_THAN("<"), + // GREATER_THAN(">"); + private Operator getOperator(SearchOp op) { + if (op.equals(SearchOp.GREATER_THAN)) { + return Operator.GREATER_THAN; + } + 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 new file mode 100644 index 00000000000..49e812458b5 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandler.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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.List; +import org.eclipse.osee.framework.core.data.IAttributeType; +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.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.search.QueryBuilder; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class ExistsTypePredicateHandler implements PredicateHandler { + + @Override + public QueryBuilder handle(QueryBuilder builder, Predicate predicate) throws OseeCoreException { + if (predicate.getType() != SearchMethod.EXISTS_TYPE) { + throw new OseeArgumentException("This predicate handler only supports [%s]", SearchMethod.EXISTS_TYPE); + } + List<String> typeParameters = predicate.getTypeParameters(); + List<String> values = predicate.getValues(); + + Conditions.checkNotNull(typeParameters, "typeParameters"); + Conditions.checkNotNull(values, "values"); + + if (typeParameters.size() == 1) { + String existsType = typeParameters.get(0); + if ("attrType".equals(existsType)) { + Collection<IAttributeType> attributeTypes = PredicateHandlerUtil.getIAttributeTypes(values); + builder = andAttrTypesExists(builder, attributeTypes); + } else if ("relType".equals(existsType)) { + Collection<IRelationTypeSide> relations = PredicateHandlerUtil.getIRelationTypeSides(values); + builder = andRelTypeSideExists(builder, relations); + } + } + + 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 new file mode 100644 index 00000000000..754f269aea1 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandler.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.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.search.QueryBuilder; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class IdsPredicateHandler implements PredicateHandler { + + @Override + public QueryBuilder handle(QueryBuilder builder, Predicate predicate) throws OseeCoreException { + if (predicate.getType() != SearchMethod.IDS) { + throw new OseeArgumentException("This predicate handler only supports [%s]", SearchMethod.IDS); + } + QueryBuilder theBuilder = builder; + List<String> values = predicate.getValues(); + + Conditions.checkNotNull(values, "values"); + + Collection<String> guids = new HashSet<String>(); + Collection<Integer> rawIds = new HashSet<Integer>(); + for (String value : values) { + if (value.matches("\\d+")) { + rawIds.add(Integer.parseInt(value)); + } else { + guids.add(value); + } + } + + if (!guids.isEmpty()) { + theBuilder = addGuids(builder, guids); + } + + if (!rawIds.isEmpty()) { + theBuilder = addIds(builder, rawIds); + } + return theBuilder; + } + + 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 new file mode 100644 index 00000000000..5feb642a3cf --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandler.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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.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.search.QueryBuilder; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class IsOfTypePredicateHandler implements PredicateHandler { + + @Override + public QueryBuilder handle(QueryBuilder builder, Predicate predicate) throws OseeCoreException { + 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(); + Conditions.checkNotNull(values, "values"); + Collection<IArtifactType> artTypes = PredicateHandlerUtil.getIArtifactTypes(values); + builder = andIsOfType(builder, artTypes); + return builder; + } + + protected QueryBuilder andIsOfType(QueryBuilder builder, Collection<IArtifactType> artTypes) throws OseeCoreException { + return builder.andIsOfType(artTypes); + } + +} 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 new file mode 100644 index 00000000000..b3b7675a5ab --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/PredicateHandlerUtil.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.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.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.TokenFactory; +import org.eclipse.osee.framework.core.enums.RelationSide; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.util.HexUtil; + +/** + * @author John Misinco + * @author Roberto E. Escobar + */ +public class PredicateHandlerUtil { + + public static Collection<IAttributeType> getIAttributeTypes(List<String> types) throws OseeCoreException { + Collection<IAttributeType> attrTypes = new HashSet<IAttributeType>(); + for (String value : types) { + long uuid = parseUuid(value); + if (uuid != -1L) { + attrTypes.add(TokenFactory.createAttributeType(uuid, "SearchAttributeType")); + } + } + return attrTypes; + } + + public static Collection<IArtifactType> getIArtifactTypes(List<String> types) throws OseeCoreException { + Collection<IArtifactType> artTypes = new HashSet<IArtifactType>(); + for (String value : types) { + long uuid = parseUuid(value); + if (uuid != -1L) { + artTypes.add(TokenFactory.createArtifactType(uuid, "SearchArtifactType")); + } + } + return artTypes; + } + + public static Collection<IRelationTypeSide> getIRelationTypeSides(List<String> rels) throws OseeCoreException { + Collection<IRelationTypeSide> relSides = new HashSet<IRelationTypeSide>(); + for (String value : rels) { + char sideChar = value.charAt(0); + String uuid = value.substring(1); + RelationSide side = RelationSide.SIDE_A; + if (sideChar == 'B') { + side = RelationSide.SIDE_B; + } + long longUuid = parseUuid(uuid); + if (longUuid != -1L) { + relSides.add(TokenFactory.createRelationTypeSide(side, longUuid, "SearchRelationTypeSide")); + } + } + return relSides; + } + + private static long parseUuid(String uuid) throws OseeCoreException { + if (uuid.matches("\\d+")) { + return Long.parseLong(uuid); + } else if (HexUtil.isHexString(uuid)) { + return HexUtil.toLong(uuid); + } + return -1L; + } +} |