Search in sources :

Example 1 with DataHolder

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);
}
Also used : Resource(org.kie.workbench.common.forms.migration.tool.Resource) MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) BPMNProcess(org.kie.workbench.common.forms.migration.tool.bpmn.BPMNProcess) Path(org.uberfire.java.nio.file.Path) FieldTypeManager(org.kie.workbench.common.forms.migration.legacy.services.FieldTypeManager) HashMap(java.util.HashMap) Files(org.uberfire.java.nio.file.Files) ArrayList(java.util.ArrayList) Paths(org.uberfire.backend.server.util.Paths) FormsMigrationConstants(org.kie.workbench.common.forms.migration.tool.util.FormsMigrationConstants) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) FileVisitResult(org.uberfire.java.nio.file.FileVisitResult) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) DataHolder(org.kie.workbench.common.forms.migration.legacy.model.DataHolder) Predicate(java.util.function.Predicate) UIDGenerator(org.kie.workbench.common.forms.services.backend.util.UIDGenerator) Set(java.util.Set) JBPMFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel) Collectors(java.util.stream.Collectors) File(java.io.File) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) IOException(org.uberfire.java.nio.IOException) List(java.util.List) FormModel(org.kie.workbench.common.forms.model.FormModel) SimpleFileVisitor(org.uberfire.java.nio.file.SimpleFileVisitor) BPMNAnalyzer(org.kie.workbench.common.forms.migration.tool.bpmn.BPMNAnalyzer) FieldTypeBuilder(org.kie.workbench.common.forms.migration.legacy.services.impl.FieldTypeBuilder) Path(org.uberfire.java.nio.file.Path) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) FieldTypeManager(org.kie.workbench.common.forms.migration.legacy.services.FieldTypeManager) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) JBPMFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel) FormModel(org.kie.workbench.common.forms.model.FormModel) DataHolder(org.kie.workbench.common.forms.migration.legacy.model.DataHolder) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 2 with DataHolder

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;
}
Also used : Field(org.kie.workbench.common.forms.migration.legacy.model.Field) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) TreeSet(java.util.TreeSet) DataHolder(org.kie.workbench.common.forms.migration.legacy.model.DataHolder) NodeList(org.w3c.dom.NodeList) XMLNode(org.kie.workbench.common.forms.migration.legacy.services.impl.util.XMLNode) Node(org.w3c.dom.Node)

Example 3 with DataHolder

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();
}
Also used : Field(org.kie.workbench.common.forms.migration.legacy.model.Field) StringWriter(java.io.StringWriter) DataHolder(org.kie.workbench.common.forms.migration.legacy.model.DataHolder)

Aggregations

DataHolder (org.kie.workbench.common.forms.migration.legacy.model.DataHolder)3 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)3 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)2 File (java.io.File)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 JBPMFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel)1 FieldTypeManager (org.kie.workbench.common.forms.migration.legacy.services.FieldTypeManager)1 FieldTypeBuilder (org.kie.workbench.common.forms.migration.legacy.services.impl.FieldTypeBuilder)1 XMLNode (org.kie.workbench.common.forms.migration.legacy.services.impl.util.XMLNode)1 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)1 Resource (org.kie.workbench.common.forms.migration.tool.Resource)1 BPMNAnalyzer (org.kie.workbench.common.forms.migration.tool.bpmn.BPMNAnalyzer)1 BPMNProcess (org.kie.workbench.common.forms.migration.tool.bpmn.BPMNProcess)1