private async Task <BuildProject> ProcessDataset(Dataset dataset, string specificationId, string relationshipId, int version, Reference user) { string dataDefinitionId = dataset.Definition.Id; DatasetVersion datasetVersion = dataset.History.Where(v => v.Version == version).SingleOrDefault(); if (datasetVersion == null) { _logger.Error("Dataset version not found for dataset '{name}' ({id}) version '{version}'", dataset.Id, dataset.Name, version); throw new NonRetriableException($"Dataset version not found for dataset '{dataset.Name}' ({dataset.Name}) version '{version}'"); } string fullBlobName = datasetVersion.BlobName; DatasetDefinition datasetDefinition = (await _datasetRepository.GetDatasetDefinitionsByQuery(m => m.Id == dataDefinitionId))?.FirstOrDefault(); if (datasetDefinition == null) { _logger.Error($"Unable to find a data definition for id: {dataDefinitionId}, for blob: {fullBlobName}"); throw new NonRetriableException($"Unable to find a data definition for id: {dataDefinitionId}, for blob: {fullBlobName}"); } BuildProject buildProject = await _calcsRepository.GetBuildProjectBySpecificationId(specificationId); if (buildProject == null) { _logger.Error($"Unable to find a build project for specification id: {specificationId}"); throw new NonRetriableException($"Unable to find a build project for id: {specificationId}"); } TableLoadResult loadResult = await GetTableResult(fullBlobName, datasetDefinition); if (loadResult == null) { _logger.Error($"Failed to load table result"); throw new NonRetriableException($"Failed to load table result"); } await PersistDataset(loadResult, dataset, datasetDefinition, buildProject, specificationId, relationshipId, version, user); return(buildProject); }
public async Task <IActionResult> GetCurrentDatasetRelationshipFieldsBySpecificationId(string specificationId) { Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId)); IEnumerable <DefinitionSpecificationRelationship> relationships = (await _datasetRepository.GetDefinitionSpecificationRelationshipsByQuery(m => m.Specification.Id == specificationId)).ToList(); if (relationships.IsNullOrEmpty()) { relationships = new DefinitionSpecificationRelationship[0]; } IEnumerable <string> definitionIds = relationships.Select(m => m.DatasetDefinition.Id); IEnumerable <DatasetDefinition> definitions = await _datasetRepository.GetDatasetDefinitionsByQuery(d => definitionIds.Contains(d.Id)); IList <DatasetSchemaRelationshipModel> schemaRelationshipModels = new List <DatasetSchemaRelationshipModel>(); foreach (DefinitionSpecificationRelationship definitionSpecificationRelationship in relationships) { string relationshipName = definitionSpecificationRelationship.Name; string datasetName = VisualBasicTypeGenerator.GenerateIdentifier(relationshipName); DatasetDefinition datasetDefinition = definitions.FirstOrDefault(m => m.Id == definitionSpecificationRelationship.DatasetDefinition.Id); schemaRelationshipModels.Add(new DatasetSchemaRelationshipModel { DefinitionId = datasetDefinition.Id, RelationshipId = definitionSpecificationRelationship.Id, RelationshipName = relationshipName, Fields = datasetDefinition.TableDefinitions.SelectMany(m => m.FieldDefinitions.Select(f => new DatasetSchemaRelationshipField { Name = f.Name, SourceName = VisualBasicTypeGenerator.GenerateIdentifier(f.Name), SourceRelationshipName = datasetName, IsAggregable = f.IsAggregable })) }); } return(new OkObjectResult(schemaRelationshipModels)); }
public async Task <IActionResult> GetDatasetDefinitionsByIds(HttpRequest request) { string json = await request.GetRawBodyStringAsync(); IEnumerable <string> definitionIds = JsonConvert.DeserializeObject <IEnumerable <string> >(json); if (!definitionIds.Any()) { _logger.Error($"No Dataset Definition Ids were provided to lookup"); return(new BadRequestObjectResult($"No DatasetDefinitionIds were provided to lookup")); } IEnumerable <DatasetDefinition> defintions = await _datasetsRepositoryPolicy.ExecuteAsync(() => _datasetsRepository.GetDatasetDefinitionsByQuery(d => definitionIds.Contains(d.Id))); return(new OkObjectResult(definitionIds)); }
public async Task <IActionResult> GetDatasetDefinitionsByIds(IEnumerable <string> definitionIds) { if (!definitionIds.Any()) { _logger.Error($"No Dataset Definition Ids were provided to lookup"); return(new BadRequestObjectResult($"No DatasetDefinitionIds were provided to lookup")); } IEnumerable <DatasetDefinition> defintions = await _datasetsRepositoryPolicy.ExecuteAsync(() => _datasetsRepository.GetDatasetDefinitionsByQuery(d => definitionIds.Contains(d.Id))); return(new OkObjectResult(definitionIds)); }