@Override public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean, ParserState parserState) throws ReaderException { StringConstantConfig strConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", StringConstantConfig.class); String value = strConfig.getValue(); if (value == null) throw new ReaderException("String constant configuration has no value set"); Configuration configuration = new Configuration(); ObjectNode json = (ObjectNode) configuration.getJson(); configuration.setType(CONSTANT.resolve("#Config")); json.put("string", value); Activity activity = parserState.getCurrentActivity(); OutputActivityPort valuePort = new OutputActivityPort(activity, VALUE); valuePort.setDepth(0); valuePort.setGranularDepth(0); return configuration; } }
@Override public Set<OutputActivityPort> getActivityOutputPorts(URI activityType, JsonNode configuration) throws ActivityNotFoundException, ActivityConfigurationException { Set<OutputActivityPort> outputPorts = new HashSet<>(); try { for (ActivityOutputPort port : getActivityFactory(activityType) .getOutputPorts(configuration)) { OutputActivityPort outputActivityPort = new OutputActivityPort(); outputActivityPort.setName(port.getName()); outputActivityPort.setDepth(port.getDepth()); outputActivityPort.setGranularDepth(port.getGranularDepth()); outputPorts.add(outputActivityPort); } } catch (org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException e) { throw new ActivityConfigurationException(e); } return outputPorts; }
private void parsePort(Scanner scanner, String next) throws ReaderException { boolean in = next.equals("In"); String portName = parseName(scanner); switch (level) { case Workflow: if (in) new InputWorkflowPort(workflow, portName); else new OutputWorkflowPort(workflow, portName); break; case Processor: if (in) new InputProcessorPort(processor, portName); else new OutputProcessorPort(processor, portName); break; case Activity: if (in) new InputActivityPort(activity, portName); else new OutputActivityPort(activity, portName); break; default: throw new ReaderException("Unexpected " + next + " at level " + level); } }
Activity activity) { ObjectNode configResource = (ObjectNode) configuration.getJson(); OutputActivityPort outputPort = new OutputActivityPort();
public void createActivityPortsFromProcessor(Activity activity, Processor processor) { for (InputProcessorPort processorPort : processor.getInputPorts()) new InputActivityPort(activity, processorPort.getName()) .setDepth(processorPort.getDepth()); for (OutputProcessorPort processorPort : processor.getOutputPorts()) { OutputActivityPort activityPort = new OutputActivityPort(activity, processorPort.getName()); activityPort.setDepth(processorPort.getDepth()); activityPort.setGranularDepth(processorPort.getGranularDepth()); } }
public Activity makeActivity() { activity = new Activity(); activity.setName("HelloScript"); activity.setType(URI .create("http://ns.taverna.org.uk/2010/activity/beanshell")); personName = new InputActivityPort(activity, "personName"); personName.setDepth(0); hello = new OutputActivityPort(activity, "hello"); hello.setDepth(0); hello.setGranularDepth(0); return activity; }
@Test public void testIncompatibleGranularDepth() { OutputActivityPort oap = new OutputActivityPort(); oap.setDepth(new Integer(0)); oap.setGranularDepth(new Integer(1));
@Test public void testCorrectnessOfGranularDepthSpecifiedIncorrectly() { OutputActivityPort oap = new OutputActivityPort(); oap.setDepth(new Integer(3)); oap.setGranularDepth(new Integer(-2)); oap.setName("fred"); oap.setParent(null); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(oap, false, rcvl); Set<NegativeValueProblem> negativeValueProblems = rcvl.getNegativeValueProblems(); assertEquals(1, negativeValueProblems.size()); if (!negativeValueProblems.isEmpty()) { NegativeValueProblem problem = negativeValueProblems.iterator().next(); assertEquals(problem.getBean(), oap); assertEquals(problem.getFieldName(), "granularDepth"); assertEquals(problem.getFieldValue(), Integer.valueOf("-2")); } Set<NullFieldProblem> nullFieldProblems = rcvl.getNullFieldProblems(); assertEquals(0, nullFieldProblems.size()); // only done when completeness check assertEquals(0, rcvl.getIncompatibleGranularDepthProblems().size()); }
@Test public void testCorrectnessOfMissingGranularDepth() { OutputActivityPort oap = new OutputActivityPort(); oap.setDepth(new Integer(3)); oap.setGranularDepth(null); oap.setName("fred"); oap.setParent(null); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(oap, false, rcvl); Set<NegativeValueProblem> negativeValueProblems = rcvl.getNegativeValueProblems(); assertEquals(0, negativeValueProblems.size()); Set<NullFieldProblem> nullFieldProblems = rcvl.getNullFieldProblems(); assertEquals(0, nullFieldProblems.size()); // only done when completeness check assertEquals(0, rcvl.getIncompatibleGranularDepthProblems().size()); }
@Test public void testCompletenessOfSpecifiedBoundActivityPort() { ProcessorOutputPortBinding pipb = new ProcessorOutputPortBinding(); pipb.setBoundActivityPort(new OutputActivityPort()); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(pipb, true, rcvl); Set<NullFieldProblem> nullFieldProblems = rcvl.getNullFieldProblems(); boolean problem = false; for (NullFieldProblem nlp : nullFieldProblems) { if (nlp.getBean().equals(pipb) && nlp.getFieldName().equals("boundActivityPort")) { problem = true; } } assertFalse(problem); }
protected void parseOutputActivityPort( org.apache.taverna.scufl2.xml.OutputActivityPort original) { OutputActivityPort port = new OutputActivityPort(); mapBean(original.getAbout(), port); port.setParent(getParserState().getCurrent(Activity.class)); port.setName(original.getName()); if (original.getPortDepth() != null) port.setDepth(original.getPortDepth().getValue()); if (original.getGranularPortDepth() != null) port.setGranularDepth(original.getGranularPortDepth().getValue()); }
@Test public void testCompletenessOfMissingGranularDepth() { OutputActivityPort oap = new OutputActivityPort(); oap.setDepth(new Integer(3)); oap.setGranularDepth(null); oap.setName("fred"); oap.setParent(null); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(oap, true, rcvl); Set<NegativeValueProblem> negativeValueProblems = rcvl.getNegativeValueProblems(); assertEquals(0, negativeValueProblems.size()); Set<NullFieldProblem> nullFieldProblems = rcvl.getNullFieldProblems(); assertEquals(2, nullFieldProblems.size()); // granular depth and parent boolean granularDepthFieldProblem = false; for (NullFieldProblem nlp : nullFieldProblems) { if (nlp.getBean().equals(oap) && nlp.getFieldName().equals("granularDepth")) { granularDepthFieldProblem = true; } } assertTrue(granularDepthFieldProblem); assertEquals(0, rcvl.getIncompatibleGranularDepthProblems().size()); }
@Override public void parseScuflObject(Object o) { StringconstantType sc = (StringconstantType) o; Configuration configuration = new Configuration(); configuration.setParent(getParserState().getCurrentProfile()); configuration.setType(CONSTANT.resolve("#Config")); ((ObjectNode) configuration.getJson()).put("string", sc.getValue()); Activity activity = new Activity(); getParserState().setCurrentActivity(activity); activity.setParent(getParserState().getCurrentProfile()); activity.setType(CONSTANT); OutputActivityPort valuePort = new OutputActivityPort(activity, VALUE); valuePort.setDepth(0); valuePort.setGranularDepth(0); configuration.setConfigures(activity); ProcessorBinding pb = new ProcessorBinding(); pb.setParent(getParserState().getCurrentProfile()); pb.setBoundProcessor(getParserState().getCurrentProcessor()); pb.setBoundActivity(activity); } }
@Test public void testCorrectnessOfOutOfScopeActivityPort1() { ProcessorBinding pb = new ProcessorBinding(); Processor processor = new Processor(); pb.setBoundProcessor(processor); ProcessorOutputPortBinding pipb = new ProcessorOutputPortBinding(); pipb.setParent(pb); OutputActivityPort orphanPort = new OutputActivityPort(); pipb.setBoundActivityPort(orphanPort); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(pipb, false, rcvl); Set<OutOfScopeValueProblem> outOfScopeValueProblems = rcvl.getOutOfScopeValueProblems(); boolean problem = false; for (OutOfScopeValueProblem nlp : outOfScopeValueProblems) { if (nlp.getBean().equals(pipb) && nlp.getFieldName().equals("boundActivityPort") && nlp.getValue().equals(orphanPort)) { problem = true; } } assertTrue(problem); }
@Test public void testCorrectnessOfInScopeActivityPort() { ProcessorBinding pb = new ProcessorBinding(); Activity activity = new Activity(); pb.setBoundActivity(activity); ProcessorOutputPortBinding pipb = new ProcessorOutputPortBinding(); pipb.setParent(pb); OutputActivityPort port = new OutputActivityPort(); port.setParent(activity); pipb.setBoundActivityPort(port); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(pipb, false, rcvl); Set<OutOfScopeValueProblem> outOfScopeValueProblems = rcvl.getOutOfScopeValueProblems(); boolean problem = false; for (OutOfScopeValueProblem nlp : outOfScopeValueProblems) { if (nlp.getBean().equals(pipb) && nlp.getFieldName().equals("boundActivityPort") && nlp.getValue().equals(port)) { problem = true; } } assertFalse(problem); }
@Test public void createProcessorFromActivity() throws Exception { Profile profile = new Profile(); Activity a = new Activity(); a.setParent(profile); new InputActivityPort(a, "in1"); new InputActivityPort(a, "in2").setDepth(1); new OutputActivityPort(a, "out1"); new OutputActivityPort(a, "out2").setDepth(0); OutputActivityPort aOut3 = new OutputActivityPort(a, "out3"); aOut3.setDepth(2); aOut3.setGranularDepth(1); ProcessorBinding binding = scufl2Tools.createProcessorAndBindingFromActivity(a); Processor p = binding.getBoundProcessor(); assertEquals(profile, binding.getParent()); assertEquals(2, p.getInputPorts().size()); assertEquals(3, p.getOutputPorts().size()); assertEquals(2, binding.getInputPortBindings().size()); assertEquals(3, binding.getOutputPortBindings().size()); assertEquals(a, binding.getBoundActivity()); assertEquals(p, binding.getBoundProcessor()); }
OutputActivityPort elsewherePort = new OutputActivityPort(); elsewherePort.setParent(otherActivity);
@Test public void createProcessorPortsFromActivityWithOverwrite() throws Exception { Activity a = new Activity(); new InputActivityPort(a, "in1"); new OutputActivityPort(a, "out1"); new OutputActivityPort(a, "out2").setDepth(1); Processor p = new Processor(); new InputProcessorPort(p, "other"); OutputProcessorPort toBeOverWritten = new OutputProcessorPort(p, "out1"); toBeOverWritten.setDepth(1); assertEquals(p, toBeOverWritten.getParent()); scufl2Tools.createProcessorPortsFromActivity(p, a); // Still there assertNotNull(p.getInputPorts().getByName("other")); // but out1 has been overwritten OutputProcessorPort pOut1 = p.getOutputPorts().getByName("out1"); assertNull(pOut1.getDepth()); assertNotSame(toBeOverWritten, pOut1); }
new InputActivityPort(a, "in2").setDepth(1); new OutputActivityPort(a, "out1"); new OutputActivityPort(a, "out2").setDepth(0); OutputActivityPort aOut3 = new OutputActivityPort(a, "out3"); aOut3.setDepth(2); aOut3.setGranularDepth(1);
@Test public void createActivityPortsFromProcessorWithOverwrite() throws Exception { Processor p = new Processor(); new InputProcessorPort(p, "in1"); new OutputProcessorPort(p, "out1"); new OutputProcessorPort(p, "out2").setDepth(1); Activity a = new Activity(); new InputActivityPort(a, "other"); OutputActivityPort toBeOverWritten = new OutputActivityPort(a, "out1"); toBeOverWritten.setDepth(1); assertEquals(a, toBeOverWritten.getParent()); scufl2Tools.createActivityPortsFromProcessor(a, p); // Still there assertNotNull(a.getInputPorts().getByName("other")); // but out1 has been overwritten OutputActivityPort aOut1 = a.getOutputPorts().getByName("out1"); assertNull(aOut1.getDepth()); assertNotSame(toBeOverWritten, aOut1); }