Search in sources :

Example 6 with FormModelerContent

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

the class FormEditorServiceImplTest method testRename.

private void testRename(boolean saveBeforeRenaming) {
    FormModelerContent content = mock(FormModelerContent.class);
    doReturn(path).when(formEditorService).save(any(Path.class), any(FormModelerContent.class), any(Metadata.class), anyString());
    doReturn(content).when(formEditorService).constructContent(any(Path.class), any(Overview.class));
    when(content.getDefinition()).thenReturn(mock(FormDefinition.class));
    Metadata metadata = mock(Metadata.class);
    FormModelerContent resultContent = formEditorService.rename(path, NEW_FORM_NAME, COMMIT_COMMENT, saveBeforeRenaming, content, metadata);
    assertSame(content, resultContent);
    VerificationMode constructContentCalls = saveBeforeRenaming ? never() : times(1);
    verify(formEditorService, constructContentCalls).constructContent(eq(path), any(Overview.class));
    verify(formEditorService).save(eq(path), eq(content), eq(metadata), eq(COMMIT_COMMENT));
    verify(renameService).rename(eq(path), eq(NEW_FORM_NAME), eq(COMMIT_COMMENT));
}
Also used : Path(org.uberfire.backend.vfs.Path) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Overview(org.guvnor.common.services.shared.metadata.model.Overview) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) VerificationMode(org.mockito.verification.VerificationMode)

Example 7 with FormModelerContent

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

the class FormEditorHelperTest method testGetContent.

@Test
public void testGetContent() {
    FormModelerContent resContent = formEditorHelper.getContent();
    assertEquals(resContent, content);
}
Also used : FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) Test(org.junit.Test)

Example 8 with FormModelerContent

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

the class FormEditorPresenterAbstractTest method loadContent.

