19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.LinkedHashMap;
24 import java.util.List;
27 import java.util.logging.Level;
28 import org.openide.nodes.AbstractNode;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31 import org.openide.util.NbBundle;
41 class AdHocSearchDelegator {
43 private final List<KeywordList> keywordLists;
44 private List<KeywordSearchQuery> queryDelegates;
45 private final Set<Long> dataSourceIds;
46 private static int resultWindowCount = 0;
47 private static final Logger logger = Logger.
getLogger(AdHocSearchDelegator.class.getName());
49 public AdHocSearchDelegator(List<KeywordList> keywordLists, Set<Long> dataSourceIds) {
50 this.keywordLists = keywordLists;
51 this.dataSourceIds = dataSourceIds;
57 queryDelegates =
new ArrayList<>();
59 for (KeywordList keywordList : keywordLists) {
60 for (Keyword keyword : keywordList.getKeywords()) {
61 KeywordSearchQuery query = KeywordSearchUtil.getQueryForKeyword(keyword, keywordList);
64 if (dataSourceIds != null && !dataSourceIds.isEmpty()) {
65 final KeywordQueryFilter dataSourceFilter =
new KeywordQueryFilter(KeywordQueryFilter.FilterType.DATA_SOURCE, dataSourceIds);
66 query.addFilter(dataSourceFilter);
69 queryDelegates.add(query);
80 public void execute(
boolean saveResults) {
81 Collection<AdHocQueryRequest> queryRequests =
new ArrayList<>();
83 StringBuilder queryConcat =
new StringBuilder();
84 for (KeywordSearchQuery q : queryDelegates) {
85 Map<String, Object> kvs =
new LinkedHashMap<>();
86 final String queryStr = q.getQueryString();
87 queryConcat.append(queryStr).append(
" ");
88 queryRequests.add(
new AdHocQueryRequest(kvs, ++queryID, q));
91 String queryConcatStr = queryConcat.toString();
92 final int queryConcatStrLen = queryConcatStr.length();
93 final String queryStrShort = queryConcatStrLen > 15 ? queryConcatStr.substring(0, 14) +
"..." : queryConcatStr;
94 final String windowTitle = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.execute.exeWinTitle", ++resultWindowCount, queryStrShort);
95 DataResultTopComponent searchResultWin = DataResultTopComponent.createInstance(windowTitle);
98 if (queryRequests.size() > 0) {
100 Children.create(
new AdHocSearchChildFactory(queryRequests, saveResults),
true);
102 rootNode =
new AbstractNode(childNodes);
104 rootNode = Node.EMPTY;
107 final String pathText = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.pathText.text");
109 DataResultTopComponent.initInstance(pathText,
new TableFilterNode(rootNode,
true, KeywordSearch.class.getName()),
110 queryRequests.size(), searchResultWin);
112 searchResultWin.requestActive();
120 public boolean validate() {
121 boolean allValid =
true;
122 for (KeywordSearchQuery tcq : queryDelegates) {
123 if (!tcq.validate()) {
124 logger.log(Level.WARNING,
"Query has invalid syntax: {0}", tcq.getQueryString());
synchronized static Logger getLogger(String name)