Search in sources :

Example 6 with MigrateResult

use of org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult in project kie-wb-common by kiegroup.

the class IntegrationServiceImplTest method testMigrateFromStunnerToJBPMDesignerFileAlreadyExists.

@Test
public void testMigrateFromStunnerToJBPMDesignerFileAlreadyExists() {
    MigrateRequest request = MigrateRequest.newFromStunnerToJBPMDesigner(path, NEW_FILE_NAME, NEW_EXTENSION, COMMIT_MESSAGE);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
    MigrateResult result = service.migrateDiagram(request);
    verify(ioService, never()).move(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.Path.class), any(CommentedOption.class));
    verify(ioService, never()).startBatch(any(FileSystem.class));
    verify(ioService, never()).endBatch();
    assertTrue(result.hasError());
    assertEquals(IntegrationService.ServiceError.JBPM_DESIGNER_PROCESS_ALREADY_EXIST, result.getError());
    assertEquals(IntegrationService.ServiceError.JBPM_DESIGNER_PROCESS_ALREADY_EXIST.i18nKey(), result.getMessageKey());
    assertEquals(1, result.getMessageArguments().size());
    assertEquals(path.toString(), result.getMessageArguments().get(0).toString());
}
Also used : Path(org.uberfire.backend.vfs.Path) MigrateResult(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) MigrateRequest(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateRequest) Test(org.junit.Test)

Example 7 with MigrateResult

use of org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult in project kie-wb-common by kiegroup.

the class IntegrationServiceImpl method migrateFromJBPMDesignerToStunner.

private MigrateResult migrateFromJBPMDesignerToStunner(final MigrateRequest request) {
    validateRequest(request);
    final org.uberfire.java.nio.file.Path _path = Paths.convert(request.getPath());
    final org.uberfire.java.nio.file.Path _target = _path.resolveSibling(request.getNewName() + request.getNewExtension());
    final Path target = Paths.convert(_target);
    if (ioService.exists(_target)) {
        return new MigrateResult(target, STUNNER_PROCESS_ALREADY_EXIST, STUNNER_PROCESS_ALREADY_EXIST.i18nKey(), Collections.singletonList(request.getPath()));
    }
    request.getProjectDiagram().getMetadata().setPath(target);
    request.getProjectDiagram().getMetadata().setTitle(request.getNewName());
    diagramService.saveOrUpdate(request.getProjectDiagram());
    return new MigrateResult(target);
}
Also used : Path(org.uberfire.backend.vfs.Path) MigrateResult(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult)

Example 8 with MigrateResult

use of org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult in project kie-wb-common by kiegroup.

the class IntegrationServiceImpl method migrateFromStunnerToJBPMDesigner.

private MigrateResult migrateFromStunnerToJBPMDesigner(final MigrateRequest request) {
    validateRequest(request);
    final org.uberfire.java.nio.file.Path _path = Paths.convert(request.getPath());
    final org.uberfire.java.nio.file.Path _target = resolveTargetPath(_path, request.getNewName(), request.getNewExtension());
    final Path target = Paths.convert(_target);
    if (ioService.exists(_target)) {
        return new MigrateResult(target, JBPM_DESIGNER_PROCESS_ALREADY_EXIST, JBPM_DESIGNER_PROCESS_ALREADY_EXIST.i18nKey(), Collections.singletonList(request.getPath()));
    }
    try {
        ioService.startBatch(_target.getFileSystem());
        ioService.move(_path, _target, optionFactory.makeCommentedOption(request.getCommitMessage()));
    } catch (Exception e) {
        final String message = String.format("An error was produced during diagram migration from Stunner to jBPMDesigner for diagram: %s", request.getPath());
        LOGGER.error(message, e);
        throw new RuntimeException(message, e);
    } finally {
        ioService.endBatch();
    }
    return new MigrateResult(target);
}
Also used : Path(org.uberfire.backend.vfs.Path) MigrateResult(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult)

Example 9 with MigrateResult

use of org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult in project kie-wb-common by kiegroup.

the class IntegrationHandlerImplTest method testMigrateFromStunnerToJBPMDesignerSuccessful.

private void testMigrateFromStunnerToJBPMDesignerSuccessful(boolean isDirty) {
    MigrateRequest expectedRequest = MigrateRequest.newFromStunnerToJBPMDesigner(stunnerPath, STUNNER_NAME, BPMN2_EXTENSION, ToJBPMCommitMessage);
    Path resultPath = mock(Path.class);
    MigrateResult result = new MigrateResult(resultPath, null, null, null);
    when(integrationService.migrateDiagram(expectedRequest)).thenReturn(result);
    handler.migrateFromStunnerToJBPMDesigner(stunnerPath, place, isDirty, saveSuccessfulCommand);
    verifySavePopupWasShownAndRespond(isDirty, true);
    verifyUserWasAskedForStartingToJBPMMigrationAndRespond(true);
    verifyMigrationFinished();
}
Also used : Path(org.uberfire.backend.vfs.Path) MigrateResult(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult) MigrateRequest(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateRequest)

Example 10 with MigrateResult

use of org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult in project kie-wb-common by kiegroup.

the class IntegrationHandlerImplTest method testMigrateFromJBPMDesignerToStunnerMarshallingWithErrors.

private void testMigrateFromJBPMDesignerToStunnerMarshallingWithErrors(boolean isDirty) {
    List<MarshallingMessage> messages = Arrays.asList(mock(MarshallingMessage.class), mock(MarshallingMessage.class));
    prepareMigrateFromJBPMDesignerToStunner(MarshallingResponse.State.ERROR, messages);
    MigrateRequest expectedRequest = MigrateRequest.newFromJBPMDesignerToStunner(jbpmPath, JBPM_NAME, BPMN_EXTENSION, ToStunnerCommitMessage, projectDiagram);
    MigrateResult result = new MigrateResult(null, IntegrationService.ServiceError.JBPM_DESIGNER_PROCESS_ALREADY_EXIST, "messageKey", new ArrayList<>());
    when(integrationService.migrateDiagram(expectedRequest)).thenReturn(result);
    handler.migrateFromJBPMDesignerToStunner(jbpmPath, place, isDirty, saveSuccessfulCommand);
    // ask user for saving and say yes.
    verifySavePopupWasShownAndRespond(isDirty, true);
    // ask user for starting the migration and say yes
    verifyUserWasAskedForStartingToStunnerMigrationAndRespond(true);
    verifyMarshallingResponseWithErrorsWereShown(messages);
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) MigrateResult(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult) MigrateRequest(org.kie.workbench.common.stunner.bpmn.integration.service.MigrateRequest)

Aggregations

MigrateResult (org.kie.workbench.common.stunner.bpmn.integration.service.MigrateResult)11 Path (org.uberfire.backend.vfs.Path)10 MigrateRequest (org.kie.workbench.common.stunner.bpmn.integration.service.MigrateRequest)9 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 ProjectDiagram (org.kie.workbench.common.stunner.project.diagram.ProjectDiagram)2 ProjectMetadata (org.kie.workbench.common.stunner.project.diagram.ProjectMetadata)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 FileSystem (org.uberfire.java.nio.file.FileSystem)2 MarshallingMessage (org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage)1 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)1