Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2012-02-21 21:40:14 +0000
committerkwilk2012-02-21 21:40:14 +0000
commitd9d755fd1a6aa2bdc0eb069fcbcc689b73d32876 (patch)
tree2ae02772eea449aa7d6723279420e0e7931552ea
parent84212140b1f54d341796b6d4fcdfb5945a9a84e0 (diff)
downloadorg.eclipse.osee-d9d755fd1a6aa2bdc0eb069fcbcc689b73d32876.tar.gz
org.eclipse.osee-d9d755fd1a6aa2bdc0eb069fcbcc689b73d32876.tar.xz
org.eclipse.osee-d9d755fd1a6aa2bdc0eb069fcbcc689b73d32876.zip
feature[ats_X6TS0]: Add ORCS restful search API
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HexUtil.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.parent/pom.xml1
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/.classpath7
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/.project28
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/META-INF/MANIFEST.MF10
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/build.properties4
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/pom.xml30
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.java24
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.java35
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java152
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java119
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java132
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java166
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java104
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java81
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java228
-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/ArtifactSearchResource.java49
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/ArtifactsResource.java8
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch.java44
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/ArtifactSearch_V1.java94
-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.java22
-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/DslTranslatorImpl.java94
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/PredicateHandlerFactory.java35
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDsl.java64
-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/predicate/AttributeTypePredicateHandler.java147
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandler.java66
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandler.java67
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandler.java46
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/search/predicate/PredicateHandlerUtil.java77
37 files changed, 2335 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HexUtil.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HexUtil.java
index bc9c60711da..5ea0696b102 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HexUtil.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/HexUtil.java
@@ -21,11 +21,15 @@ public final class HexUtil {
// Utility class
}
+ public static boolean isHexString(String hexString) {
+ return hexString.startsWith("0x");
+ }
+
public static long toLong(String hexString) throws OseeCoreException {
Long toReturn = -1L;
try {
String hex = hexString;
- if (hexString.startsWith("0x")) {
+ if (isHexString(hex)) {
hex = hexString.substring(2);
}
toReturn = Long.parseLong(hex, 16);
diff --git a/plugins/org.eclipse.osee.orcs.parent/pom.xml b/plugins/org.eclipse.osee.orcs.parent/pom.xml
index 83bc6bafec2..510d626b994 100644
--- a/plugins/org.eclipse.osee.orcs.parent/pom.xml
+++ b/plugins/org.eclipse.osee.orcs.parent/pom.xml
@@ -31,6 +31,7 @@
<module>../../plugins/org.eclipse.osee.orcs.db</module>
<module>../../plugins/org.eclipse.osee.orcs.db.mock</module>
<module>../../plugins/org.eclipse.osee.orcs.rest</module>
+ <module>../../plugins/org.eclipse.osee.orcs.rest.test</module>
<module>../../plugins/org.eclipse.osee.framework.h2</module>
<module>../../plugins/org.eclipse.osee.orcs.db.test</module>
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/.classpath b/plugins/org.eclipse.osee.orcs.rest.test/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/.project b/plugins/org.eclipse.osee.orcs.rest.test/.project
new file mode 100644
index 00000000000..76b0bfe1dce
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.orcs.rest.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.rest.test/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..0571adcfdad
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: OSEE ORCS Rest Test
+Bundle-SymbolicName: org.eclipse.osee.orcs.rest.test
+Bundle-Version: 0.10.0.qualifier
+Fragment-Host: org.eclipse.osee.orcs.rest
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Vendor: Eclipse Open System Engineering Environment
+Require-Bundle: org.junit
+Import-Package: org.eclipse.osee.executor.admin
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/build.properties b/plugins/org.eclipse.osee.orcs.rest.test/build.properties
new file mode 100644
index 00000000000..34d2e4d2dad
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/pom.xml b/plugins/org.eclipse.osee.orcs.rest.test/pom.xml
new file mode 100644
index 00000000000..3d32ee0ed7b
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/pom.xml
@@ -0,0 +1,30 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.osee</groupId>
+ <artifactId>org.eclipse.osee.x.server.parent</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ <relativePath>../../plugins/org.eclipse.osee.x.server.parent</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.osee.orcs.rest.test</artifactId>
+ <packaging>eclipse-test-plugin</packaging>
+ <name>OSEE ORCS Rest Test - (Incubation)</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <testSuite>org.eclipse.osee.orcs.rest.test</testSuite>
+ <testClass>org.eclipse.osee.orcs.rest.OrcsRestTestSuite</testClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project> \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.java
new file mode 100644
index 00000000000..02b32e7bced
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.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;
+
+import org.eclipse.osee.orcs.rest.internal.InternalTestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author John Misinco
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({InternalTestSuite.class,})
+public class OrcsRestTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.java
new file mode 100644
index 00000000000..234152a3b2f
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.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;
+
+import org.eclipse.osee.orcs.rest.internal.search.dsl.DslTranslatorImplTest;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchDslTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.AttributeTypePredicateHandlerTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.ExistsTypePredicateHandlerTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.IdsPredicateHandlerTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.IsOfTypePredicateHandlerTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author John Misinco
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ DslTranslatorImplTest.class,
+ SearchDslTest.class,
+ AttributeTypePredicateHandlerTest.class,
+ ExistsTypePredicateHandlerTest.class,
+ IdsPredicateHandlerTest.class,
+ IsOfTypePredicateHandlerTest.class,})
+public class InternalTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java
new file mode 100644
index 00000000000..850994d979e
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * 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.Random;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class DslTranslatorImplTest {
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadSearchType() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ //test bad search type
+ String test = "[t:attrTypes&tp:1000000000000070&op:==&v:AtsAdmin]";
+ translator.translate(test);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadOp() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ //test bad op
+ String test = "[t:attrType&tp:1000000000000070&op:<>&v:AtsAdmin]";
+ translator.translate(test);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadFlag() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ //test bad flags
+ String test = "[t:attrType&tp:1000000000000070&op:==&f:ti&v:AtsAdmin]";
+ translator.translate(test);
+ }
+
+ private int getNextInt(Random r) {
+ return Math.abs(r.nextInt());
+ }
+
+ private String getSearchMethod(Random r) {
+ int len = SearchMethod.values().length;
+ return SearchMethod.values()[getNextInt(r) % len].getToken();
+ }
+
+ private String getOp(Random r) {
+ int len = SearchOp.values().length;
+ return SearchOp.values()[getNextInt(r) % len].getToken();
+ }
+
+ private String getFlags(Random r, int num) {
+ if (num == 0) {
+ return "";
+ }
+ StringBuilder toReturn = new StringBuilder();
+ for (int i = 0; i < num; i++) {
+ int len = SearchFlag.values().length;
+ toReturn.append(SearchFlag.values()[getNextInt(r) % len].getToken());
+ toReturn.append(",");
+ }
+ int last = toReturn.length();
+ return toReturn.substring(0, last - 1);
+ }
+
+ private String getTestQuery(int num) {
+ Random r = new Random();
+ StringBuilder toReturn = new StringBuilder();
+ for (int i = 0; i < num; i++) {
+ toReturn.append("[t:");
+ toReturn.append(getSearchMethod(r));
+ toReturn.append("&tp:");
+ toReturn.append(r.nextLong());
+ toReturn.append("&op:");
+ toReturn.append(getOp(r));
+ toReturn.append("&f:");
+ toReturn.append(getFlags(r, getNextInt(r) % 3));
+ toReturn.append("&v:value1,value2]&");
+ }
+ int last = toReturn.length();
+ return toReturn.substring(0, last - 1);
+ }
+
+ private boolean compareStringToPredicate(String query, Predicate predicate) {
+ if (!query.contains(predicate.getType().getToken())) {
+ return false;
+ }
+ if (!query.contains(predicate.getOp().getToken())) {
+ return false;
+ }
+ for (SearchFlag flag : predicate.getFlags()) {
+ if (!query.contains(flag.getToken())) {
+ return false;
+ }
+ }
+ for (String typeParam : predicate.getTypeParameters()) {
+ if (!query.contains(typeParam)) {
+ return false;
+ }
+ }
+ for (String value : predicate.getValues()) {
+ if (!query.contains(value)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Test
+ public void testMultiplePredicates() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+ int size = 5;
+
+ String test = getTestQuery(size);
+ List<Predicate> translated = translator.translate(test);
+ Assert.assertEquals(size, translated.size());
+ String[] predicates = test.split("\\]&\\[");
+
+ for (int i = 0; i < size; i++) {
+ Assert.assertTrue(compareStringToPredicate(predicates[i], translated.get(i)));
+ }
+ }
+
+ @Test
+ public void testAttrTypeSearches() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ String test = "[t:attrType&tp:0x1000000000000070&op:==&f:t,i&v:AtsAdmin]";
+ translator.translate(test);
+
+ test = "[t:attrType&tp:1000000000000070&op:!=&f:t,i&v:AtsAdmin]";
+ translator.translate(test);
+
+ test = "[t:attrType&tp:1000000000000070&op:<&f:t,i&v:AtsAdmin]";
+ translator.translate(test);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java
new file mode 100644
index 00000000000..2696b11c267
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.data.ReadableArtifact;
+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.SearchDsl.DslTranslator;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.eclipse.osee.orcs.search.QueryFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class SearchDslTest {
+
+ private class MockTranslator implements DslTranslator {
+ public String rawString;
+ private final SearchMethod method;
+
+ public MockTranslator(SearchMethod method) {
+ this.method = method;
+ }
+
+ @Override
+ public List<Predicate> translate(String rawString) {
+ this.rawString = rawString;
+ Predicate toReturn = new Predicate(method, null, null, null, null);
+ return Collections.singletonList(toReturn);
+ }
+ }
+
+ private class MockPredicateHandler implements PredicateHandler {
+ public boolean handleCalled = false;
+
+ @Override
+ public QueryBuilder handle(QueryBuilder builder, Predicate predicate) {
+ handleCalled = true;
+ return builder;
+ }
+ }
+
+ private class MockQueryFactory implements QueryFactory {
+ public IOseeBranch branch;
+
+ @Override
+ public QueryBuilder fromBranch(IOseeBranch branch) {
+ this.branch = branch;
+ return null;
+ }
+
+ @Override
+ public QueryBuilder fromArtifactTypeAllBranches(IArtifactType artifactType) {
+ return null;
+ }
+
+ @Override
+ public QueryBuilder fromArtifacts(Collection<? extends ReadableArtifact> artifacts) {
+ return null;
+ }
+ };
+
+ @Test
+ public void testBuildValidSearchType() throws OseeCoreException {
+ Map<SearchMethod, PredicateHandler> handlers = new HashMap<SearchMethod, PredicateHandler>();
+ MockPredicateHandler handler = new MockPredicateHandler();
+ handlers.put(SearchMethod.ATTRIBUTE_TYPE, handler);
+
+ MockTranslator translator = new MockTranslator(SearchMethod.ATTRIBUTE_TYPE);
+ SearchDsl dsl = new SearchDsl(handlers, translator);
+ MockQueryFactory queryFactory = new MockQueryFactory();
+
+ IOseeBranch branch = CoreBranches.COMMON;
+ String rawQuery = "[t:attrType&tp:1000000000000070&op:==&v:AtsAdmin]";
+ dsl.build(queryFactory, branch, rawQuery);
+
+ Assert.assertEquals(rawQuery, translator.rawString);
+ Assert.assertEquals(branch, queryFactory.branch);
+ Assert.assertTrue(handler.handleCalled);
+ }
+
+ @Test
+ public void testBuildInvalidSearchType() throws OseeCoreException {
+ Map<SearchMethod, PredicateHandler> handlers = new HashMap<SearchMethod, PredicateHandler>();
+ MockPredicateHandler handler = new MockPredicateHandler();
+ handlers.put(SearchMethod.ATTRIBUTE_TYPE, handler);
+
+ MockTranslator translator = new MockTranslator(SearchMethod.EXISTS_TYPE);
+ SearchDsl dsl = new SearchDsl(handlers, translator);
+ MockQueryFactory queryFactory = new MockQueryFactory();
+
+ IOseeBranch branch = CoreBranches.COMMON;
+ String rawQuery = "[t:attrType&tp:1000000000000070&op:==&v:AtsAdmin]";
+ dsl.build(queryFactory, branch, rawQuery);
+
+ Assert.assertEquals(rawQuery, translator.rawString);
+ Assert.assertEquals(branch, queryFactory.branch);
+ Assert.assertFalse(handler.handleCalled);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java
new file mode 100644
index 00000000000..fe073e6ed5d
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+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.rest.mocks.MockQueryBuilder;
+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;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class AttributeTypePredicateHandlerTest {
+
+ private class TestAttributeTypePredicateHandler extends AttributeTypePredicateHandler {
+
+ StringOperator stringOperator;
+ Operator operator;
+ CaseType ct;
+
+ @Override
+ protected QueryBuilder and(QueryBuilder builder, Collection<IAttributeType> attributeTypes, StringOperator operator, CaseType ct, String value) {
+ this.stringOperator = operator;
+ this.ct = ct;
+ return builder;
+ }
+
+ @Override
+ protected QueryBuilder and(QueryBuilder builder, IAttributeType type, Operator operator, List<String> values) {
+ this.operator = operator;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testStringOperatorSelection() throws OseeCoreException {
+ TestAttributeTypePredicateHandler handler = new TestAttributeTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("0x0123");
+ List<SearchFlag> flags = Arrays.asList(SearchFlag.TOKENIZED_ANY);
+ List<String> values = Collections.singletonList("value");
+ Predicate testPredicate =
+ new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.TOKENIZED_ANY_ORDER, handler.stringOperator);
+
+ flags = Arrays.asList(SearchFlag.TOKENIZED_ORDERED);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.TOKENIZED_MATCH_ORDER, handler.stringOperator);
+
+ flags = Arrays.asList(SearchFlag.IGNORE_CASE);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.EQUALS, handler.stringOperator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.NOT_EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.NOT_EQUALS, handler.stringOperator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.IN, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.CONTAINS, handler.stringOperator);
+ }
+
+ @Test
+ public void testCaseTypeSelection() throws OseeCoreException {
+ TestAttributeTypePredicateHandler handler = new TestAttributeTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("0x0123");
+ List<SearchFlag> flags = Arrays.asList(SearchFlag.IGNORE_CASE);
+ List<String> values = Collections.singletonList("value");
+ Predicate testPredicate =
+ new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(CaseType.IGNORE_CASE, handler.ct);
+
+ flags = Arrays.asList(SearchFlag.TOKENIZED, SearchFlag.IGNORE_CASE);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(CaseType.IGNORE_CASE, handler.ct);
+
+ flags = Arrays.asList(SearchFlag.TOKENIZED, SearchFlag.MATCH_CASE);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(CaseType.MATCH_CASE, handler.ct);
+ }
+
+ @Test
+ public void testOperatorSelection() throws OseeCoreException {
+ TestAttributeTypePredicateHandler handler = new TestAttributeTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("0x0123");
+ List<SearchFlag> flags = Arrays.asList(SearchFlag.MATCH_CASE);
+ List<String> values = Collections.singletonList("value");
+ Predicate testPredicate =
+ new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.EQUAL, handler.operator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.GREATER_THAN, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.GREATER_THAN, handler.operator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.LESS_THAN, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.LESS_THAN, handler.operator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.NOT_EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.NOT_EQUAL, handler.operator);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java
new file mode 100644
index 00000000000..e9d0759745d
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IRelationTypeSide;
+import org.eclipse.osee.framework.core.enums.RelationSide;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+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.rest.mocks.MockQueryBuilder;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class ExistsTypePredicateHandlerTest {
+
+ private class TestExistsTypePredicateHandler extends ExistsTypePredicateHandler {
+
+ Collection<IRelationTypeSide> relations;
+ Collection<IAttributeType> attributeTypes;
+
+ @Override
+ protected QueryBuilder andRelTypeSideExists(QueryBuilder builder, Collection<IRelationTypeSide> relations) {
+ this.relations = relations;
+ return builder;
+ }
+
+ @Override
+ protected QueryBuilder andAttrTypesExists(QueryBuilder builder, Collection<IAttributeType> attributeTypes) {
+ this.attributeTypes = attributeTypes;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testHandleRelationTypeSides() throws OseeCoreException {
+ TestExistsTypePredicateHandler handler = new TestExistsTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("relType");
+ //no flags for exists type
+ List<SearchFlag> flags = Collections.emptyList();
+ //for relation type sides, first char must be A or B denoting side, followed by relation type uuid
+ String relationValue = "A12345";
+ List<String> values = Collections.singletonList(relationValue);
+ Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.relations.size());
+ IRelationTypeSide side = handler.relations.iterator().next();
+ Assert.assertEquals(relationValue.substring(1), side.getGuid().toString());
+ Assert.assertEquals(RelationSide.SIDE_A, side.getSide());
+
+ //test side B
+ relationValue = "B12345";
+ values = Collections.singletonList(relationValue);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.relations.size());
+ side = handler.relations.iterator().next();
+ Assert.assertEquals(relationValue.substring(1), side.getGuid().toString());
+ Assert.assertEquals(RelationSide.SIDE_B, side.getSide());
+
+ //test multiples
+ String relationValue1 = "A12345";
+ String relationValue2 = "B34567";
+ values = Arrays.asList(relationValue1, relationValue2);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(2, handler.relations.size());
+ boolean sideAMatched = false, sideBMatched = false;
+ for (IRelationTypeSide rts : handler.relations) {
+ if (rts.getSide() == RelationSide.SIDE_A) {
+ sideAMatched = true;
+ Assert.assertEquals(relationValue1.substring(1), rts.getGuid().toString());
+ }
+ if (rts.getSide() == RelationSide.SIDE_B) {
+ sideBMatched = true;
+ Assert.assertEquals(relationValue2.substring(1), rts.getGuid().toString());
+ }
+ }
+ Assert.assertTrue(sideAMatched);
+ Assert.assertTrue(sideBMatched);
+ }
+
+ @Test
+ public void testHandleAttrType() throws OseeCoreException {
+ TestExistsTypePredicateHandler handler = new TestExistsTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("attrType");
+ //no flags for exists type
+ List<SearchFlag> flags = Collections.emptyList();
+ //for relation type sides, first char must be A or B denoting side, followed by relation type uuid
+ String attrUuid = "12345";
+ List<String> values = Collections.singletonList(attrUuid);
+ Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.attributeTypes.size());
+ IAttributeType type = handler.attributeTypes.iterator().next();
+ Assert.assertEquals(attrUuid, type.getGuid().toString());
+
+ //test multiples
+ String attrType1 = "12345";
+ String attrType2 = "34567";
+ values = Arrays.asList(attrType1, attrType2);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(2, handler.attributeTypes.size());
+ boolean attr1Matched = false, attr2Matched = false;
+ for (IAttributeType attr : handler.attributeTypes) {
+ if (attr.getGuid().toString().equals(attrType1)) {
+ attr1Matched = true;
+ }
+ if (attr.getGuid().toString().equals(attrType2)) {
+ attr2Matched = true;
+ }
+ }
+ Assert.assertTrue(attr1Matched);
+ Assert.assertTrue(attr2Matched);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testHandleBadValues() throws OseeCoreException {
+ TestExistsTypePredicateHandler handler = new TestExistsTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("attrType");
+ //no flags for exists type
+ List<SearchFlag> flags = Collections.emptyList();
+ //for relation type sides, first char must be A or B denoting side, followed by relation type uuid
+ String value = "12A4G";
+ List<String> values = Collections.singletonList(value);
+ Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(0, handler.attributeTypes.size());
+
+ value = "A12A4G";
+ typeParameters = Collections.singletonList("relType");
+ values = Collections.singletonList(value);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(0, handler.relations.size());
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java
new file mode 100644
index 00000000000..26d75c70e25
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.mocks.MockQueryBuilder;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class IdsPredicateHandlerTest {
+
+ private class TestIdsPredicateHandler extends IdsPredicateHandler {
+
+ Collection<String> guids;
+ Collection<Integer> rawIds;
+
+ @Override
+ protected QueryBuilder addGuids(QueryBuilder builder, Collection<String> guids) throws OseeCoreException {
+ this.guids = guids;
+ return builder;
+ }
+
+ @Override
+ protected QueryBuilder addIds(QueryBuilder builder, Collection<Integer> rawIds) throws OseeCoreException {
+ this.rawIds = rawIds;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testHandle() throws OseeCoreException {
+ TestIdsPredicateHandler handler = new TestIdsPredicateHandler();
+ //no type params, op, or flags for ids - any passed are ignored
+
+ //all digits get treated as artId
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.IDS, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.rawIds.size());
+ Assert.assertNull(handler.guids);
+ Assert.assertEquals(id1, handler.rawIds.iterator().next().toString());
+
+ //if not all digits, treated as guid
+ handler = new TestIdsPredicateHandler();
+ String id2 = "AGUID234";
+ values = Collections.singletonList(id2);
+ testPredicate = new Predicate(SearchMethod.IDS, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertNull(handler.rawIds);
+ Assert.assertEquals(1, handler.guids.size());
+ Assert.assertEquals(id2, handler.guids.iterator().next());
+
+ //test a rawId and guid
+ handler = new TestIdsPredicateHandler();
+ values = Arrays.asList(id1, id2);
+ testPredicate = new Predicate(SearchMethod.IDS, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.rawIds.size());
+ Assert.assertEquals(1, handler.guids.size());
+ Assert.assertEquals(id1, handler.rawIds.iterator().next().toString());
+ Assert.assertEquals(id2, handler.guids.iterator().next());
+
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testHandleBadValues() throws OseeCoreException {
+ TestIdsPredicateHandler handler = new TestIdsPredicateHandler();
+ Predicate testPredicate = new Predicate(SearchMethod.IDS, null, null, null, null);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadSearchMethod() throws OseeCoreException {
+ TestIdsPredicateHandler handler = new TestIdsPredicateHandler();
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java
new file mode 100644
index 00000000000..963bc66246a
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+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.orcs.rest.internal.search.Predicate;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.mocks.MockQueryBuilder;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class IsOfTypePredicateHandlerTest {
+
+ private class TestIsOfTypePredicateHandler extends IsOfTypePredicateHandler {
+
+ Collection<IArtifactType> artTypes;
+
+ @Override
+ protected QueryBuilder andIsOfType(QueryBuilder builder, Collection<IArtifactType> artTypes) {
+ this.artTypes = artTypes;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testHandle() throws OseeCoreException {
+ TestIsOfTypePredicateHandler handler = new TestIsOfTypePredicateHandler();
+ //no type params, op, or flags for ids - any passed are ignored
+
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.IS_OF_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.artTypes.size());
+ Assert.assertEquals(id1, handler.artTypes.iterator().next().getGuid().toString());
+
+ String id2 = "45678";
+ values = Arrays.asList(id1, id2);
+
+ testPredicate = new Predicate(SearchMethod.IS_OF_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(2, handler.artTypes.size());
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testHandleBadValues() throws OseeCoreException {
+ TestIsOfTypePredicateHandler handler = new TestIsOfTypePredicateHandler();
+ Predicate testPredicate = new Predicate(SearchMethod.IS_OF_TYPE, null, null, null, null);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadSearchMethod() throws OseeCoreException {
+ TestIsOfTypePredicateHandler handler = new TestIsOfTypePredicateHandler();
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java
new file mode 100644
index 00000000000..1c49692b598
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * 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.mocks;
+
+import java.util.Collection;
+import org.eclipse.osee.executor.admin.CancellableCallable;
+import org.eclipse.osee.framework.core.data.IArtifactToken;
+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.ResultSet;
+import org.eclipse.osee.orcs.data.ReadableArtifact;
+import org.eclipse.osee.orcs.data.ReadableAttribute;
+import org.eclipse.osee.orcs.search.CaseType;
+import org.eclipse.osee.orcs.search.Match;
+import org.eclipse.osee.orcs.search.Operator;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.eclipse.osee.orcs.search.StringOperator;
+
+/**
+ * @author John Misinco
+ */
+public class MockQueryBuilder implements QueryBuilder {
+
+ @Override
+ public QueryBuilder includeCache() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder includeCache(boolean enabled) {
+ return this;
+ }
+
+ @Override
+ public boolean isCacheIncluded() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder includeDeleted() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder includeDeleted(boolean enabled) {
+ return this;
+ }
+
+ @Override
+ public boolean areDeletedIncluded() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder includeTypeInheritance() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder includeTypeInheritance(boolean enabled) {
+ return this;
+ }
+
+ @Override
+ public boolean isTypeInheritanceIncluded() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder fromTransaction(int transactionId) {
+ return this;
+ }
+
+ @Override
+ public int getFromTransaction() {
+ return 0;
+ }
+
+ @Override
+ public QueryBuilder headTransaction() {
+ return this;
+ }
+
+ @Override
+ public boolean isHeadTransaction() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder excludeCache() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder excludeDeleted() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder excludeTypeInheritance() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder resetToDefaults() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andLocalId(int... artifactId) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andLocalIds(Collection<Integer> artifactIds) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andGuidsOrHrids(String... ids) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andGuidsOrHrids(Collection<String> ids) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIds(IArtifactToken... artifactToken) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIds(Collection<? extends IArtifactToken> artifactTokens) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIsOfType(IArtifactType... artifactType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIsOfType(Collection<? extends IArtifactType> artifactType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andExists(IAttributeType... attributeType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andExists(Collection<? extends IAttributeType> attributeTypes) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andExists(IRelationTypeSide relationType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andNameEquals(String artifactName) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, Operator operator, String value) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, Operator operator, Collection<String> values) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, StringOperator operator, CaseType match, String value) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(Collection<? extends IAttributeType> attributeTypes, StringOperator operator, CaseType match, String value) {
+ return this;
+ }
+
+ @Override
+ public ResultSet<ReadableArtifact> getResults() {
+ return null;
+ }
+
+ @Override
+ public ResultSet<Match<ReadableArtifact, ReadableAttribute<?>>> getMatches() {
+ return null;
+ }
+
+ @Override
+ public int getCount() {
+ return 0;
+ }
+
+ @Override
+ public CancellableCallable<Integer> createCount() {
+ return null;
+ }
+
+ @Override
+ public CancellableCallable<ResultSet<ReadableArtifact>> createSearch() {
+ return null;
+ }
+
+ @Override
+ public CancellableCallable<ResultSet<Match<ReadableArtifact, ReadableAttribute<?>>>> createSearchWithMatches() {
+ return null;
+ }
+
+} \ No newline at end of file
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;
+ }
+}

Back to the top