use of org.kie.workbench.common.forms.migration.legacy.model.Form in project kie-wb-common by kiegroup.
the class AbstractFormAdapter method doCreateFormDefinition.
protected void doCreateFormDefinition(FormModel formModel, FormMigrationSummary formSummary) {
Form originalForm = formSummary.getOriginalForm().get();
FormDefinition newFormDefinition = new FormDefinition(formModel);
newFormDefinition.setId(String.valueOf(originalForm.getId()));
newFormDefinition.setName(formSummary.getBaseFormName());
Path originalPath = Paths.convert(formSummary.getOriginalForm().getPath());
Path newPath = originalPath.getParent().resolve(formSummary.getBaseFormName() + "." + FormsMigrationConstants.NEW_FOMRS_EXTENSION);
formSummary.setNewFormResource(new Resource<>(newFormDefinition, Paths.convert(newPath)));
migrateFields(originalForm.getFormFields(), newFormDefinition, formSummary);
}
use of org.kie.workbench.common.forms.migration.legacy.model.Form 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.migration.legacy.model.Form in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyInvoiceForm.
protected void verifyInvoiceForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(3);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(3);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", INVOICE_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(newForm.getFields().size());
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, INVOICE_USER, "user (invoice)", "user", SubFormFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, INVOICE_LINES, "lines (invoice)", "lines", MultipleSubFormFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 3:
checkFieldDefinition(fieldDefinition, INVOICE_LINES, "lines (invoice)", "lines", MultipleSubFormFieldDefinition.class, newForm, 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, newForm);
});
}
use of org.kie.workbench.common.forms.migration.legacy.model.Form in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyUserForm.
protected void verifyUserForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(2);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(2);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", USER_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(2);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, USER_LOGIN, "login", "login", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, USER_PASSWORD, "password", "password", TextBoxFieldDefinition.class, newForm, 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, newForm);
});
}
use of org.kie.workbench.common.forms.migration.legacy.model.Form in project kie-wb-common by kiegroup.
the class FormSerializationManagerImpl method deserializeForm.
public Form deserializeForm(Node nodeForm) throws Exception {
if (!nodeForm.getNodeName().equals(NODE_FORM)) {
return null;
}
Form form = new Form();
form.setId(Long.valueOf(StringEscapeUtils.unescapeXml(nodeForm.getAttributes().getNamedItem(ATTR_ID).getNodeValue())));
Set<Field> fields = new TreeSet<>();
NodeList childNodes = nodeForm.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node.getNodeName().equals(NODE_PROPERTY)) {
String propName = node.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
String value = StringEscapeUtils.unescapeXml(node.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());
if ("subject".equals(propName)) {
form.setSubject(value);
} else if ("name".equals(propName)) {
form.setName(value);
} else if ("displayMode".equals(propName)) {
form.setDisplayMode(value);
} else if ("labelMode".equals(propName)) {
form.setLabelMode(value);
} else if ("showMode".equals(propName)) {
form.setShowMode(value);
} else if ("status".equals(propName)) {
form.setStatus(Long.valueOf(value));
} else if ("formTemplate".equals(propName)) {
form.setFormTemplate(value);
} else if ("migrationStep".equals(propName)) {
form.setMigrationStep(Integer.decode(value));
}
} else if (node.getNodeName().equals(NODE_FIELD)) {
Field field = deserializeField(node);
field.setForm(form);
fields.add(field);
} else if (node.getNodeName().equals(NODE_DATA_HOLDER)) {
String holderId = getNodeAttributeValue(node, ATTR_ID);
String holderInputId = getNodeAttributeValue(node, ATTR_INPUT_ID);
String holderOutId = getNodeAttributeValue(node, ATTR_OUT_ID);
String holderType = getNodeAttributeValue(node, ATTR_TYPE);
String holderValue = getNodeAttributeValue(node, ATTR_VALUE);
String holderRenderColor = getNodeAttributeValue(node, ATTR_NAME);
String holderSupportedType = getNodeAttributeValue(node, ATTR_SUPPORTED_TYPE);
DataHolder dataHolder = new DataHolder(holderId, holderInputId, holderOutId, holderType, holderValue, holderRenderColor, holderSupportedType);
form.setDataHolder(dataHolder);
}
}
if (fields != null) {
form.setFormFields(fields);
}
return form;
}
Aggregations