Search in sources :

Example 1 with DataDeletionGcsFileModel

use of bio.terra.model.DataDeletionGcsFileModel in project jade-data-repo by DataBiosphere.

the class DataDeletionRequestValidator method validateFileSpec.

private void validateFileSpec(DataDeletionTableModel fileSpec, Errors errors) {
    String tableName = fileSpec.getTableName();
    if (StringUtils.isEmpty(tableName)) {
        errors.rejectValue("tables.tableName", "TableNameMissing", "Requires a table name");
    }
    DataDeletionGcsFileModel gcsFileSpec = fileSpec.getGcsFileSpec();
    if (gcsFileSpec == null) {
        errors.rejectValue("tables.gcsFileSpec", "FileSpecMissing", "Requires a file spec");
    } else {
        try {
            IngestUtils.parseBlobUri(gcsFileSpec.getPath());
        } catch (InvalidUriException ex) {
            errors.rejectValue("tables.gcsFileSpec.path", "InvalidGsUri", ex.getMessage());
        }
    }
}
Also used : InvalidUriException(bio.terra.service.dataset.exception.InvalidUriException) DataDeletionGcsFileModel(bio.terra.model.DataDeletionGcsFileModel)

Example 2 with DataDeletionGcsFileModel

use of bio.terra.model.DataDeletionGcsFileModel in project jade-data-repo by DataBiosphere.

the class DatasetConnectedTest method uploadInputFileAndBuildSoftDeleteRequest.

private DataDeletionRequest uploadInputFileAndBuildSoftDeleteRequest(String dirInCloud, String filenameInCloud, String tableName, List<String> softDeleteRowIds) throws Exception {
    Storage storage = StorageOptions.getDefaultInstance().getService();
    // load a CSV file that contains the table rows to soft delete into the test bucket
    StringBuilder csvLines = new StringBuilder();
    for (String softDeleteRowId : softDeleteRowIds) {
        csvLines.append(softDeleteRowId + "\n");
    }
    BlobInfo softDeleteBlob = BlobInfo.newBuilder(testConfig.getIngestbucket(), dirInCloud + "/" + filenameInCloud).build();
    storage.create(softDeleteBlob, csvLines.toString().getBytes(Charset.forName("UTF-8")));
    String softDeleteInputFilePath = "gs://" + testConfig.getIngestbucket() + "/" + dirInCloud + "/" + filenameInCloud;
    // make sure the JSON file gets cleaned up on test teardown
    connectedOperations.addScratchFile(dirInCloud + "/" + filenameInCloud);
    // build the soft delete request with a pointer to a file that contains the row ids to soft delete
    DataDeletionGcsFileModel softDeleteGcsFileModel = new DataDeletionGcsFileModel().fileType(DataDeletionGcsFileModel.FileTypeEnum.CSV).path(softDeleteInputFilePath);
    DataDeletionTableModel softDeleteTableModel = new DataDeletionTableModel().tableName(tableName).gcsFileSpec(softDeleteGcsFileModel);
    DataDeletionRequest softDeleteRequest = new DataDeletionRequest().deleteType(DataDeletionRequest.DeleteTypeEnum.SOFT).specType(DataDeletionRequest.SpecTypeEnum.GCSFILE).tables(Arrays.asList(softDeleteTableModel));
    return softDeleteRequest;
}
Also used : Storage(com.google.cloud.storage.Storage) DataDeletionRequest(bio.terra.model.DataDeletionRequest) DataDeletionGcsFileModel(bio.terra.model.DataDeletionGcsFileModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BlobInfo(com.google.cloud.storage.BlobInfo) DataDeletionTableModel(bio.terra.model.DataDeletionTableModel)

Aggregations

DataDeletionGcsFileModel (bio.terra.model.DataDeletionGcsFileModel)2 DataDeletionRequest (bio.terra.model.DataDeletionRequest)1 DataDeletionTableModel (bio.terra.model.DataDeletionTableModel)1 InvalidUriException (bio.terra.service.dataset.exception.InvalidUriException)1 BlobInfo (com.google.cloud.storage.BlobInfo)1 Storage (com.google.cloud.storage.Storage)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1