Example #1
0
        public async Task <List <BlobStorageItemDto> > GetFileListAsync(int datasetId, string clientIp, CancellationToken cancellationToken = default)
        {
            try
            {
                if (await _studySpecificDatasetModelService.IsStudySpecific(datasetId))
                {
                    var dataset = await _studySpecificDatasetModelService.GetForResourceAndFirewall(datasetId, UserOperation.Study_Read);

                    var datasetResourceEntry = DatasetUtils.GetStudySpecificStorageAccountResourceEntry(dataset);

                    if (datasetResourceEntry == null)
                    {
                        throw new Exception($"Resource entry for Dataset {dataset.Id} not found");
                    }

                    var study = DatasetUtils.GetStudyFromStudySpecificDatasetOrThrow(dataset);

                    await _datasetCloudResourceService.EnsureFirewallExistsAsync(study, dataset, clientIp, cancellationToken);

                    _storageService.SetConnectionParameters(datasetResourceEntry.ResourceGroupName, datasetResourceEntry.ResourceName);
                }
                else
                {
                    throw new NotImplementedException("Only Study specific datasets is supported");
                }

                return(await _storageService.GetFileList(DatasetConstants.STUDY_SPECIFIC_DATASET_DEFAULT_CONTAINER, cancellationToken));
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to get file list from Storage Account - {ex.Message}", ex);
            }
        }
Example #2
0
        public async Task <DatasetDto> CreateStudySpecificDatasetAsync(int studyId, DatasetCreateUpdateInputBaseDto newDatasetInput, string clientIp, CancellationToken cancellationToken = default)
        {
            var studyFromDb = await _studyModelService.GetForDatasetCreationAsync(studyId, UserOperation.Study_AddRemove_Dataset);

            await _studyWbsValidationService.ValidateForDatasetCreationOrThrow(studyFromDb);

            DatasetUtils.PerformUsualTestForPostedDatasets(newDatasetInput);

            ThrowIfDatasetNameTaken(studyFromDb, newDatasetInput.Name);

            var dataset = _mapper.Map <Dataset>(newDatasetInput);

            dataset.StudySpecific = true;

            var currentUser = await _userService.GetCurrentUserAsync();

            dataset.CreatedBy = currentUser.UserName;

            _db.Datasets.Add(dataset);
            await _db.SaveChangesAsync();

            // Create new linking table entry
            var studyDataset = new StudyDataset {
                StudyId = studyFromDb.Id, DatasetId = dataset.Id
            };
            await _db.StudyDatasets.AddAsync(studyDataset);

            await _db.SaveChangesAsync();

            dataset = await _studySpecificDatasetModelService.GetForResourceAndFirewall(dataset.Id, UserOperation.Study_AddRemove_Dataset);

            try
            {
                await _datasetCloudResourceService.CreateResourcesForStudySpecificDatasetAsync(studyFromDb, dataset, clientIp, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Unable to create resources for Study specific Dataset, deleting dataset");
                _db.StudyDatasets.Remove(studyDataset);
                _db.Datasets.Remove(dataset);
                await _db.SaveChangesAsync();

                throw;
            }

            var datasetDto = _mapper.Map <DatasetDto>(dataset);

            await DecorateDtoStudySpecific(_userService, studyFromDb, datasetDto.Permissions);

            return(datasetDto);
        }