Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2010-09-16 22:13:43 -0400
committerRyan D. Brooks2010-09-16 22:13:43 -0400
commit6325b1293702f722cd272761741fbebbc1a8cbb7 (patch)
treee8573abb4538e66dc68085a5ac6a098f5d1016c7 /plugins
parent300928000622912a6903903f2d5c4b277d1715f2 (diff)
downloadorg.eclipse.osee-6325b1293702f722cd272761741fbebbc1a8cbb7.tar.gz
org.eclipse.osee-6325b1293702f722cd272761741fbebbc1a8cbb7.tar.xz
org.eclipse.osee-6325b1293702f722cd272761741fbebbc1a8cbb7.zip
bug[ats_UNJKK]: Implement Search Request/Response messages, translators and tests
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/DataTestSuite.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchRequestTest.java42
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchResponseTest.java150
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/mocks/DataAsserts.java40
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/DataTranslationServiceFactoryTest.java6
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchRequestTranslatorTest.java53
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchResponseTranslatorTest.java69
-rw-r--r--plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/TranslationTestSuite.java47
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchOptions.java81
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchRequest.java50
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchResponse.java238
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchRequestTranslator.java94
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchResponseTranslator.java114
-rw-r--r--plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/SearchResultToXmlOperationTest.java44
-rw-r--r--plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/mocks/EngineAsserts.java2
-rw-r--r--plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/WordOrderMatcherTest.java30
16 files changed, 900 insertions, 162 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/DataTestSuite.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/DataTestSuite.java
index 09d9b18bdc..93199c4b54 100644
--- a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/DataTestSuite.java
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/DataTestSuite.java
@@ -23,6 +23,8 @@ import org.junit.runners.Suite;
ChangeItemUtilTest.class,
ChangeVersionTest.class,
PurgeBranchRequestTest.class,
+ SearchRequestTest.class,
+ SearchResponseTest.class,
TransactionCacheUpdateResponseTest.class,})
/**
* @author Roberto E. Escobar
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchRequestTest.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchRequestTest.java
new file mode 100644
index 0000000000..4b9ed26548
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchRequestTest.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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.framework.core.message.test.data;
+
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.message.SearchOptions;
+import org.eclipse.osee.framework.core.message.SearchRequest;
+import org.eclipse.osee.framework.core.message.test.mocks.DataAsserts;
+import org.junit.Test;
+
+/**
+ * Test Case for {@link SearchRequest}
+ *
+ * @author Roberto E. Escobar
+ */
+public class SearchRequestTest {
+
+ @Test
+ public void testDataDefaultOptions() {
+ SearchRequest request = new SearchRequest(CoreBranches.COMMON, "Search");
+ Assert.assertEquals(CoreBranches.COMMON, request.getBranch());
+ Assert.assertEquals("Search", request.getRawSearch());
+ DataAsserts.assertEquals(new SearchOptions(), request.getOptions());
+ }
+
+ @Test
+ public void testDataNullConstructedOptions() {
+ SearchRequest request = new SearchRequest(CoreBranches.COMMON, "Search", null);
+ Assert.assertEquals(CoreBranches.COMMON, request.getBranch());
+ Assert.assertEquals("Search", request.getRawSearch());
+ DataAsserts.assertEquals(new SearchOptions(), request.getOptions());
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchResponseTest.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchResponseTest.java
new file mode 100644
index 0000000000..13c38faece
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/data/SearchResponseTest.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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.framework.core.message.test.data;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.message.SearchResponse;
+import org.eclipse.osee.framework.core.message.SearchResponse.ArtifactMatchMetaData;
+import org.eclipse.osee.framework.core.message.SearchResponse.AttributeMatchMetaData;
+import org.eclipse.osee.framework.jdk.core.type.MatchLocation;
+import org.eclipse.osee.framework.jdk.core.util.Compare;
+import org.junit.Test;
+
+/**
+ * Test Case for {@link SearchResponse}
+ *
+ * @author Roberto E. Escobar
+ */
+public class SearchResponseTest {
+
+ @Test
+ public void testSetGetErrorMessage() {
+ SearchResponse searchResponse = new SearchResponse();
+ Assert.assertEquals("", searchResponse.getErrorMessage());
+
+ searchResponse.setErrorMessage(null);
+ Assert.assertEquals("", searchResponse.getErrorMessage());
+
+ searchResponse.setErrorMessage("An error");
+ Assert.assertEquals("An error", searchResponse.getErrorMessage());
+ }
+
+ @Test
+ public void testSearchTags() {
+ SearchResponse searchResponse = new SearchResponse();
+ Assert.assertEquals(0, searchResponse.getSearchTags().size());
+
+ Map<String, Long> tags = searchResponse.getSearchTags();
+ tags.put("Hello", 45L);
+ tags.put("dude", 54L);
+ tags.put("Hello", 63L);
+
+ Assert.assertEquals(2, searchResponse.getSearchTags().size());
+ Set<String> words = tags.keySet();
+ Assert.assertEquals(2, words.size());
+ Iterator<String> iterator = words.iterator();
+ Assert.assertEquals("Hello", iterator.next());
+ Assert.assertEquals("dude", iterator.next());
+
+ Collection<Long> codes = tags.values();
+ Assert.assertEquals(2, codes.size());
+ Iterator<Long> codeIterator = codes.iterator();
+ Assert.assertEquals(63L, (long) codeIterator.next());
+ Assert.assertEquals(54L, (long) codeIterator.next());
+ }
+
+ @Test
+ public void testAddMatch() {
+ MatchLocation loc1 = new MatchLocation(3, 6);
+ MatchLocation loc2 = new MatchLocation(11, 20);
+
+ SearchResponse searchResponse = new SearchResponse();
+ searchResponse.add(1, 2, 3);
+ searchResponse.add(1, 2, 4);
+ searchResponse.add(1, 2, 5);
+ searchResponse.add(1, 2, 5);
+
+ searchResponse.add(2, 1, 6);
+ searchResponse.add(2, 1, 8);
+ searchResponse.add(2, 3, 8, Arrays.asList(loc1, loc2));
+ searchResponse.add(2, 3, 8, 4, 5);
+ searchResponse.add(2, 3, 8, 4, 5);
+
+ Assert.assertEquals(8, searchResponse.matches());
+
+ Assert.assertFalse(Compare.isDifferent(Arrays.asList(1, 2), searchResponse.getBranchIds()));
+
+ // Check Branch 1
+ Collection<Integer> data1 = searchResponse.getArtifactIds(1);
+ Assert.assertEquals(1, data1.size());
+ Assert.assertEquals(2, (int) data1.iterator().next());
+
+ Collection<ArtifactMatchMetaData> arts1 = searchResponse.getArtifacts(1);
+ Assert.assertEquals(1, arts1.size());
+
+ ArtifactMatchMetaData match1 = searchResponse.getArtifactMatch(1, 2);
+ Assert.assertNotNull(match1);
+
+ Assert.assertEquals(arts1.iterator().next(), match1);
+ checkArtMatch(match1, 1, 2, 3L, 4L, 5L);
+
+ // Check Branch 2
+ Collection<Integer> data2 = searchResponse.getArtifactIds(2);
+ Assert.assertEquals(2, data2.size());
+
+ Collection<ArtifactMatchMetaData> arts = searchResponse.getArtifacts(2);
+ Assert.assertEquals(2, arts.size());
+
+ ArtifactMatchMetaData match2 = searchResponse.getArtifactMatch(2, 1);
+ Assert.assertNotNull(match2);
+
+ ArtifactMatchMetaData match3 = searchResponse.getArtifactMatch(2, 3);
+ Assert.assertNotNull(match3);
+
+ Assert.assertFalse(Compare.isDifferent(Arrays.asList(match2, match3), arts));
+
+ checkArtMatch(match2, 2, 1, 6L, 8L);
+
+ Assert.assertEquals(3, match3.getArtId());
+ Assert.assertEquals(2, match3.getBranchId());
+ Assert.assertEquals(3, match3.matches());
+
+ AttributeMatchMetaData attrMatch = match3.getAttributeMatch(8L);
+ checkAttrMatch(attrMatch, 3, 8L, loc1, loc2, new MatchLocation(4, 5));
+
+ Assert.assertFalse(Compare.isDifferent(Arrays.asList(match1, match2, match3), searchResponse.getAll()));
+ }
+
+ private static void checkArtMatch(ArtifactMatchMetaData data, int expectedBranchId, int expectedArtId, long... attrs) {
+ Assert.assertEquals(expectedArtId, data.getArtId());
+ Assert.assertEquals(expectedBranchId, data.getBranchId());
+ Assert.assertEquals(attrs.length, data.matches());
+ Assert.assertEquals(attrs.length, data.size());
+ for (long attr : attrs) {
+ AttributeMatchMetaData attrData = data.getAttributeMatch(attr);
+ Assert.assertNotNull("Can't get attrData id: " + attr, attrData);
+ checkAttrMatch(attrData, expectedArtId, attr);
+ }
+ }
+
+ private static void checkAttrMatch(AttributeMatchMetaData data, int expectedArtId, long expectedGammaId, MatchLocation... expectedLocs) {
+ Assert.assertEquals(expectedArtId, data.getArtId());
+ Assert.assertEquals(expectedGammaId, data.getGammaId());
+ Collection<MatchLocation> actualLocs = data.getLocations();
+ Assert.assertEquals(expectedLocs.length, actualLocs.size());
+ Assert.assertFalse(Compare.isDifferent(Arrays.asList(expectedLocs), actualLocs));
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/mocks/DataAsserts.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/mocks/DataAsserts.java
index 9355cf2a0a..f13bafb614 100644
--- a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/mocks/DataAsserts.java
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/mocks/DataAsserts.java
@@ -27,6 +27,9 @@ import org.eclipse.osee.framework.core.message.DatastoreInitRequest;
import org.eclipse.osee.framework.core.message.OseeImportModelRequest;
import org.eclipse.osee.framework.core.message.OseeImportModelResponse;
import org.eclipse.osee.framework.core.message.PurgeBranchRequest;
+import org.eclipse.osee.framework.core.message.SearchOptions;
+import org.eclipse.osee.framework.core.message.SearchRequest;
+import org.eclipse.osee.framework.core.message.SearchResponse;
import org.eclipse.osee.framework.core.message.TableData;
import org.eclipse.osee.framework.core.model.AbstractOseeType;
import org.eclipse.osee.framework.core.model.Branch;
@@ -35,6 +38,7 @@ import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.model.type.AttributeType;
import org.eclipse.osee.framework.core.model.type.RelationType;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.jdk.core.util.Compare;
/**
@@ -286,4 +290,40 @@ public final class DataAsserts {
Assert.assertEquals(expected.getTableDataSpace(), actual.getTableDataSpace());
Assert.assertEquals(expected.isUseFileSpecifiedSchemas(), actual.isUseFileSpecifiedSchemas());
}
+
+ public static void assertEquals(SearchRequest expected, SearchRequest actual) {
+ if (expected == null) {
+ Assert.assertNull(actual);
+ } else {
+ Assert.assertEquals(expected.getBranch(), actual.getBranch());
+ Assert.assertEquals(expected.getRawSearch(), actual.getRawSearch());
+ assertEquals(expected.getOptions(), actual.getOptions());
+ }
+ }
+
+ public static void assertEquals(SearchOptions expected, SearchOptions actual) {
+ if (expected == null) {
+ Assert.assertNull(actual);
+ } else {
+ Assert.assertEquals(expected.isAttributeTypeFiltered(), actual.isAttributeTypeFiltered());
+ Assert.assertEquals(expected.isCaseSensitive(), actual.isCaseSensitive());
+ Assert.assertEquals(expected.isFindAllLocationsEnabled(), actual.isFindAllLocationsEnabled());
+ Assert.assertEquals(expected.getDeletionFlag(), actual.getDeletionFlag());
+ Assert.assertEquals(expected.isMatchWordOrder(), actual.isMatchWordOrder());
+
+ Assert.assertTrue(Collections.isEqual(expected.getAttributeTypeFilter(), actual.getAttributeTypeFilter()));
+ }
+ }
+
+ public static void assertEquals(SearchResponse expected, SearchResponse actual) {
+ if (expected == null) {
+ Assert.assertNull(actual);
+ } else {
+ Assert.assertEquals(expected.getErrorMessage(), actual.getErrorMessage());
+ Assert.assertFalse(Compare.isDifferent(expected.getSearchTags(), actual.getSearchTags()));
+ Assert.assertEquals(expected.matches(), actual.matches());
+ Assert.assertFalse(Compare.isDifferent(expected.getAll(), actual.getAll()));
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/DataTranslationServiceFactoryTest.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/DataTranslationServiceFactoryTest.java
index 4e81cf7083..708c77abf1 100644
--- a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/DataTranslationServiceFactoryTest.java
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/DataTranslationServiceFactoryTest.java
@@ -32,6 +32,8 @@ import org.eclipse.osee.framework.core.message.internal.translation.OseeEnumType
import org.eclipse.osee.framework.core.message.internal.translation.OseeImportModelRequestTranslator;
import org.eclipse.osee.framework.core.message.internal.translation.OseeImportModelResponseTranslator;
import org.eclipse.osee.framework.core.message.internal.translation.RelationTypeCacheUpdateResponseTranslator;
+import org.eclipse.osee.framework.core.message.internal.translation.SearchRequestTranslator;
+import org.eclipse.osee.framework.core.message.internal.translation.SearchResponseTranslator;
import org.eclipse.osee.framework.core.message.internal.translation.TableDataTranslator;
import org.eclipse.osee.framework.core.message.internal.translation.TransactionCacheUpdateResponseTranslator;
import org.eclipse.osee.framework.core.message.internal.translation.TransactionRecordTranslator;
@@ -85,6 +87,10 @@ public class DataTranslationServiceFactoryTest {
checkExists(srvc, TableDataTranslator.class, CoreTranslatorId.TABLE_DATA);
checkExists(srvc, DatastoreInitRequestTranslator.class, CoreTranslatorId.OSEE_DATASTORE_INIT_REQUEST);
+
+ checkExists(srvc, SearchRequestTranslator.class, CoreTranslatorId.SEARCH_REQUEST);
+ checkExists(srvc, SearchResponseTranslator.class, CoreTranslatorId.SEARCH_RESPONSE);
+
}
private void checkExists(IDataTranslationService service, Class<? extends ITranslator<?>> expected, ITranslatorId key) throws OseeCoreException {
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchRequestTranslatorTest.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchRequestTranslatorTest.java
index ba3ee640e7..10a634a38b 100644
--- a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchRequestTranslatorTest.java
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchRequestTranslatorTest.java
@@ -13,11 +13,13 @@ package org.eclipse.osee.framework.core.message.test.translation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.eclipse.osee.framework.core.message.internal.translation.TransactionRecordTranslator;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.enums.DeletionFlag;
+import org.eclipse.osee.framework.core.message.SearchOptions;
+import org.eclipse.osee.framework.core.message.SearchRequest;
+import org.eclipse.osee.framework.core.message.internal.translation.SearchRequestTranslator;
import org.eclipse.osee.framework.core.message.test.mocks.DataAsserts;
-import org.eclipse.osee.framework.core.model.TransactionRecord;
-import org.eclipse.osee.framework.core.model.TransactionRecordFactory;
-import org.eclipse.osee.framework.core.model.test.mocks.MockDataFactory;
import org.eclipse.osee.framework.core.translation.ITranslator;
import org.junit.Assert;
import org.junit.runner.RunWith;
@@ -25,30 +27,57 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
- * Test Case For {@link TransactionRecordTranslator}
+ * Test Case For {@link SearchRequestTranslator}
*
* @author Roberto E. Escobar
*/
@RunWith(Parameterized.class)
-public class SearchRequestTranslatorTest extends BaseTranslatorTest<TransactionRecord> {
+public class SearchRequestTranslatorTest extends BaseTranslatorTest<SearchRequest> {
- public SearchRequestTranslatorTest(TransactionRecord data, ITranslator<TransactionRecord> translator) {
+ public SearchRequestTranslatorTest(SearchRequest data, ITranslator<SearchRequest> translator) {
super(data, translator);
}
@Override
- protected void checkEquals(TransactionRecord expected, TransactionRecord actual) {
+ protected void checkEquals(SearchRequest expected, SearchRequest actual) {
Assert.assertNotSame(expected, actual);
DataAsserts.assertEquals(expected, actual);
}
@Parameters
public static Collection<Object[]> data() {
- ITranslator<TransactionRecord> translator = new TransactionRecordTranslator(new TransactionRecordFactory());
+ ITranslator<SearchRequest> translator = new SearchRequestTranslator();
List<Object[]> data = new ArrayList<Object[]>();
- for (int index = 1; index <= 2; index++) {
- data.add(new Object[] {MockDataFactory.createTransaction(index * 10, index * 3), translator});
- }
+
+ SearchOptions options = new SearchOptions();
+ data.add(new Object[] {new SearchRequest(CoreBranches.COMMON, "", options), translator});
+
+ options = new SearchOptions();
+ options.setDeletedIncluded(DeletionFlag.INCLUDE_DELETED);
+ options.setCaseSensive(true);
+ options.setFindAllLocationsEnabled(false);
+ options.setMatchWordOrder(false);
+ options.setAttributeTypeFilter(CoreAttributeTypes.Active);
+
+ data.add(new Object[] {
+ new SearchRequest(CoreBranches.SYSTEM_ROOT, "a search &&!@#$%!%@!$^!$^!.+", options),
+ translator});
+
+ options = new SearchOptions();
+ options.setDeletedIncluded(DeletionFlag.EXCLUDE_DELETED);
+ options.setCaseSensive(false);
+ options.setFindAllLocationsEnabled(true);
+ options.setMatchWordOrder(false);
+ options.setAttributeTypeFilter(CoreAttributeTypes.Afha, CoreAttributeTypes.Annotation);
+ data.add(new Object[] {new SearchRequest(CoreBranches.SYSTEM_ROOT, "a search string", options), translator});
+
+ options = new SearchOptions();
+ options.setDeletedIncluded(DeletionFlag.INCLUDE_DELETED);
+ options.setCaseSensive(false);
+ options.setFindAllLocationsEnabled(false);
+ options.setMatchWordOrder(true);
+ options.setAttributeTypeFilter(CoreAttributeTypes.ContentUrl, CoreAttributeTypes.Country);
+ data.add(new Object[] {new SearchRequest(CoreBranches.COMMON, "one more", options), translator});
return data;
}
}
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchResponseTranslatorTest.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchResponseTranslatorTest.java
new file mode 100644
index 0000000000..d338b1bd1a
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/SearchResponseTranslatorTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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.framework.core.message.test.translation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.osee.framework.core.message.SearchResponse;
+import org.eclipse.osee.framework.core.message.internal.translation.SearchResponseTranslator;
+import org.eclipse.osee.framework.core.message.test.mocks.DataAsserts;
+import org.eclipse.osee.framework.core.translation.ITranslator;
+import org.junit.Assert;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Test Case For {@link SearchResponseTranslator}
+ *
+ * @author Roberto E. Escobar
+ */
+@RunWith(Parameterized.class)
+public class SearchResponseTranslatorTest extends BaseTranslatorTest<SearchResponse> {
+
+ public SearchResponseTranslatorTest(SearchResponse data, ITranslator<SearchResponse> translator) {
+ super(data, translator);
+ }
+
+ @Override
+ protected void checkEquals(SearchResponse expected, SearchResponse actual) {
+ Assert.assertNotSame(expected, actual);
+ DataAsserts.assertEquals(expected, actual);
+ }
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ ITranslator<SearchResponse> translator = new SearchResponseTranslator();
+ List<Object[]> data = new ArrayList<Object[]>();
+ createTest(data, translator, null, false, false);
+ createTest(data, translator, "An Error", false, true);
+ createTest(data, translator, null, true, true);
+ return data;
+ }
+
+ private static void createTest(Collection<Object[]> data, ITranslator<SearchResponse> translator, String errorMessage, boolean hasSearchTags, boolean addMatchData) {
+ SearchResponse response = new SearchResponse();
+ response.setErrorMessage(errorMessage);
+
+ if (hasSearchTags) {
+ response.getSearchTags().put("one", -123141L);
+ response.getSearchTags().put("two", -123141L);
+ }
+ if (addMatchData) {
+ response.add(0, 1, 1);
+ response.add(0, 1, 2);
+ response.add(1, 2, 3, 1, 2);
+ response.add(1, 3, 4, 3, 4);
+ }
+ data.add(new Object[] {response, translator});
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/TranslationTestSuite.java b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/TranslationTestSuite.java
index aa600d676e..6474f500b3 100644
--- a/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/TranslationTestSuite.java
+++ b/plugins/org.eclipse.osee.framework.core.message.test/src/org/eclipse/osee/framework/core/message/test/translation/TranslationTestSuite.java
@@ -14,31 +14,32 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses({//
-BranchCommitRequestTranslatorTest.class, //
- BranchCommitResponseTranslatorTest.class, //
- BranchCreationRequestTranslatorTest.class, //
- BranchCreationResponseTranslatorTest.class, //
- CacheUpdateRequestTranslatorTest.class, //
- ChangeItemTranslatorTest.class, //
- ChangeReportResponseTranslatorTest.class,//
- ChangeVersionTranslatorTest.class, //
- DatastoreInitRequestTranslatorTest.class, //
- DataTranslationServiceFactoryTest.class, //
- DataTranslationServiceTest.class, //
- OseeImportModelRequestTranslatorTest.class, //
- OseeImportModelResponseTranslatorTest.class, //
- TableDataTranslatorTest.class, //
- TransactionCacheUpdateResponseTranslatorTest.class, //
- TransactionRecordTranslatorTest.class, //
- PurgeBranchRequestTranslatorTest.class, //
- BranchChangeTypeRequestTranslatorTest.class, //
- BranchChangeStateRequestTranslatorTest.class, //
- BranchChangeArchivedStateRequestTranslatorTest.class//
-})
+@Suite.SuiteClasses({
+ BranchCommitRequestTranslatorTest.class,
+ BranchCommitResponseTranslatorTest.class,
+ BranchCreationRequestTranslatorTest.class,
+ BranchCreationResponseTranslatorTest.class,
+ CacheUpdateRequestTranslatorTest.class,
+ ChangeItemTranslatorTest.class,
+ ChangeReportResponseTranslatorTest.class,
+ ChangeVersionTranslatorTest.class,
+ DatastoreInitRequestTranslatorTest.class,
+ DataTranslationServiceFactoryTest.class,
+ DataTranslationServiceTest.class,
+ OseeImportModelRequestTranslatorTest.class,
+ OseeImportModelResponseTranslatorTest.class,
+ SearchRequestTranslatorTest.class,
+ SearchResponseTranslatorTest.class,
+ TableDataTranslatorTest.class,
+ TransactionCacheUpdateResponseTranslatorTest.class,
+ TransactionRecordTranslatorTest.class,
+ PurgeBranchRequestTranslatorTest.class,
+ BranchChangeTypeRequestTranslatorTest.class,
+ BranchChangeStateRequestTranslatorTest.class,
+ BranchChangeArchivedStateRequestTranslatorTest.class})
/**
* @author Roberto E. Escobar
*/
public class TranslationTestSuite {
-
+ // Test Suite
}
diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchOptions.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchOptions.java
index 008806c58f..b86e523c1f 100644
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchOptions.java
+++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchOptions.java
@@ -8,53 +8,86 @@
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
-package org.eclipse.osee.framework.search.engine;
+package org.eclipse.osee.framework.core.message;
-import java.util.Properties;
+import java.util.Collection;
+import java.util.HashSet;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.enums.DeletionFlag;
/**
* @author Roberto E. Escobar
*/
public class SearchOptions {
- public enum SearchOptionsEnum {
- include_deleted,
- match_word_order,
- as_xml,
- find_all_locations,
- case_sensitive;
+ private final Collection<IAttributeType> attributeTypeGuids = new HashSet<IAttributeType>();
+ private DeletionFlag deletionFlag;
+ private boolean isMatchWordOrder;
+ private boolean isCaseSensive;
+ private boolean isFindAllLocationsEnabled;
- public String asStringOption() {
- return name().replaceAll("_", " ");
- }
+ public SearchOptions() {
+ super();
+ deletionFlag = DeletionFlag.EXCLUDE_DELETED;
}
- private final Properties properties;
+ public DeletionFlag getDeletionFlag() {
+ return deletionFlag;
+ }
- public SearchOptions() {
- this.properties = new Properties();
+ public boolean isMatchWordOrder() {
+ return isMatchWordOrder;
+ }
+
+ public boolean isCaseSensitive() {
+ return isCaseSensive;
}
- public boolean getBoolean(String key) {
- return new Boolean(getString(key));
+ public boolean isFindAllLocationsEnabled() {
+ return isFindAllLocationsEnabled;
}
- public String getString(String key) {
- return this.properties.getProperty(key, "");
+ public Collection<IAttributeType> getAttributeTypeFilter() {
+ return attributeTypeGuids;
}
- public void put(String key, String value) {
- if (value != null && value.length() > 0) {
- this.properties.put(key, value);
+ public void setAttributeTypeFilter(IAttributeType... typeFilter) {
+ for (IAttributeType attributeType : typeFilter) {
+ addAttributeTypeFilter(attributeType);
}
}
- public void put(String key, boolean value) {
- this.properties.put(key, Boolean.toString(value));
+ public void clearTypeFilter() {
+ attributeTypeGuids.clear();
+ }
+
+ public void addAttributeTypeFilter(IAttributeType type) {
+ attributeTypeGuids.add(type);
+ }
+
+ public boolean isAttributeTypeFiltered() {
+ return !attributeTypeGuids.isEmpty();
+ }
+
+ public void setDeletedIncluded(DeletionFlag deletionFlag) {
+ this.deletionFlag = deletionFlag;
+ }
+
+ public void setMatchWordOrder(boolean isMatchWordOrder) {
+ this.isMatchWordOrder = isMatchWordOrder;
+ }
+
+ public void setCaseSensive(boolean isCaseSensive) {
+ this.isCaseSensive = isCaseSensive;
+ }
+
+ public void setFindAllLocationsEnabled(boolean isFindAllLocationsEnabled) {
+ this.isFindAllLocationsEnabled = isFindAllLocationsEnabled;
}
@Override
public String toString() {
- return properties.toString();
+ return "SearchOptions [attributeTypeGuids=" + attributeTypeGuids + ", isIncludeDeleted=" + getDeletionFlag() + ", isMatchWordOrder=" + isMatchWordOrder + ", isCaseSensive=" + isCaseSensive + ", isFindAllLocationsEnabled=" + isFindAllLocationsEnabled + "]";
}
+
}
diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchRequest.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchRequest.java
index 202772a70d..7fa12201b2 100644
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchRequest.java
+++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchRequest.java
@@ -10,58 +10,42 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.message;
-import java.util.Collection;
-import java.util.HashSet;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
/**
* @author Roberto E. Escobar
*/
public class SearchRequest {
- private final int branchId;
+ private final IOseeBranch branch;
private final String rawSearch;
- private boolean isIncludeDeleted;
- private boolean isMatchWordOrder;
- private boolean isCaseSensive;
- private boolean isFindAllLocationsEnabled;
- private final Collection<String> attributeTypeGuids;
+ private final SearchOptions options;
- public SearchRequest(int branchId, String rawSearch) {
+ public SearchRequest(IOseeBranch branch, String rawSearch) {
+ this(branch, rawSearch, null);
+ }
+
+ public SearchRequest(IOseeBranch branch, String rawSearch, SearchOptions options) {
super();
- this.attributeTypeGuids = new HashSet<String>();
- this.branchId = branchId;
+ this.branch = branch;
this.rawSearch = rawSearch;
+ this.options = options != null ? options : new SearchOptions();
}
- public int getBranchId() {
- return branchId;
+ public IOseeBranch getBranch() {
+ return branch;
}
public String getRawSearch() {
return rawSearch;
}
- public boolean isIncludeDeleted() {
- return isIncludeDeleted;
- }
-
- public boolean isMatchWordOrder() {
- return isMatchWordOrder;
- }
-
- public boolean isCaseSensive() {
- return isCaseSensive;
- }
-
- public boolean isFindAllLocationsEnabled() {
- return isFindAllLocationsEnabled;
- }
-
- public Collection<String> getAttributeTypeFilter() {
- return attributeTypeGuids;
+ public SearchOptions getOptions() {
+ return options;
}
- public boolean isAttributeTypeFiltered() {
- return !attributeTypeGuids.isEmpty();
+ @Override
+ public String toString() {
+ return "SearchRequest [branch=" + branch + ", rawSearch=" + rawSearch + "," + options + "]";
}
}
diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchResponse.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchResponse.java
index 735050c89b..2f97e64cec 100644
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchResponse.java
+++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchResponse.java
@@ -10,9 +10,247 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.message;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
+import org.eclipse.osee.framework.jdk.core.type.MatchLocation;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
/**
* @author Roberto E. Escobar
*/
public class SearchResponse {
+ private final Map<String, Long> searchTags = new LinkedHashMap<String, Long>();
+ private final CompositeKeyHashMap<Integer, Integer, ArtifactMatchMetaData> data =
+ new CompositeKeyHashMap<Integer, Integer, ArtifactMatchMetaData>();
+
+ private String errorMessage;
+
+ public SearchResponse() {
+ this.errorMessage = Strings.emptyString();
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage != null ? errorMessage : Strings.emptyString();
+ }
+
+ public Map<String, Long> getSearchTags() {
+ return searchTags;
+ }
+
+ public AttributeMatchMetaData add(int branchId, int artId, long gammaId) {
+ ArtifactMatchMetaData artifact = getOrCreateArtifactMatch(branchId, artId);
+ return artifact.getOrCreate(artId, gammaId);
+ }
+
+ public void add(int branchId, int artId, long gammaId, int startPosition, int endPosition) {
+ AttributeMatchMetaData attribute = add(branchId, artId, gammaId);
+ attribute.addLocation(startPosition, endPosition);
+ }
+
+ public void add(int branchId, int artId, long gammaId, Collection<MatchLocation> matches) {
+ AttributeMatchMetaData attribute = add(branchId, artId, gammaId);
+ attribute.addLocations(matches);
+ }
+
+ private ArtifactMatchMetaData getOrCreateArtifactMatch(int branchId, int artId) {
+ ArtifactMatchMetaData artifact = getArtifactMatch(branchId, artId);
+ if (artifact == null) {
+ artifact = new ArtifactMatchMetaData(branchId, artId);
+ data.put(branchId, artId, artifact);
+ }
+ return artifact;
+ }
+
+ public Collection<ArtifactMatchMetaData> getAll() {
+ return data.values();
+ }
+
+ public int matches() {
+ int count = 0;
+ for (ArtifactMatchMetaData meta : data.values()) {
+ count += meta.matches();
+ }
+ return count;
+ }
+
+ public Set<Integer> getBranchIds() {
+ Set<Integer> branchIds = new HashSet<Integer>();
+ for (Pair<Integer, Integer> entry : data.getEnumeratedKeys()) {
+ branchIds.add(entry.getFirst());
+ }
+ return branchIds;
+ }
+
+ public Collection<Integer> getArtifactIds(int branchId) {
+ return data.getKeyedValues(branchId).keySet();
+ }
+
+ public Collection<ArtifactMatchMetaData> getArtifacts(int branchId) {
+ return data.getValues(branchId);
+ }
+
+ public ArtifactMatchMetaData getArtifactMatch(int branchId, int artId) {
+ return data.get(branchId, artId);
+ }
+
+ public boolean isEmpty() {
+ return data.isEmpty();
+ }
+
+ public static final class ArtifactMatchMetaData {
+ private final int artId;
+ private final int branchId;
+ private final Map<Long, AttributeMatchMetaData> attributeMatch = new HashMap<Long, AttributeMatchMetaData>();
+
+ public ArtifactMatchMetaData(int branchId, int artId) {
+ this.branchId = branchId;
+ this.artId = artId;
+ }
+
+ public int getArtId() {
+ return artId;
+ }
+
+ public int getBranchId() {
+ return branchId;
+ }
+
+ public Collection<AttributeMatchMetaData> getAll() {
+ return attributeMatch.values();
+ }
+
+ AttributeMatchMetaData getOrCreate(int artId, Long gammaId) {
+ AttributeMatchMetaData attribute = getAttributeMatch(gammaId);
+ if (attribute == null) {
+ attribute = new AttributeMatchMetaData(artId, gammaId);
+ attributeMatch.put(gammaId, attribute);
+ }
+ return attribute;
+ }
+
+ public AttributeMatchMetaData getAttributeMatch(Long gammaId) {
+ return attributeMatch.get(gammaId);
+ }
+
+ public int size() {
+ return attributeMatch.size();
+ }
+
+ public int matches() {
+ int count = 0;
+ for (AttributeMatchMetaData match : attributeMatch.values()) {
+ count += match.matches();
+ }
+ return count;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 11;
+ int result = 1;
+ result = prime * result + (artId * 53);
+ result = prime * result + (branchId * 11);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ArtifactMatchMetaData other = (ArtifactMatchMetaData) obj;
+ if (artId != other.artId) {
+ return false;
+ }
+ if (branchId != other.branchId) {
+ return false;
+ }
+ return true;
+ }
+
+ }
+
+ public static final class AttributeMatchMetaData {
+ private final int artId;
+ private final long gammaId;
+ private final Set<MatchLocation> matches = new HashSet<MatchLocation>(0);
+
+ public AttributeMatchMetaData(int artId, long gammaId) {
+ this.artId = artId;
+ this.gammaId = gammaId;
+ }
+
+ public int getArtId() {
+ return artId;
+ }
+
+ public long getGammaId() {
+ return gammaId;
+ }
+
+ public void addLocation(int start, int stop) {
+ matches.add(new MatchLocation(start, stop));
+ }
+
+ public void addLocations(Collection<MatchLocation> locations) {
+ matches.addAll(locations);
+ }
+
+ public Collection<MatchLocation> getLocations() {
+ return matches;
+ }
+
+ public int matches() {
+ int locData = matches.size();
+ return locData == 0 ? 1 : locData;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 17;
+ int result = 1;
+ result = prime * result + (int) (gammaId ^ (gammaId >>> 32));
+ result = prime * result + (artId * 53);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ AttributeMatchMetaData other = (AttributeMatchMetaData) obj;
+ if (gammaId != other.gammaId) {
+ return false;
+ }
+ if (artId != other.artId) {
+ return false;
+ }
+ return true;
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchRequestTranslator.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchRequestTranslator.java
index 3fbfd7951f..b761845dbf 100644
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchRequestTranslator.java
+++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchRequestTranslator.java
@@ -10,21 +10,105 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.message.internal.translation;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.data.NamedIdentity;
+import org.eclipse.osee.framework.core.enums.DeletionFlag;
+import org.eclipse.osee.framework.core.message.SearchOptions;
import org.eclipse.osee.framework.core.message.SearchRequest;
import org.eclipse.osee.framework.core.translation.ITranslator;
import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+/**
+ * @author Roberto E. Escobar
+ */
public class SearchRequestTranslator implements ITranslator<SearchRequest> {
+ private static enum Entry {
+ BRANCH_GUID,
+ BRANCH_NAME,
+ RAW_SEARCH,
+ OPTION_IS_CASE_SENSITIVE,
+ OPTION_MATCH_WORD_ORDER,
+ OPTION_IS_INCLUDE_DELETED,
+ OPTION_FIND_ALL_LOCATIONS,
+ OPTION_ATTRIBUTE_TYPE_FILTER_GUIDS,
+ OPTION_ATTRIBUTE_TYPE_FILTER_NAMES
+ }
+
@Override
- public SearchRequest convert(PropertyStore propertyStore) throws OseeCoreException {
- return null;
+ public SearchRequest convert(PropertyStore store) {
+ String guid = store.get(Entry.BRANCH_GUID.name());
+ String name = store.get(Entry.BRANCH_NAME.name());
+ IOseeBranch branch = new BranchToken(guid, name);
+
+ String rawSearch = store.get(Entry.RAW_SEARCH.name());
+ SearchOptions options = new SearchOptions();
+
+ options.setCaseSensive(store.getBoolean(Entry.OPTION_IS_CASE_SENSITIVE.name()));
+ options.setFindAllLocationsEnabled(store.getBoolean(Entry.OPTION_FIND_ALL_LOCATIONS.name()));
+ options.setMatchWordOrder(store.getBoolean(Entry.OPTION_MATCH_WORD_ORDER.name()));
+
+ boolean areDeletedAllowed = store.getBoolean(Entry.OPTION_IS_INCLUDE_DELETED.name());
+ options.setDeletedIncluded(DeletionFlag.allowDeleted(areDeletedAllowed));
+
+ String[] typeFilterGuids = store.getArray(Entry.OPTION_ATTRIBUTE_TYPE_FILTER_GUIDS.name());
+ String[] typeFilterNames = store.getArray(Entry.OPTION_ATTRIBUTE_TYPE_FILTER_NAMES.name());
+ if (typeFilterGuids.length > 0 && typeFilterNames.length > 0) {
+ for (int index = 0; index < typeFilterGuids.length; index++) {
+ guid = typeFilterGuids[index];
+ name = index < typeFilterNames.length ? typeFilterNames[index] : Strings.emptyString();
+ IAttributeType type = new AttributeTypeFilter(guid, name);
+ options.addAttributeTypeFilter(type);
+ }
+ }
+ return new SearchRequest(branch, rawSearch, options);
}
@Override
- public PropertyStore convert(SearchRequest object) throws OseeCoreException {
- return null;
+ public PropertyStore convert(SearchRequest object) {
+ PropertyStore store = new PropertyStore();
+ IOseeBranch branch = object.getBranch();
+
+ store.put(Entry.BRANCH_GUID.name(), branch.getGuid());
+ store.put(Entry.BRANCH_NAME.name(), branch.getName());
+
+ store.put(Entry.RAW_SEARCH.name(), object.getRawSearch());
+ SearchOptions options = object.getOptions();
+ if (options != null) {
+ store.put(Entry.OPTION_IS_CASE_SENSITIVE.name(), options.isCaseSensitive());
+ store.put(Entry.OPTION_MATCH_WORD_ORDER.name(), options.isMatchWordOrder());
+ store.put(Entry.OPTION_IS_INCLUDE_DELETED.name(), options.getDeletionFlag().areDeletedAllowed());
+ store.put(Entry.OPTION_FIND_ALL_LOCATIONS.name(), options.isFindAllLocationsEnabled());
+
+ if (options.isAttributeTypeFiltered()) {
+ Collection<IAttributeType> types = options.getAttributeTypeFilter();
+ String[] guids = new String[types.size()];
+ String[] names = new String[types.size()];
+ int index = 0;
+ for (IAttributeType type : types) {
+ guids[index] = type.getGuid();
+ names[index] = type.getName();
+ index++;
+ }
+ store.put(Entry.OPTION_ATTRIBUTE_TYPE_FILTER_GUIDS.name(), guids);
+ store.put(Entry.OPTION_ATTRIBUTE_TYPE_FILTER_NAMES.name(), names);
+ }
+ }
+ return store;
}
+ private static final class BranchToken extends NamedIdentity implements IOseeBranch {
+ public BranchToken(String guid, String name) {
+ super(guid, name);
+ }
+ }
+
+ private static final class AttributeTypeFilter extends NamedIdentity implements IAttributeType {
+ public AttributeTypeFilter(String guid, String name) {
+ super(guid, name);
+ }
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchResponseTranslator.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchResponseTranslator.java
index 40d4ff43b4..3807f4ea57 100644
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchResponseTranslator.java
+++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchResponseTranslator.java
@@ -10,21 +10,121 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.message.internal.translation;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.message.SearchRequest;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.eclipse.osee.framework.core.message.SearchResponse;
+import org.eclipse.osee.framework.core.message.SearchResponse.ArtifactMatchMetaData;
+import org.eclipse.osee.framework.core.message.SearchResponse.AttributeMatchMetaData;
+import org.eclipse.osee.framework.core.message.TranslationUtil;
import org.eclipse.osee.framework.core.translation.ITranslator;
+import org.eclipse.osee.framework.jdk.core.type.MatchLocation;
import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
-public class SearchResponseTranslator implements ITranslator<SearchRequest> {
+/**
+ * @author Roberto E. Escobar
+ */
+public class SearchResponseTranslator implements ITranslator<SearchResponse> {
+
+ private static final int WITH_MATCH_LOCATION_ROW_SIZE = 5;
+ private static final int NO_MATCH_LOCATION_ROW_SIZE = 3;
+
+ private static enum Key {
+ ERROR_MSG,
+ SEARCH_TAGS_COUNT,
+ SEARCH_TAG,
+ MATCH_DATA,
+ MATCH_LOCATION,
+ MATCH_COUNT
+ }
@Override
- public SearchRequest convert(PropertyStore propertyStore) throws OseeCoreException {
- return null;
+ public SearchResponse convert(PropertyStore propertyStore) {
+ SearchResponse response = new SearchResponse();
+ response.setErrorMessage(propertyStore.get(Key.ERROR_MSG.name()));
+
+ int count = propertyStore.getInt(Key.MATCH_COUNT.name());
+ for (int index = 0; index < count; index++) {
+ String key = TranslationUtil.createKey(Key.MATCH_DATA, index);
+ int[] data = asIntArray(propertyStore.getArray(key));
+ int branchId = data[0];
+ int artId = data[1];
+ int gammaId = data[2];
+ if (data.length == WITH_MATCH_LOCATION_ROW_SIZE) {
+ response.add(branchId, artId, gammaId, data[3], data[4]);
+ } else {
+ response.add(branchId, artId, gammaId);
+ }
+ }
+
+ count = propertyStore.getInt(Key.SEARCH_TAGS_COUNT.name());
+ Map<String, Long> codedWords = response.getSearchTags();
+ for (int index = 0; index < count; index++) {
+ String key = TranslationUtil.createKey(Key.SEARCH_TAG, index);
+ String[] data = propertyStore.getArray(key);
+ codedWords.put(data[0], Long.parseLong(data[1]));
+ }
+ return response;
}
@Override
- public PropertyStore convert(SearchRequest object) throws OseeCoreException {
- return null;
+ public PropertyStore convert(SearchResponse object) {
+ PropertyStore store = new PropertyStore();
+ store.put(Key.ERROR_MSG.name(), object.getErrorMessage());
+ Collection<String[]> data = toArray(object);
+ int count = 0;
+ for (String[] row : data) {
+ String key = TranslationUtil.createKey(Key.MATCH_DATA, count);
+ store.put(key, row);
+ count++;
+ }
+ store.put(Key.MATCH_COUNT.name(), data.size());
+
+ Map<String, Long> codedWords = object.getSearchTags();
+ count = 0;
+ for (Entry<String, Long> entry : codedWords.entrySet()) {
+ String key = TranslationUtil.createKey(Key.SEARCH_TAG, count);
+ store.put(key, new String[] {entry.getKey(), String.valueOf(entry.getValue())});
+ count++;
+ }
+ store.put(Key.SEARCH_TAGS_COUNT.name(), codedWords.size());
+ return store;
+ }
+
+ private int[] asIntArray(String[] data) {
+ int[] toReturn = new int[data.length];
+ for (int index = 0; index < data.length; index++) {
+ toReturn[index] = Integer.valueOf(data[index]);
+ }
+ return toReturn;
}
+ private Collection<String[]> toArray(SearchResponse object) {
+ Collection<String[]> toReturn = new ArrayList<String[]>();
+ for (ArtifactMatchMetaData artMeta : object.getAll()) {
+ int branchId = artMeta.getBranchId();
+ for (AttributeMatchMetaData attrMeta : artMeta.getAll()) {
+ Collection<MatchLocation> locs = attrMeta.getLocations();
+ if (!locs.isEmpty()) {
+ for (MatchLocation location : locs) {
+ String[] row = new String[WITH_MATCH_LOCATION_ROW_SIZE];
+ row[0] = String.valueOf(branchId);
+ row[1] = String.valueOf(attrMeta.getArtId());
+ row[2] = String.valueOf(attrMeta.getGammaId());
+ row[3] = String.valueOf(location.getStartPosition());
+ row[4] = String.valueOf(location.getEndPosition());
+ toReturn.add(row);
+ }
+ } else {
+ String[] row = new String[NO_MATCH_LOCATION_ROW_SIZE];
+ row[0] = String.valueOf(branchId);
+ row[1] = String.valueOf(attrMeta.getArtId());
+ row[2] = String.valueOf(attrMeta.getGammaId());
+ toReturn.add(row);
+ }
+ }
+ }
+ return toReturn;
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/SearchResultToXmlOperationTest.java b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/SearchResultToXmlOperationTest.java
deleted file mode 100644
index aaf7f786f5..0000000000
--- a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/SearchResultToXmlOperationTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 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.framework.search.engine.test;
-
-import java.io.StringWriter;
-import org.eclipse.osee.framework.core.exception.OseeArgumentException;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.operation.IOperation;
-import org.eclipse.osee.framework.core.operation.Operations;
-import org.eclipse.osee.framework.search.engine.SearchResult;
-import org.eclipse.osee.framework.search.engine.SearchResultToXmlOperation;
-import org.junit.Test;
-
-/**
- * Test Case for {@link SearchResultToXmlOperation }
- *
- * @author Roberto E. Escobar
- */
-public class SearchResultToXmlOperationTest {
-
- @Test(expected = OseeArgumentException.class)
- public void testArgumentException1() throws OseeCoreException {
- IOperation operation = new SearchResultToXmlOperation(null, new StringWriter());
- Operations.executeWorkAndCheckStatus(operation);
- }
-
- @Test(expected = OseeArgumentException.class)
- public void testArgumentException2() throws OseeCoreException {
- IOperation operation = new SearchResultToXmlOperation(new SearchResult(""), null);
- Operations.executeWorkAndCheckStatus(operation);
- }
-
- public void testSearchResult() {
-
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/mocks/EngineAsserts.java b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/mocks/EngineAsserts.java
index fa8755b656..9abdd1e113 100644
--- a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/mocks/EngineAsserts.java
+++ b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/mocks/EngineAsserts.java
@@ -13,8 +13,8 @@ package org.eclipse.osee.framework.search.engine.test.mocks;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
+import org.eclipse.osee.framework.jdk.core.type.MatchLocation;
import org.eclipse.osee.framework.jdk.core.type.Pair;
-import org.eclipse.osee.framework.search.engine.MatchLocation;
import org.eclipse.osee.framework.search.engine.attribute.AttributeData;
/**
diff --git a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/WordOrderMatcherTest.java b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/WordOrderMatcherTest.java
index aee9c5a9fa..05535bbd8c 100644
--- a/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/WordOrderMatcherTest.java
+++ b/plugins/org.eclipse.osee.framework.search.engine.test/src/org/eclipse/osee/framework/search/engine/test/utility/WordOrderMatcherTest.java
@@ -17,9 +17,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.search.engine.MatchLocation;
-import org.eclipse.osee.framework.search.engine.SearchOptions;
-import org.eclipse.osee.framework.search.engine.SearchOptions.SearchOptionsEnum;
+import org.eclipse.osee.framework.core.message.SearchOptions;
+import org.eclipse.osee.framework.jdk.core.type.MatchLocation;
import org.eclipse.osee.framework.search.engine.test.mocks.EngineAsserts;
import org.eclipse.osee.framework.search.engine.utility.WordOrderMatcher;
import org.junit.Test;
@@ -40,14 +39,12 @@ public class WordOrderMatcherTest {
private final List<MatchLocation> expected;
private final SearchOptions options;
- public WordOrderMatcherTest(String data, String toSearch, boolean caseSensitive, boolean allLocations, List<MatchLocation> expected) {
+ public WordOrderMatcherTest(String data, String toSearch, SearchOptions options, List<MatchLocation> expected) {
super();
this.toSearch = toSearch;
this.data = data;
+ this.options = options;
this.expected = expected;
- this.options = new SearchOptions();
- options.put(SearchOptionsEnum.case_sensitive.asStringOption(), caseSensitive);
- options.put(SearchOptionsEnum.find_all_locations.asStringOption(), allLocations);
}
@Test
@@ -60,15 +57,22 @@ public class WordOrderMatcherTest {
@Parameters
public static Collection<Object[]> data() {
List<Object[]> data = new ArrayList<Object[]>();
- data.add(new Object[] {"Why is this here again.", "THIS", false, false, getLocs(8, 11)});
- data.add(new Object[] {"Why is this here again.", "THIS", true, false, getLocs()});
- data.add(new Object[] {"Why is this here this again.", "THIS", false, false, getLocs(8, 11)});
- data.add(new Object[] {"Why is this here this again.", "THIS", false, true, getLocs(8, 11, 18, 21)});
- data.add(new Object[] {"hello #@!@$$%'- again.", "hello again", false, false, getLocs(1, 21)});
- data.add(new Object[] {"hello word again.", "hello again", false, false, getLocs()});
+ addTest(data, "Why is this here again.", "THIS", false, false, getLocs(8, 11));
+ addTest(data, "Why is this here again.", "THIS", true, false, getLocs());
+ addTest(data, "Why is this here this again.", "THIS", false, false, getLocs(8, 11));
+ addTest(data, "Why is this here this again.", "THIS", false, true, getLocs(8, 11, 18, 21));
+ addTest(data, "hello #@!@$$%'- again.", "hello again", false, false, getLocs(1, 21));
+ addTest(data, "hello word again.", "hello again", false, false, getLocs());
return data;
}
+ private static void addTest(Collection<Object[]> testData, String data, String toSearch, boolean caseSensitive, boolean isFindAllLocationsEnabled, List<MatchLocation> expectedLocs) {
+ SearchOptions options = new SearchOptions();
+ options.setCaseSensive(caseSensitive);
+ options.setFindAllLocationsEnabled(isFindAllLocationsEnabled);
+ testData.add(new Object[] {data, toSearch, options, expectedLocs});
+ }
+
private static List<MatchLocation> getLocs(int... data) {
return EngineAsserts.asLocations(data);
}

Back to the top