Search in sources :

Example 11 with KObject

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

the class RuleNameResponseBuilder method getRuleNamesFromKObject.

private Set<RuleName> getRuleNamesFromKObject(final KObject kObject) {
    // Some resources (e.g. Decision Tables etc) contain multiple rule names so add them all
    final Set<RuleName> ruleNames = new HashSet<>();
    if (kObject == null) {
        return ruleNames;
    }
    // Extract KProperties
    final Set<KProperty<?>> kProperties = StreamSupport.stream(kObject.getProperties().spliterator(), false).collect(Collectors.toSet());
    // Get Package Name (all Rules for a single Index entry *should* be in a single Package)
    final Optional<KProperty<?>> packageName = kProperties.stream().filter((kp) -> kp.getName().equals(PackageNameIndexTerm.TERM)).findFirst();
    // Assign Rules to packages
    packageName.flatMap((pkg) -> Optional.of(pkg.getValue().toString())).ifPresent((pkgName) -> kProperties.stream().filter((kp) -> kp.getName().equals(ResourceType.RULE.toString())).forEach((r) -> ruleNames.add(new RuleName(r.getValue().toString().replace(pkgName, "").replaceFirst("\\.", ""), pkgName))));
    return ruleNames;
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) Set(java.util.Set) RuleName(org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) RefactoringRuleNamePageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow) KProperty(org.uberfire.ext.metadata.model.KProperty) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) ResourceType(org.kie.workbench.common.services.refactoring.service.ResourceType) PackageNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.PackageNameIndexTerm) Optional(java.util.Optional) StreamSupport(java.util.stream.StreamSupport) PageResponse(org.uberfire.paging.PageResponse) KProperty(org.uberfire.ext.metadata.model.KProperty) RuleName(org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName) HashSet(java.util.HashSet)

Example 12 with KObject

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

the class IndexingTest method assertContains.

protected void assertContains(final Iterable<KObject> results, final Path path) {
    for (KObject kObject : results) {
        final String key = kObject.getKey();
        final String fileName = path.getFileName().toString();
        if (key.endsWith(fileName)) {
            return;
        }
    }
    fail("Results do not contain expected Path '" + path.toUri().toString());
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject)

Example 13 with KObject

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

the class IndexingTest method searchFor.

public void searchFor(List<String> indices, Query query, int expectedNumHits, Path... paths) {
    int hits = 10 > expectedNumHits ? 10 : expectedNumHits;
    List<KObject> found = config.getIndexProvider().findByQuery(indices, query, hits);
    if (paths != null && paths.length > 0) {
        assertEquals("Number of docs fulfilling the given query criteria", expectedNumHits, found.size());
        for (Path path : paths) {
            assertContains(found, path);
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) KObject(org.uberfire.ext.metadata.model.KObject)

Example 14 with KObject

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

the class TestPackageNameDrlFileIndexer method toKObject.

@Override
public KObject toKObject(final Path path) {
    KObject index = null;
    try {
        final String drl = ioService.readAllString(path);
        final DrlParser drlParser = new DrlParser();
        final PackageDescr packageDescr = drlParser.parse(true, drl);
        if (drlParser.hasErrors()) {
            final List<DroolsError> errors = drlParser.getErrors();
            logger.warn(ErrorMessageUtilities.makeErrorMessage(path, errors.toArray(new DroolsError[errors.size()])));
            return index;
        }
        if (packageDescr == null) {
            logger.warn(ErrorMessageUtilities.makeErrorMessage(path));
            return index;
        }
        final ModuleDataModelOracle dmo = getModuleDataModelOracle(path);
        final Module module = moduleService.resolveModule(Paths.convert(path));
        // This is the reason we're overriding toKObject and not using fillDrlIndextBuilder(..)
        final Package pkg = mock(Package.class);
        when(pkg.getPackageName()).thenReturn(packageDescr.getName());
        final DefaultIndexBuilder builder = new DefaultIndexBuilder(Paths.convert(path).getFileName(), module, pkg);
        final PackageDescrIndexVisitor visitor = new PackageDescrIndexVisitor(dmo, builder, packageDescr);
        visitor.visit();
        addReferencedResourcesToIndexBuilder(builder, visitor);
        index = KObjectUtil.toKObject(path, IndexTerm.REFACTORING_CLASSIFIER, builder.build());
    } catch (Exception e) {
        logger.error("Unable to index '" + path.toUri().toString() + "'.", e);
    }
    return index;
}
Also used : DroolsError(org.drools.compiler.compiler.DroolsError) KObject(org.uberfire.ext.metadata.model.KObject) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) DrlParser(org.drools.compiler.compiler.DrlParser) Package(org.guvnor.common.services.project.model.Package) DefaultIndexBuilder(org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Module(org.guvnor.common.services.project.model.Module) PackageDescrIndexVisitor(org.kie.workbench.common.services.refactoring.backend.server.indexing.PackageDescrIndexVisitor)

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