示例#1
0
        // Method to add tags based on the id and a bit messy because it is sent as a string.
        public async Task <DatasetResponse> SaveAsync(Dataset dataset)
        {
            try
            {
                (Boolean success, String error)check = await idChecks(dataset);

                if (!check.success)
                {
                    return(new DatasetResponse(check.error));
                }
                // Sets the date and time for the attributes published and last updated to current time.
                dataset.DatePublished   = DateTime.Now;
                dataset.DateLastUpdated = DateTime.Now;

                var createDatasetTask = Task.Run(async() => {
                    dataset = await _datasetRepository.AddAsync(dataset);
                    await addTags(dataset);
                    dataset.Identifier = (Startup.Configuration != null ? Startup.Configuration["identifierUrl"] : "http://www.test.no/") + dataset.Id;
                    _datasetRepository.Update(dataset);
                    await _unitOfWork.CompleteAsync();
                    return(dataset);
                });

                return(await CreateGitLabProject(createDatasetTask, dataset));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new DatasetResponse($"An error occurred when saving the dataset: {ex.Message}"));
            }
        }
示例#2
0
        public async Task AddAsync(DefinedDatasetModel definedDatasetModel)
        {
            var definedDataset       = _mapper.Map <DefinedDataset>(definedDatasetModel);
            var dataset              = _mapper.Map <Dataset>(definedDatasetModel);
            var definedDatasetValues = _mapper.Map <IEnumerable <DefinedDatasetValue> >(definedDatasetModel.Values).Select(item => { item.Dataset = definedDataset; return(item); });

            await _definedDatasetRepository.AddAsync(definedDataset);

            await _definedDatasetRepository.AddValuesAsync(definedDatasetValues);

            await _datasetRepository.AddAsync(dataset);

            await _uow.CommitAsync();
        }
        public async Task AddAsync(CustomDatasetModel customDatasetModel)
        {
            var customDataset       = _mapper.Map <CustomDataset>(customDatasetModel);
            var dataset             = _mapper.Map <Dataset>(customDatasetModel);
            var customDatasetValues = _mapper.Map <IEnumerable <CustomDatasetValue> >(customDatasetModel.Values).Select(item => { item.Dataset = customDataset; return(item); }).ToList();

            await _customDatasetRepository.AddAsync(customDataset);

            await _customDatasetRepository.AddValuesAsync(customDatasetValues);

            dataset.Type = await _typesRepository.GetByNameAsync(Enum.GetName(typeof(SupportedTypes), SupportedTypes.String).ToLower());

            await _datasetRepository.AddAsync(dataset);

            await _uow.CommitAsync();
        }
        // Add a dataset in a graph to the database
        public async Task <DatasetResponse> AddDataset(Graph g, int categoryId)
        {
            // Find publisher id
            Publisher publisher = await AddPublisher(g);

            await _unitOfWork.CompleteAsync();

            // Find the dataset subject uri
            IUriNode dcatDataset = g.CreateUriNode("dcat:Dataset");

            String[] datasetUri = findSubjectUri(g, dcatDataset).Split(",");
            // From the dataset uri make a dictionary with the attributes
            Dictionary <string, string> attributes = getAttributesFromSubject(g, datasetUri[0]);
            // Add relevant attributes to a new dataset
            Dataset dataset = new Dataset {
                Title             = attributes.GetValueOrDefault("title", "Ingen tittel"),
                Identifier        = datasetUri[0],
                Description       = attributes.GetValueOrDefault("description", ""),
                PublicationStatus = attributes.ContainsKey("distribution") ? EPublicationStatus.published : EPublicationStatus.notPublished,
                PublisherId       = publisher.Id,
                CategoryId        = categoryId,
                DatePublished     = getDateOrNow(attributes.GetValueOrDefault("issued", "")),
                DateLastUpdated   = getDateOrNow(attributes.GetValueOrDefault("modified", "")),
                AccessLevel       = EAccessLevel.green,
            };

            var createDatasetTask = Task.Run(async() => {
                // Add the dataset to the database
                dataset = await _datasetRepository.AddAsync(dataset);
                await _unitOfWork.CompleteAsync();

                await AddTags(g, attributes.GetValueOrDefault("keyword", ""), dataset);
                await AddDistribution(g, dataset.Id);
                return(dataset);
            });

            return(await _datasetService.CreateGitLabProject(createDatasetTask, dataset));
        }