Search in sources :

Example 1 with FormModelHandler

use of org.kie.workbench.common.forms.editor.service.backend.FormModelHandler in project kie-wb-common by kiegroup.

the class BPMNVFSFormDefinitionGeneratorService method extractModelFields.

@Override
protected List<FieldDefinition> extractModelFields(JavaFormModel formModel, GenerationContext<Path> context) {
    FormModelHandler handler = formModelHandlerManager.getFormModelHandler(formModel.getClass());
    handler.init(formModel, context.getSource());
    handler.synchronizeFormModel();
    return formModel.getProperties().stream().map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toList());
}
Also used : FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)

Example 2 with FormModelHandler

use of org.kie.workbench.common.forms.editor.service.backend.FormModelHandler in project kie-wb-common by kiegroup.

the class BPMNVFSFormDefinitionGeneratorService method createRootFormDefinition.

public FormDefinition createRootFormDefinition(GenerationContext<Path> context) {
    FormModelHandler modelHandler = formModelHandlerManager.getFormModelHandler(context.getFormModel().getClass());
    modelHandler.init(context.getFormModel(), context.getSource());
    final FormDefinition form;
    org.uberfire.java.nio.file.Path kiePath = Paths.convert(context.getSource());
    logger.info("Started form generation for '{}'", kiePath);
    if (ioService.exists(kiePath)) {
        form = formSerializer.deserialize(ioService.readAllString(kiePath));
        logger.warn("Already exists form '{}'. Synchronizing form fields:", kiePath);
        // If the form exists on the VFS let's synchronize form fields
        FormModelSynchronizationResult synchronizationResult = modelHandler.synchronizeFormModelProperties(form.getModel(), context.getFormModel().getProperties());
        formModelSynchronizationUtil.init(form, synchronizationResult);
        if (synchronizationResult.hasRemovedProperties()) {
            logger.warn("Process/Task has removed variables, checking fields:");
            formModelSynchronizationUtil.fixRemovedFields();
        }
        if (synchronizationResult.hasConflicts()) {
            logger.warn("Process/Task has some variables which type has changed. Checking fields:");
            formModelSynchronizationUtil.resolveConflicts();
        }
        if (synchronizationResult.hasNewProperties()) {
            logger.warn("Process/Task has new variables. Adding them to form:");
            formModelSynchronizationUtil.addNewFields(fieldManager::getDefinitionByModelProperty);
        }
        form.setModel(context.getFormModel());
    } else {
        form = new FormDefinition(context.getFormModel());
        form.setId(UIDGenerator.generateUID());
        form.setName(context.getSource().getFileName());
        form.getFields().addAll(context.getFormModel().getProperties().stream().map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toList()));
    }
    form.setModel(context.getFormModel());
    return form;
}
Also used : FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 3 with FormModelHandler

use of org.kie.workbench.common.forms.editor.service.backend.FormModelHandler in project kie-wb-common by kiegroup.

the class FormEditorServiceImpl method constructContent.

