Search in sources :

Example 1 with PropertyType

use of org.kie.workbench.common.stunner.core.definition.property.PropertyType in project kie-wb-common by kiegroup.

the class BackendBindablePropertyAdapter method getType.

@Override
public PropertyType getType(final T property) {
    Class<?> type = property.getClass();
    PropertyType pType = null;
    try {
        pType = getFieldValue(property, propertyTypeFieldNames.get(type));
        if (null == pType) {
            pType = propertyTypes.get(type);
        }
    } catch (IllegalAccessException e) {
        LOG.error("Error obtaining type for Property with id " + getId(property));
    }
    return pType;
}
Also used : PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType)

Example 2 with PropertyType

use of org.kie.workbench.common.stunner.core.definition.property.PropertyType in project kie-wb-common by kiegroup.

the class BackendPropertyAdapter method getType.

@Override
public PropertyType getType(final T property) {
    PropertyType pType = null;
    try {
        pType = getAnnotatedFieldValue(property, Type.class);
        // If no type found from annotations, try to figure it out given the class for the value instance.
        if (null == pType) {
            final Collection<Field> valueFields = ReflectionAdapterUtils.getFieldAnnotations(property.getClass(), Value.class);
            if (null != valueFields && !valueFields.isEmpty()) {
                final Class<?> valueType = valueFields.iterator().next().getType();
                final Class<? extends PropertyType> defaultPropertyType = DefinitionUtils.getDefaultPropertyType(valueType);
                if (null != defaultPropertyType) {
                    pType = defaultPropertyType.newInstance();
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error obtaining annotated category for Property with id " + getId(property));
    }
    if (null == pType) {
        LOG.error("No property type specified for Property with id " + getId(property));
    }
    return pType;
}
Also used : Field(java.lang.reflect.Field) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) Type(org.kie.workbench.common.stunner.core.definition.annotation.property.Type) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType)

Example 3 with PropertyType

use of org.kie.workbench.common.stunner.core.definition.property.PropertyType in project kie-wb-common by kiegroup.

the class BackendPropertyAdapterTest method testGetPropertyTypeFromAnnotation.

@Test
public void testGetPropertyTypeFromAnnotation() {
    final FooProperty2TestBean p = new FooProperty2TestBean(FOO1_VALUE);
    final PropertyType type = tested.getType(p);
    assertEquals(BooleanType.class, type.getClass());
}
Also used : FooProperty2TestBean(org.kie.workbench.common.stunner.core.backend.definition.adapter.FooProperty2TestBean) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) Test(org.junit.Test)

Example 4 with PropertyType

use of org.kie.workbench.common.stunner.core.definition.property.PropertyType in project kie-wb-common by kiegroup.

the class AbstractObjectBuilder method setProperties.

@SuppressWarnings("unchecked")
protected void setProperties(final BuilderContext context, final BPMNDefinition definition) {
    assert definition != null;
    Bpmn2OryxPropertyManager propertyManager = context.getOryxManager().getPropertyManager();
    OryxIdMappings idMappings = context.getOryxManager().getMappingsManager();
    Set<?> defProperties = context.getDefinitionManager().adapters().forDefinition().getProperties(definition);
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        final String oryxId = entry.getKey();
        if (!idMappings.isSkipProperty(definition.getClass(), oryxId)) {
            final String pValue = entry.getValue();
            final String pId = idMappings.getPropertyId(definition, oryxId);
            boolean found = false;
            if (null != pId) {
                final Object property = GraphUtils.getProperty(context.getDefinitionManager(), defProperties, pId);
                if (null != property) {
                    try {
                        PropertyType propertyType = context.getDefinitionManager().adapters().forProperty().getType(property);
                        Object value = propertyManager.parse(property, propertyType, pValue);
                        context.getDefinitionManager().adapters().forProperty().setValue(property, value);
                        found = true;
                    } catch (Exception e) {
                        LOG.error("Cannot parse value [" + pValue + "] for property [" + pId + "]", e);
                    }
                }
            }
            if (!found && null != pId) {
            // LOG.warn( "Property [" + pId + "] not found for definition [" + definition.getClass().getName() + "]" );
            }
        }
    }
}
Also used : Bpmn2OryxPropertyManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertyManager) OryxIdMappings(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.OryxIdMappings) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with PropertyType

