@Override public Job to(UriInfo uriInfo, JobModel representation) { return Job.Builder.build( j -> { j.setJobName(representation.getName()); j.setExternalIds(representation.getExternalIds()); j.setJobType(JobType.valueOf(representation.getType())); Optional.ofNullable(representation.getStatus()) .map(ResourceStatusModel::getCurrent) .map(JobStatus::valueOf) .ifPresent(j::setStatus); j.setJobConfiguration( modelMapper.map( representation.getConfiguration(), getJobConfigurationClass(representation.getType()))); Optional.ofNullable(representation.getPriority()).ifPresent(j::setPriority); }); }
@Override public JobModel from(UriInfo uriInfo, Job job) { JobModel jobModel = new JobModel(); jobModel.setId(job.getId()); jobModel.setName(job.getJobName()); jobModel.setExternalIds(job.getExternalIds()); jobModel.setType(job.getJobType().name()); jobModel.setStatus( new ResourceStatusModel( job.getStatus().name(), ZonedDateTime.ofInstant(job.getStatusTimestamp().toInstant(), ZoneId.systemDefault()))); jobModel.setPriority(job.getPriority()); jobModel.setCreated( ZonedDateTime.ofInstant(job.getCreated().toInstant(), ZoneId.systemDefault())); jobModel.setCreatedBy(job.getCreatedBy()); jobModel.setLastModified( ZonedDateTime.ofInstant(job.getLastModified().toInstant(), ZoneId.systemDefault())); jobModel.setLastModifiedBy(job.getLastModifiedBy()); ImmutableMap.Builder<String, Href> builder = ImmutableMap.builder(); builder.put("self", new Href(getJobResourceUrlAsString(uriInfo, job, null))); builder.put( "configuration", new Href(getJobResourceUrlAsString(uriInfo, job, "configuration"))); builder.put("status", new Href(getJobResourceUrlAsString(uriInfo, job, "status"))); jobModel.setLinks(builder.build()); return jobModel; }