@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; }
/** * Get the collection of processors that can be downstream of this * processor. * * @return A set of processors that it is legal to have a datalink or * control link from this processor to. * @see Scufl2Tools#possibleDownStreamProcessors(Workflow,Processor) */ public Set<Processor> getPossibleDownStreamProcessors() { return getTools().possibleDownStreamProcessors(getParent(), this); }
/** * Get the collection of processors that can be upstream of this * processor. * * @return A set of processors that it is legal to have a datalink or * control link to this processor from. * @see Scufl2Tools#possibleUpStreamProcessors(Workflow,Processor) */ public Set<Processor> getPossibleUpStreamProcessors() { return getTools().possibleUpStreamProcessors(getParent(), this); } }
/** * Returns true if processor contains a nested workflow in any of its * activities in any of its profiles. */ public boolean containsNestedWorkflow(Processor processor) { for (Profile profile : processor.getParent().getParent().getProfiles()) if (containsNestedWorkflow(processor, profile)) return true; return false; }
/** * 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 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"); } }
@Ignore @Test public void writeBundleFileSetParents() throws Exception { File bundleFile = tempFile(); // Deliberately orphan a profile and a processor Profile profile = wfBundle.getProfiles().getByName("tavernaWorkbench"); profile.setParent(null); wfBundle.getProfiles().add(profile); processor.setParent(null); workflow.getProcessors().add(processor); assertNull(processor.getParent()); assertNull(profile.getParent()); bundleIO.writeBundle(wfBundle, bundleFile, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); assertNotNull(processor.getParent()); assertNotNull(profile.getParent()); String bundleTxt = FileUtils.readFileToString(bundleFile, UTF_8); assertTrue(bundleTxt.contains("Processor 'Hello'")); assertTrue(bundleTxt.contains("Profile 'tavernaWorkbench'")); }
@Test public void setParents() throws Exception { // Deliberately orphan a profile and a processor Profile profile = workflowBundle.getProfiles().getByName("tavernaWorkbench"); profile.setParent(null); workflowBundle.getProfiles().add(profile); processor.setParent(null); workflow.getProcessors().add(processor); assertNull(processor.getParent()); assertNull(profile.getParent()); scufl2Tools.setParents(workflowBundle); assertNotNull(processor.getParent()); assertNotNull(profile.getParent()); }
@Test public void cloneProcessor() throws Exception { Workflow wf = originalWfBundle.getMainWorkflow(); Processor original = wf.getProcessors().getByName("Hello"); Processor clone = (Processor) original.clone(); assertEquals(clone.getName(), original.getName()); assertNotNull(original.getParent()); assertNull(clone.getParent()); wf.getProcessors().addWithUniqueName(clone); assertTrue(!clone.getName().equals(original.getName())); // Now it is safe to set the parent without loosing original clone.setParent(wf); assertSame(original, wf.getProcessors().getByName("Hello")); assertSame(clone, wf.getProcessors().getByName(clone.getName())); }
newLine(3); append("Processor"); String name = " '" + escapeName(pb.getBoundProcessor().getParent().getName()); name = name + ":" + escapeName(pb.getBoundProcessor().getName()) + "'"; append(name);
@Test public void nullParentNotCopied() throws Exception { Workflow wf = new Workflow(); Processor orphan = new Processor(); orphan.setName("orphan"); // NOTE: NOT calling // orphan.setParent(wf) wf.getProcessors().add(orphan); assertNull(orphan.getParent()); Workflow clone = (Workflow) wf.clone(); assertTrue(clone.getProcessors().isEmpty()); orphan.setParent(wf); Workflow clone2 = (Workflow) wf.clone(); assertEquals(Collections.singleton("orphan"), clone2.getProcessors() .getNames()); }