@Override
protected FormModelerContent constructContent(Path path, Overview overview) {
    FormModelerContent formModelConent = new FormModelerContent();
    try {
        org.uberfire.java.nio.file.Path kiePath = Paths.convert(path);
        FormDefinition form = findForm(kiePath);
        formModelConent.setDefinition(form);
        formModelConent.setPath(path);
        formModelConent.setOverview(overview);
        FormEditorRenderingContext context = createRenderingContext(form, path);
        formModelConent.setRenderingContext(context);
        if (Optional.ofNullable(form.getModel()).isPresent()) {
            FormModel formModel = form.getModel();
            Optional<FormModelHandler> modelHandlerOptional = getHandlerForForm(form);
            if (modelHandlerOptional.isPresent()) {
                try {
                    FormModelHandler formModelHandler = modelHandlerOptional.get();
                    formModelHandler.init(formModel, path);
                    formModelHandler.checkSourceModel();
                    FormModelSynchronizationResult synchronizationResult = formModelHandler.synchronizeFormModel();
                    formModel.getProperties().forEach(property -> {
                        Optional<FieldDefinition> fieldOptional = Optional.ofNullable(form.getFieldByBinding(property.getName()));
                        if (!fieldOptional.isPresent()) {
                            synchronizationResult.resolveConflict(property.getName());
                        }
                    });
                    formModelConent.setSynchronizationResult(synchronizationResult);
                } catch (SourceFormModelNotFoundException ex) {
                    formModelConent.setError(new FormModelerContentError(ex.getShortKey(), ex.getShortKeyParams(), ex.getLongKey(), ex.getLongKeyParams(), ex.getModelSourceKey()));
                }
            }
        }
    } catch (Exception e) {
        StringWriter writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer));
        formModelConent.setError(new FormModelerContentError(SHORT_KEY, null, LONG_KEY, new String[] { writer.toString() }, null));
        log.warn("Error loading form " + path.toURI(), e);
    }
    resourceOpenedEvent.fire(new ResourceOpenedEvent(path, sessionInfo));
    return formModelConent;
}
Also used : FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) SourceFormModelNotFoundException(org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) StringWriter(java.io.StringWriter) FormModel(org.kie.workbench.common.forms.model.FormModel) FormModelerContentError(org.kie.workbench.common.forms.editor.model.FormModelerContentError) SourceFormModelNotFoundException(org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) PrintWriter(java.io.PrintWriter)

Example 4 with FormModelHandler

use of org.kie.workbench.common.forms.editor.service.backend.FormModelHandler in project kie-wb-common by kiegroup.

the class FormEditorServiceImplTest method init.

@Before
public void init() {
    Instance<FormModelHandler<? extends FormModel>> instances = mock(Instance.class);
    when(dataObjectFormModelHandler.getModelType()).thenReturn(DataObjectFormModel.class);
    when(dataObjectFormModelHandler.newInstance()).thenReturn(dataObjectFormModelHandler);
    List<FormModelHandler> handlers = Arrays.asList(dataObjectFormModelHandler);
    when(instances.iterator()).then(invocationOnMock -> handlers.iterator());
    modelHandlerManager = spy(new FormModelHandlerManagerImpl(instances));
    formDefinitionSerializer = spy(new FormDefinitionSerializerImpl(new FieldSerializer(), new FormModelSerializer(), new TestMetaDataEntryManager()));
    formEditorService = spy(new FormEditorServiceImpl(ioService, sessionInfo, resourceOpenedEvent, fieldManager, modelHandlerManager, moduleService, formDefinitionSerializer, moduleFormFinderService, deleteService, commentedOptionFactory, renameService, copyService));
    when(path.toURI()).thenReturn("file:///src/main/resources/test.frm");
    when(moduleService.resolveModule(any())).thenReturn(module);
}
Also used : FieldSerializer(org.kie.workbench.common.forms.services.backend.serialization.impl.FieldSerializer) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel) FormModel(org.kie.workbench.common.forms.model.FormModel) FormDefinitionSerializerImpl(org.kie.workbench.common.forms.services.backend.serialization.impl.FormDefinitionSerializerImpl) FormModelSerializer(org.kie.workbench.common.forms.services.backend.serialization.impl.FormModelSerializer) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) TestMetaDataEntryManager(org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager) Before(org.junit.Before)

Aggregations

FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)4 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)2 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)2 FormModel (org.kie.workbench.common.forms.model.FormModel)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Before (org.junit.Before)1 DataObjectFormModel (org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)1 FormModelerContent (org.kie.workbench.common.forms.editor.model.FormModelerContent)1 FormModelerContentError (org.kie.workbench.common.forms.editor.model.FormModelerContentError)1 SourceFormModelNotFoundException (org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException)1 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)1 TestMetaDataEntryManager (org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager)1 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)1 FieldSerializer (org.kie.workbench.common.forms.services.backend.serialization.impl.FieldSerializer)1 FormDefinitionSerializerImpl (org.kie.workbench.common.forms.services.backend.serialization.impl.FormDefinitionSerializerImpl)1 FormModelSerializer (org.kie.workbench.common.forms.services.backend.serialization.impl.FormModelSerializer)1 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1 ResourceOpenedEvent (org.uberfire.workbench.events.ResourceOpenedEvent)1