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);
}
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;
}
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;
}
Aggregations