Search in sources :

Example 6 with Resource

use of org.kie.workbench.common.forms.migration.tool.Resource in project kie-wb-common by kiegroup.

the class FormDefinitionGeneratorWithUnsupportedFieldsTest method doInit.

@Override
protected void doInit() throws Exception {
    List<FormMigrationSummary> summaries = new ArrayList<>();
    initForm(form -> userForm = form, DATAOBJECTS_RESOURCES, USER_WITH_UNSUPPORTED_FIELDS, userFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(userForm, userFormPath)));
    context = new MigrationContext(workspaceProject, weldContainer, migrationServicesCDIWrapper, new RealSystemAccess(), summaries);
}
Also used : MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) RealSystemAccess(org.kie.workbench.common.migration.cli.RealSystemAccess) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) ArrayList(java.util.ArrayList) Resource(org.kie.workbench.common.forms.migration.tool.Resource)

Example 7 with Resource

use of org.kie.workbench.common.forms.migration.tool.Resource 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 Resource

use of org.kie.workbench.common.forms.migration.tool.Resource in project kie-wb-common by kiegroup.

the class AbstractMigrationStep method persist.

private void persist(MigrationContext migrationContext) {
    FormSerializationManager oldFormSerializer = new FormSerializationManagerImpl();
    FormDefinitionSerializer formDefinitionSerializer = migrationContext.getCDIWrapper().getFormDefinitionSerializer();
    Function<Resource<Form>, String> originaldFormSerializationFunction = formResource -> {
        Form originalForm = formResource.get();
        originalForm.setMigrationStep(getStep());
        return oldFormSerializer.generateFormXML(originalForm, migrationContext.getSystem());
    };
    Function<Resource<FormDefinition>, String> newFormSerializationFuncion = formResource -> formDefinitionSerializer.serialize(formResource.get());
    migrationContext.getSummaries().forEach(summary -> {
        if (summary.getResult().isSuccess()) {
            serializeResource(summary.getOriginalForm().getPath(), originaldFormSerializationFunction.apply(summary.getOriginalForm()), migrationContext);
            serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
        }
    });
    migrationContext.getExtraSummaries().forEach(summary -> {
        serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
    });
}
Also used : Resource(org.kie.workbench.common.forms.migration.tool.Resource) FormSerializationManager(org.kie.workbench.common.forms.migration.legacy.services.FormSerializationManager) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) Function(java.util.function.Function) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) Path(org.uberfire.backend.vfs.Path) FormSerializationManagerImpl(org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) FormSerializationManagerImpl(org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl) Resource(org.kie.workbench.common.forms.migration.tool.Resource) FormSerializationManager(org.kie.workbench.common.forms.migration.legacy.services.FormSerializationManager)

Aggregations

Resource (org.kie.workbench.common.forms.migration.tool.Resource)8 ArrayList (java.util.ArrayList)7 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)7 MigrationContext (org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext)7 RealSystemAccess (org.kie.workbench.common.migration.cli.RealSystemAccess)6 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)2 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)2 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 JBPMFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel)1 DataHolder (org.kie.workbench.common.forms.migration.legacy.model.DataHolder)1 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)1 FieldTypeManager (org.kie.workbench.common.forms.migration.legacy.services.FieldTypeManager)1 FormSerializationManager (org.kie.workbench.common.forms.migration.legacy.services.FormSerializationManager)1 FieldTypeBuilder (org.kie.workbench.common.forms.migration.legacy.services.impl.FieldTypeBuilder)1