Beispiel #1
0
        public async Task <IActionResult> GetRelationshipsBySpecificationId(string specificationId)
        {
            if (string.IsNullOrWhiteSpace(specificationId))
            {
                _logger.Error("No specification id was provided to GetRelationshipsBySpecificationId");

                return(new BadRequestObjectResult("No specification id was provided to GetRelationshipsBySpecificationId"));
            }

            IEnumerable <DefinitionSpecificationRelationship> relationships =
                await _datasetRepository.GetDefinitionSpecificationRelationshipsByQuery(m => m.Content.Specification.Id == specificationId);

            if (relationships.IsNullOrEmpty())
            {
                relationships = new DefinitionSpecificationRelationship[0];
            }

            IList <DatasetSpecificationRelationshipViewModel> relationshipViewModels = new List <DatasetSpecificationRelationshipViewModel>();

            if (relationships.IsNullOrEmpty())
            {
                return(new OkObjectResult(relationshipViewModels));
            }

            IList <Task <DatasetSpecificationRelationshipViewModel> > tasks = new List <Task <DatasetSpecificationRelationshipViewModel> >();

            IEnumerable <KeyValuePair <string, int> > datasetLatestVersions =
                await _datasetRepository.GetDatasetLatestVersions(relationships.Select(_ => _.DatasetVersion?.Id));

            foreach (DefinitionSpecificationRelationship relationship in relationships)
            {
                KeyValuePair <string, int> datasetLatestVersion       = datasetLatestVersions.SingleOrDefault(_ => _.Key == relationship.DatasetVersion?.Id);
                Task <DatasetSpecificationRelationshipViewModel> task = CreateViewModel(relationship, datasetLatestVersion);

                tasks.Add(task);
            }

            await Task.WhenAll(tasks);

            foreach (Task <DatasetSpecificationRelationshipViewModel> task in tasks)
            {
                relationshipViewModels.Add(task.Result);
            }

            return(new OkObjectResult(tasks.Select(m => m.Result)));
        }
        public async Task RegenerateProviderSourceDatasets_GivenSpecificationId_ThenCallJobServiceToProcess()
        {
            // Arrange
            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "specificationId", new StringValues(SpecificationId) },
            });

            HttpRequest request = Substitute.For <HttpRequest>();

            request.Query.Returns(queryStringValues);

            IDatasetRepository datasetRepository = CreateDatasetsRepository();

            datasetRepository
            .GetDefinitionSpecificationRelationshipsByQuery(Arg.Any <Expression <Func <DefinitionSpecificationRelationship, bool> > >())
            .Returns(new List <DefinitionSpecificationRelationship>
            {
                new DefinitionSpecificationRelationship {
                    DatasetVersion = new DatasetRelationshipVersion {
                        Id = "DSRV1", Version = 1
                    },
                    Specification = new Common.Models.Reference {
                        Id = SpecificationId, Name = "SpecAbc"
                    }
                }
            });
            datasetRepository
            .GetDatasetsByQuery(Arg.Any <Expression <Func <Dataset, bool> > >())
            .Returns(new List <Dataset>
            {
                new Dataset {
                    Id = "DS1"
                }
            });

            IJobsApiClient jobsApiClient = CreateJobsApiClient();

            DatasetService service = CreateDatasetService(datasetRepository: datasetRepository, jobsApiClient: jobsApiClient);

            // Act
            await service.RegenerateProviderSourceDatasets(request);

            // Assert
            await jobsApiClient
            .Received(1)
            .CreateJob(Arg.Is <JobCreateModel>(j =>
                                               j.JobDefinitionId == "MapDatasetJob" &&
                                               j.Properties.ContainsKey("session-id") &&
                                               j.Properties["session-id"] == SpecificationId));
        }
        public async Task <IActionResult> GetRelationshipsBySpecificationId(HttpRequest request)
        {
            request.Query.TryGetValue("specificationId", out Microsoft.Extensions.Primitives.StringValues specId);

            string specificationId = specId.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(specificationId))
            {
                _logger.Error("No specification id was provided to GetRelationshipsBySpecificationId");

                return(new BadRequestObjectResult("No specification id was provided to GetRelationshipsBySpecificationId"));
            }

            IEnumerable <DefinitionSpecificationRelationship> relationships =
                await _datasetRepository.GetDefinitionSpecificationRelationshipsByQuery(m => m.Specification.Id == specificationId);

            if (relationships.IsNullOrEmpty())
            {
                relationships = new DefinitionSpecificationRelationship[0];
            }

            return(new OkObjectResult(relationships));
        }
Beispiel #4
0
        public async Task RegenerateProviderSourceDatasets_GivenSpecificationId_ThenCallJobServiceToProcess()
        {
            // Arrange
            IDatasetRepository datasetRepository = CreateDatasetsRepository();

            datasetRepository
            .GetDefinitionSpecificationRelationshipsByQuery(Arg.Any <Expression <Func <DocumentEntity <DefinitionSpecificationRelationship>, bool> > >())
            .Returns(new List <DefinitionSpecificationRelationship>
            {
                new DefinitionSpecificationRelationship {
                    DatasetVersion = new DatasetRelationshipVersion {
                        Id = "DSRV1", Version = 1
                    },
                    Specification = new Common.Models.Reference {
                        Id = SpecificationId, Name = "SpecAbc"
                    }
                }
            });
            datasetRepository
            .GetDatasetsByQuery(Arg.Any <Expression <Func <DocumentEntity <Dataset>, bool> > >())
            .Returns(new List <Dataset>
            {
                new Dataset {
                    Id = "DS1"
                }
            });

            IJobManagement jobManagement = CreateJobManagement();

            DatasetService service = CreateDatasetService(datasetRepository: datasetRepository, jobManagement: jobManagement);

            // Act
            await service.RegenerateProviderSourceDatasets(SpecificationId, null, null);

            // Assert
            await jobManagement
            .Received(1)
            .QueueJob(Arg.Is <JobCreateModel>(j =>
                                              j.JobDefinitionId == "MapDatasetJob" &&
                                              j.Properties.ContainsKey("session-id") &&
                                              j.Properties["session-id"] == SpecificationId));
        }
 private void AndRelationshipsForSpecification(IEnumerable <DefinitionSpecificationRelationship> relationships)
 {
     _datasetRepository.GetDefinitionSpecificationRelationshipsByQuery(Arg.Any <Expression <Func <DocumentEntity <DefinitionSpecificationRelationship>, bool> > >())
     .Returns(relationships);
 }