use of org.kie.workbench.common.forms.migration.legacy.model.DataHolder 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.DataHolder 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;
}
use of org.kie.workbench.common.forms.migration.legacy.model.DataHolder in project kie-wb-common by kiegroup.
the class FormSerializationManagerImpl method generateFormXML.
/**
* Generates the xml representation and mount in rootNode the structure to be included.
* Fills the XMLNode structure with the form representation and returns the string.
*/
public String generateFormXML(Form form, XMLNode rootNode) throws Exception {
rootNode.addAttribute(ATTR_ID, form.getId().toString());
addXMLNode("subject", form.getSubject(), rootNode);
addXMLNode("name", form.getName(), rootNode);
addXMLNode("displayMode", form.getDisplayMode(), rootNode);
addXMLNode("labelMode", form.getLabelMode(), rootNode);
addXMLNode("showMode", form.getShowMode(), rootNode);
addXMLNode("status", (form.getStatus() != null ? String.valueOf(form.getStatus()) : null), rootNode);
addXMLNode("formTemplate", form.getFormTemplate(), rootNode);
addXMLNode("migrationStep", String.valueOf(form.getMigrationStep()), rootNode);
for (Field field : form.getFormFields()) {
generateFieldXML(field, rootNode);
}
for (DataHolder dataHolder : form.getHolders()) {
generateDataHolderXML(dataHolder, rootNode);
}
StringWriter sw = new StringWriter();
rootNode.writeXML(sw, true);
return sw.toString();
}
Aggregations