@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"); } }
@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); }
workflow.newRevision(); Profile profile = new Profile(); profile.setName("profile1"); profile.setParent(wb); profile.newRevision();
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 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); }
/** * 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()); }
protected void parseProfile(Profile original, URI profileUri) { org.apache.taverna.scufl2.api.profiles.Profile p = new org.apache.taverna.scufl2.api.profiles.Profile(); p.setParent(getParserState().getCurrent(WorkflowBundle.class)); getParserState().push(p); if (original.getAbout() != null) { URI about = getParserState().getCurrentBase().resolve( original.getAbout()); mapBean(about, p); } else mapBean(profileUri, p); if (original.getName() != null) p.setName(original.getName()); // Note - we'll pop() in profileSecond() instead }
@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); }
@Test public void testOutOfScopeMainProfile() { DummyWorkflowBundle dwb = new DummyWorkflowBundle(); Profile orphanProfile = new Profile(); dwb.setMainProfile(orphanProfile); dwb.setProfiles(new NamedSet<Profile>()); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(dwb, false, rcvl); Set<OutOfScopeValueProblem> outOfScopeValueProblems = rcvl.getOutOfScopeValueProblems(); assertFalse(outOfScopeValueProblems.isEmpty()); boolean problem = false; for (OutOfScopeValueProblem nlp : outOfScopeValueProblems) { if (nlp.getBean().equals(dwb) && nlp.getFieldName().equals("mainProfile") && nlp.getValue().equals(orphanProfile)) { problem = true; } } assertTrue(problem); }
@Test public void testCorrectnessOfValidProfilePosition() { Profile profile = new Profile(); Integer profilePosition = Integer.valueOf(3); profile.setProfilePosition(profilePosition); CorrectnessValidator cv = new CorrectnessValidator(); ReportCorrectnessValidationListener rcvl = new ReportCorrectnessValidationListener(); cv.checkCorrectness(profile, false, rcvl); Set<NegativeValueProblem> negativeValueProblems = rcvl.getNegativeValueProblems(); assertEquals(Collections.EMPTY_SET, negativeValueProblems); }
@Test public void awkwardFilenames() throws Exception { workflowBundle.getProfiles().removeByName("tavernaServer"); String funnyName = "Funny_%2f_characters_50%_of the time"; workflowBundle.getMainProfile().setName(funnyName); workflowBundle.getMainWorkflow().setName(funnyName); File bundleFile = tempFile(); bundleIO.writeBundle(workflowBundle, bundleFile, APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE); UCFPackage ucfPackage = new UCFPackage(bundleFile); Map<String, ResourceEntry> profiles = ucfPackage.listResources("profile"); assertEquals(2, profiles.size()); assertTrue(profiles.keySet().contains("Funny_%252f_characters_50%25_of%20the%20time.rdf")); assertTrue(profiles.keySet().contains("Funny_%252f_characters_50%25_of%20the%20time/")); Map<String, ResourceEntry> workflows = ucfPackage.listResources("workflow"); assertEquals(1, workflows.size()); assertEquals("Funny_%252f_characters_50%25_of%20the%20time.rdf", workflows.keySet().iterator().next()); // and.. can we read it in again correctly? WorkflowBundle readBundle = bundleIO.readBundle(bundleFile, APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE); assertEquals(funnyName, readBundle.getMainProfile().getName()); assertEquals(funnyName, readBundle.getMainWorkflow().getName()); // did the JSON parse back in? JsonNode oldJson = workflowBundle.getMainProfile().getConfigurations().getByName("Hello").getJson(); assertTrue(oldJson.get("script").asText().startsWith("hello")); JsonNode newJson = readBundle.getMainProfile().getConfigurations().getByName("Hello").getJson(); assertTrue(newJson.get("script").asText().startsWith("hello")); assertEquals(oldJson, newJson); }
/** * Returns the name of the <code>Profile</code> to use when running the * <code>Workflow</code>. If no <code>Profile</code> name is set the main * <code>Profile</code> from the <code>WorkflowBundle</code> will be used. * * @return the <code>Profile</code> to use when running the * <code>Workflow</code> */ public String getProfileName() { if (profileName == null && workflowBundle.getMainProfile() != null) { return workflowBundle.getMainProfile().getName(); } return profileName; }
@Test public void cloneProfile() throws Exception { Profile original = originalWfBundle.getMainProfile(); assertEquals(originalWfBundle, original.getParent()); Profile clone = (Profile) original.clone(); assertNull(clone.getParent()); assertEquals(original.getName(), clone.getName()); ProcessorBinding originalBinding = original.getProcessorBindings() .getByName("Hello"); ProcessorBinding cloneBinding = clone.getProcessorBindings().getByName( "Hello"); assertNotSame(originalBinding, cloneBinding); assertNotSame(originalBinding.getBoundActivity(), cloneBinding.getBoundActivity()); // but processor is the same, as we did not clone the workflow assertSame(originalBinding.getBoundProcessor(), cloneBinding.getBoundProcessor()); }
@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()); }
@Override public void setParent(Profile parent) { if (this.parent != null && this.parent != parent) this.parent.getProcessorBindings().remove(this); this.parent = parent; if (parent != null) parent.getProcessorBindings().add(this); }
Profile p = new Profile(); ro.getProfiles().add(p); p.getActivities().add(activity);
@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()); }