use of org.kie.workbench.common.stunner.core.definition.property.PropertyType in project kie-wb-common by kiegroup.

the class NodePropertyMorphBuilderImpl method getDefinitionToBuild.

@Override
@SuppressWarnings("unchecked")
protected String getDefinitionToBuild(final BuilderContext context) {
    final String defaultDefinitionId = propertyMorphDefinition.getDefault();
    final String definitionId = BindableAdapterUtils.getDefinitionId(definitionClass);
    Collection<MorphProperty> mps = new LinkedList<MorphProperty>();
    // TODO: Iterate over all morph properties.
    final Iterable<MorphProperty> mps1 = propertyMorphDefinition.getMorphProperties(definitionId);
    if (mps1 != null && mps1.iterator().hasNext()) {
        mps.add(mps1.iterator().next());
    }
    DefinitionAdapter<Object> definitionAdapter = context.getDefinitionManager().adapters().registry().getDefinitionAdapter(definitionClass);
    String baseId = ((HasInheritance) definitionAdapter).getBaseType(definitionClass);
    if (null != baseId) {
        final Iterable<MorphProperty> mps2 = propertyMorphDefinition.getMorphProperties(baseId);
        if (mps2 != null && mps2.iterator().hasNext()) {
            mps.add(mps2.iterator().next());
        }
    }
    final MorphProperty morphProperty = mps.iterator().next();
    final Object defaultDefinition = context.getFactoryManager().newDefinition(defaultDefinitionId);
    final DefinitionUtils definitionUtils = new DefinitionUtils(context.getDefinitionManager(), context.getFactoryManager());
    final Object mp = definitionUtils.getProperty(defaultDefinition, morphProperty.getProperty());
    final PropertyType propertyType = context.getDefinitionManager().adapters().forProperty().getType(mp);
    final String oryxId = context.getOryxManager().getMappingsManager().getOryxPropertyId(mp.getClass());
    final String pRawValue = properties.get(oryxId);
    final Object pValue = context.getOryxManager().getPropertyManager().parse(mp, propertyType, pRawValue);
    return morphProperty.getMorphTarget(pValue);
}
Also used : HasInheritance(org.kie.workbench.common.stunner.core.definition.adapter.binding.HasInheritance) MorphProperty(org.kie.workbench.common.stunner.core.definition.morph.MorphProperty) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) LinkedList(java.util.LinkedList)

Aggregations

PropertyType (org.kie.workbench.common.stunner.core.definition.property.PropertyType)10 Test (org.junit.Test)4 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 OryxIdMappings (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.OryxIdMappings)1 Bpmn2OryxPropertyManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertyManager)1 ObjectParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.ObjectParser)1 StringFieldParser (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.parser.common.StringFieldParser)1 MetaDataType (org.kie.workbench.common.stunner.bpmn.definition.property.type.MetaDataType)1 FooProperty2TestBean (org.kie.workbench.common.stunner.core.backend.definition.adapter.FooProperty2TestBean)1 PropertyAdapter (org.kie.workbench.common.stunner.core.definition.adapter.PropertyAdapter)1 HasInheritance (org.kie.workbench.common.stunner.core.definition.adapter.binding.HasInheritance)1 Type (org.kie.workbench.common.stunner.core.definition.annotation.property.Type)1 MorphProperty (org.kie.workbench.common.stunner.core.definition.morph.MorphProperty)1 BooleanType (org.kie.workbench.common.stunner.core.definition.property.type.BooleanType)1 StringType (org.kie.workbench.common.stunner.core.definition.property.type.StringType)1 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)1 DefinitionUtils (org.kie.workbench.common.stunner.core.util.DefinitionUtils)1