Search in sources :

Example 11 with KProperty

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);
}
Also used : KProperty(org.uberfire.ext.metadata.model.KProperty) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) HashSet(java.util.HashSet)

Example 12 with KProperty

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());
}
Also used : KProperty(org.uberfire.ext.metadata.model.KProperty) SharedPart(org.kie.workbench.common.services.refactoring.SharedPart) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr) Test(org.junit.Test)

Example 13 with KProperty

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;
}
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 14 with KProperty

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();
        }
    };
}
Also used : KObject(org.uberfire.ext.metadata.model.KObject) KProperty(org.uberfire.ext.metadata.model.KProperty) FileSystemId(org.uberfire.java.nio.base.FileSystemId) SegmentedPath(org.uberfire.java.nio.base.SegmentedPath) Base64.encodeBase64String(org.apache.commons.codec.binary.Base64.encodeBase64String)

Aggregations

KProperty (org.uberfire.ext.metadata.model.KProperty)14 ArrayList (java.util.ArrayList)7 KObject (org.uberfire.ext.metadata.model.KObject)7 Test (org.junit.Test)6 HashSet (java.util.HashSet)4 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)3 Path (org.uberfire.java.nio.file.Path)3 List (java.util.List)2 ValuePartIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm)2 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)2 PageResponse (org.uberfire.paging.PageResponse)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1