Search in sources :

Example 16 with AnnotationImpl

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

the class GenerationEngineTest method testEqualsStringGeneration.

@Test
public void testEqualsStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    ObjectPropertyImpl prop1 = (ObjectPropertyImpl) object1.addProperty("attribute1", "java.lang.String");
    prop1.setFileOrder(0);
    ObjectPropertyImpl prop2 = (ObjectPropertyImpl) object1.addProperty("attribute2", "java.lang.Boolean");
    prop2.setFileOrder(1);
    ObjectPropertyImpl prop3 = (ObjectPropertyImpl) object1.addProperty("attribute3", object2.getClassName());
    prop3.setFileOrder(2);
    ObjectPropertyImpl prop4 = (ObjectPropertyImpl) object1.addProperty("attribute4", "long");
    prop4.setFileOrder(3);
    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.generateEqualsString(generationContext, object1);
        assertEquals(results.getProperty("testEqualsStringGeneration"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

Example 17 with AnnotationImpl

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

the class GenerationEngineTest method testCompleteFieldStringGeneration.

@Test
public // Return field definition + annotations
void testCompleteFieldStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
    Annotation label = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Label.class.getName()));
    label.setValue("value", "Attribute 1");
    Annotation desc = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Description.class.getName()));
    desc.setValue("value", "Description for Attribute 1");
    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");
    prop1.addAnnotation(label);
    prop1.addAnnotation(desc);
    prop1.addAnnotation(key);
    prop1.addAnnotation(position);
    GenerationContext generationContext = new GenerationContext(dataModelOracleDriver.createModel());
    try {
        String result = engine.generateCompleteFieldString(generationContext, prop1);
        assertEquals(results.getProperty("testCompleteFieldStringGeneration"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) Test(org.junit.Test)

Example 18 with AnnotationImpl

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

the class GenerationEngineTest method testHashCodeStringGeneration.

@Test
public void testHashCodeStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
    ((ObjectPropertyImpl) prop1).setFileOrder(0);
    ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
    ((ObjectPropertyImpl) prop2).setFileOrder(1);
    ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
    ((ObjectPropertyImpl) prop3).setFileOrder(2);
    ObjectProperty prop4 = object1.addProperty("attribute4", "long");
    ((ObjectPropertyImpl) prop4).setFileOrder(3);
    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.generateHashCodeString(generationContext, object1);
        assertEquals(results.getProperty("testHashCodeStringGeneration"), 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) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

Example 19 with AnnotationImpl

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

the class DecisionTableXLSToDecisionTableGuidedConverter method addAnnotations.

private void addAnnotations(final DataObject dataObject, final List<AnnotationMetaModel> annotationMetaModelList) {
    for (AnnotationMetaModel annotationMetaModel : annotationMetaModelList) {
        final String name = annotationMetaModel.getName();
        final Map<String, String> values = annotationMetaModel.getValues();
        Annotation annotation;
        String key = DroolsDomainAnnotations.VALUE_PARAM;
        String value = "";
        if (values.size() > 0) {
            key = values.keySet().iterator().next();
            value = values.values().iterator().next();
        }
        if ("Role".equals(name)) {
            annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.ROLE_ANNOTATION));
            annotation.setValue(key, value);
            dataObject.addAnnotation(annotation);
        } else if ("Position".equals(name)) {
            annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.POSITION_ANNOTATION));
            annotation.setValue(key, value);
            dataObject.addAnnotation(annotation);
        } else if ("Equals".equals(name)) {
            annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.KEY_ANNOTATION));
            annotation.setValue(key, value);
            dataObject.addAnnotation(annotation);
        }
    }
}
Also used : AnnotationMetaModel(org.drools.workbench.screens.factmodel.model.AnnotationMetaModel) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Example 20 with AnnotationImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl 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)

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