protected void loadContent() {
    when(formDefinitionResourceType.getSuffix()).thenReturn("form.frm");
    when(formDefinitionResourceType.accept(path)).thenReturn(true);
    when(editorFieldLayoutComponents.get()).thenAnswer(invocationOnMock -> mock(EditorFieldLayoutComponent.class));
    when(formEditorService.loadContent(any())).then(invocation -> serviceLoad());
    editorServiceCallerMock = new CallerMock<>(formEditorService);
    editorHelper = spy(new TestFormEditorHelper(fieldManager, editorFieldLayoutComponents));
    when(layoutEditorMock.getLayout()).thenReturn(new LayoutTemplate());
    when(menuBuilderMock.addSave(any(MenuItem.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addCopy(any(ObservablePath.class), any(DefaultFileNameValidator.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addRename(any(ObservablePath.class), any(DefaultFileNameValidator.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addRename(any(Command.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addDelete(any(ObservablePath.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addNewTopLevelMenu(any(MenuItem.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.build()).thenReturn(mock(Menus.class));
    when(versionRecordManager.getCurrentPath()).thenReturn(path);
    when(translationService.format(anyString(), anyString())).thenReturn("");
    showAssetUsagesDisplayer = spy(new ShowAssetUsagesDisplayer(assetUsagesDisplayerView, translationService, new CallerMock<>(assetsUsagService)));
    when(assetUsagesDisplayerView.getDefaultMessageContainer()).thenReturn(mock(HTMLElement.class));
    when(assetsUsagService.getAssetUsages(anyString(), any(), any())).thenReturn(assetUsages);
    deletePopUpPresenter = spy(new DeletePopUpPresenter(deletePopUpView, toggleCommentPresenter));
    presenter = new FormEditorPresenter(view, modelChangesDisplayer, formDefinitionResourceType, editorServiceCallerMock, translationService, editorFieldLayoutComponents, showAssetUsagesDisplayer) {

        {
            kieView = mock(KieEditorWrapperView.class);
            versionRecordManager = FormEditorPresenterAbstractTest.this.versionRecordManager;
            editorHelper = FormEditorPresenterAbstractTest.this.editorHelper;
            busyIndicatorView = mock(BusyIndicatorView.class);
            overviewWidget = mock(OverviewWidgetPresenter.class);
            layoutEditor = layoutEditorMock;
            layoutDragComponentPalette = layoutDragComponentPaletteMock;
            layoutFocusEvent = layoutFocusEventMock;
            htmlLayoutDragComponent = FormEditorPresenterAbstractTest.this.htmlLayoutDragComponent;
            notification = notificationEvent;
            fileMenuBuilder = menuBuilderMock;
            workbenchContext = FormEditorPresenterAbstractTest.this.workbenchContext;
            projectController = FormEditorPresenterAbstractTest.this.projectController;
            deletePopUpPresenter = FormEditorPresenterAbstractTest.this.deletePopUpPresenter;
            renamePopUpPresenter = FormEditorPresenterAbstractTest.this.renamePopUpPresenter;
            alertsButtonMenuItemBuilder = FormEditorPresenterAbstractTest.this.alertsButtonMenuItemBuilder;
            formEditorContext = mock(FormEditorContext.class);
        }

        @Override
        public void doLoadContent(FormModelerContent content) {
            super.doLoadContent(content);
            employeeFields.addAll(editorHelper.getAvailableFields().values());
        }

        @Override
        protected void addSourcePage() {
        }
    };
    presenter.onStartup(path, mock(PlaceRequest.class));
    assertTrue("There should exist base field draggables", editorHelper.getBaseFieldsDraggables().size() > 0);
}
Also used : PlaceRequest(org.uberfire.mvp.PlaceRequest) ShowAssetUsagesDisplayer(org.kie.workbench.common.services.refactoring.client.usages.ShowAssetUsagesDisplayer) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) HTMLElement(org.jboss.errai.common.client.dom.HTMLElement) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent) MenuItem(org.uberfire.workbench.model.menu.MenuItem) DefaultFileNameValidator(org.uberfire.ext.editor.commons.client.validation.DefaultFileNameValidator) DeletePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.DeletePopUpPresenter) Command(org.uberfire.mvp.Command) Menus(org.uberfire.workbench.model.menu.Menus) TestFormEditorHelper(org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper) ObservablePath(org.uberfire.backend.vfs.ObservablePath)

Example 9 with FormModelerContent

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

the class FormEditorServiceImpl method rename.

@Override
public FormModelerContent rename(Path path, String newFileName, String commitMessage, boolean saveBeforeRenaming, FormModelerContent content, Metadata metadata) {
    FormModelerContent contentToSave = content;
    if (!saveBeforeRenaming) {
        contentToSave = constructContent(path, content.getOverview());
    }
    contentToSave.getDefinition().setName(newFileName);
    save(path, contentToSave, metadata, commitMessage);
    renameService.rename(path, newFileName, commitMessage);
    return contentToSave;
}
Also used : FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent)

Example 10 with FormModelerContent

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

the class FormEditorServiceImpl method constructContent.

@Override
protected FormModelerContent constructContent(Path path, Overview overview) {
    try {
        org.uberfire.java.nio.file.Path kiePath = Paths.convert(path);
        FormDefinition form = findForm(kiePath);
        FormModelerContent formModelConent = new FormModelerContent();
        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, path);
            if (modelHandlerOptional.isPresent()) {
                FormModelHandler formModelHandler = modelHandlerOptional.get();
                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);
            }
        }
        resourceOpenedEvent.fire(new ResourceOpenedEvent(path, sessionInfo));
        return formModelConent;
    } catch (Exception e) {
        log.warn("Error loading form " + path.toURI(), e);
    }
    return null;
}
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) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FormModel(org.kie.workbench.common.forms.model.FormModel) 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)

Aggregations

FormModelerContent (org.kie.workbench.common.forms.editor.model.FormModelerContent)10 Overview (org.guvnor.common.services.shared.metadata.model.Overview)4 TestFieldManager (org.kie.workbench.common.forms.fields.test.TestFieldManager)3 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)3 Test (org.junit.Test)2 FormEditorHelper (org.kie.workbench.common.forms.editor.client.editor.FormEditorHelper)2 EditorFieldLayoutComponent (org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)2 TestFormEditorHelper (org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper)2 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)2 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 ArrayList (java.util.ArrayList)1 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)1 HTMLElement (org.jboss.errai.common.client.dom.HTMLElement)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 RunWith (org.junit.runner.RunWith)1 StaticFormLayoutTemplateGenerator (org.kie.workbench.common.forms.commons.shared.layout.impl.StaticFormLayoutTemplateGenerator)1 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)1 TypeConflictImpl (org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl)1 FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)1