use of com.accenture.trac.svc.orch.cache.JobState in project tracdap by finos.
the class JobLifecycle method loadResourcesResponse.
CompletionStage<JobState> loadResourcesResponse(JobState jobState, List<String> mappingKeys, MetadataBatchResponse batchResponse) {
if (batchResponse.getTagCount() != mappingKeys.size())
throw new EUnexpected();
var jobLogic = JobLogic.forJobType(jobState.jobType);
var resources = new HashMap<String, ObjectDefinition>(mappingKeys.size());
var mappings = new HashMap<String, TagHeader>(mappingKeys.size());
for (var resourceIndex = 0; resourceIndex < mappingKeys.size(); resourceIndex++) {
var resourceTag = batchResponse.getTag(resourceIndex);
var resourceKey = MetadataUtil.objectKey(resourceTag.getHeader());
var mappingKey = mappingKeys.get(resourceIndex);
resources.put(resourceKey, resourceTag.getDefinition());
mappings.put(mappingKey, resourceTag.getHeader());
}
jobState.resources.putAll(resources);
jobState.resourceMapping.putAll(mappings);
var extraResources = jobLogic.requiredMetadata(resources).stream().filter(selector -> !jobState.resources.containsKey(MetadataUtil.objectKey(selector))).filter(selector -> !jobState.resourceMapping.containsKey(MetadataUtil.objectKey(selector))).collect(Collectors.toList());
if (!extraResources.isEmpty())
return loadResources(jobState, extraResources);
return CompletableFuture.completedFuture(jobState);
}
Aggregations