use of org.kie.workbench.common.forms.model.FormModel in project kie-wb-common by kiegroup.
the class BPMNFormAdapter method doCreateFormDefinition.
@Override
protected void doCreateFormDefinition(FormModel formModel, FormMigrationSummary formSummary) {
Form originalForm = formSummary.getOriginalForm().get();
Set<DataHolder> objectDataHolders = originalForm.getHolders().stream().filter(dataHolder -> !dataHolder.getType().equals(FormsMigrationConstants.DATA_HOLDER_TYPE_BASIC)).collect(Collectors.toSet());
if (!objectDataHolders.isEmpty()) {
FieldTypeManager fieldTypeManager = FieldTypeManager.get();
objectDataHolders.forEach(dataHolder -> {
Set<Field> dataHolderFields = originalForm.getFieldsForDataHolder(dataHolder);
if (dataHolderFields.isEmpty()) {
return;
}
FormModel newFormModel = createModelForDO(dataHolder);
String formName = formSummary.getBaseFormName() + "-" + dataHolder.getUniqeId();
String formAssetName = formName + "." + FormsMigrationConstants.NEW_FOMRS_EXTENSION;
FormDefinition newFormDefinition = new FormDefinition(newFormModel);
newFormDefinition.setId(UIDGenerator.generateUID());
newFormDefinition.setName(formName);
migrateFields(dataHolderFields, newFormDefinition, formSummary);
dataHolderFields.forEach(field -> field.setMovedToForm(formName));
Path newFormPath = Paths.convert(formSummary.getOriginalForm().getPath()).getParent().resolve(formAssetName);
FormMigrationSummary extraSummary = new FormMigrationSummary(formSummary.getOriginalForm());
extraSummary.setBaseFormName(formName);
extraSummary.setNewFormResource(new Resource<>(newFormDefinition, Paths.convert(newFormPath)));
migrationContext.getExtraSummaries().add(extraSummary);
Field field = new Field();
field.setFieldType(fieldTypeManager.getTypeByCode(FieldTypeBuilder.SUBFORM));
field.setId(System.currentTimeMillis());
field.setFieldName(dataHolder.getUniqeId());
field.setInputBinding(dataHolder.getUniqeId());
field.setLabel(new HashMap<>());
field.getLabel().put(FormsMigrationConstants.DEFAULT_LANG, dataHolder.getUniqeId());
field.setPosition(originalForm.getFormFields().size() + 1000);
field.setForm(originalForm);
originalForm.getFormFields().add(field);
});
}
super.doCreateFormDefinition(formModel, formSummary);
}
use of org.kie.workbench.common.forms.model.FormModel in project kie-wb-common by kiegroup.
the class AbstractFormModelHandler method synchronizeFormModelProperties.
@Override
public FormModelSynchronizationResult synchronizeFormModelProperties(final F formModel, final List<ModelProperty> currentProperties) {
final FormModelSynchronizationResultImpl result = new FormModelSynchronizationResultImpl();
List<ModelProperty> modelProperties = Optional.ofNullable(formModel.getProperties()).orElse(new ArrayList<>());
result.setPreviousProperties(modelProperties);
currentProperties.forEach((currentProperty) -> {
Optional<ModelProperty> optional = result.getPreviousProperties().stream().filter(oldProperty -> oldProperty.getName().equals(currentProperty.getName())).findFirst();
if (optional.isPresent()) {
ModelProperty oldProperty = optional.get();
if (!oldProperty.equals(currentProperty)) {
// currentProperty exists on the Model oldProperties but type doesn't match -> adding it to conlfict
result.getConflicts().put(oldProperty.getName(), new TypeConflictImpl(oldProperty.getName(), oldProperty.getTypeInfo(), currentProperty.getTypeInfo()));
}
} else {
// currentPproperty doesn't exist on the previous properties -> adding to new properties
result.getNewProperties().add(currentProperty);
}
});
modelProperties.forEach(oldProperty -> {
Optional<ModelProperty> optional = currentProperties.stream().filter(currentProperty -> currentProperty.getName().equals(oldProperty.getName())).findFirst();
if (!optional.isPresent()) {
result.getRemovedProperties().add(oldProperty);
}
});
formModel.getProperties().clear();
formModel.getProperties().addAll(currentProperties);
return result;
}
use of org.kie.workbench.common.forms.model.FormModel in project kie-wb-common by kiegroup.
the class FormEditorServiceImplTest method testCreateForm.
@Test
public void testCreateForm() {
when(formDefinitionSerializer.serialize(any())).thenAnswer(this::verifyNewForm);
FormModel formModel = mock(FormModel.class);
Path resultPath = formEditorService.createForm(path, FULL_FORM_NAME, formModel);
assertNotNull(resultPath);
}
use of org.kie.workbench.common.forms.model.FormModel in project kie-wb-common by kiegroup.
the class FormEditorServiceImplTest method testCreateFormThatExistsOnVFS.
@Test
public void testCreateFormThatExistsOnVFS() {
try {
when(ioService.exists(any())).thenReturn(true);
FormModel formModel = mock(FormModel.class);
formEditorService.createForm(path, FULL_FORM_NAME, formModel);
fail("If form exists we shouldn't be here");
} catch (FileAlreadyExistsException ex) {
}
}
use of org.kie.workbench.common.forms.model.FormModel in project kie-wb-common by kiegroup.
the class NestedFormsBPMNVFSFormDefinitionGeneratorServiceTest method findVFSForms.
private List<FormDefinition> findVFSForms(InvocationOnMock invocationOnMock) {
String className = invocationOnMock.getArguments()[0].toString();
if (Expense.class.getName().equals(className)) {
FormModel formModel = new DataObjectFormModel(className, className);
// Creating empty form
FormDefinition emptyForm = new FormDefinition(formModel);
emptyForm.setName(EMPTY_FORM_ID);
emptyForm.setId(EMPTY_FORM_ID);
// Creating a form with a field
FormDefinition fullForm = new FormDefinition(formModel);
fullForm.setName(EXPENSE_FORM_ID);
fullForm.setId(EXPENSE_FORM_ID);
DatePickerFieldDefinition field = new DatePickerFieldDefinition();
field.setId(DATE_VARIABLE);
field.setName(DATE_VARIABLE);
field.setLabel(DATE_VARIABLE);
field.setBinding(DATE_VARIABLE);
fullForm.getFields().add(field);
return Arrays.asList(emptyForm, fullForm);
}
return null;
}
Aggregations