diff options
author | ddunne | 2010-09-14 16:23:18 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2010-09-14 16:23:18 +0000 |
commit | 10673accf4f116ce9071e40bd47680538867fd48 (patch) | |
tree | 57cf81b97ec886c2e86837bfb716f9ab2de7a424 /plugins | |
parent | dfbf32b3e486a38251bc8354942670a71b04cd61 (diff) | |
download | org.eclipse.osee-10673accf4f116ce9071e40bd47680538867fd48.tar.gz org.eclipse.osee-10673accf4f116ce9071e40bd47680538867fd48.tar.xz org.eclipse.osee-10673accf4f116ce9071e40bd47680538867fd48.zip |
feature[ats_49K1T]: Improve search error dialog to show that no words in search string
Diffstat (limited to 'plugins')
5 files changed, 68 insertions, 19 deletions
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SearchEngineServlet.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SearchEngineServlet.java index 2c9314329b2..df05841d7f6 100644 --- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SearchEngineServlet.java +++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SearchEngineServlet.java @@ -25,6 +25,7 @@ import org.eclipse.osee.framework.core.services.IOseeCachingService; import org.eclipse.osee.framework.database.core.JoinUtility; import org.eclipse.osee.framework.database.core.JoinUtility.ArtifactJoinQuery; import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.manager.servlet.data.HttpSearchInfo; import org.eclipse.osee.framework.manager.servlet.internal.Activator; @@ -87,7 +88,9 @@ public class SearchEngineServlet extends SecureOseeHttpServlet { SearchResult results = searchEngine.search(searchInfo.getQuery(), searchInfo.getId(), searchInfo.getOptions(), attributeTypes); response.setStatus(wasFromGet ? HttpServletResponse.SC_OK : HttpServletResponse.SC_ACCEPTED); - if (!results.isEmpty()) { + if (results.isEmpty() && Strings.isValid(results.getErrorMessage())) { + sendEmptyAsXml(response, results); + } else if (!results.isEmpty()) { long start = System.currentTimeMillis(); if (!searchInfo.getOptions().getBoolean(SearchOptionsEnum.as_xml.asStringOption())) { sendAsDbJoin(response, results); @@ -125,6 +128,17 @@ public class SearchEngineServlet extends SecureOseeHttpServlet { response.getWriter().write(String.format("%d,%d", joinQuery.getQueryId(), joinQuery.size())); } + private void sendEmptyAsXml(HttpServletResponse response, SearchResult results) throws Exception { + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/xml"); + PrintWriter writer = response.getWriter(); + + writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); + writer.write("<search>"); + writer.write(String.format("<errorMessage=\"%s\">", results.getErrorMessage())); + writer.write("</search>"); + } + /** * <match artId="" branchId=""> <attr gammaId=""><location start="" end="" /></attr> </match> */ @@ -135,6 +149,7 @@ public class SearchEngineServlet extends SecureOseeHttpServlet { writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); writer.write("<search>"); + writer.write(String.format("<error message=\"%s\"", results.getErrorMessage())); for (Integer branchId : results.getBranchIds()) { writer.write(String.format("<match branchId=\"%s\">", branchId)); for (ArtifactMatch match : results.getArtifacts(branchId)) { diff --git a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/SearchResult.java b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/SearchResult.java index 42bcc3e8063..a1f679b0916 100644 --- a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/SearchResult.java +++ b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/SearchResult.java @@ -25,6 +25,7 @@ public class SearchResult { private final Map<Integer, Map<Integer, ArtifactMatch>> entries; private int size; + private String errorMessage; public SearchResult() { this.entries = new HashMap<Integer, Map<Integer, ArtifactMatch>>(); @@ -126,4 +127,12 @@ public class SearchResult { } } + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + } diff --git a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/data/AttributeSearch.java b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/data/AttributeSearch.java index 6f0dcb0f6ac..f9b05bf40a2 100644 --- a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/data/AttributeSearch.java +++ b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/data/AttributeSearch.java @@ -17,6 +17,7 @@ import java.util.logging.Level; import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.search.engine.SearchOptions; +import org.eclipse.osee.framework.search.engine.SearchResult; import org.eclipse.osee.framework.search.engine.attribute.AttributeData; import org.eclipse.osee.framework.search.engine.attribute.AttributeDataStore; import org.eclipse.osee.framework.search.engine.utility.ITagCollector; @@ -42,10 +43,14 @@ public final class AttributeSearch implements ITagCollector { this.attributeTypes = attributeTypes; } - public Set<AttributeData> getMatchingAttributes() throws Exception { + public Set<AttributeData> getMatchingAttributes(SearchResult results) throws Exception { Set<AttributeData> toReturn = null; long start = System.currentTimeMillis(); tagProcessor.collectFromString(searchString, this); + if (tagStore.isEmpty()) { + results.setErrorMessage("No words found in search string. Please reformat and try again."); + return Collections.emptySet(); + } toReturn = AttributeDataStore.getAttributesByTags(branchId, options, tagStore, attributeTypes); if (toReturn == null) { toReturn = Collections.emptySet(); diff --git a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/internal/search/SearchEngine.java b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/internal/search/SearchEngine.java index 270a351d79f..67126ca0180 100644 --- a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/internal/search/SearchEngine.java +++ b/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/internal/search/SearchEngine.java @@ -50,7 +50,7 @@ public class SearchEngine implements ISearchEngine { AttributeSearch attributeSearch = new AttributeSearch(tagProcessor, searchString, branchId, options, attributeTypes); - Collection<AttributeData> tagMatches = attributeSearch.getMatchingAttributes(); + Collection<AttributeData> tagMatches = attributeSearch.getMatchingAttributes(results); long timeAfterPass1 = System.currentTimeMillis() - startTime; long secondPass = System.currentTimeMillis(); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/HttpArtifactQuery.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/HttpArtifactQuery.java index 800f80a270f..1d071ab6a93 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/HttpArtifactQuery.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/search/HttpArtifactQuery.java @@ -21,11 +21,14 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.osee.framework.core.client.ClientSessionManager; import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.data.OseeServerContext; +import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.exception.OseeDataStoreException; import org.eclipse.osee.framework.core.exception.OseeExceptions; @@ -139,24 +142,29 @@ final class HttpArtifactQuery { try { if (data.getFirst().endsWith("xml")) { - List<XmlArtifactSearchResult> results = handleAsXmlResults(data.getSecond()); - for (XmlArtifactSearchResult result : results) { - try { - result.getJoinQuery().store(); - List<Artifact> artifacts = - ArtifactLoader.loadArtifactsFromQueryId(result.getJoinQuery().getQueryId(), loadLevel, - confirmer, result.getJoinQuery().size(), reload, historical, allowDeleted); - for (Artifact artifact : artifacts) { - ArtifactMatch artMatch = new ArtifactMatch(artifact); - HashCollection<Long, MatchLocation> attributeMatches = - result.getAttributeMatches(artifact.getArtId()); - if (attributeMatches != null) { - artMatch.addMatches(attributeMatches); + String errorMessage = isErrorMessage(data.getSecond()); + if (Strings.isValid(errorMessage)) { + throw new OseeArgumentException(errorMessage); + } else { + List<XmlArtifactSearchResult> results = handleAsXmlResults(data.getSecond()); + for (XmlArtifactSearchResult result : results) { + try { + result.getJoinQuery().store(); + List<Artifact> artifacts = + ArtifactLoader.loadArtifactsFromQueryId(result.getJoinQuery().getQueryId(), loadLevel, + confirmer, result.getJoinQuery().size(), reload, historical, allowDeleted); + for (Artifact artifact : artifacts) { + ArtifactMatch artMatch = new ArtifactMatch(artifact); + HashCollection<Long, MatchLocation> attributeMatches = + result.getAttributeMatches(artifact.getArtId()); + if (attributeMatches != null) { + artMatch.addMatches(attributeMatches); + } + toReturn.add(artMatch); } - toReturn.add(artMatch); + } finally { + result.getJoinQuery().delete(); } - } finally { - result.getJoinQuery().delete(); } } } else if (data.getFirst().endsWith("plain")) { @@ -181,6 +189,18 @@ final class HttpArtifactQuery { return toReturn; } + private static Pattern errorMessagePattern = Pattern.compile("<errorMessage=\"(.*?)\">"); + + private String isErrorMessage(ByteArrayOutputStream outputStream) { + String results = outputStream.toString(); + Matcher matcher = errorMessagePattern.matcher(results); + if (matcher.find()) { + String message = matcher.group(1); + return message; + } + return null; + } + private Pair<String, ByteArrayOutputStream> executeSearch(boolean withMatches, boolean findAllMatchLocations) throws OseeCoreException { Pair<String, ByteArrayOutputStream> toReturn = null; String sessionId = ClientSessionManager.getSessionId(); |