use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorImplTest method checkSingleSelectedTaskFormGenerated.
private void checkSingleSelectedTaskFormGenerated(String taskId, String taskName) {
generator.generateSelectedForms(diagram, taskId);
verify(generator, times(1)).createFormForModel(formModelArgumentCaptor.capture(), any());
verify(formDefinitionSerializer, times(1)).serialize(formDefinitionArgumentCaptor.capture());
verify(ioService, times(1)).startBatch(any());
verify(ioService, times(1)).getFileSystem(any());
verify(ioService, times(1)).createFile(any());
verify(ioService, times(1)).write(any(), anyString());
verify(ioService, times(1)).endBatch();
JBPMFormModel formModel = formModelArgumentCaptor.getValue();
FormDefinition taskForm = formDefinitionArgumentCaptor.getValue();
Assertions.assertThat(formModel).isNotNull().isInstanceOf(TaskFormModel.class);
checkTaskFormGenerated((TaskFormModel) formModel, taskName, taskForm);
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class AbstractMigrationStep method persist.
private void persist(MigrationContext migrationContext) {
FormSerializationManager oldFormSerializer = new FormSerializationManagerImpl();
FormDefinitionSerializer formDefinitionSerializer = migrationContext.getCDIWrapper().getFormDefinitionSerializer();
Function<Resource<Form>, String> originaldFormSerializationFunction = formResource -> {
Form originalForm = formResource.get();
originalForm.setMigrationStep(getStep());
return oldFormSerializer.generateFormXML(originalForm, migrationContext.getSystem());
};
Function<Resource<FormDefinition>, String> newFormSerializationFuncion = formResource -> formDefinitionSerializer.serialize(formResource.get());
migrationContext.getSummaries().forEach(summary -> {
if (summary.getResult().isSuccess()) {
serializeResource(summary.getOriginalForm().getPath(), originaldFormSerializationFunction.apply(summary.getOriginalForm()), migrationContext);
serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
}
});
migrationContext.getExtraSummaries().forEach(summary -> {
serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
});
}
use of org.kie.workbench.common.forms.model.FormDefinition 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.FormDefinition 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);
});
}
Aggregations