Search in sources :

Example 1 with AnnotationDefinitionImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl in project kie-wb-common by kiegroup.

the class AbstractDataObjectFinderTest method init.

@Before
public void init() {
    dataObject = dataModel.addDataObject(PACKAGE, DATA_OBJECT_NAME);
    addProperty(dataObject, DataObjectFormModelHandler.SERIAL_VERSION_UID, Long.class.getName(), false, false);
    ObjectProperty property = addProperty(dataObject, PERSISTENCE_ID_PROPERTY, Long.class.getName(), false, false);
    property.addAnnotation(new AnnotationImpl(new AnnotationDefinitionImpl(DataObjectFormModelHandler.PERSISTENCE_ANNOTATION)));
    addProperty(dataObject, NAME_PROPERTY, String.class.getName(), false, true);
    addProperty(dataObject, LAST_NAME_PROPERTY, String.class.getName(), false, true);
    addProperty(dataObject, AGE_PROPERTY, Integer.class.getName(), false, true);
    addProperty(dataObject, BIRTHDATE_PROPERTY, Date.class.getName(), false, true);
    addProperty(dataObject, MARRIED_PROPERTY, Boolean.class.getName(), false, true);
    when(dataModelerService.loadModel(any())).thenReturn(dataModel);
    service = new DataObjectFinderServiceImpl(moduleService, dataModelerService);
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) AnnotationDefinitionImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Date(java.util.Date) Before(org.junit.Before)

Example 2 with AnnotationDefinitionImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl in project kie-wb-common by kiegroup.

the class AbstractDataObjectTest method addProperty.

protected ObjectProperty addProperty(DataObject dataObject, String propertyName, String className, boolean multiple, boolean withLabels) {
    ObjectProperty property = dataObject.addProperty(propertyName, className, multiple);
    if (withLabels) {
        Annotation labelAnnotation = new AnnotationImpl(new AnnotationDefinitionImpl(MainDomainAnnotations.LABEL_ANNOTATION));
        labelAnnotation.setValue(MainDomainAnnotations.VALUE_PARAM, LABEL_SUFFIX + propertyName);
        property.addAnnotation(labelAnnotation);
    }
    return property;
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) AnnotationDefinitionImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 3 with AnnotationDefinitionImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl in project kie-wb-common by kiegroup.

the class DriverUtils method buildAnnotationDefinition.

public static AnnotationDefinition buildAnnotationDefinition(Class cls) {
    if (!cls.isAnnotation())
        return null;
    AnnotationDefinitionImpl annotationDefinition = new AnnotationDefinitionImpl(NamingUtils.normalizeClassName(cls.getName()));
    // set retention and target.
    DriverUtils.copyAnnotationRetention(cls, annotationDefinition);
    DriverUtils.copyAnnotationTarget(cls, annotationDefinition);
    Method[] methods = cls.getMethods();
    Method method;
    AnnotationValuePairDefinitionImpl valuePairDefinition;
    Class returnType;
    boolean isArray = false;
    for (int i = 0; methods != null && i < methods.length; i++) {
        method = methods[i];
        if (DriverUtils.isAnnotationMember(cls, method)) {
            returnType = method.getReturnType();
            if ((isArray = returnType.isArray()))
                returnType = returnType.getComponentType();
            valuePairDefinition = new AnnotationValuePairDefinitionImpl(method.getName(), NamingUtils.normalizeClassName(returnType.getName()), DriverUtils.buildValuePairType(returnType), isArray, // TODO, review this default value assignment, when we have annotations the default value should be an AnnotationInstance
            method.getDefaultValue() != null ? method.getDefaultValue().toString() : null);
            if (valuePairDefinition.isAnnotation()) {
                valuePairDefinition.setAnnotationDefinition(buildAnnotationDefinition(returnType));
            }
            if (valuePairDefinition.isEnum()) {
                Object[] enumConstants = returnType.getEnumConstants();
                if (enumConstants != null) {
                    String[] strEnumConstants = new String[enumConstants.length];
                    for (int j = 0; j < enumConstants.length; j++) {
                        strEnumConstants[j] = enumConstants[j].toString();
                    }
                    valuePairDefinition.setEnumValues(strEnumConstants);
                }
            }
            annotationDefinition.addValuePair(valuePairDefinition);
        }
    }
    return annotationDefinition;
}
Also used : AnnotationDefinitionImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl) Method(java.lang.reflect.Method) AnnotationValuePairDefinitionImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationValuePairDefinitionImpl)

Aggregations

AnnotationDefinitionImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl)3 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)2 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)2 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 Before (org.junit.Before)1 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)1 AnnotationValuePairDefinitionImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationValuePairDefinitionImpl)1