ConfigurationAlgorithm { static void removeTrivialGateway(final Definitions definitions, final Gateway gateway) { final SequenceFlow incomingFlow = gateway.getIncomingSequenceFlows().get(0), outgoingFlow = gateway.getOutgoingSequenceFlows().get(0); Map<BaseElement, DiagramElement> bpmndiMap = findBpmndiMap(definitions); assert bpmndiMap.containsKey(incomingFlow); assert bpmndiMap.containsKey(outgoingFlow); ((de.hpi.bpmn2_0.model.bpmndi.di.Edge) bpmndiMap.get(incomingFlow)).getWaypoint().addAll( ((de.hpi.bpmn2_0.model.bpmndi.di.Edge) bpmndiMap.get(outgoingFlow)).getWaypoint() ); incomingFlow.setTargetRef(outgoingFlow.getTargetRef()); for (Edge edge : outgoingFlow.getIncoming()) { assert edge.getTargetRef() == outgoingFlow; edge.setTargetRef(incomingFlow); incomingFlow.getIncoming().add(edge); } outgoingFlow.getIncoming().clear(); for (Edge edge : outgoingFlow.getOutgoing()) { assert edge.getSourceRef() == outgoingFlow; edge.setSourceRef(incomingFlow); incomingFlow.getOutgoing().add(edge); } outgoingFlow.getOutgoing().clear(); for (final BaseElement rootElement : definitions.getRootElement()) { if (rootElement instanceof Process) { final Process process = (Process) rootElement; for (final FlowElement flowElement : new ArrayList<FlowElement>(process.getFlowElement())) { substituteReferences(flowElement, Collections.singleton((BaseElement) outgoingFlow), incomingFlow); } } } Set<BaseElement> pruningSet = new HashSet<BaseElement>(); pruningSet.add(gateway); pruningSet.add(outgoingFlow); prune(definitions, pruningSet); }  static void configure(final Definitions definitions); static Map<BaseElement, DiagramElement> findBpmndiMap(final Definitions definitions); static Set<Gateway> findConfiguredGateways(final Definitions definitions); static Set<SequenceFlow> findAbsentSequenceFlows(final Set<Gateway> reconfiguredGatewaySet); static void main(final String[] arg);  }
@Test public final void testRemoveTrivialGateway1() throws IOException, JAXBException, SAXException { Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setProperty(IDResolver.class.getName(), new DefinitionsIDResolver()); Definitions definitions = (Definitions) unmarshaller.unmarshal(trivialGatewayFile); Process process = (Process) definitions.getRootElement().get(0); StartEvent monday = (StartEvent) process.getFlowElement().get(0); assertEquals("sid-3A72224F-859B-4BA6-BAF8-8BE8F038EDCA", monday.getId()); SequenceFlow tuesday = (SequenceFlow) process.getFlowElement().get(4); assertEquals("sid-C354ED3F-6C0A-4A04-B25B-AA5A4B63227B", tuesday.getId()); Gateway wednesday = (Gateway) process.getFlowElement().get(1); assertEquals("sid-6A5EAA84-D4F8-4E3B-B5A0-EE93A65D0F10", wednesday.getId()); SequenceFlow thursday = (SequenceFlow) process.getFlowElement().get(3); assertEquals("sid-F73F742A-DF4B-41D6-B0EA-10740E5718ED", thursday.getId()); EndEvent friday = (EndEvent) process.getFlowElement().get(2); assertEquals("sid-1FA55E81-D95D-4288-B8AE-B9739C47766B", friday.getId()); Association tuesdayAssoc = (Association) process.getFlowElement().get(5); assertEquals("sid-DF727F05-4C45-40C3-B4C8-9EECBFAE95AB", tuesdayAssoc.getId()); assertEquals(tuesday, tuesdayAssoc.getTargetRef()); Association thursdayAssoc = (Association) process.getFlowElement().get(6); assertEquals("sid-E2325258-5152-43D4-BBF5-1F58BF541336", thursdayAssoc.getId()); assertEquals(thursday, thursdayAssoc.getTargetRef()); assertEquals(1, tuesday.getIncoming().size()); assertTrue(tuesday.getIncoming().contains(tuesdayAssoc)); BPMNShape wednesdayGui = (BPMNShape) definitions.getDiagram().get(0).getBPMNPlane().getDiagramElement().get(1); assertEquals("sid-6A5EAA84-D4F8-4E3B-B5A0-EE93A65D0F10_gui", wednesdayGui.getId()); assertSame(wednesday, wednesdayGui.getBpmnElement()); ConfigurationAlgorithm.removeTrivialGateway(definitions, wednesday); assertSame(process, definitions.getRootElement().get(0)); assertSame(monday, process.getFlowElement().get(0)); assertSame(tuesday, process.getFlowElement().get(2)); assertSame(friday, process.getFlowElement().get(1)); assertEquals(monday, tuesday.getSourceRef()); assertEquals(friday, tuesday.getTargetRef()); assertEquals(tuesday, tuesdayAssoc.getTargetRef()); assertEquals(tuesday, thursdayAssoc.getTargetRef()); assertEquals(2, tuesday.getIncoming().size()); assertTrue(tuesday.getIncoming().contains(tuesdayAssoc)); assertTrue(tuesday.getIncoming().contains(thursdayAssoc)); assertNotSame(wednesdayGui, definitions.getDiagram().get(0).getBPMNPlane().getDiagramElement().get(1)); }