Search in sources :

Example 51 with DataObject

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

the class ModuleDataModelOracleUtils method addDataObjectType.

private static void addDataObjectType(DataModel dataModel, ModuleDataModelOracle oracleDataModel, String factType, ClassMetadata classMetadata) throws ModelDriverException {
    String superClass = DataModelOracleUtilities.getSuperType(oracleDataModel, factType);
    Visibility visibility = DriverUtils.buildVisibility(classMetadata.getModifiers());
    DataObject dataObject;
    logger.debug("Adding dataObjectType: " + factType + ", to dataModel: " + dataModel + ", from oracleDataModel: " + oracleDataModel);
    dataObject = dataModel.addDataObject(factType, visibility, Modifier.isAbstract(classMetadata.getModifiers()), Modifier.isFinal(classMetadata.getModifiers()), ObjectSource.DEPENDENCY);
    dataObject.setSuperClassName(superClass);
    Map<String, ModelField[]> fields = oracleDataModel.getModuleModelFields();
    if (fields != null) {
        ModelField[] factFields = fields.get(factType);
        ModelField field;
        if (factFields != null && factFields.length > 0) {
            for (int j = 0; j < factFields.length; j++) {
                field = factFields[j];
                if (isLoadableField(field)) {
                    if (field.getType().equals("Collection")) {
                        // read the correct bag and item classes.
                        String bag = DataModelOracleUtilities.getFieldClassName(oracleDataModel, factType, field.getName());
                        String itemsClass = DataModelOracleUtilities.getParametricFieldType(oracleDataModel, factType, field.getName());
                        if (itemsClass == null) {
                            // if we don't know the items class, the property will be managed as a simple property.
                            dataObject.addProperty(field.getName(), bag);
                        } else {
                            dataObject.addProperty(field.getName(), itemsClass, true, bag);
                        }
                    } else {
                        dataObject.addProperty(field.getName(), field.getClassName());
                    }
                }
            }
        }
    } else {
        logger.debug("No fields found for factTye: " + factType);
    }
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility)

Example 52 with DataObject

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

the class DataModelImpl method addDataObject.

private DataObject addDataObject(String packageName, String name, Visibility visibility, boolean isAbstract, boolean isFinal, Map<String, DataObject> objectsMap) {
    DataObject dataObject = new DataObjectImpl(packageName, name, visibility, isAbstract, isFinal);
    objectsMap.put(dataObject.getClassName(), dataObject);
    return dataObject;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 53 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject 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 54 with DataObject

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

the class DataObjectFinderServiceImplFinderTest method testFindDataObject.

@Test
public void testFindDataObject() {
    DataObject result = service.getDataObject(TYPE_NAME, path);
    assertEquals(dataObject, result);
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Test(org.junit.Test)

Example 55 with DataObject

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

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