use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class FireStoreDao method lookupDirectoryEntryByPath.
public FireStoreDirectoryEntry lookupDirectoryEntryByPath(Dataset dataset, String path) {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
String datasetId = dataset.getId().toString();
return directoryDao.retrieveByPath(firestore, datasetId, path);
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class FireStoreDao method validateRefIds.
public List<String> validateRefIds(Dataset dataset, List<String> refIdArray) {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
String datasetId = dataset.getId().toString();
return directoryDao.validateRefIds(firestore, datasetId, refIdArray);
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class DataLocationService method getProject.
/**
* Fetch existing DatasetDataProject for the Dataset.
* Delete it if it's invalid, that is, the referenced cloud resource doesn't exist.
* @param dataset
* @return a populated DatasetDataProject if one exists, empty if not
*/
public Optional<DatasetDataProject> getProject(Dataset dataset) {
DatasetDataProjectSummary datasetDataProjectSummary = null;
try {
// first, check if DatasetDataProjectSummary (= mapping btw Dataset ID and cloud Project ID) exists
datasetDataProjectSummary = dataProjectDao.retrieveDatasetDataProject(dataset.getId());
// second, check if the referenced cloud resource exists
GoogleProjectResource googleProjectResource = resourceService.getProjectResourceById(datasetDataProjectSummary.getProjectResourceId());
// if both exist, then create the DatasetDataProject object from the summary and return here
return Optional.of(new DatasetDataProject(datasetDataProjectSummary).googleProjectResource(googleProjectResource));
} catch (DataProjectNotFoundException projNfEx) {
// suppress exception here, will create later
} catch (GoogleResourceNotFoundException rsrcNfEx) {
// I don't think this null check will ever be false, but just in case
if (datasetDataProjectSummary != null) {
logger.warn("metadata has a project resource id it can't resolve for dataset: " + dataset.getName());
dataProjectDao.deleteDatasetDataProject(datasetDataProjectSummary.getId());
}
}
// did not find a valid DatasetDataProject for the given Dataset
return Optional.empty();
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class DataLocationService method getOrCreateProject.
/**
* Fetch existing DatasetDataProject for the Dataset.
* Create a new one if none exists already.
* Note that there can be only one project for a Dataset. This is assumed throughout the application logic, most of
* which currently resides in the Flights, and they would not work correctly if this one-to-one mapping were ever
* violated. For this reason, the check for an existing project below needs to stay at the beginning of this method.
* @param dataset
* @return a populated and valid DatasetDataProject
*/
public DatasetDataProject getOrCreateProject(Dataset dataset) throws InterruptedException {
// check if for an existing DatasetDataProject first, and return here if found one
Optional<DatasetDataProject> existingDataProject = getProject(dataset);
if (existingDataProject.isPresent()) {
return existingDataProject.get();
}
// if we've made it here, then we need to create a new cloud resource and DatasetDataProject
// TODO: if we are in production, don't reuse projects we don't know about
// TODO: add a property to specify which people can view data projects
GoogleProjectRequest googleProjectRequest = new GoogleProjectRequest().projectId(dataLocationSelector.projectIdForDataset(dataset)).profileId(dataset.getDefaultProfileId()).serviceIds(DATA_PROJECT_SERVICE_IDS).roleIdentityMapping(getStewardPolicy());
GoogleProjectResource googleProjectResource = resourceService.getOrCreateProject(googleProjectRequest);
// create the DatasetDataProjectSummary object first, which just holds all the IDs
DatasetDataProjectSummary datasetDataProjectSummary = new DatasetDataProjectSummary().projectResourceId(googleProjectResource.getRepositoryId()).datasetId(dataset.getId());
UUID datasetDataProjectId = dataProjectDao.createDatasetDataProject(datasetDataProjectSummary);
datasetDataProjectSummary.id(datasetDataProjectId);
// then create the DatasetDataProject object from the summary
return new DatasetDataProject(datasetDataProjectSummary).googleProjectResource(googleProjectResource);
}
use of bio.terra.service.dataset.DatasetDataProject in project jade-data-repo by DataBiosphere.
the class FireStoreDao method deleteDirectoryEntry.
public boolean deleteDirectoryEntry(Dataset dataset, String fileId) {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
Firestore firestore = FireStoreProject.get(dataProject.getGoogleProjectId()).getFirestore();
String datasetId = dataset.getId().toString();
return directoryDao.deleteDirectoryEntry(firestore, datasetId, fileId);
}
Aggregations