]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/DependenciesSearchFunction.java
Move platform to only work with JDK's >= 11
[simantics/platform.git] / bundles / org.simantics.workbench.search / src / org / simantics / workbench / search / DependenciesSearchFunction.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.workbench.search;
13
14 import java.util.Collection;
15 import java.util.Map;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.genericrelation.Dependencies;
22 import org.simantics.operation.Layer0X;
23 import org.simantics.scl.runtime.function.FunctionImpl5;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * dependenciesSearchFunction:
29  *      (IProgressMonitor, ReadGraph, model : Resource, query : String, maxResults : Integer) -> QueryResult
30  * 
31  * @author Tuukka Lehtonen
32  */
33 public class DependenciesSearchFunction extends FunctionImpl5<IProgressMonitor, ReadGraph, Resource, SearchQuery, Integer, SearchResult> {
34
35     private static final Logger LOGGER = LoggerFactory.getLogger(DependenciesSearchFunction.class);
36
37     @Override
38     public SearchResult apply(IProgressMonitor monitor, ReadGraph graph, Resource model, SearchQuery query, Integer maxResults) {
39         try {
40             Collection<Map<String, Object>> results = Searching.performSearch(graph,
41                     Layer0X.getInstance(graph).Dependencies, model,
42                     query.escapedWithForcedCase(false, false).getQuery(Dependencies.FIELD_NAME_SEARCH, Dependencies.FIELD_TYPES_SEARCH),
43                     maxResults);
44
45             return Searching.generateDependenciesSearchResult(graph, results);
46         } catch (DatabaseException e) {
47             LOGGER.error("Search query {} failed", query, e);
48         }
49         return null;
50     }
51
52 }