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);
}
}
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));
}
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));
}
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));
}
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));
}
Aggregations