@Override protected void cloneInto(WorkflowBean clone, Cloning cloning) { BlockingControlLink cloneLink = (BlockingControlLink) clone; cloneLink.setBlock(cloning.cloneOrOriginal(getBlock())); cloneLink.setUntilFinished(cloning.cloneOrOriginal(getUntilFinished())); }
/** * Constructs a <code>BlockingControlLink</code> with the specified blocked * and control <code>Processor</code>s. * <p> * The parent {@link Workflow} is set to be the same as the parent of the * block <code>Processor</code>. * * @param block * the <code>Processor</code> that is blocked from starting. * <strong>Must not</strong> be <code>null</code> * @param untilFinished * the <code>Processor</code> that controls the block. Can be * <code>null</code>. */ public BlockingControlLink(Processor block, Processor untilFinished) { setUntilFinished(untilFinished); setBlock(block); setParent(block.getParent()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BlockingControlLink other = (BlockingControlLink) obj; if (getUntilFinished() == null) { if (other.getUntilFinished() != null) return false; } else if (!getUntilFinished().equals(other.getUntilFinished())) return false; if (getParent() == null) { if (other.getParent() != null) return false; } else if (!getParent().equals(other.getParent())) return false; if (getBlock() == null) { if (other.getBlock() != null) return false; } else if (!getBlock().equals(other.getBlock())) return false; return true; }
@Override public String toString() { String blockName = getBlock() != null ? getBlock().getName() : ""; String untilName = getUntilFinished() != null ? getUntilFinished() .getName() : ""; return String.format("%s %s-|%s", getClass().getSimpleName(), untilName, blockName); }
protected void parseControlLink(Blocking original) { URI blockUri = getParserState().getCurrentBase().resolve( original.getBlock().getResource()); URI untilFinishedUri = getParserState().getCurrentBase().resolve( original.getUntilFinished().getResource()); WorkflowBean block = resolveBeanUri(blockUri); WorkflowBean untilFinished = resolveBeanUri(untilFinishedUri); BlockingControlLink blocking = new BlockingControlLink(); blocking.setBlock((org.apache.taverna.scufl2.api.core.Processor) block); blocking.setUntilFinished((org.apache.taverna.scufl2.api.core.Processor) untilFinished); blocking.setParent(getParserState().getCurrent(Workflow.class)); mapBean(getParserState().getCurrentBase().resolve(original.getAbout()), blocking); }
@Test public void testValidlyScopedBlock() { Workflow wf = new Workflow(); BlockingControlLink bcl = new BlockingControlLink(); bcl.setParent(wf); Processor block = new Processor(); block.setParent(wf); bcl.setBlock(block); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(bcl, false, rcvl); Set<OutOfScopeValueProblem> outOfScopeValueProblems = rcvl.getOutOfScopeValueProblems(); assertEquals(0, outOfScopeValueProblems.size()); } }
@Test public void testCorrectnessOfMissingBlock() { BlockingControlLink bcl = new BlockingControlLink(); Processor untilFinished = new Processor(); bcl.setUntilFinished(untilFinished); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(bcl, false, rcvl); assertEquals(0, rcvl.getNullFieldProblems().size()); }
@Test public void testCorrectnessOfMissingUntilFinished() { BlockingControlLink bcl = new BlockingControlLink(); Processor block = new Processor(); bcl.setBlock(block); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(bcl, false, rcvl); assertEquals(0, rcvl.getNullFieldProblems().size()); }
@SuppressWarnings("unchecked") @Test public void expectedOrder() throws Exception { Workflow wf = new Workflow(); wf.setName("wf"); Processor a = new Processor(wf, "a"); Processor b = new Processor(wf, "b"); Processor c = new Processor(wf, "c"); Processor d = new Processor(wf, "d"); BlockingControlLink b_blocks_c = new BlockingControlLink(c, b); BlockingControlLink a_blocks_c = new BlockingControlLink(c, a); BlockingControlLink a_blocks_b = new BlockingControlLink(b, a); BlockingControlLink b_blocks_d = new BlockingControlLink(d, b); BlockingControlLink a_blocks_d = new BlockingControlLink(d, a); ArrayList<ControlLink> links = new ArrayList<ControlLink>(wf.getControlLinks()); assertEquals(Arrays.asList(a_blocks_b, a_blocks_c, a_blocks_d, b_blocks_c, b_blocks_d), links); Collections.shuffle(links); Collections.sort(links); assertEquals(Arrays.asList(a_blocks_b, a_blocks_c, a_blocks_d, b_blocks_c, b_blocks_d), links); }
@SuppressWarnings("unchecked") public List<BlockingControlLink> controlLinksBlocking(Processor blocked) { List<BlockingControlLink> controlLinks = new ArrayList<>(); for (ControlLink link : blocked.getParent().getControlLinks()) { if (!(link instanceof BlockingControlLink)) continue; BlockingControlLink blockingControlLink = (BlockingControlLink) link; if (blockingControlLink.getBlock().equals(blocked)) controlLinks.add(blockingControlLink); } Collections.sort(controlLinks); return controlLinks; }
@SuppressWarnings("unchecked") public List<BlockingControlLink> controlLinksWaitingFor( Processor untilFinished) { List<BlockingControlLink> controlLinks = new ArrayList<>(); for (ControlLink link : untilFinished.getParent().getControlLinks()) { if (!(link instanceof BlockingControlLink)) continue; BlockingControlLink blockingControlLink = (BlockingControlLink) link; if (blockingControlLink.getUntilFinished().equals(untilFinished)) controlLinks.add(blockingControlLink); } Collections.sort(controlLinks); return controlLinks; }
Processor d = new Processor(wf, "d"); BlockingControlLink b_blocks_c = new BlockingControlLink(c, b); BlockingControlLink null_blocks_c = new BlockingControlLink(); null_blocks_c.setBlock(c); null_blocks_c.setParent(wf); BlockingControlLink a_blocks_b = new BlockingControlLink(b, a); BlockingControlLink b_blocks_null = new BlockingControlLink(); b_blocks_null.setUntilFinished(b); b_blocks_null.setParent(wf); BlockingControlLink null_blocks_null = new BlockingControlLink(); null_blocks_null.setParent(wf); Collections.sort(links); BlockingControlLink a_blocks_d_no_parent = new BlockingControlLink(); a_blocks_d_no_parent.setBlock(d); a_blocks_d_no_parent.setUntilFinished(a);
@SuppressWarnings("unchecked") @Override public int compareTo(Object o) { if (!(o instanceof BlockingControlLink)) return o.getClass().getCanonicalName() .compareTo(getClass().getCanonicalName()); BlockingControlLink o1 = this; BlockingControlLink o2 = (BlockingControlLink) o; int untilFinishedCompare = nullSafeCompare.compare( o1.getUntilFinished(), o2.getUntilFinished()); if (untilFinishedCompare != 0) return untilFinishedCompare; return nullSafeCompare.compare(o1.getBlock(), o2.getBlock()); }
@Test public void testWronglyScopedBlock() { Workflow wf = new Workflow(); BlockingControlLink bcl = new BlockingControlLink(); bcl.setParent(wf); Processor block = new Processor(); Workflow otherWorkflow = new Workflow(); block.setParent(otherWorkflow); bcl.setBlock(block); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(bcl, false, rcvl); Set<OutOfScopeValueProblem> outOfScopeValueProblems = rcvl.getOutOfScopeValueProblems(); assertEquals(1, outOfScopeValueProblems.size()); boolean outOfScopeValueProblem = false; for (OutOfScopeValueProblem oosvp : outOfScopeValueProblems) { if (oosvp.getBean().equals(bcl) && oosvp.getFieldName().equals("block") && oosvp.getValue().equals(block)) { outOfScopeValueProblem = true; } } assertTrue(outOfScopeValueProblem); }
@Test public void testCompletenessOfMissingBlock() { BlockingControlLink bcl = new BlockingControlLink(); Processor untilFinished = new Processor(); bcl.setUntilFinished(untilFinished); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(bcl, true, rcvl); Set<NullFieldProblem> nullFieldProblems = rcvl.getNullFieldProblems(); assertEquals(2, rcvl.getNullFieldProblems().size()); // parent and block boolean nullFieldProblem = false; for (NullFieldProblem nfp : nullFieldProblems) { if (nfp.getBean().equals(bcl) && nfp.getFieldName().equals("block")) { nullFieldProblem = true; } } assertTrue(nullFieldProblem); }
@Test public void testCompletenessOfMissingUntilFinished() { BlockingControlLink bcl = new BlockingControlLink(); Processor block = new Processor(); bcl.setBlock(block); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(bcl, true, rcvl); Set<NullFieldProblem> nullFieldProblems = rcvl.getNullFieldProblems(); assertEquals(2, rcvl.getNullFieldProblems().size()); // parent and untilFinished boolean nullFieldProblem = false; for (NullFieldProblem nfp : nullFieldProblems) { if (nfp.getBean().equals(bcl) && nfp.getFieldName().equals("untilFinished")) { nullFieldProblem = true; } } assertTrue(nullFieldProblem); }
private Set<ControlLink> parseControlLinks(Conditions conditions) throws ReaderException { Set<ControlLink> links = new HashSet<>(); for (Condition condition : conditions.getCondition()) { NamedSet<Processor> processors = parserState.get() .getCurrentWorkflow().getProcessors(); String target = condition.getTarget(); Processor block = processors.getByName(target); if (block == null && isStrict()) throw new ReaderException( "Unrecognized blocking processor in control link: " + target); String control = condition.getControl(); Processor untilFinished = processors.getByName(control); if (untilFinished == null && isStrict()) throw new ReaderException( "Unrecognized untilFinished processor in control link: " + control); BlockingControlLink newLink = new BlockingControlLink(block, untilFinished); // FIXME: missing from t2flow and schema //parseAnnotations(newLink, condition.getAnnotations()); links.add(newLink); } return links; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (getUntilFinished() == null ? 0 : getUntilFinished() .hashCode()); result = prime * result + (parent == null ? 0 : parent.hashCode()); result = prime * result + (getBlock() == null ? 0 : getBlock().hashCode()); return result; }
@Override public void visitBlockingControlLink(BlockingControlLink bean) { // Also checks from Child Workflow parent = bean.getParent(); Processor block = bean.getBlock(); Processor untilFinished = bean.getUntilFinished(); // Check the block and untilFinished processors are in the same workflow if (block != null) { Workflow blockParent = block.getParent(); if ((parent == null) || !parent.equals(blockParent)) listener.outOfScopeValue(bean, "block", block); } if (untilFinished != null) { Workflow untilFinishedParent = untilFinished.getParent(); if ((parent == null) || !parent.equals(untilFinishedParent)) listener.outOfScopeValue(bean, "untilFinished", untilFinished); } // Check the block and untilFinished processors are specified if (checkComplete) { if (block == null) listener.nullField(bean, "block"); if (untilFinished == null) listener.nullField(bean, "untilFinished"); } }
Processor untilFinishedProc = workflow.getProcessors() .getByName(untilFinish); new BlockingControlLink(blockProc, untilFinishedProc);