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

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

Introduction

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

Prototype

public ParameterType getType() 

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  . jav a 2 s. 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.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 a  v  a2  s.  c  om
        } 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.//  w  w w  .j  a  v a  2 s .  co 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  .j a va  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;
}