Search in sources :

Example 6 with Form

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);
}
Also used : Path(org.uberfire.java.nio.file.Path) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 7 with Form

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);
}
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 8 with Form

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);
    });
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) IntStream(java.util.stream.IntStream)

Example 9 with Form

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);
    });
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) IntStream(java.util.stream.IntStream)

Example 10 with Form

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;
}
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)

Aggregations

Form (org.kie.workbench.common.forms.migration.legacy.model.Form)13 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)10 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)7 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)6 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)6 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)6 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)5 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)5 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)5 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)5 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)5 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)5 IntStream (java.util.stream.IntStream)4 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)4 MigrationContext (org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Resource (org.kie.workbench.common.forms.migration.tool.Resource)3 Path (org.uberfire.backend.vfs.Path)3 File (java.io.File)2