@Test public void testSwitchView() throws IOException { final DefinitionSetService definitionSetService1 = mock(DefinitionSetService.class); String defSetId = "defSetId"; when(definitionSetService1.accepts(eq(defSetId))).thenReturn(true); tested.definitionSetServices.add(definitionSetService1); final DiagramMarshaller diagramMarsaller1 = mock(DiagramMarshaller.class); String rawData = "rawData"; when(diagramMarsaller1.marshall(any(Diagram.class))).thenReturn(rawData); when(definitionSetService1.getDiagramMarshaller()).thenReturn(diagramMarsaller1); final DefinitionSetService definitionSetService2 = mock(DefinitionSetService.class); String mappedDefSetId = "mappedDefSetId"; when(definitionSetService2.accepts(eq(mappedDefSetId))).thenReturn(true); tested.definitionSetServices.add(definitionSetService2); final DiagramMarshaller diagramMarsaller2 = mock(DiagramMarshaller.class); final Graph graph = mock(Graph.class); final DefinitionSet content = mock(DefinitionSet.class); when(graph.getContent()).thenReturn(content); when(diagramMarsaller2.unmarshall(any(Metadata.class), any(InputStream.class))).thenReturn(graph); when(definitionSetService2.getDiagramMarshaller()).thenReturn(diagramMarsaller2); final FactoryRegistry factoryRegistry = mock(FactoryRegistry.class); final DiagramFactory diagramFactory = mock(DiagramFactory.class); when(factoryRegistry.getDiagramFactory(any(String.class), any(Class.class))).thenReturn(diagramFactory); when(factoryManager.registry()).thenReturn(factoryRegistry); final ProjectDiagram projectDiagram = mock(ProjectDiagram.class); final ProjectMetadata projectMetadata = mock(ProjectMetadata.class); when(projectDiagram.getMetadata()).thenReturn(projectMetadata); when(diagramFactory.build(any(String.class), any(Metadata.class), any(Graph.class))).thenReturn(projectDiagram); final Diagram diagram = mock(Diagram.class); final AbstractMetadata metadata = mock(AbstractMetadata.class); when(diagram.getMetadata()).thenReturn(metadata); when(metadata.getDefinitionSetId()).thenReturn(defSetId); String mappedShapeSetId = "mappedShapeSetId"; Optional<ProjectDiagram> result = tested.switchView(diagram, mappedDefSetId, mappedShapeSetId); assertTrue(result.filter(d -> projectDiagram.equals(d)).isPresent()); verify(metadata).setDefinitionSetId(eq(mappedDefSetId)); verify(projectMetadata).setShapeSetId(eq(mappedShapeSetId)); }
@Override @SuppressWarnings("unchecked") public Optional<ProjectDiagram> switchView(final Diagram diagram, final String mappedDefSetId, final String mappedShapeSetId) { final Metadata metadata = diagram.getMetadata(); final String defSetId = metadata.getDefinitionSetId(); final Optional<DefinitionSetService> definitionSetServiceOptional = definitionSetServices.stream().filter(s -> s.accepts(defSetId)).findAny(); return definitionSetServiceOptional.map(service -> { try { final String rawData = service.getDiagramMarshaller().marshall(diagram); final Optional<DefinitionSetService> mappedDefinitionSetServiceOptional = definitionSetServices.stream() .filter(s -> s.accepts(mappedDefSetId)).findAny(); return mappedDefinitionSetServiceOptional.map(mappedService -> { ((AbstractMetadata) metadata).setDefinitionSetId(mappedDefSetId); try (final InputStream inputStream = new ByteArrayInputStream(rawData.getBytes())) { final Graph<DefinitionSet, Node> graph = mappedService.getDiagramMarshaller().unmarshall(metadata, inputStream); final DiagramFactory factory = factoryManager.registry().getDiagramFactory(graph.getContent().getDefinition(), metadata.getMetadataType()); final ProjectDiagram mappedDiagram = (ProjectDiagram) factory.build(metadata.getTitle(), metadata, graph); mappedDiagram.getMetadata().setShapeSetId(mappedShapeSetId); return mappedDiagram; } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }).orElseGet(() -> CaseManagementSwitchViewServiceImpl.this.handleError(Optional.empty())); } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }); }
CaseManagementSwitchViewServiceImpl implements CaseManagementSwitchViewService { @Override @SuppressWarnings("unchecked") public Optional<ProjectDiagram> switchView(final Diagram diagram, final String mappedDefSetId, final String mappedShapeSetId) { final Metadata metadata = diagram.getMetadata(); final String defSetId = metadata.getDefinitionSetId(); final Optional<DefinitionSetService> definitionSetServiceOptional = definitionSetServices.stream().filter(s -> s.accepts(defSetId)).findAny(); return definitionSetServiceOptional.map(service -> { try { final String rawData = service.getDiagramMarshaller().marshall(diagram); final Optional<DefinitionSetService> mappedDefinitionSetServiceOptional = definitionSetServices.stream() .filter(s -> s.accepts(mappedDefSetId)).findAny(); return mappedDefinitionSetServiceOptional.map(mappedService -> { ((AbstractMetadata) metadata).setDefinitionSetId(mappedDefSetId); try (final InputStream inputStream = new ByteArrayInputStream(rawData.getBytes())) { final Graph<DefinitionSet, Node> graph = mappedService.getDiagramMarshaller().unmarshall(metadata, inputStream); final DiagramFactory factory = factoryManager.registry().getDiagramFactory(graph.getContent().getDefinition(), metadata.getMetadataType()); final ProjectDiagram mappedDiagram = (ProjectDiagram) factory.build(metadata.getTitle(), metadata, graph); mappedDiagram.getMetadata().setShapeSetId(mappedShapeSetId); return mappedDiagram; } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }).orElseGet(() -> CaseManagementSwitchViewServiceImpl.this.handleError(Optional.empty())); } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }); } }
CaseManagementSwitchViewServiceImpl implements CaseManagementSwitchViewService { @Override @SuppressWarnings("unchecked") public Optional<ProjectDiagram> switchView(final Diagram diagram, final String mappedDefSetId, final String mappedShapeSetId) { final Metadata metadata = diagram.getMetadata(); final String defSetId = metadata.getDefinitionSetId(); final Optional<DefinitionSetService> definitionSetServiceOptional = definitionSetServices.stream().filter(s -> s.accepts(defSetId)).findAny(); return definitionSetServiceOptional.map(service -> { try { final String rawData = service.getDiagramMarshaller().marshall(diagram); final Optional<DefinitionSetService> mappedDefinitionSetServiceOptional = definitionSetServices.stream() .filter(s -> s.accepts(mappedDefSetId)).findAny(); return mappedDefinitionSetServiceOptional.map(mappedService -> { ((AbstractMetadata) metadata).setDefinitionSetId(mappedDefSetId); try (final InputStream inputStream = new ByteArrayInputStream(rawData.getBytes())) { final Graph<DefinitionSet, Node> graph = mappedService.getDiagramMarshaller().unmarshall(metadata, inputStream); final DiagramFactory factory = factoryManager.registry().getDiagramFactory(graph.getContent().getDefinition(), metadata.getMetadataType()); final ProjectDiagram mappedDiagram = (ProjectDiagram) factory.build(metadata.getTitle(), metadata, graph); mappedDiagram.getMetadata().setShapeSetId(mappedShapeSetId); return mappedDiagram; } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }).orElseGet(() -> CaseManagementSwitchViewServiceImpl.this.handleError(Optional.empty())); } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }); } @Inject  CaseManagementSwitchViewServiceImpl(final FactoryManager factoryManager,
                                               final Instance<DefinitionSetService> definitionSetServiceInstances); }
