use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl 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.AnnotationImpl in project kie-wb-common by kiegroup.
the class JPADomainHandler method setDefaultValues.
@Override
public void setDefaultValues(DataObject dataObject, Map<String, Object> portableParams) {
if (portableParams != null) {
Object currentValue = portableParams.get("persistable");
boolean isPersistable = Boolean.valueOf(currentValue != null ? currentValue.toString() : null);
currentValue = portableParams.get("tableName");
String tableName = currentValue != null ? currentValue.toString() : null;
if (isPersistable) {
// add default parameters for a persistable data object
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
// mark the class as Entity
dataObject.addAnnotation(new AnnotationImpl(modelDriver.getConfiguredAnnotation(Entity.class.getName())));
if (tableName != null && !"".equals(tableName.trim())) {
Annotation tableAnnotation = new AnnotationImpl(modelDriver.getConfiguredAnnotation(Table.class.getName()));
tableAnnotation.setValue("name", tableName.trim());
dataObject.addAnnotation(tableAnnotation);
}
// add the by default id field
ObjectProperty id = dataObject.addProperty("id", Long.class.getName());
id.addAnnotation(new AnnotationImpl(modelDriver.getConfiguredAnnotation(Id.class.getName())));
// set the by default generated value annotation.
String generatorName = createDefaultGeneratorName(dataObject.getName());
Annotation generatedValue = new AnnotationImpl(modelDriver.getConfiguredAnnotation(GeneratedValue.class.getName()));
generatedValue.setValue("generator", generatorName);
generatedValue.setValue("strategy", GenerationType.AUTO.name());
id.addAnnotation(generatedValue);
// set by default sequence generator
Annotation sequenceGenerator = new AnnotationImpl(modelDriver.getConfiguredAnnotation(SequenceGenerator.class.getName()));
String sequenceName = createDefaultSequenceName(dataObject.getName());
sequenceGenerator.setValue("name", generatorName);
sequenceGenerator.setValue("sequenceName", sequenceName);
id.addAnnotation(sequenceGenerator);
boolean isAuditable = portableParams.containsKey("audited") ? Boolean.valueOf(portableParams.get("audited").toString()) : false;
if (isAuditable) {
Annotation audited = new AnnotationImpl(modelDriver.getConfiguredAnnotation(Audited.class.getName()));
audited.setValue("targetAuditMode", RelationTargetAuditMode.NOT_AUDITED.name());
dataObject.addAnnotation(audited);
}
}
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class DataModelTestUtil method createAnnotation.
public Annotation createAnnotation(Map<String, AnnotationDefinition> systemAnnotations, String className, String memberName, Object value) {
AnnotationDefinition annotationDefinition = systemAnnotations.get(className);
Annotation annotation = new AnnotationImpl(annotationDefinition);
if (memberName != null) {
annotation.setValue(memberName, value);
}
return annotation;
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class FieldAddOrRemoveAnnotationCommand method execute.
@Override
public void execute() {
if (doAdd && field.getAnnotation(annotationClassName) == null) {
field.addAnnotation(new AnnotationImpl(context.getAnnotationDefinition(annotationClassName)));
notifyFieldChange(ChangeType.FIELD_ANNOTATION_ADD_CHANGE, context, source, dataObject, field, annotationClassName, null, null, null);
} else if (!doAdd && field.getAnnotation(annotationClassName) != null) {
field.removeAnnotation(annotationClassName);
notifyFieldChange(ChangeType.FIELD_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, field, annotationClassName, null, null, null);
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class DefaultJavaModelAnnotationDriver method buildAnnotation.
@Override
public Annotation buildAnnotation(AnnotationDefinition annotationDefinition, Object annotationToken) throws ModelDriverException {
AnnotationDescr javaAnnotationToken = (AnnotationDescr) annotationToken;
AnnotationImpl annotation = new AnnotationImpl(annotationDefinition);
if (annotationDefinition.isMarker()) {
return annotation;
} else {
// try to read annotation parameters
if (javaAnnotationToken.hasElementValue()) {
for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) {
if ("value".equals(annotationMember.getName())) {
annotation.setValue(annotationMember.getName(), parseParamValue(annotationDefinition, annotationMember.getName(), javaAnnotationToken.getElementValue().getValue()));
}
}
} else if (javaAnnotationToken.hasElementValuePairs()) {
ElementValuePairListDescr valuePairListDescr = javaAnnotationToken.getElementValuePairs();
if (valuePairListDescr != null && valuePairListDescr.getValuePairs() != null) {
Map<String, ElementValueDescr> valuePairValues = new HashMap<String, ElementValueDescr>();
for (ElementValuePairDescr valuePair : valuePairListDescr.getValuePairs()) {
valuePairValues.put(valuePair.getIdentifier().getIdentifier(), valuePair.getValue());
}
for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) {
ElementValueDescr value = valuePairValues.get(annotationMember.getName());
if (value != null) {
annotation.setValue(annotationMember.getName(), parseParamValue(annotationDefinition, annotationMember.getName(), value.getValue()));
}
}
}
}
}
return annotation;
}
Aggregations