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