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;
}
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());
}
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);
}
}
}
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;
}
Aggregations