From 241609e09f4d478518af5de24a6514042a2398f5 Mon Sep 17 00:00:00 2001 From: dsyer Date: Mon, 4 Feb 2008 18:09:31 +0000 Subject: [PATCH] remove JobInstanceLabelGenerator strategy --- .../DefaultJobInstanceLabelGenerator.java | 59 ------------------- .../resource/JobInstanceLabelGenerator.java | 41 ------------- ...DefaultJobInstanceLabelGeneratorTests.java | 57 ------------------ 3 files changed, 157 deletions(-) delete mode 100644 spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGenerator.java delete mode 100644 spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/JobInstanceLabelGenerator.java delete mode 100644 spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGeneratorTests.java diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGenerator.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGenerator.java deleted file mode 100644 index a78b65eb2..000000000 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGenerator.java +++ /dev/null @@ -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(); - } -} diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/JobInstanceLabelGenerator.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/JobInstanceLabelGenerator.java deleted file mode 100644 index ad6edf94c..000000000 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/resource/JobInstanceLabelGenerator.java +++ /dev/null @@ -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); - -} diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGeneratorTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGeneratorTests.java deleted file mode 100644 index 666111004..000000000 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobInstanceLabelGeneratorTests.java +++ /dev/null @@ -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)); - } - -}