Search in sources :

Example 21 with AnnotationImpl

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;
}
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 22 with AnnotationImpl

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);
            }
        }
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Entity(javax.persistence.Entity) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Id(javax.persistence.Id) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 23 with AnnotationImpl

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;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 24 with AnnotationImpl

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);
    }
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)

Example 25 with AnnotationImpl

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;
}
Also used : ElementValuePairDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr) ElementValuePairListDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairListDescr) AnnotationDescr(org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) HashMap(java.util.HashMap) Map(java.util.Map) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) ElementValueDescr(org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)

Aggregations

AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)34 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)24 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)11 Test (org.junit.Test)10 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)10 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)7 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)5 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)4 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)4 Entity (javax.persistence.Entity)2 Before (org.junit.Before)2 AnnotationDefinitionImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationDefinitionImpl)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Id (javax.persistence.Id)1 AnnotationMetaModel (org.drools.workbench.screens.factmodel.model.AnnotationMetaModel)1 Module (org.guvnor.common.services.project.model.Module)1 ValuePair (org.jboss.forge.roaster.model.ValuePair)1 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)1