Search in sources :

Example 1 with FormModel

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

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;
}
Also used : TypeConflictImpl(org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl) ModuleClassLoaderHelper(org.kie.workbench.common.services.backend.project.ModuleClassLoaderHelper) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) FormModelSynchronizationResultImpl(org.kie.workbench.common.forms.editor.model.impl.FormModelSynchronizationResultImpl) ArrayList(java.util.ArrayList) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) List(java.util.List) FormModel(org.kie.workbench.common.forms.model.FormModel) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) ModelPropertiesGenerator(org.kie.workbench.common.forms.service.backend.util.ModelPropertiesGenerator) Optional(java.util.Optional) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) Path(org.uberfire.backend.vfs.Path) TypeConflictImpl(org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl) FormModelSynchronizationResultImpl(org.kie.workbench.common.forms.editor.model.impl.FormModelSynchronizationResultImpl) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty)

Example 3 with FormModel

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);
}
Also used : Path(org.uberfire.backend.vfs.Path) FormModel(org.kie.workbench.common.forms.model.FormModel) Test(org.junit.Test)

Example 4 with FormModel

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) {
    }
}
Also used : FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FormModel(org.kie.workbench.common.forms.model.FormModel) Test(org.junit.Test)

Example 5 with FormModel

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;
}
Also used : Expense(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.model.Expense) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel) FormModel(org.kie.workbench.common.forms.model.FormModel) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) Matchers.anyString(org.mockito.Matchers.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)

Aggregations

FormModel (org.kie.workbench.common.forms.model.FormModel)11 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 DataObjectFormModel (org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)2 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)2 FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)2 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)2 Path (org.uberfire.backend.vfs.Path)2 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 DataBindingEditor (org.kie.workbench.common.forms.editor.client.editor.properties.binding.DataBindingEditor)1 DynamicFormModel (org.kie.workbench.common.forms.editor.client.editor.properties.binding.DynamicFormModel)1 StaticFormModel (org.kie.workbench.common.forms.editor.client.editor.properties.binding.StaticFormModel)1