remove JobInstanceLabelGenerator strategy
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.execution.resource;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
|
||||
/**
|
||||
* {@link JobInstanceLabelGenerator} that knows about {@link JobParameters} and
|
||||
* provides a fixed format label for each.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class DefaultJobInstanceLabelGenerator implements JobInstanceLabelGenerator {
|
||||
|
||||
private static final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
/**
|
||||
* Concatenate the properties of the {@link JobInstance}. From an instance
|
||||
* with no additional parameters we just get the name, otherwise we get the
|
||||
* parameters joined by hyphens (Strings then Longs then Dates). The date
|
||||
* format is "yyyyMMdd".
|
||||
*
|
||||
* @see org.springframework.batch.execution.resource.JobInstanceLabelGenerator#getLabel(JobInstance)
|
||||
*/
|
||||
public String getLabel(JobInstance jobInstance) {
|
||||
if (jobInstance == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(""+jobInstance.getJobName());
|
||||
Map map = jobInstance.getJobParameters().getParameters();
|
||||
for (Iterator iterator = map.values().iterator(); iterator.hasNext();) {
|
||||
Object value = iterator.next();
|
||||
builder.append("-" + ((value instanceof Date) ? dateFormat.format(value) : ""+value));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.execution.resource;
|
||||
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
|
||||
/**
|
||||
* Strategy for generating a label (e.g. for a file name) from a
|
||||
* {@link JobIdentifier}. A label is a short string with no special characters
|
||||
* that can be used to recognise the {@link JobIdentifier}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface JobInstanceLabelGenerator {
|
||||
|
||||
/**
|
||||
* Create a label from the {@link JobIdentifier}.
|
||||
*
|
||||
* @param jobInstance
|
||||
* a {@link JobInstance}
|
||||
* @return a short string describing the job instance with no whitespace or
|
||||
* special characters. Return null if the identifier is null.
|
||||
*/
|
||||
String getLabel(JobInstance jobInstance);
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package org.springframework.batch.execution.resource;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.domain.JobSupport;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.JobParametersBuilder;
|
||||
|
||||
public class DefaultJobInstanceLabelGeneratorTests extends TestCase {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final Date DATE = new Date(0);
|
||||
|
||||
DefaultJobInstanceLabelGenerator instance = new DefaultJobInstanceLabelGenerator();
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.resource.DefaultJobInstanceLabelGenerator#getLabel()}.
|
||||
*/
|
||||
public void testGetLabelFromNull() {
|
||||
assertEquals(null, instance.getLabel(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.resource.DefaultJobInstanceLabelGenerator#getLabel()}.
|
||||
*/
|
||||
public void testGetLabel() {
|
||||
assertEquals("foo", instance.getLabel(new JobInstance(null, new JobParameters(), new JobSupport("foo"))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.resource.DefaultJobInstanceLabelGenerator#getLabel()}.
|
||||
*/
|
||||
public void testDefaultGetLabel() throws Exception {
|
||||
JobParameters jobParameters = new JobParametersBuilder().addDate("schedule.date", DATE).addString("key", "bar").toJobParameters();
|
||||
JobInstance job = new JobInstance(null, jobParameters, new JobSupport(null));
|
||||
assertEquals("null-bar-"+dateFormat.format(DATE), instance.getLabel(job));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.execution.resource.DefaultJobInstanceLabelGenerator#getLabel()}.
|
||||
*/
|
||||
public void testGetLabelWithAllProperties() throws Exception {
|
||||
JobParameters jobParameters = new JobParametersBuilder().addDate("schedule.date", DATE).addString("key", "bar").toJobParameters();
|
||||
JobInstance job = new JobInstance(null, jobParameters, new JobSupport("foo"));
|
||||
assertEquals("foo-bar-"+dateFormat.format(DATE), instance.getLabel(job));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user