Search in sources :

Example 1 with FormModelerContentError

use of org.kie.workbench.common.forms.editor.model.FormModelerContentError in project kie-wb-common by kiegroup.

the class ErrorMessageDisplayerTest method fullMessageTest.

@Test
public void fullMessageTest() {
    verify(view).init(displayer);
    FormModelerContentError error = new FormModelerContentError(MESSAGE, new String[1], FULL_MESSAGE, new String[1], SOURCE_TYPE);
    displayer.show(error, closeCommand);
    verify(translationService).format(eq(MESSAGE), any());
    verify(translationService).format(eq(FULL_MESSAGE), any());
    verify(translationService).getTranslation(eq(SOURCE_TYPE));
    verify(view).setSourceType(eq(SOURCE_TYPE));
    verify(view).displayShowMoreAnchor(true);
    verify(translationService, times(1)).getTranslation(FormEditorConstants.ShowMoreLabel);
    verify(view, times(1)).setShowMoreLabel(any());
    verify(view).show(MESSAGE);
    displayer.notifyShowMorePressed();
    verify(view, times(1)).show(eq(FULL_MESSAGE));
    verify(translationService, times(1)).getTranslation(FormEditorConstants.ShowLessLabel);
    verify(view, times(2)).setShowMoreLabel(any());
    displayer.notifyShowMorePressed();
    verify(view, times(2)).show(eq(MESSAGE));
    verify(translationService, times(2)).getTranslation(FormEditorConstants.ShowMoreLabel);
    verify(view, times(3)).setShowMoreLabel(any());
    displayer.notifyShowMorePressed();
    verify(view, times(2)).show(eq(FULL_MESSAGE));
    verify(translationService, times(2)).getTranslation(FormEditorConstants.ShowLessLabel);
    verify(view, times(4)).setShowMoreLabel(any());
    displayer.notifyClose();
    verify(closeCommand, never()).execute();
    when(view.isClose()).thenReturn(true);
    displayer.notifyClose();
    verify(closeCommand).execute();
}
Also used : FormModelerContentError(org.kie.workbench.common.forms.editor.model.FormModelerContentError) Test(org.junit.Test)

Example 2 with FormModelerContentError

use of org.kie.workbench.common.forms.editor.model.FormModelerContentError in project kie-wb-common by kiegroup.

the class FormEditorPresenter method doLoadContent.

public void doLoadContent(final FormModelerContent content) {
    busyIndicatorView.hideBusyIndicator();
    // Clear LayoutEditor before loading new content.
    if (editorHelper.getContent() != null) {
        layoutEditor.clear();
    }
    editorHelper.initHelper(content);
    resetEditorPages(content.getOverview());
    view.init(this);
    if (content.getError() != null) {
        FormModelerContentError error = content.getError();
        errorMessageDisplayer.show(error, () -> placeManager.forceClosePlace(place));
        errorMessageDisplayer.enableContinue(content.getDefinition() != null);
    }
    if (content.getDefinition() != null) {
        loadEditor(content);
    }
}
Also used : FormModelerContentError(org.kie.workbench.common.forms.editor.model.FormModelerContentError)

Example 3 with FormModelerContentError

use of org.kie.workbench.common.forms.editor.model.FormModelerContentError 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 FormModelerContentError

use of org.kie.workbench.common.forms.editor.model.FormModelerContentError in project kie-wb-common by kiegroup.

the class ErrorMessageDisplayerTest method simpleMessageTest.

@Test
public void simpleMessageTest() {
    verify(view).init(displayer);
    FormModelerContentError error = new FormModelerContentError(MESSAGE, null, null, null, SOURCE_TYPE);
    displayer.show(error, closeCommand);
    verify(translationService).getTranslation(MESSAGE);
    verify(translationService).getTranslation(SOURCE_TYPE);
    verify(view).setSourceType(eq(SOURCE_TYPE));
    verify(view).displayShowMoreAnchor(false);
    verify(view, never()).setShowMoreLabel(any());
    verify(view).show(eq(MESSAGE));
    displayer.notifyShowMorePressed();
    verify(view, times(1)).show(any());
    verify(translationService, never()).getTranslation(FormEditorConstants.ShowLessLabel);
    verify(view, never()).setShowMoreLabel(any());
    displayer.notifyShowMorePressed();
    verify(view, times(1)).show(any());
    verify(translationService, never()).getTranslation(FormEditorConstants.ShowMoreLabel);
    verify(view, never()).setShowMoreLabel(any());
}
Also used : FormModelerContentError(org.kie.workbench.common.forms.editor.model.FormModelerContentError) Test(org.junit.Test)

Aggregations

FormModelerContentError (org.kie.workbench.common.forms.editor.model.FormModelerContentError)4 Test (org.junit.Test)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)1 FormModelerContent (org.kie.workbench.common.forms.editor.model.FormModelerContent)1 FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)1 SourceFormModelNotFoundException (org.kie.workbench.common.forms.editor.service.backend.SourceFormModelNotFoundException)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 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1 ResourceOpenedEvent (org.uberfire.workbench.events.ResourceOpenedEvent)1