diff options
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.message')
5 files changed, 508 insertions, 69 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 index 008806c58fc..b86e523c1f5 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 202772a70d4..7fa12201b2e 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 735050c89b8..2f97e64cece 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 3fbfd7951fe..b761845dbf5 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 40d4ff43b4e..3807f4ea57d 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; + } } |