use of bio.terra.workspace.db.exception.InvalidMetadataException in project terra-workspace-manager by DataBiosphere.
the class ReferencedResourceService method createReferenceResource.
@Traced
public ReferencedResource createReferenceResource(ReferencedResource resource, AuthenticatedUserRequest userRequest) {
workspaceService.validateWorkspaceAndAction(userRequest, resource.getWorkspaceId(), SamConstants.SamWorkspaceAction.CREATE_REFERENCE);
String jobDescription = String.format("Create reference %s; id %s; name %s", resource.getResourceType(), resource.getResourceId(), resource.getName());
// The reason for separately passing in the ResourceType is to retrieve the class for this
// particular request. In the flight, when we get the request object from the input parameters,
// we can supply the right target class.
JobBuilder createJob = jobService.newJob().description(jobDescription).flightClass(CreateReferenceResourceFlight.class).resource(resource).userRequest(userRequest).operationType(OperationType.CREATE).workspaceId(resource.getWorkspaceId().toString()).resourceType(resource.getResourceType()).stewardshipType(StewardshipType.REFERENCED);
UUID resourceIdResult = createJob.submitAndWait(UUID.class);
if (!resourceIdResult.equals(resource.getResourceId())) {
throw new InvalidMetadataException("Input and output resource ids do not match");
}
return getReferenceResource(resource.getWorkspaceId(), resourceIdResult, userRequest);
}
Aggregations