Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2013-12-09 10:46:25 -0500
committerjmisinco2013-12-12 15:38:09 -0500
commitb080a40051b990baea9340fbd326b1bd823cfb63 (patch)
treec8ea64b216854feaac7e39fbc154f05caef25789 /plugins/org.eclipse.osee.framework.core.message/src
parentfe5e2d94c5a592a23ddbd7b6ae5ff60f9a449d49 (diff)
downloadorg.eclipse.osee-b080a40051b990baea9340fbd326b1bd823cfb63.tar.gz
org.eclipse.osee-b080a40051b990baea9340fbd326b1bd823cfb63.tar.xz
org.eclipse.osee-b080a40051b990baea9340fbd326b1bd823cfb63.zip
feature[ats_EPQBU]: Add support for match locations to search REST API
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.message/src')
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchOptions.java97
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchRequest.java48
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchResponse.java256
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java5
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchRequestTranslator.java101
-rw-r--r--plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchResponseTranslator.java130
6 files changed, 0 insertions, 637 deletions
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
deleted file mode 100644
index ca9fd6601b..0000000000
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchOptions.java
+++ /dev/null
@@ -1,97 +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.core.message;
-
-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 {
-
- private final Collection<IAttributeType> attributeTypeGuids = new HashSet<IAttributeType>();
- private DeletionFlag deletionFlag;
- private boolean isMatchWordOrder;
- private boolean isCaseSensive;
- private boolean isFindAllLocationsEnabled;
- private boolean isSearchAll;
-
- public SearchOptions() {
- deletionFlag = DeletionFlag.EXCLUDE_DELETED;
- }
-
- public DeletionFlag getDeletionFlag() {
- return deletionFlag;
- }
-
- public boolean isMatchWordOrder() {
- return isMatchWordOrder;
- }
-
- public boolean isCaseSensitive() {
- return isCaseSensive;
- }
-
- public boolean isFindAllLocationsEnabled() {
- return isFindAllLocationsEnabled;
- }
-
- public boolean isSearchAll() {
- return isSearchAll;
- }
-
- public Collection<IAttributeType> getAttributeTypeFilter() {
- return attributeTypeGuids;
- }
-
- public void setAttributeTypeFilter(IAttributeType... typeFilter) {
- for (IAttributeType attributeType : typeFilter) {
- addAttributeTypeFilter(attributeType);
- }
- }
-
- public void clearTypeFilter() {
- attributeTypeGuids.clear();
- }
-
- public void addAttributeTypeFilter(IAttributeType type) {
- attributeTypeGuids.add(type);
- }
-
- 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;
- }
-
- public void setIsSearchAll(boolean isSearchAll) {
- this.isSearchAll = isSearchAll;
- }
-
- @Override
- public String 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
deleted file mode 100644
index b7884dcec0..0000000000
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchRequest.java
+++ /dev/null
@@ -1,48 +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.core.message;
-
-import org.eclipse.osee.framework.core.data.HasBranch;
-import org.eclipse.osee.framework.core.data.IOseeBranch;
-
-/**
- * @author Roberto E. Escobar
- */
-public class SearchRequest implements HasBranch {
-
- private final IOseeBranch branch;
- private final String rawSearch;
- private final SearchOptions options;
-
- public SearchRequest(IOseeBranch branch, String rawSearch, SearchOptions options) {
- this.branch = branch;
- this.rawSearch = rawSearch;
- this.options = options != null ? options : new SearchOptions();
- }
-
- @Override
- public IOseeBranch getBranch() {
- return branch;
- }
-
- public String getRawSearch() {
- return rawSearch;
- }
-
- public SearchOptions getOptions() {
- return options;
- }
-
- @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
deleted file mode 100644
index 8f407744ea..0000000000
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/SearchResponse.java
+++ /dev/null
@@ -1,256 +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.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<Long, Integer, ArtifactMatchMetaData> data =
- new CompositeKeyHashMap<Long, 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(long branchId, int artId, long gammaId) {
- ArtifactMatchMetaData artifact = getOrCreateArtifactMatch(branchId, artId);
- return artifact.getOrCreate(artId, gammaId);
- }
-
- public void add(long branchId, int artId, long gammaId, int startPosition, int endPosition) {
- AttributeMatchMetaData attribute = add(branchId, artId, gammaId);
- attribute.addLocation(startPosition, endPosition);
- }
-
- public void add(long branchId, int artId, long gammaId, Collection<MatchLocation> matches) {
- AttributeMatchMetaData attribute = add(branchId, artId, gammaId);
- attribute.addLocations(matches);
- }
-
- private ArtifactMatchMetaData getOrCreateArtifactMatch(long 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<Long> getBranchIds() {
- Set<Long> branchIds = new HashSet<Long>();
- for (Pair<Long, Integer> entry : data.getEnumeratedKeys()) {
- branchIds.add(entry.getFirst());
- }
- return branchIds;
- }
-
- public Collection<Integer> getArtifactIds(long branchId) {
- return data.getKeyedValues(branchId).keySet();
- }
-
- public Collection<ArtifactMatchMetaData> getArtifacts(long branchId) {
- return data.getValues(branchId);
- }
-
- public ArtifactMatchMetaData getArtifactMatch(long 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 Long branchId;
- private final Map<Long, AttributeMatchMetaData> attributeMatch = new HashMap<Long, AttributeMatchMetaData>();
-
- public ArtifactMatchMetaData(long branchId, int artId) {
- this.branchId = branchId;
- this.artId = artId;
- }
-
- public int getArtId() {
- return artId;
- }
-
- public long 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.hashCode() * 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/DataTranslationServiceFactory.java b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java
index d7a3507c66..b43548fe11 100644
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java
+++ b/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/DataTranslationServiceFactory.java
@@ -31,8 +31,6 @@ import org.eclipse.osee.framework.core.message.internal.translation.OseeImportMo
import org.eclipse.osee.framework.core.message.internal.translation.OseeImportModelResponseTranslator;
import org.eclipse.osee.framework.core.message.internal.translation.PurgeBranchRequestTranslator;
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;
@@ -97,8 +95,5 @@ public class DataTranslationServiceFactory {
service.addTranslator(new TableDataTranslator(), CoreTranslatorId.TABLE_DATA);
service.addTranslator(new DatastoreInitRequestTranslator(), CoreTranslatorId.OSEE_DATASTORE_INIT_REQUEST);
-
- service.addTranslator(new SearchRequestTranslator(), CoreTranslatorId.SEARCH_REQUEST);
- service.addTranslator(new SearchResponseTranslator(), CoreTranslatorId.SEARCH_RESPONSE);
}
}
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
deleted file mode 100644
index 8213d6bebd..0000000000
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchRequestTranslator.java
+++ /dev/null
@@ -1,101 +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.core.message.internal.translation;
-
-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.TokenFactory;
-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 store) {
- String guid = store.get(Entry.BRANCH_GUID.name());
- String name = store.get(Entry.BRANCH_NAME.name());
- IOseeBranch branch = TokenFactory.createBranch(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++) {
- long id = Long.valueOf(typeFilterGuids[index]);
- name = index < typeFilterNames.length ? typeFilterNames[index] : Strings.emptyString();
- IAttributeType type = TokenFactory.createAttributeType(id, name);
- options.addAttributeTypeFilter(type);
- }
- }
- return new SearchRequest(branch, rawSearch, options);
- }
-
- @Override
- 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());
-
- 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] = String.valueOf(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;
- }
-}
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
deleted file mode 100644
index 2b74cd6c00..0000000000
--- a/plugins/org.eclipse.osee.framework.core.message/src/org/eclipse/osee/framework/core/message/internal/translation/SearchResponseTranslator.java
+++ /dev/null
@@ -1,130 +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.core.message.internal.translation;
-
-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;
-
-/**
- * @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 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(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()) {
- long 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;
- }
-}

Back to the top