Search in sources :

Example 11 with ObjectPropertyImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl 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 12 with ObjectPropertyImpl

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

the class DataObjectValidationServiceImplTest method validateObjectPropertyDeletion.

@Test
public void validateObjectPropertyDeletion() {
    Collection<ValidationMessage> result = validationService.validateObjectPropertyDeletion(new DataObjectImpl(), new ObjectPropertyImpl());
    assertEquals(2, result.size());
    assertTrue(result.contains(message1));
    assertTrue(result.contains(message2));
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Test(org.junit.Test)

Example 13 with ObjectPropertyImpl

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

the class DataObjectBrowserTest method safeObjectPropertyDeleteEmptyValidationMessages.

@Test
public void safeObjectPropertyDeleteEmptyValidationMessages() {
    DataObjectBrowser dataObjectBrowser = createBrowser();
    DataObjectImpl dataObject = new DataObjectImpl("test", "DataObject");
    dataObjectBrowser.setDataObject(dataObject);
    ObjectProperty objectProperty = new ObjectPropertyImpl("safeField", Integer.class.getName(), false);
    when(dataObjectValidationService.validateObjectPropertyDeletion(dataObject, objectProperty)).thenReturn(Collections.emptyList());
    dataObjectBrowser.onDeleteProperty(objectProperty, 0);
    verify(view, never()).showValidationPopupForDeletion(anyListOf(ValidationMessage.class), any(Command.class), any(Command.class));
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Command(org.uberfire.mvp.Command) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 14 with ObjectPropertyImpl

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

the class DataObjectBrowserTest method safeObjectPropertyDeleteHasValidationMessages.

@Test
public void safeObjectPropertyDeleteHasValidationMessages() {
    DataObjectBrowser dataObjectBrowser = createBrowser();
    DataObjectImpl dataObject = new DataObjectImpl("test", "DataObject");
    dataObjectBrowser.setDataObject(dataObject);
    ObjectProperty objectProperty = new ObjectPropertyImpl("safeField", Integer.class.getName(), false);
    List<ValidationMessage> validationMessages = Arrays.asList(new ValidationMessage());
    when(dataObjectValidationService.validateObjectPropertyDeletion(dataObject, objectProperty)).thenReturn(validationMessages);
    dataObjectBrowser.onDeleteProperty(objectProperty, 0);
    verify(view, times(1)).showValidationPopupForDeletion(anyListOf(ValidationMessage.class), any(Command.class), any(Command.class));
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Command(org.uberfire.mvp.Command) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 15 with ObjectPropertyImpl

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

the class DataObjectBrowserTest method addValidPropertyTest.

private void addValidPropertyTest(boolean createAndContinue) {
    DataObjectBrowser objectBrowser = createBrowser();
    DataModelerContext context = createContext();
    objectBrowser.setContext(context);
    // the dataObject has fields: field1, field2 and field3
    DataObject dataObject = context.getDataObject();
    // open the new property dialog.
    objectBrowser.onNewProperty();
    // check the new field popup is shown
    verify(newFieldPopupView, times(1)).show();
    // emulate the user data entering in the new field popup
    when(newFieldPopupView.getFieldName()).thenReturn("field4");
    when(newFieldPopupView.getSelectedType()).thenReturn("java.lang.String");
    when(newFieldPopupView.getIsMultiple()).thenReturn(false);
    // emulate that the provided field name is correct
    Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
    validationResult.put("field4", true);
    when(validationService.evaluateJavaIdentifiers(new String[] { "field4" })).thenReturn(validationResult);
    // emulate the user pressing the create button in the new field popup
    newFieldPopup.onCreate();
    // the new field popup should have been closed and the new property shoud have been added o the data object.
    ObjectProperty expectedProperty = new ObjectPropertyImpl("field4", "java.lang.String", false);
    if (createAndContinue) {
        verify(newFieldPopupView, times(1)).clear();
    } else {
        verify(newFieldPopupView, times(1)).hide();
    }
    verify(view, times(1)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(3));
    verify(view, times(1)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(4));
    assertEquals(4, dataObject.getProperties().size());
    assertEquals(expectedProperty, dataObject.getProperties().get(3));
}
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) HashMap(java.util.HashMap) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)

Aggregations

ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)18 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)14 Test (org.junit.Test)11 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)10 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)7 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)6 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)5 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)5 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 FieldSource (org.jboss.forge.roaster.model.source.FieldSource)2 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)2 MethodSource (org.jboss.forge.roaster.model.source.MethodSource)2 DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)2 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)2 Command (org.uberfire.mvp.Command)2 Column (com.google.gwt.user.cellview.client.Column)1 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1