List of usage examples for org.springframework.batch.core JobParameter getValue
public Object getValue()
From source file:org.springframework.cloud.dataflow.rest.client.support.JobParameterJacksonDeserializer.java
@Override public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); final String value = node.get("value").asText(); final boolean identifying = node.get("identifying").asBoolean(); final String type = node.get("type").asText(); final JobParameter jobParameter; if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) { if ("DATE".equalsIgnoreCase(type)) { // TODO: when upgraded to Java8 use java DateTime jobParameter = new JobParameter(DateTime.parse(value).toDate(), identifying); } else if ("DOUBLE".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Double.valueOf(value), identifying); } else if ("LONG".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Long.valueOf(value), identifying); } else {//w ww .ja v a2 s .c om throw new IllegalStateException("Unsupported JobParameter type: " + type); } } else { jobParameter = new JobParameter(value, identifying); } if (logger.isDebugEnabled()) { logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)", jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying())); } return jobParameter; }
From source file:org.springframework.batch.admin.domain.support.JobParameterJacksonDeserializer.java
@Override public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { SimpleDateFormat formatter = new SimpleDateFormat(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); final String value = node.get("value").asText(); final boolean identifying = node.get("identifying").asBoolean(); final String type = node.get("type").asText(); final JobParameter jobParameter; if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) { if ("DATE".equalsIgnoreCase(type)) { try { jobParameter = new JobParameter(formatter.parse(value), identifying); } catch (ParseException e) { throw new IOException(e); }//from w w w.j av a2 s. com } else if ("DOUBLE".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Double.valueOf(value), identifying); } else if ("LONG".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Long.valueOf(value), identifying); } else { throw new IllegalStateException("Unsupported JobParameter type: " + type); } } else { jobParameter = new JobParameter(value, identifying); } if (logger.isDebugEnabled()) { logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)", jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying())); } return jobParameter; }
From source file:org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.java
/** * Convenience method that inserts all parameters from the provided * JobParameters./*from ww w . j a va 2s . c o m*/ * */ private void insertJobParameters(Long executionId, JobParameters jobParameters) { for (Entry<String, JobParameter> entry : jobParameters.getParameters().entrySet()) { JobParameter jobParameter = entry.getValue(); insertParameter(executionId, jobParameter.getType(), entry.getKey(), jobParameter.getValue(), jobParameter.isIdentifying()); } }
From source file:org.springframework.xd.rest.client.impl.support.JobParameterJacksonDeserializer.java
@Override public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); final String value = node.get("value").asText(); final boolean identifying = node.get("identifying").asBoolean(); final String type = node.get("type").asText(); final JobParameter jobParameter; if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) { if ("DATE".equalsIgnoreCase(type)) { jobParameter = new JobParameter(DateTime.parse(value).toDate(), identifying); } else if ("DOUBLE".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Double.valueOf(value), identifying); } else if ("LONG".equalsIgnoreCase(type)) { jobParameter = new JobParameter(Long.valueOf(value), identifying); } else {/* w ww. java 2s .c om*/ throw new IllegalStateException("Unsupported JobParameter type: " + type); } } else { jobParameter = new JobParameter(value, identifying); } if (logger.isDebugEnabled()) { logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)", jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying())); } return jobParameter; }
From source file:org.springframework.xd.shell.command.JobCommandTests.java
@Test public void testJobDeployWithParameters() throws InterruptedException { logger.info("Create batch job with parameters"); JobParametersHolder.reset();//from www . ja v a2 s. c o m String jobName = generateJobName(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); CommandResult cr = deployJob(jobName); checkForSuccess(cr); checkDeployedJobMessage(cr, jobName); triggerJobWithParams(jobName, "{\"param1\":\"spring rocks!\"}"); boolean done = jobParametersHolder.isDone(); assertTrue("The countdown latch expired and did not count down.", done); int numberOfJobParameters = JobParametersHolder.getJobParameters().size(); assertTrue("Expecting 2 parameters but got " + numberOfJobParameters, numberOfJobParameters == 2); assertNotNull(JobParametersHolder.getJobParameters().get("random")); final JobParameter parameter1 = JobParametersHolder.getJobParameters().get("param1"); assertNotNull(parameter1); assertEquals("spring rocks!", parameter1.getValue()); }
From source file:org.springframework.xd.shell.command.JobCommandTests.java
@Test public void testJobDeployWithTypedParameters() throws InterruptedException, ParseException { logger.info("Create batch job with typed parameters"); JobParametersHolder.reset();// w w w. ja va 2 s . c om String jobName = generateJobName(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false); final JobParametersHolder jobParametersHolder = new JobParametersHolder(); final CommandResult cr = deployJob(jobName); checkForSuccess(cr); checkDeployedJobMessage(cr, jobName); triggerJobWithParams(jobName, "{\"-param1(long)\":\"12345\",\"param2(date)\":\"1990-10-03\"}"); boolean done = jobParametersHolder.isDone(); assertTrue("The countdown latch expired and did not count down.", done); assertTrue("Expecting 3 parameters.", JobParametersHolder.getJobParameters().size() == 3); assertNotNull(JobParametersHolder.getJobParameters().get("random")); final JobParameter parameter1 = JobParametersHolder.getJobParameters().get("param1"); final JobParameter parameter2 = JobParametersHolder.getJobParameters().get("param2"); assertNotNull(parameter1); assertNotNull(parameter2); assertTrue("parameter1 should be a Long", parameter1.getValue() instanceof Long); assertTrue("parameter2 should be a java.util.Date", parameter2.getValue() instanceof Date); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); final Date expectedDate = dateFormat.parse("1990/10/03"); assertEquals("Was expecting the Long value 12345", Long.valueOf(12345), parameter1.getValue()); assertEquals("Should be the same dates", expectedDate, parameter2.getValue()); assertFalse("parameter1 should be non-identifying", parameter1.isIdentifying()); assertTrue("parameter2 should be identifying", parameter2.isIdentifying()); }
From source file:org.springframework.xd.shell.command.JobCommandTests.java
@Test public void testLaunchJobWithParameters() throws InterruptedException, ParseException { logger.info("Launch batch job with typed parameters"); String myJobParams = "{\"-param1(long)\":\"12345\",\"param2(date)\":\"1990-10-03\"}"; JobParametersHolder.reset();/*from w ww . j a v a2 s . c om*/ final JobParametersHolder jobParametersHolder = new JobParametersHolder(); String jobName = generateJobName(); executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR); checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true); executeJobLaunch(jobName, myJobParams); boolean done = jobParametersHolder.isDone(); assertTrue("The countdown latch expired and did not count down.", done); // Make sure the job parameters are set when passing through job launch command assertTrue("Expecting 3 parameters, but got: " + JobParametersHolder.getJobParameters(), JobParametersHolder.getJobParameters().size() == 3); assertNotNull(JobParametersHolder.getJobParameters().get("random")); final JobParameter parameter1 = JobParametersHolder.getJobParameters().get("param1"); final JobParameter parameter2 = JobParametersHolder.getJobParameters().get("param2"); assertNotNull(parameter1); assertNotNull(parameter2); assertTrue("parameter1 should be a Long", parameter1.getValue() instanceof Long); assertTrue("parameter2 should be a java.util.Date", parameter2.getValue() instanceof Date); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); final Date expectedDate = dateFormat.parse("1990/10/03"); assertEquals("Was expecting the Long value 12345", Long.valueOf(12345), parameter1.getValue()); assertEquals("Should be the same dates", expectedDate, parameter2.getValue()); assertFalse("parameter1 should be non-identifying", parameter1.isIdentifying()); assertTrue("parameter2 should be identifying", parameter2.isIdentifying()); }