PipelineModel implements HasChangeDataHandlers<PipelineModel> { public PipelineElement addElement(final PipelineElement parent, final PipelineElementType elementType, final String id) throws PipelineModelException { PipelineElement element; if (id == null || id.length() == 0) { throw new PipelineModelException("No id has been set for this element"); } else if (elementType == null) { throw new PipelineModelException("No element type has been chosen"); } else if (parent == null) { throw new PipelineModelException("No parent element has been selected"); } else { if (combinedData.getElements().containsKey(id)) { throw new PipelineModelException("An element with this id already exists"); } element = PipelineDataUtil.createElement(id, elementType.getType()); element.setElementType(elementType); if (pipelineData.getRemovedElements().contains(element)) { throw new PipelineModelException( "Attempt to add an element with an id that matches a hidden element. Restore the existing element if required or change the element id."); } pipelineData.addElement(element); pipelineData.addLink(PipelineDataUtil.createLink(parent.getId(), id)); buildCombinedData(); refresh(); } return element; } PipelineModel(); void build(); PipelineData diff(); List<PipelineElement> getRemovedElements(); Map<PipelineElement, List<PipelineElement>> getChildMap(); Map<PipelineElement, PipelineElement> getParentMap(); PipelineElement addElement(final PipelineElement parent, final PipelineElementType elementType,
                                      final String id); boolean moveElement(final PipelineElement parent, final PipelineElement child); void removeElement(final PipelineElement element); List<PipelineProperty> getProperties(final PipelineElement element); PipelineDataMerger getBaseData(); void setBaseStack(final List<PipelineData> baseStack); PipelineData getPipelineData(); void setPipelineData(final PipelineData pipelineData); @Override HandlerRegistration addChangeDataHandler(final ChangeDataHandler<PipelineModel> handler); @Override void fireEvent(final GwtEvent<?> event); static final PipelineElement SOURCE_ELEMENT; }
@Test void testSimple() { final PipelineData pipelineData = new PipelineData(); pipelineData.addElement(ELEM_TYPE, "test1"); pipelineData.addElement(ELEM_TYPE, "test2"); pipelineData.addLink("test1", "test2"); test(null, pipelineData, 2, 0, 0, 0, 0, 0, 1, 0); }
@Test void testUnknownElement() { final PipelineData pipelineData = new PipelineData(); pipelineData.addElement(ELEM_TYPE, "test"); pipelineData.addLink("unknown", "test"); test(null, pipelineData, 0, 0, 0, 0, 0, 0, 0, 0); }
@Test void testInheritanceAdditive() { final List<PipelineData> baseStack = new ArrayList<>(); final PipelineData base = new PipelineData(); base.addElement(ELEM_TYPE, "test1"); base.addElement(ELEM_TYPE, "test2"); base.addLink("test1", "test2"); baseStack.add(base); final PipelineData override = new PipelineData(); override.addElement(ELEM_TYPE, "test3"); override.addLink("test2", "test3"); test(baseStack, override, 1, 0, 0, 0, 0, 0, 1, 0); }
@Test void testInheritancePropertiesSame() { final List<PipelineData> baseStack = new ArrayList<>(); final PipelineData base = new PipelineData(); base.addElement(ELEM_TYPE, "test1"); base.addElement(ELEM_TYPE, "test2"); base.addProperty("test1", PROP_TYPE1, false); base.addLink("test1", "test2"); baseStack.add(base); final PipelineData override = new PipelineData(); override.addProperty("test1", PROP_TYPE1, false); test(baseStack, override, 0, 0, 1, 0, 0, 0, 0, 0); }
@Test void testInheritancePropertiesDiff() { final List<PipelineData> baseStack = new ArrayList<>(); final PipelineData base = new PipelineData(); base.addElement(ELEM_TYPE, "test1"); base.addElement(ELEM_TYPE, "test2"); base.addProperty("test1", PROP_TYPE1, false); base.addLink("test1", "test2"); baseStack.add(base); final PipelineData override = new PipelineData(); override.addProperty("test1", PROP_TYPE1, true); test(baseStack, override, 0, 0, 1, 0, 0, 0, 0, 0); }
@Test void testInheritancePropertiesRemove() { final List<PipelineData> baseStack = new ArrayList<>(); final PipelineData base = new PipelineData(); base.addElement(ELEM_TYPE, "test1"); base.addElement(ELEM_TYPE, "test2"); base.addProperty("test1", PROP_TYPE1, false); base.addLink("test1", "test2"); baseStack.add(base); final PipelineData override = new PipelineData(); override.removeProperty("test1", PROP_TYPE1); test(baseStack, override, 0, 0, 0, 1, 0, 0, 0, 0); }
@Test void testInheritanceRefsSame() { final DocRef pipeline = new DocRef(PipelineDoc.DOCUMENT_TYPE, "1"); final DocRef feed = new DocRef(FeedDoc.DOCUMENT_TYPE, "1"); final List<PipelineData> baseStack = new ArrayList<>(); final PipelineData base = new PipelineData(); base.addElement(ELEM_TYPE, "test1"); base.addElement(ELEM_TYPE, "test2"); base.addPipelineReference( PipelineDataUtil.createReference("test1", "testProp", pipeline, feed, StreamTypeNames.EVENTS)); base.addLink("test1", "test2"); baseStack.add(base); final PipelineData override = new PipelineData(); override.addPipelineReference( PipelineDataUtil.createReference("test1", "testProp", pipeline, feed, StreamTypeNames.EVENTS)); test(baseStack, override, 0, 0, 0, 0, 1, 0, 0, 0); }
@Test void testInheritanceRefsDiff() { final DocRef pipeline = new DocRef(PipelineDoc.DOCUMENT_TYPE, "1"); final DocRef feed = new DocRef(FeedDoc.DOCUMENT_TYPE, "1"); final List<PipelineData> baseStack = new ArrayList<>(); final PipelineData base = new PipelineData(); base.addElement(ELEM_TYPE, "test1"); base.addElement(ELEM_TYPE, "test2"); base.addPipelineReference( PipelineDataUtil.createReference("test1", "testProp", pipeline, feed, StreamTypeNames.EVENTS)); base.addLink("test1", "test2"); baseStack.add(base); final PipelineData override = new PipelineData(); override.addPipelineReference( PipelineDataUtil.createReference("test1", "testProp", pipeline, feed, StreamTypeNames.REFERENCE)); test(baseStack, override, 0, 0, 0, 0, 1, 0, 0, 0); }
@Test void testInheritanceRefsRemove() { final DocRef pipeline = new DocRef(PipelineDoc.DOCUMENT_TYPE, "1"); final DocRef feed = new DocRef(FeedDoc.DOCUMENT_TYPE, "1"); final List<PipelineData> baseStack = new ArrayList<>(); final PipelineData base = new PipelineData(); base.addElement(ELEM_TYPE, "test1"); base.addElement(ELEM_TYPE, "test2"); base.addPipelineReference( PipelineDataUtil.createReference("test1", "testProp", pipeline, feed, StreamTypeNames.EVENTS)); base.addLink("test1", "test2"); baseStack.add(base); final PipelineData override = new PipelineData(); override.removePipelineReference( PipelineDataUtil.createReference("test1", "testProp", pipeline, feed, StreamTypeNames.EVENTS)); test(baseStack, override, 0, 0, 0, 0, 0, 1, 0, 0); }