use of bio.terra.app.controller.exception.ValidationException in project jade-data-repo by DataBiosphere.
the class RepositoryApiController method deleteDatasetPolicyMember.
@Override
public ResponseEntity<PolicyResponse> deleteDatasetPolicyMember(@PathVariable("id") String id, @PathVariable("policyName") String policyName, @PathVariable("memberEmail") String memberEmail) {
// member email can't be null since it is part of the URL
if (!ValidationUtils.isValidEmail(memberEmail)) {
throw new ValidationException("InvalidMemberEmail");
}
PolicyModel policy = iamService.deletePolicyMember(getAuthenticatedInfo(), IamResourceType.DATASET, UUID.fromString(id), policyName, memberEmail);
PolicyResponse response = new PolicyResponse().policies(Collections.singletonList(policy));
return new ResponseEntity<>(response, HttpStatus.OK);
}
use of bio.terra.app.controller.exception.ValidationException in project jade-data-repo by DataBiosphere.
the class RepositoryApiController method deleteSnapshotPolicyMember.
@Override
public ResponseEntity<PolicyResponse> deleteSnapshotPolicyMember(@PathVariable("id") String id, @PathVariable("policyName") String policyName, @PathVariable("memberEmail") String memberEmail) {
// member email can't be null since it is part of the URL
if (!ValidationUtils.isValidEmail(memberEmail)) {
throw new ValidationException("InvalidMemberEmail");
}
PolicyModel policy = iamService.deletePolicyMember(getAuthenticatedInfo(), IamResourceType.DATASNAPSHOT, UUID.fromString(id), policyName, memberEmail);
PolicyResponse response = new PolicyResponse().policies(Collections.singletonList(policy));
return new ResponseEntity<>(response, HttpStatus.OK);
}
use of bio.terra.app.controller.exception.ValidationException in project jade-data-repo by DataBiosphere.
the class SnapshotService method makeSnapshotFromSnapshotRequest.
/**
* Make a Snapshot structure with all of its parts from an incoming snapshot request.
* Note that the structure does not have UUIDs or created dates filled in. Those are
* updated by the DAO when it stores the snapshot in the repository metadata.
*
* @param snapshotRequestModel
* @return Snapshot
*/
public Snapshot makeSnapshotFromSnapshotRequest(SnapshotRequestModel snapshotRequestModel) {
// Make this early so we can hook up back links to it
Snapshot snapshot = new Snapshot();
List<SnapshotRequestContentsModel> requestContentsList = snapshotRequestModel.getContents();
// TODO: for MVM we only allow one source list
if (requestContentsList.size() > 1) {
throw new ValidationException("Only a single snapshot contents entry is currently allowed.");
}
SnapshotRequestContentsModel requestContents = requestContentsList.get(0);
Dataset dataset = datasetService.retrieveByName(requestContents.getDatasetName());
SnapshotSource snapshotSource = new SnapshotSource().snapshot(snapshot).dataset(dataset);
switch(snapshotRequestModel.getContents().get(0).getMode()) {
case BYASSET:
// TODO: When we implement explicit definition of snapshot tables, we will handle that here.
// For now, we generate the snapshot tables directly from the asset tables of the one source
// allowed in a snapshot.
AssetSpecification assetSpecification = getAssetSpecificationFromRequest(requestContents);
snapshotSource.assetSpecification(assetSpecification);
conjureSnapshotTablesFromAsset(snapshotSource.getAssetSpecification(), snapshot, snapshotSource);
break;
case BYFULLVIEW:
conjureSnapshotTablesFromDatasetTables(snapshot, snapshotSource);
break;
case BYQUERY:
SnapshotRequestQueryModel queryModel = requestContents.getQuerySpec();
String assetName = queryModel.getAssetName();
String snapshotQuery = queryModel.getQuery();
Query query = Query.parse(snapshotQuery);
List<String> datasetNames = query.getDatasetNames();
// TODO this makes the assumption that there is only one dataset
// (based on the validation flight step that already occurred.)
// This will change when more than 1 dataset is allowed
String datasetName = datasetNames.get(0);
Dataset queryDataset = datasetService.retrieveByName(datasetName);
AssetSpecification queryAssetSpecification = queryDataset.getAssetSpecificationByName(assetName).orElseThrow(() -> new AssetNotFoundException("This dataset does not have an asset specification with name: " + assetName));
snapshotSource.assetSpecification(queryAssetSpecification);
// TODO this is wrong? why dont we just pass the assetSpecification?
conjureSnapshotTablesFromAsset(snapshotSource.getAssetSpecification(), snapshot, snapshotSource);
break;
case BYROWID:
SnapshotRequestRowIdModel requestRowIdModel = requestContents.getRowIdSpec();
conjureSnapshotTablesFromRowIds(requestRowIdModel, snapshot, snapshotSource);
break;
default:
throw new InvalidSnapshotException("Snapshot does not have required mode information");
}
return snapshot.name(snapshotRequestModel.getName()).description(snapshotRequestModel.getDescription()).snapshotSources(Collections.singletonList(snapshotSource)).profileId(UUID.fromString(snapshotRequestModel.getProfileId())).relationships(createSnapshotRelationships(dataset.getRelationships(), snapshotSource));
}
use of bio.terra.app.controller.exception.ValidationException in project jade-data-repo by DataBiosphere.
the class DeleteDatasetValidateStep method doStep.
@Override
public StepResult doStep(FlightContext context) {
List<SnapshotSummary> snapshots = snapshotDao.retrieveSnapshotsForDataset(datasetId);
Dataset dataset = datasetService.retrieve(datasetId);
if (snapshots.size() != 0) {
throw new ValidationException("Can not delete a dataset being used by snapshots");
}
// if there are no snapshots returned from retrieveSnapshotsForDataset.
if (dependencyDao.datasetHasSnapshotReference(dataset)) {
throw new FileSystemCorruptException("File system has snapshot dependencies; metadata does not");
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.app.controller.exception.ValidationException in project jade-data-repo by DataBiosphere.
the class RepositoryApiController method lookupSnapshotFileByPath.
@Override
public ResponseEntity<FileModel> lookupSnapshotFileByPath(@PathVariable("id") String id, @RequestParam(value = "path", required = true) String path, @RequestParam(value = "depth", required = false, defaultValue = "0") Integer depth) {
iamService.verifyAuthorization(getAuthenticatedInfo(), IamResourceType.DATASNAPSHOT, id, IamAction.READ_DATA);
if (!ValidationUtils.isValidPath(path)) {
throw new ValidationException("InvalidPath");
}
FileModel fileModel = fileService.lookupSnapshotPath(id, path, depth);
return new ResponseEntity<>(fileModel, HttpStatus.OK);
}
Aggregations