Example usage for org.springframework.batch.core JobParameter isIdentifying

List of usage examples for org.springframework.batch.core JobParameter isIdentifying

Introduction

In this page you can find the example usage for org.springframework.batch.core JobParameter isIdentifying.

Prototype

public boolean isIdentifying() 

Source Link

Usage

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 {//from  w ww .  j  ava 2  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);
            }/* w  w  w  . j  a v a  2s.c  o  m*/
        } 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 w  w w .  j ava 2 s.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 {/*from   w w w  .ja v  a  2s .c  o m*/
            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 testJobDeployWithTypedParameters() throws InterruptedException, ParseException {
    logger.info("Create batch job with typed parameters");
    JobParametersHolder.reset();/*from  ww  w . j  a v a 2  s  . co  m*/
    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 w w. ja v  a  2 s. co m
    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());
}