@Override public void setParent(Profile parent) { if (this.parent != null && this.parent != parent) this.parent.getActivities().remove(this); this.parent = parent; if (parent != null) parent.getActivities().add(this); }
private void parseConfigures(Scanner scanner) { String configures = parseName(scanner); if (!configures.startsWith(ACTIVITY_SLASH)) throw new UnsupportedOperationException("Unknown Configures " + configures); activity = profile.getActivities().getByName( configures.substring(ACTIVITY_SLASH.length(), configures.length())); configuration.setConfigures(activity); level = Level.JSON; }
@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); }
protected org.apache.taverna.scufl2.api.activity.Activity parseActivityAndAddToProfile( Activity origActivity) throws ReaderException { org.apache.taverna.scufl2.api.activity.Activity newActivity = parseActivity(origActivity); newActivity.setName(parserState.get().getCurrentProcessorBinding() .getName()); parserState.get().getCurrentProfile().getActivities() .addWithUniqueName(newActivity); newActivity.setParent(parserState.get().getCurrentProfile()); return newActivity; }
@Test public void looping() throws Exception { Processor looping = processors.getByName("looping"); Configuration config = scufl2Tools.configurationFor(looping, profile); ObjectNode json = config.getJsonAsObjectNode(); JsonNode loop = json.get(LOOP); // System.out.println(loop); String activityName = loop.get("conditionActivity").asText(); Activity activity = profile.getActivities().getByName(activityName); assertNotNull("Unknown activity " + activityName, activity); assertEquals(true, loop.get("runFirst").asBoolean()); // The properties assertEquals("fred", loop.get("compareValue").asText()); assertEquals("value", loop.get("comparePort").asText()); assertEquals(0.5, loop.get("delay").asDouble(), 0.01); assertEquals(false, loop.get("isFeedBack").asBoolean()); }
protected void parseActivityBinding(Activity origActivity, int activityPosition) throws ReaderException, JAXBException { ProcessorBinding processorBinding = new ProcessorBinding(); processorBinding.setName(parserState.get().getCurrentProcessor() .getName()); parserState.get().getCurrentProfile().getProcessorBindings() .addWithUniqueName(processorBinding); processorBinding.setBoundProcessor(parserState.get() .getCurrentProcessor()); parserState.get().setCurrentProcessorBinding(processorBinding); org.apache.taverna.scufl2.api.activity.Activity newActivity = parseActivityAndAddToProfile(origActivity); parserState.get().setCurrentActivity(newActivity); parserState.get().getCurrentProfile().getActivities().add(newActivity); processorBinding.setBoundActivity(newActivity); processorBinding.setActivityPosition(activityPosition); parserState.get().setCurrentConfigurable(newActivity); try { parseConfigurationAndAddToProfile(origActivity.getConfigBean()); } catch (JAXBException e) { if (isStrict()) throw e; logger.log(WARNING, "Can't configure activity" + newActivity, e); } parseActivityInputMap(origActivity.getInputMap()); parseActivityOutputMap(origActivity.getOutputMap()); parserState.get().setCurrentConfigurable(null); parserState.get().setCurrentActivity(null); parserState.get().setCurrentProcessorBinding(null); }
@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 uriForActivity() throws Exception { Activity activity = wfBundle.getMainProfile().getActivities() .getByName("HelloScript"); URI uri = uriTools.uriForBean(activity); assertEquals(BUNDLE_URI + "profile/tavernaWorkbench/" + "activity/HelloScript/", uri.toASCIIString()); }
@Test public void resolveActivity() throws Exception { Activity helloScript = wfBundle.getMainProfile().getActivities().getByName("HelloScript"); assertSame(helloScript, uriTools.resolveUri(PROFILE_URI.resolve("activity/HelloScript/"), wfBundle)); }
@Test public void resolveActivityOutput() throws Exception { Activity helloScript = wfBundle.getMainProfile().getActivities() .getByName("HelloScript"); assertSame(helloScript.getOutputPorts().getByName("hello"), uriTools.resolveUri( PROFILE_URI.resolve("activity/HelloScript/out/hello"), wfBundle)); }
@Test public void uriForActivityInput() throws Exception { Activity activity = wfBundle.getMainProfile().getActivities() .getByName("HelloScript"); URI uri = uriTools.uriForBean(activity.getInputPorts().getByName( "personName")); assertEquals(BUNDLE_URI + "profile/tavernaWorkbench/" + "activity/HelloScript/in/personName", uri.toASCIIString()); }
@Test public void resolveActivityInput() throws Exception { Activity helloScript = wfBundle.getMainProfile().getActivities() .getByName("HelloScript"); assertSame(helloScript.getInputPorts().getByName("personName"), uriTools.resolveUri(PROFILE_URI .resolve("activity/HelloScript/in/personName"), wfBundle)); }
@Test public void uriForActivityOutput() throws Exception { Activity activity = wfBundle.getMainProfile().getActivities() .getByName("HelloScript"); URI uri = uriTools.uriForBean(activity.getOutputPorts().getByName( "hello")); assertEquals(BUNDLE_URI + "profile/tavernaWorkbench/" + "activity/HelloScript/out/hello", uri.toASCIIString()); }
@Test public void processorPortBindingForInputActivityPort() throws Exception { Profile profile = workflowBundle.getMainProfile(); Activity helloScript = profile.getActivities().getByName("HelloScript"); InputActivityPort port = helloScript.getInputPorts().getByName( "personName"); ProcessorBinding processorBinding = profile.getProcessorBindings() .getByName("Hello"); ProcessorInputPortBinding inputPortBinding = processorBinding .getInputPortBindings().iterator().next(); assertSame(inputPortBinding, scufl2Tools.processorPortBindingForPort(port, profile)); }
@Test public void processorPortBindingForOutputActivityPort() throws Exception { Profile profile = workflowBundle.getMainProfile(); Activity helloScript = profile.getActivities().getByName("HelloScript"); OutputActivityPort port = helloScript.getOutputPorts().getByName( "hello"); ProcessorBinding processorBinding = profile.getProcessorBindings() .getByName("Hello"); ProcessorOutputPortBinding outputPortBinding = processorBinding .getOutputPortBindings().iterator().next(); assertSame(outputPortBinding, scufl2Tools.processorPortBindingForPort(port, profile)); }
@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()); }
@Test public void activity() throws Exception { assertEquals(1, profile.getActivities().size()); Activity helloScript = profile.getActivities().getByName("HelloScript"); assertEquals("HelloScript", helloScript.getName()); assertEquals( "http://ns.taverna.org.uk/2010/activity/beanshell", helloScript.getType().toASCIIString()); assertEquals(1, helloScript.getInputPorts().size()); InputActivityPort personName = helloScript.getInputPorts().getByName( "personName"); assertEquals("personName", personName.getName()); assertEquals(0, personName.getDepth().intValue()); assertEquals(1, helloScript.getOutputPorts().size()); OutputActivityPort hello = helloScript.getOutputPorts().getByName( "hello"); assertEquals("hello", hello.getName()); assertEquals(0, hello.getDepth().intValue()); assertEquals(0, hello.getGranularDepth().intValue()); }
@Test public void portBindings() throws Exception { ProcessorBinding hello = profile.getProcessorBindings().getByName( "Hello"); assertEquals(1, hello.getInputPortBindings().size()); assertEquals(1, hello.getOutputPortBindings().size()); ProcessorInputPortBinding input = hello.getInputPortBindings() .iterator().next(); InputActivityPort inputActivityPort = profile.getActivities() .getByName("HelloScript").getInputPorts() .getByName("personName"); assertEquals(inputActivityPort, input.getBoundActivityPort()); InputProcessorPort inputProcessorPort = bundle.getMainWorkflow() .getProcessors().getByName("Hello").getInputPorts() .getByName("name"); assertEquals(inputProcessorPort, input.getBoundProcessorPort()); ProcessorOutputPortBinding output = hello.getOutputPortBindings() .iterator().next(); OutputActivityPort outputActivityPort = profile.getActivities() .getByName("HelloScript").getOutputPorts().getByName("hello"); assertEquals(outputActivityPort, output.getBoundActivityPort()); OutputProcessorPort outputProcessorPort = bundle.getMainWorkflow() .getProcessors().getByName("Hello").getOutputPorts() .getByName("greeting"); assertEquals(outputProcessorPort, output.getBoundProcessorPort()); }
@Test public void processorBinding() throws Exception { assertEquals(1, profile.getProcessorBindings().size()); ProcessorBinding hello = profile.getProcessorBindings().getByName( "Hello"); assertEquals(profile.getActivities().getByName("HelloScript"), hello.getBoundActivity()); assertEquals(bundle.getMainWorkflow().getProcessors() .getByName("Hello"), hello.getBoundProcessor()); assertEquals("Hello", hello.getName()); assertEquals(10, hello.getActivityPosition().intValue()); }
Profile p = new Profile(); ro.getProfiles().add(p); p.getActivities().add(activity);