use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorImplTest method checkGeneratedForm.
private void checkGeneratedForm(FormDefinition formDefinition, JBPMFormModel expectedFormModel, boolean readOnly) {
Assertions.assertThat(formDefinition).isNotNull().hasFieldOrPropertyWithValue("name", expectedFormModel.getFormName() + ".frm");
Assertions.assertThat(formDefinition.getFields()).isNotEmpty().hasSize(VARIABLES.size());
assertEquals(expectedFormModel, formDefinition.getModel());
VARIABLES.forEach((key, value) -> {
FieldDefinition field = formDefinition.getFieldByBinding(key);
switch(key) {
case STRING_VARIABLE:
checkStringField(field, readOnly);
break;
case INTEGER_VARIABLE:
checkIntegerField(field, readOnly);
break;
case BOOLEAN_VARIABLE:
checkBooleanField(field, readOnly);
break;
case FLOAT_VARIABLE:
checkFloatField(field, readOnly);
break;
case OBJECT_VARIABLE:
checkObjectField(field, readOnly);
break;
}
});
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionGenerator method maybeArrangeNestedForms.
private void maybeArrangeNestedForms(FormMigrationSummary summary, List<FormMigrationSummary> modelForms) {
final Form originalForm = summary.getOriginalForm().get();
final FormDefinition formDefinition = summary.getNewForm().get();
formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof HasNestedForm).map(fieldDefinition -> (HasNestedForm) fieldDefinition).forEach(hasNestedForm -> {
modelForms.stream().filter(modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(hasNestedForm.getNestedForm())).findFirst().ifPresent(modelSummary -> {
hasNestedForm.setNestedForm(modelSummary.getNewForm().get().getId());
updateNestedFormsModelProperties(formDefinition, (FieldDefinition) hasNestedForm, modelSummary.getOriginalForm().get());
});
});
formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof IsCRUDDefinition).map(fieldDefinition -> (IsCRUDDefinition) fieldDefinition).forEach(crudDefinition -> {
// update Creation Form
updateCrudDefinitionForms(modelForms, modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(crudDefinition.getCreationForm()), modelSummary -> crudDefinition.setCreationForm(modelSummary.getNewForm().get().getId()));
// update Edition Form
updateCrudDefinitionForms(modelForms, modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(crudDefinition.getEditionForm()), modelSummary -> crudDefinition.setEditionForm(modelSummary.getNewForm().get().getId()));
// update Table Columns Form
updateCrudDefinitionForms(modelForms, modelSummary -> {
Field originalField = originalForm.getField(((FieldDefinition) crudDefinition).getName());
return modelSummary.getOriginalForm().getPath().getFileName().equals(StringUtils.defaultIfBlank(originalField.getTableSubform(), originalField.getDefaultSubform()));
}, modelSummary -> {
FormDefinition modelFormDefinition = modelSummary.getNewForm().get();
modelFormDefinition.getFields().forEach(fieldDefinition -> {
if (!(fieldDefinition instanceof EmbedsForm)) {
crudDefinition.getColumnMetas().add(new TableColumnMeta(fieldDefinition.getLabel(), fieldDefinition.getBinding()));
}
});
updateNestedFormsModelProperties(formDefinition, (FieldDefinition) crudDefinition, modelSummary.getOriginalForm().get());
});
});
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class AbstractFieldAdapter method parseField.
@Override
public void parseField(Field originalField, FormMigrationSummary formSummary, FormDefinition newFormDefinition, Consumer<LayoutComponent> layoutElementConsumer) {
FieldDefinition fieldDefinition = getFieldDefinition(originalField);
fieldDefinition.setId(String.valueOf(originalField.getId()));
fieldDefinition.setName(originalField.getFieldName());
fieldDefinition.setLabel(lookupI18nValue(originalField.getLabel()));
fieldDefinition.setHelpMessage(lookupI18nValue(originalField.getTitle()));
fieldDefinition.setStandaloneClassName(StringUtils.defaultIfBlank(originalField.getBag(), originalField.getFieldType().getFieldClass()));
fieldDefinition.setReadOnly(originalField.getReadonly());
fieldDefinition.setRequired(originalField.getFieldRequired());
String binding = StringUtils.defaultString(StringUtils.defaultIfBlank(originalField.getInputBinding(), originalField.getOutputBinding()));
if (!StringUtils.isEmpty(binding)) {
if (binding.contains("/")) {
binding = binding.substring(binding.indexOf("/") + 1);
}
ModelPropertyImpl property = new ModelPropertyImpl(binding, fieldDefinition.getFieldTypeInfo());
newFormDefinition.getModel().getProperties().add(property);
}
fieldDefinition.setBinding(binding);
newFormDefinition.getFields().add(fieldDefinition);
LayoutComponent component = new LayoutComponent(DRAGGABLE_TYPE);
component.addProperty(FormLayoutComponent.FORM_ID, newFormDefinition.getId());
component.addProperty(FormLayoutComponent.FIELD_ID, fieldDefinition.getId());
layoutElementConsumer.accept(component);
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyLineForm.
protected void verifyLineForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(4);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(4);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", LINE_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(1);
LayoutRow fieldRow = formLayout.getRows().get(0);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, LINE_PRODUCT, "product", "product", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, LINE_PRICE, "price", "price", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 2:
checkFieldDefinition(fieldDefinition, LINE_QUANTITY, "quantity", "quantity", IntegerBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 3:
checkFieldDefinition(fieldDefinition, LINE_TOTAL, "total", "total", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
}
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(4);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(index);
assertNotNull(fieldColumn);
assertEquals("3", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
});
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorForBPMNWithComplexVariableTest method checkInvoiceFormDefinition.
protected void checkInvoiceFormDefinition(FormDefinition invoiceForm, Form originalForm) {
assertNotNull(invoiceForm);
Assertions.assertThat(invoiceForm.getModel()).isNotNull().isInstanceOf(DataObjectFormModel.class).hasFieldOrPropertyWithValue("className", INVOICE_MODEL);
Assertions.assertThat(invoiceForm.getFields()).isNotEmpty().hasSize(3);
IntStream indexStream = IntStream.range(0, invoiceForm.getFields().size());
LayoutTemplate formLayout = invoiceForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(3);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = invoiceForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, "invoice_user", "User Data:", "user", SubFormFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, "lines", "Invoice Lines", "lines", MultipleSubFormFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
break;
case 2:
checkFieldDefinition(fieldDefinition, "invoice_total", "Invoice Total:", "total", DecimalBoxFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
break;
}
LayoutRow fieldRow = formLayout.getRows().get(index);
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);
assertNotNull(fieldColumn);
assertEquals("12", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, invoiceForm);
});
}
Aggregations