CaseManagementSwitchViewServiceImpl implements CaseManagementSwitchViewService { @Override @SuppressWarnings("unchecked") public Optional<ProjectDiagram> switchView(final Diagram diagram, final String mappedDefSetId, final String mappedShapeSetId) { final Metadata metadata = diagram.getMetadata(); final String defSetId = metadata.getDefinitionSetId(); final Optional<DefinitionSetService> definitionSetServiceOptional = definitionSetServices.stream().filter(s -> s.accepts(defSetId)).findAny(); return definitionSetServiceOptional.map(service -> { try { final String rawData = service.getDiagramMarshaller().marshall(diagram); final Optional<DefinitionSetService> mappedDefinitionSetServiceOptional = definitionSetServices.stream() .filter(s -> s.accepts(mappedDefSetId)).findAny(); return mappedDefinitionSetServiceOptional.map(mappedService -> { ((AbstractMetadata) metadata).setDefinitionSetId(mappedDefSetId); try (final InputStream inputStream = new ByteArrayInputStream(rawData.getBytes())) { final Graph<DefinitionSet, Node> graph = mappedService.getDiagramMarshaller().unmarshall(metadata, inputStream); final DiagramFactory factory = factoryManager.registry().getDiagramFactory(graph.getContent().getDefinition(), metadata.getMetadataType()); final ProjectDiagram mappedDiagram = (ProjectDiagram) factory.build(metadata.getTitle(), metadata, graph); mappedDiagram.getMetadata().setShapeSetId(mappedShapeSetId); return mappedDiagram; } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }).orElseGet(() -> CaseManagementSwitchViewServiceImpl.this.handleError(Optional.empty())); } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }); } @Inject  CaseManagementSwitchViewServiceImpl(final FactoryManager factoryManager,
                                               final Instance<DefinitionSetService> definitionSetServiceInstances); @PostConstruct void init(); @Override @SuppressWarnings("unchecked") Optional<ProjectDiagram> switchView(final Diagram diagram, final String mappedDefSetId, final String mappedShapeSetId); }
