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;
}
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 + "'.");
}
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;
}
Aggregations