Search in sources :

Example 1 with InvalidMetadataException

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);
}
Also used : InvalidMetadataException(bio.terra.workspace.db.exception.InvalidMetadataException) JobBuilder(bio.terra.workspace.service.job.JobBuilder) UUID(java.util.UUID) Traced(io.opencensus.contrib.spring.aop.Traced)

Aggregations

InvalidMetadataException (bio.terra.workspace.db.exception.InvalidMetadataException)1 JobBuilder (bio.terra.workspace.service.job.JobBuilder)1 Traced (io.opencensus.contrib.spring.aop.Traced)1 UUID (java.util.UUID)1