Search in sources :

Example 91 with DataObject

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

the class GenerationEngineTest method testAllFieldAnnotationsStringGeneration.

@Test
public void testAllFieldAnnotationsStringGeneration() {
    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.generateAllAnnotationsString(generationContext, prop1);
        assertEquals(results.getProperty("testAllFieldAnnotationsStringGeneration"), 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 92 with DataObject

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

the class GenerationEngineTest method testKeyFieldsConstructorStringGeneration.

@Test
public void testKeyFieldsConstructorStringGeneration() {
    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(1);
    ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
    ((ObjectPropertyImpl) prop2).setFileOrder(2);
    ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
    ((ObjectPropertyImpl) prop3).setFileOrder(0);
    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()));
    prop3.addAnnotation(key);
    prop1.addAnnotation(key);
    prop2.addAnnotation(key);
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateKeyFieldsConstructorString(generationContext, object1);
        assertEquals(results.getProperty("testKeyFieldsConstructorStringGeneration"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) 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) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) Test(org.junit.Test)

Example 93 with DataObject

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

the class GenerationEngineTest method testAllConstructorsStringGeneration.

@Test
public void testAllConstructorsStringGeneration() {
    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");
    prop3.addAnnotation(key);
    prop3.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");
    prop4.addAnnotation(position);
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateAllConstructorsString(generationContext, object1);
        assertEquals(results.getProperty("testAllConstructorsStringGeneration"), 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 94 with DataObject

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

the class GenerationEngineTest method testFieldAccessorStringGeneration.

@Test
public void testFieldAccessorStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object = dataModel.addDataObject("com.test.Object1");
    ObjectProperty property = object.addProperty("attribute1", "java.lang.String");
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateFieldGetterString(generationContext, property);
        assertEquals(results.getProperty("testFieldAccessorStringGeneration"), 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) Test(org.junit.Test)

Example 95 with DataObject

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

the class DataModelerUtils method buildFieldTypeOptions.

public static List<Pair<String, String>> buildFieldTypeOptions(final Collection<PropertyType> baseTypes, final Collection<DataObject> dataObjects, final Collection<JavaEnum> javaEnums, final Collection<DataObject> externalClasses, final Collection<JavaEnum> externalEnums, final String selectedType, final boolean includeEmptyItem) {
    List<Pair<String, String>> typeList = new ArrayList<Pair<String, String>>();
    Collection<JavaType> javaTypes = new ArrayList<JavaType>();
    Collection<JavaType> externalJavaTypes = new ArrayList<JavaType>();
    SortedMap<String, String> sortedModelTypeNames = new TreeMap<String, String>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    SortedMap<String, String> sortedExternalTypeNames = new TreeMap<String, String>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    Map<String, PropertyType> orderedBaseTypes = new TreeMap<String, PropertyType>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    Map<String, PropertyType> baseTypesByClassName = new TreeMap<String, PropertyType>(SortHelper.ALPHABETICAL_ORDER_COMPARATOR);
    boolean selectedTypeIncluded = false;
    if (includeEmptyItem) {
        typeList.add(UIUtil.emptyValue());
    }
    if (baseTypes != null) {
        for (PropertyType type : baseTypes) {
            orderedBaseTypes.put(type.getName(), type);
            baseTypesByClassName.put(type.getClassName(), type);
        }
    }
    // First add all base types, ordered
    for (Map.Entry<String, PropertyType> baseType : orderedBaseTypes.entrySet()) {
        if (!baseType.getValue().isPrimitive()) {
            typeList.add(new Pair(baseType.getKey(), baseType.getValue().getClassName()));
        }
    }
    // collect all model types, ordered
    if (dataObjects != null) {
        javaTypes.addAll(dataObjects);
    }
    if (javaEnums != null) {
        javaTypes.addAll(javaEnums);
    }
    for (JavaType javaType : javaTypes) {
        String className = javaType.getClassName();
        String classLabel;
        if (javaType instanceof DataObject) {
            classLabel = DataModelerUtils.getDataObjectFullLabel((DataObject) javaType);
        } else {
            classLabel = javaType.getClassName();
        }
        sortedModelTypeNames.put(classLabel, className);
        if (selectedType != null && selectedType.equals(className)) {
            selectedTypeIncluded = true;
        }
    }
    // collect external types, ordered
    if (externalClasses != null) {
        externalJavaTypes.addAll(externalClasses);
    }
    if (externalEnums != null) {
        externalJavaTypes.addAll(externalEnums);
    }
    if (externalClasses != null) {
        for (JavaType externalJavaType : externalJavaTypes) {
            String extClass = externalJavaType.getClassName();
            sortedExternalTypeNames.put(DataModelerUtils.EXTERNAL_PREFIX + extClass, extClass);
            if (selectedType != null && selectedType.equals(extClass)) {
                selectedTypeIncluded = true;
            }
        }
    }
    // check selectedType isn't present
    if (selectedType != null && !selectedTypeIncluded && !baseTypesByClassName.containsKey(selectedType)) {
        // uncommon case. A field was loaded but the class isn't within the model or external classes.
        String extClass = selectedType;
        sortedExternalTypeNames.put(DataModelerUtils.EXTERNAL_PREFIX + extClass, extClass);
    }
    // add project classes to the selector.
    for (Map.Entry<String, String> typeName : sortedModelTypeNames.entrySet()) {
        typeList.add(new Pair<String, String>(typeName.getKey(), typeName.getValue()));
    }
    // add external classes to the selector.
    for (Map.Entry<String, String> typeName : sortedExternalTypeNames.entrySet()) {
        typeList.add(new Pair<String, String>(typeName.getKey(), typeName.getValue()));
    }
    // finally add primitives
    for (Map.Entry<String, PropertyType> baseType : orderedBaseTypes.entrySet()) {
        if (baseType.getValue().isPrimitive()) {
            typeList.add(new Pair<String, String>(baseType.getKey(), baseType.getValue().getClassName()));
        }
    }
    return typeList;
}
Also used : ArrayList(java.util.ArrayList) PropertyType(org.kie.workbench.common.services.datamodeller.core.PropertyType) TreeMap(java.util.TreeMap) JavaType(org.kie.workbench.common.services.datamodeller.core.JavaType) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Pair(org.uberfire.commons.data.Pair)

Aggregations

DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)95 Test (org.junit.Test)45 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)40 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)29 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)28 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)21 ArrayList (java.util.ArrayList)17 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)17 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)17 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)17 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)17 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)17 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)17 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)16 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)15 MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)12 List (java.util.List)11 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)11 Method (org.kie.workbench.common.services.datamodeller.core.Method)10 Generated (javax.annotation.Generated)8