Search in sources :

Example 6 with KObject

use of org.uberfire.ext.metadata.model.KObject in project kie-wb-common by kiegroup.

the class FindResourcePartsQueryValidIndexTermsTest method testIndexJavaFilesAndFindResourcePartsQuery.

@Test
public void testIndexJavaFilesAndFindResourcePartsQuery() throws Exception {
    // setup
    ioService();
    // Add test files
    String pojo1FileName = "Pojo1.java";
    Path path = basePath.resolve(pojo1FileName);
    String javaSourceText = loadText("../" + pojo1FileName);
    ioService().write(path, javaSourceText);
    // 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 Query query = new SingleTermQueryBuilder(new ValueResourceIndexTerm("*", ResourceType.JAVA, TermSearchType.WILDCARD)).build();
        List<KObject> hits = getConfig().getIndexProvider().findByQuery(index, query, 10);
        assertEquals(1, hits.size());
        List<Pair<String, String>> expectedValues = initExpectedValues();
        KObject doc = null;
        for (KObject kObject : hits) {
            doc = kObject;
            for (KProperty<?> property : doc.getProperties()) {
                String fieldVal = property.getValue().toString();
                if (fieldVal.startsWith("git://")) {
                    if (fieldVal.contains(pojo1FileName)) {
                        break;
                    }
                } else {
                    continue;
                }
            }
        }
        assertContains(expectedValues, doc);
    }
    {
        HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
        queryTerms.add(new ValuePartIndexTerm("o_BigDecimal", PartType.FIELD));
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartsQuery.NAME, queryTerms, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull("No documents found!", response);
            assertEquals(1, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Could not execute query: " + e.getMessage());
        }
    }
    ;
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) Query(org.apache.lucene.search.Query) FindResourcePartsQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindResourcePartsQuery) NamedQuery(org.kie.workbench.common.services.refactoring.backend.server.query.NamedQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) KObject(org.uberfire.ext.metadata.model.KObject) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) KProperty(org.uberfire.ext.metadata.model.KProperty) PageResponse(org.uberfire.paging.PageResponse) ArrayList(java.util.ArrayList) List(java.util.List) ValuePartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 7 with KObject

use of org.uberfire.ext.metadata.model.KObject in project kie-wb-common by kiegroup.

the class AbstractFileIndexer method toKObject.

/**
 * This method should not be overridden by implementation classes!
 * </p>
 * However, we can not make this method final because otherwise Weld/Errai will complain
 * when they try to make proxy beans.
 */
@Override
public KObject toKObject(Path path) {
    KObject index = null;
    try {
        // create a builder with the default information
        DefaultIndexBuilder builder = fillIndexBuilder(path);
        Set<KProperty<?>> indexElements = null;
        if (builder != null) {
            // build index document
            indexElements = builder.build();
        } else {
            indexElements = Collections.emptySet();
        }
        index = KObjectUtil.toKObject(path, IndexTerm.REFACTORING_CLASSIFIER, indexElements);
    } catch (Exception e) {
        // Unexpected parsing or processing error
        logger.error("Unable to index '" + path.toUri().toString() + "'.", e.getMessage(), e);
    }
    return index;
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) KProperty(org.uberfire.ext.metadata.model.KProperty)

Example 8 with KObject

use of org.uberfire.ext.metadata.model.KObject in project kie-wb-common by kiegroup.

the class RefactoringQueryServiceImpl method query.

@Override
public PageResponse<RefactoringPageRow> query(final RefactoringPageRequest request) {
    PortablePreconditions.checkNotNull("request", request);
    final String queryName = PortablePreconditions.checkNotNull("queryName", request.getQueryName());
    final NamedQuery namedQuery = namedQueries.findNamedQuery(queryName);
    // Validate provided terms against those required for the named query
    namedQuery.validateTerms(request.getQueryTerms());
    final Query query = namedQuery.toQuery(request.getQueryTerms());
    final Sort sort = namedQuery.getSortOrder();
    final int pageSize = request.getPageSize();
    final int startIndex = request.getStartRowIndex();
    List<KObject> kObjects = search(query, sort, () -> (startIndex), // start index of docs to get
    (numHits) -> (numHits - startIndex > pageSize ? pageSize : numHits - startIndex), request.distinctResults());
    if (!kObjects.isEmpty()) {
        final ResponseBuilder responseBuilder = namedQuery.getResponseBuilder();
        return responseBuilder.buildResponse(pageSize, startIndex, new ArrayList<>(kObjects));
    } else {
        return emptyResponse;
    }
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) Query(org.apache.lucene.search.Query) FindAllChangeImpactQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindAllChangeImpactQuery) Sort(org.apache.lucene.search.Sort) ResponseBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.response.ResponseBuilder)

Example 9 with KObject

use of org.uberfire.ext.metadata.model.KObject in project kie-wb-common by kiegroup.

the class RefactoringQueryServiceImpl method queryHitCount.

@Override
public int queryHitCount(final RefactoringPageRequest request) {
    PortablePreconditions.checkNotNull("request", request);
    final String queryName = PortablePreconditions.checkNotNull("queryName", request.getQueryName());
    final NamedQuery namedQuery = namedQueries.findNamedQuery(queryName);
    // Validate provided terms against those required for the named query
    namedQuery.validateTerms(request.getQueryTerms());
    final Query query = namedQuery.toQuery(request.getQueryTerms());
    final Sort sort = namedQuery.getSortOrder();
    try {
        List<KObject> found = config.getIndexProvider().findByQuery(Collections.EMPTY_LIST, query, sort, 0);
        if (request.distinctResults()) {
            found = distinct(found);
        }
        return found.size();
    } catch (final Exception ex) {
        throw new RuntimeException("Error during Query!", ex);
    }
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) Query(org.apache.lucene.search.Query) FindAllChangeImpactQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindAllChangeImpactQuery) Sort(org.apache.lucene.search.Sort)

Example 10 with KObject

use of org.uberfire.ext.metadata.model.KObject in project kie-wb-common by kiegroup.

the class DefaultResponseBuilder method buildResponse.

@Override
public List<RefactoringPageRow> buildResponse(final List<KObject> kObjects) {
    final List<RefactoringPageRow> result = new ArrayList<RefactoringPageRow>(kObjects.size());
    for (final KObject kObject : kObjects) {
        final Path path = Paths.convert(ioService.get(URI.create(kObject.getKey())));
        final RefactoringPathPageRow row = new RefactoringPathPageRow();
        row.setValue(path);
        result.add(row);
    }
    return result;
}
Also used : Path(org.uberfire.backend.vfs.Path) KObject(org.uberfire.ext.metadata.model.KObject) ArrayList(java.util.ArrayList) RefactoringPathPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPathPageRow) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)

Aggregations

KObject (org.uberfire.ext.metadata.model.KObject)14 ArrayList (java.util.ArrayList)5 Query (org.apache.lucene.search.Query)4 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)4 KProperty (org.uberfire.ext.metadata.model.KProperty)4 HashSet (java.util.HashSet)3 Sort (org.apache.lucene.search.Sort)3 FindAllChangeImpactQuery (org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindAllChangeImpactQuery)3 List (java.util.List)2 Test (org.junit.Test)2 DefaultIndexBuilder (org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder)2 ResponseBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.response.ResponseBuilder)2 RefactoringPathPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPathPageRow)2 RefactoringRuleNamePageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow)2 RuleName (org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName)2 Path (org.uberfire.backend.vfs.Path)2 Path (org.uberfire.java.nio.file.Path)2 PageResponse (org.uberfire.paging.PageResponse)2 Optional (java.util.Optional)1 Set (java.util.Set)1