Search in sources :

Example 1 with RuleName

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName 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 2 with RuleName

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName in project kie-wb-common by kiegroup.

the class BaseIndexingTest method assertResponseContains.

protected void assertResponseContains(final List<RefactoringPageRow> rows, final String simpleRuleName, final String packageName) {
    for (RefactoringPageRow row : rows) {
        final RuleName r = (RuleName) row.getValue();
        final String rowRuleName = r.getSimpleRuleName();
        final String rowPackageName = r.getPackageName();
        if (rowRuleName.equals(simpleRuleName) && rowPackageName.equals(packageName)) {
            return;
        }
    }
    fail("Response does not contain expected Rule Name '" + simpleRuleName + "' in package '" + packageName + "'.");
}
Also used : RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) RuleName(org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName)

Example 3 with RuleName

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName 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)

Aggregations

RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)3 RuleName (org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow.RuleName)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 RefactoringRuleNamePageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow)2 KObject (org.uberfire.ext.metadata.model.KObject)2 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 PackageNameIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.PackageNameIndexTerm)1 ResourceType (org.kie.workbench.common.services.refactoring.service.ResourceType)1 KProperty (org.uberfire.ext.metadata.model.KProperty)1 PageResponse (org.uberfire.paging.PageResponse)1