Search in sources :

Example 1 with DataModelImpl

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

the class DataModelTestUtil method createModel.

public DataModel createModel(Class... classes) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    DataModel dataModel = new DataModelImpl();
    for (Class clazz : classes) {
        DataObject dataObject = createDataObject(clazz);
        dataModel.addDataObject(dataObject);
    }
    return dataModel;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)

Example 2 with DataModelImpl

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

the class ModuleDataModelOracleUtilsTest method loadExternalDepsTest.

@Test
public void loadExternalDepsTest() {
    DataModel dataModel = new DataModelImpl();
    try {
        ModuleDataModelOracleUtils.loadExternalDependencies(dataModel, dataModelOracle, ModuleDataModelOracleUtilsTest.class.getClassLoader());
        // check that the expected classes were properly loaded.
        List<DataObject> expectedExternalClasses = createExpectedExternalClasses();
        assertEquals(expectedExternalClasses.size(), dataModel.getExternalClasses().size());
        for (DataObject externalClass : dataModel.getExternalClasses()) {
            // properties read from DMO are not necessary sorted.
            sortProperties(externalClass);
            assertTrue(expectedExternalClasses.contains(externalClass));
        }
        // check that the expected enums where properly loaded.
        List<JavaEnum> expectedExternalEnums = createExpectedExternalEnums();
        assertEquals(expectedExternalEnums.size(), dataModel.getDependencyJavaEnums().size());
        for (JavaEnum externalEnum : dataModel.getDependencyJavaEnums()) {
            assertTrue(expectedExternalEnums.contains(externalEnum));
        }
    } catch (Exception e) {
        fail("External deps loading test failed: " + e.getMessage());
    }
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) Test(org.junit.Test)

Example 3 with DataModelImpl

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

the class JavaRoasterModelDriverTest method createModel.

private DataModel createModel() {
    DataModel dataModel = new DataModelImpl();
    dataModel.addDataObject(createPojo1());
    dataModel.addDataObject(createPojo2());
    dataModel.addJavaEnum(createInternalEnum1());
    dataModel.addDataObject(createAnnotationValuesAnnotationTest());
    dataModel.addDataObject(createClassAnnotationTest());
    dataModel.addDataObject(createEnumsAnnotationTest());
    dataModel.addDataObject(createMarkerAnnotationTest());
    dataModel.addDataObject(createPrimitivesAnnotationTest());
    dataModel.addDataObject(createAnnotationsUpdateTest());
    dataModel.addDataObject(createAnnotationsUpdateTestResult());
    dataModel.addDataObject(createNestedClassUpdateTest());
    dataModel.addDataObject(createNestedClassUpdateTestResult());
    dataModel.addDataObject(createMethodsUpdateTest());
    dataModel.addDataObject(createMethodsUpdateTestResult());
    dataModel.addDataObject(createImportsUpdateTest());
    dataModel.addDataObject(createImportsUpdateTestResult());
    return dataModel;
}
Also used : DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)

Example 4 with DataModelImpl

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

the class DecisionTableXLSToDecisionTableGuidedConverter method makeNewJavaTypes.

private void makeNewJavaTypes(final Path context, final List<String> declaredTypes, final ConversionResult result) {
    if (declaredTypes == null || declaredTypes.isEmpty()) {
        return;
    }
    final KieModule module = moduleService.resolveModule(context);
    for (String declaredType : declaredTypes) {
        final FactModels factModels = FactModelPersistence.unmarshal(declaredType);
        final String packageName = factModels.getPackageName();
        final DataModel dataModel = new DataModelImpl();
        for (FactMetaModel factMetaModel : factModels.getModels()) {
            final DataObject dataObject = new DataObjectImpl(packageName, factMetaModel.getName());
            dataObject.setSuperClassName(factMetaModel.getSuperType());
            final List<AnnotationMetaModel> annotationMetaModel = factMetaModel.getAnnotations();
            addAnnotations(dataObject, annotationMetaModel);
            final List<FieldMetaModel> fields = factMetaModel.getFields();
            for (FieldMetaModel fieldMetaModel : fields) {
                final String fieldName = fieldMetaModel.getName();
                final String fieldType = fieldMetaModel.getType();
                // Guvnor 5.5 (and earlier) does not have MultipleType
                boolean isMultiple = false;
                ObjectProperty property = new ObjectPropertyImpl(fieldName, fieldType, isMultiple);
                // field has no annotation in Guvnor 5.5 (and earlier)
                dataObject.addProperty(property);
                result.addMessage("Created Java Type " + getJavaTypeFQCN(dataObject), ConversionMessageType.INFO);
            }
            dataModel.getDataObjects().add(dataObject);
        }
        modellerService.saveModel(dataModel, module);
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) FactMetaModel(org.drools.workbench.screens.factmodel.model.FactMetaModel) FactModels(org.drools.workbench.screens.factmodel.model.FactModels) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) FieldMetaModel(org.drools.workbench.screens.factmodel.model.FieldMetaModel) 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) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) AnnotationMetaModel(org.drools.workbench.screens.factmodel.model.AnnotationMetaModel) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 5 with DataModelImpl

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

the class DataObjectFormModelHandlerTest method createModel.

private void createModel() {
    dataModel = new DataModelImpl();
    dataObject = dataModel.addDataObject("Person1");
    // makeTheClassPersistable
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("persistable", true);
    JPADomainHandler jpaDomainHandler = new JPADomainHandler();
    jpaDomainHandler.setDefaultValues(dataObject, params);
    // adding serialVersionUID field
    addProperty(dataObject, DataObjectFormModelHandler.SERIAL_VERSION_UID, Long.class.getName(), false, false);
    // add all base type properties
    PropertyTypeFactoryImpl propertyTypeFactory = new PropertyTypeFactoryImpl();
    propertyTypeFactory.getBasePropertyTypes().forEach(baseProperty -> addProperty(dataObject, baseProperty.getName(), baseProperty.getClassName(), false, false));
    // add data object property
    addProperty(dataObject, "address", NESTED_CLASSNAME, false, false);
    // add list of data objects
    addProperty(dataObject, "address_list", NESTED_CLASSNAME, true, false);
}
Also used : JPADomainHandler(org.kie.workbench.common.screens.datamodeller.backend.server.handler.JPADomainHandler) HashMap(java.util.HashMap) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) PropertyTypeFactoryImpl(org.kie.workbench.common.services.datamodeller.core.impl.PropertyTypeFactoryImpl)

Aggregations

DataModelImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)5 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)4 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)4 HashMap (java.util.HashMap)1 AnnotationMetaModel (org.drools.workbench.screens.factmodel.model.AnnotationMetaModel)1 FactMetaModel (org.drools.workbench.screens.factmodel.model.FactMetaModel)1 FactModels (org.drools.workbench.screens.factmodel.model.FactModels)1 FieldMetaModel (org.drools.workbench.screens.factmodel.model.FieldMetaModel)1 Test (org.junit.Test)1 JPADomainHandler (org.kie.workbench.common.screens.datamodeller.backend.server.handler.JPADomainHandler)1 JavaEnum (org.kie.workbench.common.services.datamodeller.core.JavaEnum)1 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)1 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)1 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)1 PropertyTypeFactoryImpl (org.kie.workbench.common.services.datamodeller.core.impl.PropertyTypeFactoryImpl)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1