Search in sources :

Example 11 with AnnotationImpl

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

the class FieldAnnotationValueChangeCommand method execute.

@Override
public void execute() {
    Object oldValue = null;
    Annotation annotation = field.getAnnotation(annotationClassName);
    if (annotation != null) {
        oldValue = annotation.getValue(valuePair);
        if (newValue != null && !newValue.equals(oldValue)) {
            // notify annotation value change
            annotation.setValue(valuePair, newValue);
            notifyFieldChange(ChangeType.FIELD_ANNOTATION_VALUE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
        } else if (newValue == null) {
            if (removeAnnotationIfValueIsNull) {
                field.removeAnnotation(annotationClassName);
                // notify annotation removed
                notifyFieldChange(ChangeType.FIELD_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
            } else {
                // annotations do not support nulls for the value paris, so just remove the value pair.
                annotation.removeValue(valuePair);
                // notify annotation value change
                notifyFieldChange(ChangeType.FIELD_ANNOTATION_VALUE_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
            }
        }
    } else if (newValue != null) {
        annotation = new AnnotationImpl(context.getAnnotationDefinitions().get(annotationClassName));
        annotation.setValue(valuePair, newValue);
        field.addAnnotation(annotation);
        // notify annotation added
        notifyFieldChange(ChangeType.FIELD_ANNOTATION_ADD_CHANGE, context, source, dataObject, field, annotationClassName, valuePair, oldValue, newValue);
    }
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 12 with AnnotationImpl

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

the class AddPropertyCommand method execute.

@Override
public void execute() {
    // extra check
    boolean multiple = isMultiple && !getContext().getHelper().isPrimitiveType(propertyType);
    property = new ObjectPropertyImpl(propertyName, propertyType, multiple);
    if (propertyLabel != null && !"".equals(propertyLabel)) {
        Annotation annotation = new AnnotationImpl(getContext().getAnnotationDefinitions().get(MainDomainAnnotations.LABEL_ANNOTATION));
        annotation.setValue(MainDomainAnnotations.VALUE_PARAM, propertyLabel);
        property.addAnnotation(annotation);
    }
    dataObject.addProperty(property);
    if (!property.isBaseType()) {
        getContext().getHelper().dataObjectReferenced(property.getClassName(), dataObject.getClassName());
    }
    notifyChange(new DataObjectFieldCreatedEvent(getContext().getContextId(), getSource(), getDataObject(), property));
}
Also used : ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObjectFieldCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectFieldCreatedEvent) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 13 with AnnotationImpl

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

the class DataObjectAddAnnotationCommand method execute.

@Override
public void execute() {
    if (annotation == null) {
        annotation = new AnnotationImpl(context.getAnnotationDefinition(annotationClassName));
        if (valuePairs != null) {
            for (ValuePair valuePair : valuePairs) {
                annotation.setValue(valuePair.getName(), valuePair.getValue());
            }
        }
    }
    dataObject.addAnnotation(annotation);
    notifyObjectChange(ChangeType.TYPE_ANNOTATION_ADD_CHANGE, context, source, dataObject, annotation.getClassName(), null, null, null);
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)

Example 14 with AnnotationImpl

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

the class DataObjectAddOrRemoveAnnotationCommand method execute.

@Override
public void execute() {
    if (doAdd && dataObject.getAnnotation(annotationClassName) == null) {
        dataObject.addAnnotation(new AnnotationImpl(context.getAnnotationDefinition(annotationClassName)));
        notifyObjectChange(ChangeType.TYPE_ANNOTATION_ADD_CHANGE, context, source, dataObject, annotationClassName, null, null, null);
    } else if (!doAdd && dataObject.getAnnotation(annotationClassName) != null) {
        dataObject.removeAnnotation(annotationClassName);
        notifyObjectChange(ChangeType.TYPE_ANNOTATION_REMOVE_CHANGE, context, source, dataObject, annotationClassName, null, null, null);
    }
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)

Example 15 with AnnotationImpl

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

the class GenerationEngineTest method testJavaClassStringGeneration.

@Test
public void testJavaClassStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    Annotation label = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Label.class.getName()));
    label.setValue("value", "Object1 Label");
    object1.addAnnotation(label);
    Annotation classReactive = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.ClassReactive.class.getName()));
    object1.addAnnotation(classReactive);
    Annotation propReactive = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.PropertyReactive.class.getName()));
    object1.addAnnotation(propReactive);
    Annotation role = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Role.class.getName()));
    role.setValue("value", org.kie.api.definition.type.Role.Type.EVENT.name());
    object1.addAnnotation(role);
    ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
    ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
    ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
    ObjectProperty prop4 = object1.addProperty("attribute4", "long");
    Annotation key = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Key.class.getName()));
    Annotation position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "0");
    prop4.addAnnotation(key);
    prop4.addAnnotation(position);
    position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "1");
    prop1.addAnnotation(key);
    prop1.addAnnotation(position);
    position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "2");
    prop2.addAnnotation(key);
    prop2.addAnnotation(position);
    position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "3");
    prop3.addAnnotation(position);
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateJavaClassString(generationContext, object1);
        logger.debug(result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

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