Search in sources :

Example 1 with SourceFormModelNotFoundException

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

the class FormEditorServiceImplTest method testConstructContentWithCheckModelFailure.

@Test
public void testConstructContentWithCheckModelFailure() throws IOException, SourceFormModelNotFoundException {
    SourceFormModelNotFoundException exception = new SourceFormModelNotFoundException("exception", null, "exception", null, "model", null);
    doThrow(exception).when(dataObjectFormModelHandler).checkSourceModel();
    String formContent = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("test.frm")));
    when(ioService.readAllString(any())).thenReturn(formContent);
    FormModelerContent content = formEditorService.constructContent(path, overview);
    verify(modelHandlerManager).getFormModelHandler(any());
    verify(dataObjectFormModelHandler).init(any(), any());
    verify(dataObjectFormModelHandler).checkSourceModel();
    verify(dataObjectFormModelHandler, never()).synchronizeFormModel();
    verify(resourceOpenedEvent).fire(any());
    assertNotNull(content);
    assertNotNull(content.getError());
    assertEquals(exception.getShortKey(), content.getError().getShortKey());
    assertArrayEquals(exception.getShortKeyParams(), content.getError().getShortKeyParams());
    assertEquals(exception.getLongKey(), content.getError().getLongKey());
    assertArrayEquals(exception.getLongKeyParams(), content.getError().getLongKeyParams());
}
Also used : InputStreamReader(java.io.InputStreamReader) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) SourceFormModelNotFoundException(org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 2 with SourceFormModelNotFoundException

use of org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException 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)

Aggregations

FormModelerContent (org.kie.workbench.common.forms.editor.model.FormModelerContent)2 SourceFormModelNotFoundException (org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException)2 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)1 FormModelerContentError (org.kie.workbench.common.forms.editor.model.FormModelerContentError)1 FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)1 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)1 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1 FormModel (org.kie.workbench.common.forms.model.FormModel)1 Mockito.anyString (org.mockito.Mockito.anyString)1 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1 ResourceOpenedEvent (org.uberfire.workbench.events.ResourceOpenedEvent)1