use of org.uberfire.ext.metadata.model.KProperty in project kie-wb-common by kiegroup.
the class TestPropertiesFileIndexer method toKObject.
@Override
public KObject toKObject(final Path path) {
InputStream is = null;
final Properties properties = new Properties();
try {
is = ioService.newInputStream(path);
properties.load(is);
is.close();
} catch (IOException e) {
// Swallow
}
final Set<KProperty<?>> indexElements = new HashSet<>();
for (String propertyName : properties.stringPropertyNames()) {
indexElements.add(new KPropertyImpl<>(propertyName, properties.getProperty(propertyName)));
}
return KObjectUtil.toKObject(path, IndexTerm.REFACTORING_CLASSIFIER, indexElements);
}
use of org.uberfire.ext.metadata.model.KProperty in project kie-wb-common by kiegroup.
the class AttributeIndexBuilderTest method testValidValue.
@Test()
public void testValidValue() {
new AttributeIndexBuilder(builder).visit(new AttributeDescr("activation-group", "value"));
verify(builder).addGenerator(captor.capture());
final SharedPart value = captor.getValue();
List<KProperty<?>> kProperties = value.toIndexElements();
assertEquals(1, kProperties.size());
assertEquals("shared:activationgroup", kProperties.get(0).getName());
assertEquals("value", kProperties.get(0).getValue());
}
use of org.uberfire.ext.metadata.model.KProperty 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.KProperty in project kie-wb-common by kiegroup.
the class KObjectUtil method toKObject.
public static KObject toKObject(final Path path, final String classifier, final Set<KProperty<?>> indexElements) {
return new KObject() {
@Override
public String getId() {
return sha1(getType().getName() + "|" + classifier + "|" + getKey());
}
@Override
public MetaType getType() {
return META_TYPE;
}
@Override
public String getClusterId() {
final String fsId = ((FileSystemId) path.getFileSystem()).id();
final String segmentId = ((SegmentedPath) path).getSegmentId();
return fsId + CLUSTER_ID_SEGMENT_SEPARATOR + segmentId;
}
@Override
public String getSegmentId() {
return ((SegmentedPath) path).getSegmentId();
}
@Override
public String getKey() {
return path.toUri().toString();
}
@Override
public Iterable<KProperty<?>> getProperties() {
return indexElements;
}
@Override
public boolean fullText() {
return false;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("KObject{" + ", key='" + getKey() + '\'' + ", id='" + getId() + '\'' + ", type=" + getType() + ", clusterId='" + getClusterId() + '\'' + ", segmentId='" + getSegmentId() + '\'');
for (KProperty<?> xproperty : getProperties()) {
sb.append(", " + xproperty.getName() + "='" + xproperty.getValue() + '\'');
}
sb.append('}');
return sb.toString();
}
};
}
Aggregations