BATCH-1670: fix nested split referenences
This commit is contained in:
@@ -26,14 +26,14 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Internal parser for the <split/> elements inside a job. A split element
|
||||
* references a bean definition for a
|
||||
* {@link org.springframework.batch.core.job.flow.JobExecutionDecider} and goes
|
||||
* optionally references a bean definition for a {@link TaskExecutor} and goes
|
||||
* on to list a set of transitions to other states with <next on="pattern"
|
||||
* to="stepName"/>. Used by the {@link JobParser}.
|
||||
*
|
||||
@@ -48,6 +48,7 @@ public class SplitParser {
|
||||
*
|
||||
*/
|
||||
private static final String PARENT_ATTR = "parent";
|
||||
|
||||
private final String jobFactoryRef;
|
||||
|
||||
/**
|
||||
@@ -93,12 +94,13 @@ public class SplitParser {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> flows = new ManagedList();
|
||||
int i = 0;
|
||||
String prefix = idAttribute.startsWith(jobFactoryRef) ? idAttribute : jobFactoryRef+"."+idAttribute;
|
||||
String prefix = idAttribute;
|
||||
for (Element nextElement : flowElements) {
|
||||
String ref = nextElement.getAttribute(PARENT_ATTR);
|
||||
if (StringUtils.hasText(ref)) {
|
||||
if (nextElement.getElementsByTagName("*").getLength() > 0) {
|
||||
parserContext.getReaderContext().error("A <flow/> in a <split/> must have ref= or nested <flow/>, but not both.", nextElement);
|
||||
parserContext.getReaderContext().error(
|
||||
"A <flow/> in a <split/> must have ref= or nested <flow/>, but not both.", nextElement);
|
||||
}
|
||||
AbstractBeanDefinition flowDefinition = new GenericBeanDefinition();
|
||||
flowDefinition.setParentName(ref);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2006-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SplitNestedJobParserTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("job")
|
||||
private Job job;
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Test
|
||||
public void testSplitJob() throws Exception {
|
||||
assertNotNull(job);
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
|
||||
job.execute(jobExecution);
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<beans:import resource="classpath:/org/springframework/batch/core/configuration/xml/common-context.xml" />
|
||||
|
||||
<job id="job">
|
||||
<split id="split1" next="s4">
|
||||
<flow>
|
||||
<!-- Missing state for [StateTransition: [state=job.split1.0.f2step1, pattern=*, next=job.split1.0.f2split1]] -->
|
||||
<step id="f2step1" parent="step3" next="f2split1" />
|
||||
<split id="f2split1">
|
||||
<flow>
|
||||
<step id="f2split1s1" parent="step1" />
|
||||
</flow>
|
||||
<flow>
|
||||
<step id="f2split1s2" parent="step1" />
|
||||
</flow>
|
||||
</split>
|
||||
</flow>
|
||||
<flow>
|
||||
<step id="f1step1" parent="step1" />
|
||||
</flow>
|
||||
</split>
|
||||
<step id="s4" parent="step4" />
|
||||
</job>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user