Search in sources :

Example 1 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm in project kie-wb-common by kiegroup.

the class CalledElementFormProvider method getBusinessProcessIDs.

public Map<Object, String> getBusinessProcessIDs() {
    final Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>() {

        {
            add(new ValueResourceIndexTerm("*", ResourceType.BPMN2, ValueIndexTerm.TermSearchType.WILDCARD));
        }
    };
    List<RefactoringPageRow> results = queryService.query(FindBpmnProcessIdsQuery.NAME, queryTerms);
    Map<Object, String> businessProcessIDs = new TreeMap<Object, String>();
    for (RefactoringPageRow row : results) {
        Map<String, Path> mapRow = (Map<String, Path>) row.getValue();
        for (String rKey : mapRow.keySet()) {
            businessProcessIDs.put(rKey, rKey);
        }
    }
    return businessProcessIDs;
}
Also used : Path(org.uberfire.backend.vfs.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) TreeMap(java.util.TreeMap) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) TreeMap(java.util.TreeMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm in project kie-wb-common by kiegroup.

the class MultipleTermQueryBuilder method build.

public Query build() {
    BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
    for (ValueIndexTerm valueTerm : terms) {
        Query termQuery = getQuery(valueTerm);
        queryBuilder.add(termQuery, Occur.MUST);
    }
    BooleanQuery query = queryBuilder.build();
    return query;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)

Example 3 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm in project kie-wb-common by kiegroup.

the class FindRulesByModuleQuery method toQuery.

@Override
public Query toQuery(final Set<ValueIndexTerm> terms) {
    checkNotNullAndNotEmpty(terms);
    ValuePackageNameIndexTerm packageTerm = null;
    ValueModuleRootPathIndexTerm projectTerm = null;
    ValueResourceIndexTerm ruleTerm = null;
    for (ValueIndexTerm term : terms) {
        if (term instanceof ValuePackageNameIndexTerm) {
            packageTerm = (ValuePackageNameIndexTerm) term;
        } else if (term instanceof ValueModuleRootPathIndexTerm) {
            projectTerm = (ValueModuleRootPathIndexTerm) term;
        } else if (term instanceof ValueResourceIndexTerm) {
            ruleTerm = (ValueResourceIndexTerm) term;
        }
    }
    SearchEmptyQueryBuilder queryBuilder = new SearchEmptyQueryBuilder().addTerm(packageTerm).addTerm(projectTerm);
    if (ruleTerm != null) {
        queryBuilder.addTerm(ruleTerm);
    } else {
        queryBuilder.addRuleNameWildCardTerm();
    }
    return queryBuilder.build();
}
Also used : ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) SearchEmptyQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SearchEmptyQueryBuilder) ValuePackageNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePackageNameIndexTerm) ValueModuleRootPathIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm)

Example 4 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm in project kie-wb-common by kiegroup.

the class FindDataTypesQueryTest method testDesignerFindDataTypesQuery.

@Test
public void testDesignerFindDataTypesQuery() {
    FindDataTypesQuery query = new FindDataTypesQuery();
    Set<ValueIndexTerm> queryTerms = new HashSet<>();
    try {
        query.validateTerms(queryTerms);
        fail("The required java term is missing, but no exception was thrown.");
    } catch (IllegalArgumentException iae) {
        assertTrue("Incorrect error message: " + iae.getMessage(), iae.getMessage().contains("At least 1 term"));
    }
    queryTerms = new HashSet<>();
    queryTerms.add(new ValueSharedPartIndexTerm("not-rule-flow", PartType.ACTIVATION_GROUP));
    try {
        query.validateTerms(queryTerms);
        fail("The required java term is missing, but no exception was thrown.");
    } catch (IllegalArgumentException iae) {
        assertTrue("Incorrect error message: " + iae.getMessage(), iae.getMessage().contains(ERROR_MSG));
    }
    queryTerms = new HashSet<>();
    queryTerms.add(new ValueSharedPartIndexTerm("not-rule-flow", PartType.ACTIVATION_GROUP));
    queryTerms.add(new ValueResourceIndexTerm("java.class", ResourceType.JAVA));
    try {
        query.validateTerms(queryTerms);
        fail("The activation term is not acceptable here, but no exception was thrown.");
    } catch (IllegalArgumentException iae) {
        assertTrue("Incorrect error message: " + iae.getMessage(), iae.getMessage().contains(ERROR_MSG));
    }
    queryTerms = new HashSet<>();
    queryTerms.add(new ValueResourceIndexTerm("java.class", ResourceType.JAVA));
    query.validateTerms(queryTerms);
}
Also used : ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm in project drools-wb by kiegroup.

the class IndexRuleAttributeNameAndValueTest method testIndexDrlRuleAttributeNameAndValue.

@Test
public void testIndexDrlRuleAttributeNameAndValue() throws IOException, InterruptedException {
    // Add test files
    final Path path = basePath.resolve("drl1.drl");
    final String drl = loadText("drl1.drl");
    ioService().write(path, drl);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
        queryBuilder.add(new TermQuery(new Term((new SharedPartIndexTerm(PartType.RULEFLOW_GROUP)).getTerm())), BooleanClause.Occur.MUST);
        queryBuilder.add(new TermQuery(new Term("nonexistent")), BooleanClause.Occur.MUST);
        searchFor(index, queryBuilder.build(), 0);
    }
    // This note replaces an earlier note, if it doesn't make sense, delete or ignore it.
    // Both pieces of info (that it's a ruleflow group, and that the ruleflow group is called "myruleflowgroup")
    // are present in the same field ("shared:ruleflowgroup" => "myruleflowgroup"), so this only returns
    // documents that match that field (as opposed to the structure we had before).
    {
        final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
        ValueIndexTerm termVals = new ValueSharedPartIndexTerm("myruleflowgroup", PartType.RULEFLOW_GROUP);
        queryBuilder.add(new TermQuery(new Term(termVals.getTerm(), termVals.getValue())), BooleanClause.Occur.MUST);
        searchFor(index, queryBuilder.build(), 1);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) SharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.SharedPartIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) Term(org.apache.lucene.index.Term) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) SharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.SharedPartIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Aggregations

ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)23 HashSet (java.util.HashSet)13 Test (org.junit.Test)12 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)10 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)8 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)8 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)7 Path (org.uberfire.java.nio.file.Path)6 ArrayList (java.util.ArrayList)5 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)5 ValueSharedPartIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm)5 PageResponse (org.uberfire.paging.PageResponse)5 Map (java.util.Map)4 Term (org.apache.lucene.index.Term)4 List (java.util.List)3 Set (java.util.Set)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)3 Query (org.apache.lucene.search.Query)3 TermQuery (org.apache.lucene.search.TermQuery)3 Path (org.uberfire.backend.vfs.Path)3