Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AdHocSearchDelegator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
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;
35 
41 class AdHocSearchDelegator {
42 
43  private final List<KeywordList> keywordLists;
44  private List<KeywordSearchQuery> queryDelegates;
45  private final Set<Long> dataSourceIds;
46  private static int resultWindowCount = 0; //keep track of unique window ids to display
47  private static final Logger logger = Logger.getLogger(AdHocSearchDelegator.class.getName());
48 
49  public AdHocSearchDelegator(List<KeywordList> keywordLists, Set<Long> dataSourceIds) {
50  this.keywordLists = keywordLists;
51  this.dataSourceIds = dataSourceIds;
52  init();
53  }
54 
55  private void init() {
56  // make a query for each keyword
57  queryDelegates = new ArrayList<>();
58 
59  for (KeywordList keywordList : keywordLists) {
60  for (Keyword keyword : keywordList.getKeywords()) {
61  KeywordSearchQuery query = KeywordSearchUtil.getQueryForKeyword(keyword, keywordList);
62 
63  //Limit search to a set of data sources
64  if (dataSourceIds != null && !dataSourceIds.isEmpty()) {
65  final KeywordQueryFilter dataSourceFilter = new KeywordQueryFilter(KeywordQueryFilter.FilterType.DATA_SOURCE, dataSourceIds);
66  query.addFilter(dataSourceFilter);
67  }
68 
69  queryDelegates.add(query);
70  }
71  }
72  }
73 
78  public void execute() {
79  Collection<AdHocQueryRequest> queryRequests = new ArrayList<>();
80  int queryID = 0;
81  StringBuilder queryConcat = new StringBuilder(); // concatenation of all query strings
82  for (KeywordSearchQuery q : queryDelegates) {
83  Map<String, Object> kvs = new LinkedHashMap<>();
84  final String queryStr = q.getQueryString();
85  queryConcat.append(queryStr).append(" ");
86  queryRequests.add(new AdHocQueryRequest(kvs, ++queryID, q));
87  }
88 
89  String queryConcatStr = queryConcat.toString();
90  final int queryConcatStrLen = queryConcatStr.length();
91  final String queryStrShort = queryConcatStrLen > 15 ? queryConcatStr.substring(0, 14) + "..." : queryConcatStr;
92  final String windowTitle = NbBundle.getMessage(this.getClass(), "KeywordSearchQueryManager.execute.exeWinTitle", ++resultWindowCount, queryStrShort);
93  DataResultTopComponent searchResultWin = DataResultTopComponent.createInstance(windowTitle);
94 
95  Node rootNode;
96  if (queryRequests.size() > 0) {
97  Children childNodes =
98  Children.create(new AdHocSearchChildFactory(queryRequests), true);
99 
100  rootNode = new AbstractNode(childNodes);
101  } else {
102  rootNode = Node.EMPTY;
103  }
104 
105  final String pathText = NbBundle.getMessage(this.getClass(), "KeywordSearchQueryManager.pathText.text");
106 
107  DataResultTopComponent.initInstance(pathText, new TableFilterNode(rootNode, true, KeywordSearch.class.getName()),
108  queryRequests.size(), searchResultWin);
109 
110  searchResultWin.requestActive();
111  }
112 
118  public boolean validate() {
119  boolean allValid = true;
120  for (KeywordSearchQuery tcq : queryDelegates) {
121  if (!tcq.validate()) {
122  logger.log(Level.WARNING, "Query has invalid syntax: {0}", tcq.getQueryString()); //NON-NLS
123  allValid = false;
124  break;
125  }
126  }
127  return allValid;
128  }
129 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.