Search in sources :

Example 1 with KObject

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

the class RefactoringQueryServiceImpl method query.

@Override
public List<RefactoringPageRow> query(final String queryName, final Set<ValueIndexTerm> queryTerms) {
    PortablePreconditions.checkNotNull("queryName", queryName);
    PortablePreconditions.checkNotNull("queryTerms", queryTerms);
    final NamedQuery namedQuery = namedQueries.findNamedQuery(queryName);
    // Validate provided terms against those required for the named query
    namedQuery.validateTerms(queryTerms);
    final Query query = namedQuery.toQuery(queryTerms);
    final Sort sort = namedQuery.getSortOrder();
    final List<KObject> kObjects = search(query, sort, () -> (0), // start index of docs to get
    (numHits) -> (numHits), false);
    if (!kObjects.isEmpty()) {
        final ResponseBuilder responseBuilder = namedQuery.getResponseBuilder();
        return responseBuilder.buildResponse(kObjects);
    } else {
        return Collections.emptyList();
    }
}
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 2 with KObject

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

the class FileDetailsResponseBuilder 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)

Example 3 with KObject

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

the class RuleNameResponseBuilder method buildResponse.

@Override
public List<RefactoringPageRow> buildResponse(final List<KObject> kObjects) {
    // Both "child" rule and "parent" rule (when one extends another) are stored
    // in the index. We therefore need to build a set of unique Rule Names
    final List<RefactoringPageRow> result = new ArrayList<RefactoringPageRow>(kObjects.size());
    final Set<RuleName> uniqueRuleNames = new HashSet<>();
    for (final KObject kObject : kObjects) {
        final Set<RuleName> ruleNames = getRuleNamesFromKObject(kObject);
        uniqueRuleNames.addAll(ruleNames);
    }
    for (RuleName ruleName : uniqueRuleNames) {
        final RefactoringRuleNamePageRow row = new RefactoringRuleNamePageRow();
        row.setValue(ruleName);
        result.add(row);
    }
    return result;
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) ArrayList(java.util.ArrayList) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) RuleName(org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName) HashSet(java.util.HashSet) RefactoringRuleNamePageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow)

Example 4 with KObject

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

the class LibraryIndexer method toKObject.

@Override
public KObject toKObject(final 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, LIBRARY_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) DefaultIndexBuilder(org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder)

Example 5 with KObject

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

the class FindAllLibraryAssetsQueryTest method cleanupLibraryResults.

@Test
public void cleanupLibraryResults() {
    // This is a temporary way to cleanup index results
    // for library assets list and count.
    // In cluster environment library index each file more than once.
    // The index should be revised on next release (7.6).
    KObject k1 = new KObjectImpl("", "", "clusterId1", "", "key1", new ArrayList<>(), false);
    KObject k2 = new KObjectImpl("", "", "clusterId2", "", "key2", new ArrayList<>(), false);
    List<KObject> kObjects = service.distinct(Arrays.asList(k1, k1, k2));
    assertEquals(2, kObjects.size());
    assertEquals(k1, kObjects.get(0));
    assertEquals(k2, kObjects.get(1));
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) KObjectImpl(org.uberfire.ext.metadata.model.impl.KObjectImpl) Test(org.junit.Test)

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