Skip to content

Commit

Permalink
Support for JobConfig properties with non-String types. No-arg and al…
Browse files Browse the repository at this point in the history
…l-arg constructor for JobConfig
  • Loading branch information
chrisgleissner committed Mar 8, 2020
1 parent f45980c commit 344e957
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Expand Up @@ -14,6 +14,7 @@
import org.springframework.stereotype.Component;

import javax.batch.operations.BatchRuntimeException;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -55,7 +56,7 @@ public JobExecution start(JobConfig jobConfig) {
jobPropertyResolvers.started(jobConfig);

Map<String, JobParameter> params = Optional.ofNullable(jobConfig.getProperties()).orElse(emptyMap()).entrySet().stream()
.collect(toMap(e -> e.getKey(), e -> new JobParameter(e.getValue())));
.collect(toMap(Map.Entry::getKey, e -> createJobParameter(e.getValue())));
if (addUniqueJobParameter)
params.put("uuid", new JobParameter(UUID.randomUUID().toString()));
JobParameters jobParameters = new JobParameters(params);
Expand All @@ -71,4 +72,15 @@ public JobExecution start(JobConfig jobConfig) {
jobConfig.getName(), jobConfig, e.getMessage()), e);
}
}

private JobParameter createJobParameter(Object value) {
if (value instanceof Date)
return new JobParameter((Date) value);
else if (value instanceof Long)
return new JobParameter((Long) value);
else if (value instanceof Double)
return new JobParameter((Double) value);
else
return new JobParameter("" + value);
}
}
@@ -1,18 +1,14 @@
package com.github.chrisgleissner.springbatchrest.util.core;

import lombok.Builder;
import lombok.Data;
import lombok.Singular;
import lombok.*;

import java.util.HashMap;
import java.util.Map;

@Data
@Builder(toBuilder = true)
@Data @NoArgsConstructor @AllArgsConstructor @Builder(toBuilder = true)
public class JobConfig {

private String name;
@Singular("property")
private Map<String, String> properties = new HashMap<>();
private Map<String, Object> properties = new HashMap<>();
private boolean asynchronous;
}

0 comments on commit 344e957

Please sign in to comment.