CaseManagementSwitchViewServiceImpl implements CaseManagementSwitchViewService { @Override @SuppressWarnings("unchecked") public Optional<ProjectDiagram> switchView(final Diagram diagram, final String mappedDefSetId, final String mappedShapeSetId) { final Metadata metadata = diagram.getMetadata(); final String defSetId = metadata.getDefinitionSetId(); final Optional<DefinitionSetService> definitionSetServiceOptional = definitionSetServices.stream().filter(s -> s.accepts(defSetId)).findAny(); return definitionSetServiceOptional.map(service -> { try { final String rawData = service.getDiagramMarshaller().marshall(diagram); final Optional<DefinitionSetService> mappedDefinitionSetServiceOptional = definitionSetServices.stream() .filter(s -> s.accepts(mappedDefSetId)).findAny(); return mappedDefinitionSetServiceOptional.map(mappedService -> { ((AbstractMetadata) metadata).setDefinitionSetId(mappedDefSetId); try (final InputStream inputStream = new ByteArrayInputStream(rawData.getBytes())) { final Graph<DefinitionSet, Node> graph = mappedService.getDiagramMarshaller().unmarshall(metadata, inputStream); final DiagramFactory factory = factoryManager.registry().getDiagramFactory(graph.getContent().getDefinition(), metadata.getMetadataType()); final ProjectDiagram mappedDiagram = (ProjectDiagram) factory.build(metadata.getTitle(), metadata, graph); mappedDiagram.getMetadata().setShapeSetId(mappedShapeSetId); return mappedDiagram; } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }).orElseGet(() -> CaseManagementSwitchViewServiceImpl.this.handleError(Optional.empty())); } catch (IOException e) { return CaseManagementSwitchViewServiceImpl.this.handleError(Optional.of(e)); } }); } @Inject  CaseManagementSwitchViewServiceImpl(final FactoryManager factoryManager,
                                               final Instance<DefinitionSetService> definitionSetServiceInstances); @PostConstruct void init(); @Override @SuppressWarnings("unchecked") Optional<ProjectDiagram> switchView(final Diagram diagram, final String mappedDefSetId, final String mappedShapeSetId);  }