@Override public void setParent(Profile parent) { if (this.parent != null && this.parent != parent) this.parent.getConfigurations().remove(this); this.parent = parent; if (parent != null) parent.getConfigurations().add(this); }
/** * Returns the list of {@link Configuration Configurations} for a * {@link Configurable} in the given {@link Profile}. * * @param configurable * the <code>Configurable</code> to find a * <code>Configuration</code> for * @param profile * the <code>Profile</code> to look for the * <code>Configuration</code> in * @return the list of <code>Configurations</code> for a * <code>Configurable</code> in the given <code>Profile</code> */ public List<Configuration> configurationsFor(Configurable configurable, Profile profile) { List<Configuration> configurations = new ArrayList<>(); for (Configuration config : profile.getConfigurations()) if (configurable.equals(config.getConfigures())) configurations.add(config); // Collections.sort(configurations); return configurations; }
public Set<Processor> getConstants(Workflow workflow, Profile profile) { Set<Processor> procs = new LinkedHashSet<>(); for (Configuration config : profile.getConfigurations()) { Configurable configurable = config.getConfigures(); if (!CONSTANT.equals(configurable.getType()) || !(configurable instanceof Activity)) continue; for (ProcessorBinding bind : processorBindingsToActivity((Activity) configurable)) procs.add(bind.getBoundProcessor()); } return procs; } }
@Override public boolean accept(Visitor visitor) { if (visitor.visitEnter(this)) { List<Iterable<? extends WorkflowBean>> children = new ArrayList<>(); children.add(getActivities()); children.add(getProcessorBindings()); children.add(getConfigurations()); outer: for (Iterable<? extends WorkflowBean> it : children) for (WorkflowBean bean : it) if (!bean.accept(visitor)) break outer; } return visitor.visitLeave(this); }
private void parseConfiguration(Scanner scanner) { level = Level.Configuration; configuration = new Configuration(); String configName = parseName(scanner); configuration.setName(configName); profile.getConfigurations().add(configuration); }
protected Configuration parseConfigurationAndAddToProfile(ConfigBean configBean) throws JAXBException, ReaderException { Configuration configuration = parseConfiguration(configBean); if (configuration == null) return null; Profile profile = parserState.get().getCurrentProfile(); configuration.setName(parserState.get().getCurrentActivity() .getName()); profile.getConfigurations().addWithUniqueName(configuration); configuration.setConfigures(parserState.get().getCurrentConfigurable()); return configuration; }
public Profile makeSecondaryProfile() { Profile profile = makeMainProfile(); profile.setName("tavernaServer"); Configuration config = profile.getConfigurations().getByName("Hello"); ObjectNode json = JsonNodeFactory.instance.objectNode(); json.put("script", "hello = \"Hello, \" + personName;\n" + "System.out.println(\"Server says: \" + hello);"); config.setJson(json); return profile; }
public Configuration createConfigurationFor(Processor processor, Profile profile) { Configuration config = new Configuration(processor.getName() + "-proc"); profile.getConfigurations().addWithUniqueName(config); config.setParent(profile); config.setConfigures(processor); config.setType(Processor.CONFIG_TYPE); return config; }
public Configuration createConfigurationFor(Activity activity, URI configType) { Profile profile = activity.getParent(); Configuration config = new Configuration(activity.getName()); profile.getConfigurations().addWithUniqueName(config); config.setParent(profile); config.setConfigures(activity); config.setType(configType); return config; }
@Test public void readSimpleWorkflow() throws Exception { URL wfResource = getClass().getResource(WF_ALL_ACTIVITIES); assertNotNull("Could not find workflow " + WF_ALL_ACTIVITIES, wfResource); T2FlowParser parser = new T2FlowParser(); parser.setValidating(true); // parser.setStrict(true); WorkflowBundle wfBundle = parser .parseT2Flow(wfResource.openStream()); NamedSet<Configuration> cfgs = wfBundle.getProfiles().iterator().next() .getConfigurations(); // System.out.println(cfgs); }
@Override public void visitProfile(Profile bean) { Integer profilePosition = bean.getProfilePosition(); if (profilePosition != null && profilePosition < 0) listener.negativeValue(bean, "profilePosition", profilePosition); if (checkComplete) { if (bean.getProcessorBindings() == null) listener.nullField(bean, "processorBindings"); if (bean.getConfigurations() == null) listener.nullField(bean, "configurations"); // It may be OK for the profilePosition to be null if (bean.getActivities() == null) listener.nullField(bean, "activities"); } }
@Test public void simpleFasta() throws Exception { URL wfResource = getClass().getResource(WF_SIMPLE_FASTA); assertNotNull("Could not find workflow " + WF_SIMPLE_FASTA, wfResource); T2FlowParser parser = new T2FlowParser(); parser.setValidating(true); // parser.setStrict(true); WorkflowBundle wfBundle = parser.parseT2Flow(wfResource.openStream()); Profile p = wfBundle.getMainProfile(); for (Configuration c : p.getConfigurations()) { System.out.println(c.getConfigures()); System.out.println(c.getJson()); } }
@Test public void fastaPscan() throws Exception { URL wfResource = getClass().getResource(WF_FASTA_AND_PSCAN); assertNotNull("Could not find workflow " + WF_FASTA_AND_PSCAN, wfResource); T2FlowParser parser = new T2FlowParser(); parser.setValidating(true); // parser.setStrict(true); WorkflowBundle wfBundle = parser.parseT2Flow(wfResource.openStream()); Profile p = wfBundle.getMainProfile(); for (Configuration c : p.getConfigurations()) { System.out.println(c.getConfigures()); System.out.println(c.getJson()); } }
@Test public void fastaPscanDbfetch() throws Exception { URL wfResource = getClass().getResource(WF_FASTA_PSCAN_AND_DBFETCH); assertNotNull("Could not find workflow " + WF_FASTA_PSCAN_AND_DBFETCH, wfResource); T2FlowParser parser = new T2FlowParser(); parser.setValidating(true); // parser.setStrict(true); WorkflowBundle wfBundle = parser.parseT2Flow(wfResource.openStream()); Profile p = wfBundle.getMainProfile(); for (Configuration c : p.getConfigurations()) { System.out.println(c.getConfigures()); System.out.println(c.getJson()); } }
@Test public void configurationReadTwice() throws Exception { InputStream inputStream = new ByteArrayInputStream( getStructureFormatWorkflowBundle().getBytes("utf-8")); WorkflowBundle readBundle = bundleIO.readBundle(inputStream, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); assertEquals(1, readBundle.getMainProfile().getConfigurations().size()); new Scufl2Tools().setParents(readBundle); assertEquals(1, readBundle.getMainProfile().getConfigurations().size()); ByteArrayOutputStream output = new ByteArrayOutputStream(); bundleIO.writeBundle(readBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); assertEquals(1, readBundle.getMainProfile().getConfigurations().size()); String bundleTxt = new String(output.toByteArray(), UTF_8); String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle(); bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", ""); getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", ""); assertEquals(getStructureFormatWorkflowBundle, bundleTxt); }
@Test public void uriForConfig() throws Exception { Configuration config = wfBundle.getMainProfile().getConfigurations() .getByName("Hello"); URI uri = uriTools.uriForBean(config); assertEquals(BUNDLE_URI + "profile/tavernaWorkbench/" + "configuration/Hello/", uri.toASCIIString()); }
@Test public void resolveConfiguration() throws Exception { Configuration config = wfBundle.getMainProfile().getConfigurations().getByName("Hello"); assertSame(config, uriTools.resolveUri( PROFILE_URI.resolve("configuration/Hello/"), wfBundle)); }
@Test public void configurationNotAddedTwiceExample() throws Exception { Profile p = workflowBundle.getMainProfile(); assertEquals(1, p.getConfigurations().size()); new Scufl2Tools().setParents(workflowBundle); assertEquals(1, p.getConfigurations().size()); }
/** * Similar bug to {@link DataLinkCompareTest#dataLinkNotAddedTwice()} */ @Test public void configurationNotAddedTwice() throws Exception { Configuration c1a = new Configuration("c1"); Profile p1 = new Profile("p1"); p1.getConfigurations().add(c1a); c1a.setParent(p1); p1.getConfigurations().add(c1a); Configuration c1b = new Configuration("c1"); Profile p2 = new Profile("p2"); p2.getConfigurations().add(c1b); c1b.setParent(p2); p2.getConfigurations().add(c1b); WorkflowBundle bundle = new WorkflowBundle(); p1.setParent(bundle); p2.setParent(bundle); new Scufl2Tools().setParents(bundle); assertEquals(1, p1.getConfigurations().size()); assertEquals(1, p2.getConfigurations().size()); }
@Test public void configuration() throws Exception { assertEquals(1, profile.getConfigurations().size()); Configuration hello = profile.getConfigurations().getByName("Hello"); assertEquals("Hello", hello.getName()); assertEquals(profile.getActivities().getByName("HelloScript"), hello.getConfigures()); assertEquals( "http://ns.taverna.org.uk/2010/activity/beanshell#Config", hello.getType().toASCIIString()); }