Source:
public static JobSpecification toJobSpecificationDto(final JobSpecificationProjection jobSpecificationProjection) { final String id = jobSpecificationProjection.getUniqueId(); final ClusterEntity clusterEntity = jobSpecificationProjection .getCluster() .orElseThrow( () -> new GenieRuntimeException("No cluster found for job " + id + ". Was expected to exist.") ); final CommandEntity commandEntity = jobSpecificationProjection .getCommand() .orElseThrow( () -> new GenieRuntimeException("No command found for job " + id + ". Was expected to exist.") ); final File jobDirectoryLocation = jobSpecificationProjection .getJobDirectoryLocation() .map(File::new) .orElseThrow( () -> new GenieRuntimeException( "No job directory location available for job " + id + ". Was expected to exist" ) ); final JobSpecification.ExecutionResource job = toExecutionResource( id, jobSpecificationProjection.getConfigs(), jobSpecificationProjection.getDependencies(), jobSpecificationProjection.getSetupFile().orElse(null) ); final JobSpecification.ExecutionResource cluster = toExecutionResource( clusterEntity.getUniqueId(), clusterEntity.getConfigs(), clusterEntity.getDependencies(), clusterEntity.getSetupFile().orElse(null) ); final JobSpecification.ExecutionResource command = toExecutionResource( commandEntity.getUniqueId(), commandEntity.getConfigs(), commandEntity.getDependencies(), commandEntity.getSetupFile().orElse(null) ); final List<JobSpecification.ExecutionResource> applications = jobSpecificationProjection .getApplications() .stream() .map( applicationEntity -> toExecutionResource( applicationEntity.getUniqueId(), applicationEntity.getConfigs(), applicationEntity.getDependencies(), applicationEntity.getSetupFile().orElse(null) ) ) .collect(Collectors.toList()); final List<String> commandArgs = Lists.newArrayList(commandEntity.getExecutable()); commandArgs.addAll(jobSpecificationProjection.getCommandArgs()); return new JobSpecification( commandArgs, job, cluster, command, applications, jobSpecificationProjection.getEnvironmentVariables(), jobSpecificationProjection.isInteractive(), jobDirectoryLocation ); }

Target:
public static JobSpecification toJobSpecificationDto(final JobSpecificationProjection jobSpecificationProjection) { final String id = jobSpecificationProjection.getUniqueId(); final ClusterEntity clusterEntity = jobSpecificationProjection .getCluster() .orElseThrow( () -> new GenieClusterNotFoundException("No cluster found for job " + id + ". Was expected to exist.") ); final CommandEntity commandEntity = jobSpecificationProjection .getCommand() .orElseThrow( () -> new GenieCommandNotFoundException("No command found for job " + id + ". Was expected to exist.") ); final File jobDirectoryLocation = jobSpecificationProjection .getJobDirectoryLocation() .map(File::new) .orElseThrow( () -> new GenieRuntimeException( "No job directory location available for job " + id + ". Was expected to exist" ) ); final JobSpecification.ExecutionResource job = toExecutionResource( id, jobSpecificationProjection.getConfigs(), jobSpecificationProjection.getDependencies(), jobSpecificationProjection.getSetupFile().orElse(null) ); final JobSpecification.ExecutionResource cluster = toExecutionResource( clusterEntity.getUniqueId(), clusterEntity.getConfigs(), clusterEntity.getDependencies(), clusterEntity.getSetupFile().orElse(null) ); final JobSpecification.ExecutionResource command = toExecutionResource( commandEntity.getUniqueId(), commandEntity.getConfigs(), commandEntity.getDependencies(), commandEntity.getSetupFile().orElse(null) ); final List<JobSpecification.ExecutionResource> applications = jobSpecificationProjection .getApplications() .stream() .map( applicationEntity -> toExecutionResource( applicationEntity.getUniqueId(), applicationEntity.getConfigs(), applicationEntity.getDependencies(), applicationEntity.getSetupFile().orElse(null) ) ) .collect(Collectors.toList()); final List<String> commandArgs = Lists.newArrayList(commandEntity.getExecutable()); commandArgs.addAll(jobSpecificationProjection.getCommandArgs()); return new JobSpecification( commandArgs, job, cluster, command, applications, jobSpecificationProjection.getEnvironmentVariables(), jobSpecificationProjection.isInteractive(), jobDirectoryLocation ); }