From 3510285c8ba4b38bd4d93602ce6708ed4e015cce Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Thu, 20 Feb 2014 16:18:51 -0600 Subject: [PATCH] BATCH-2179: Updated to add unidentifying flag to properties as they are returned if applicable --- .../DefaultJobParametersConverter.java | 8 ++++++-- .../DefaultJobParametersConverterTests.java | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/converter/DefaultJobParametersConverter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/converter/DefaultJobParametersConverter.java index 91230d117..a40d84547 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/converter/DefaultJobParametersConverter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/converter/DefaultJobParametersConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2014 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. @@ -180,7 +180,10 @@ public class DefaultJobParametersConverter implements JobParametersConverter { /** * Use the same suffixes to create properties (omitting the string suffix - * because it is the default). + * because it is the default). Non-identifying parameters will be prefixed + * with the {@link #NON_IDENTIFYING_FLAG}. However, since parameters are + * identifying by default, they will not be prefixed with the + * {@link #IDENTIFYING_FLAG}. * * @see org.springframework.batch.core.converter.JobParametersConverter#getProperties(org.springframework.batch.core.JobParameters) */ @@ -199,6 +202,7 @@ public class DefaultJobParametersConverter implements JobParametersConverter { JobParameter jobParameter = entry.getValue(); Object value = jobParameter.getValue(); if (value != null) { + key = (!jobParameter.isIdentifying()? NON_IDENTIFYING_FLAG : "") + key; if (jobParameter.getType() == ParameterType.DATE) { synchronized (dateFormat) { result.setProperty(key + DATE_TYPE, dateFormat.format(value)); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/converter/DefaultJobParametersConverterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/converter/DefaultJobParametersConverterTests.java index 3f5f99d54..cad9c6510 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/converter/DefaultJobParametersConverterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/converter/DefaultJobParametersConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2014 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. @@ -281,6 +281,22 @@ public class DefaultJobParametersConverterTests { assertEquals("1.23", props.getProperty("double.key(double)")); } + @Test + public void testRoundTripWithIdentifyingAndNonIdentifying() throws Exception { + + String[] args = new String[] { "schedule.date(date)=2008/01/23", "+job.key=myKey", "-vendor.id(long)=33243243", + "double.key(double)=1.23" }; + + JobParameters parameters = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "=")); + + Properties props = factory.getProperties(parameters); + assertNotNull(props); + assertEquals("myKey", props.getProperty("job.key")); + assertEquals("33243243", props.getProperty("-vendor.id(long)")); + assertEquals("2008/01/23", props.getProperty("schedule.date(date)")); + assertEquals("1.23", props.getProperty("double.key(double)")); + } + @Test public void testRoundTripWithNumberFormat() throws Exception {