コード例 #1
0
        // TODO: De fra data.norge.no har flere format på en distribution?? Skal vi støtte det? :o
        // RART: Finner ikke kategori kobling i rdfene
        // Import dataset from link containing rdf schema.
        public async Task <DatasetResponse> import(String url, int categoryId)
        {
            Graph g;

            try
            {
                // Guess the url is actually an url.
                if (url.Contains("/"))
                {
                    // If it is in fellesdatakatalog API we need to request with headers to get on rdf format
                    if (url.Contains("fellesdatakatalog.digdir.no"))
                    {
                        g = NetworkHandling.LoadFromUriWithHeadersTurtle(url);
                    }
                    // If the url is directly to the page on data.norge.no fetch with the id
                    else if (url.Contains("data.norge.no"))
                    {
                        g = NetworkHandling.LoadFromUriWithHeadersTurtle("https://fellesdatakatalog.digdir.no/api/datasets/" + url.Substring(url.LastIndexOf("/") + 1));
                    }
                    // Otherwise hope the url is directly to a rdf file location on XML format
                    else
                    {
                        g = NetworkHandling.LoadFromUriXml(url);
                    }
                }
                // Guess it is not an url, and instead ID to some dataset in data.norge.no
                else
                {
                    g = NetworkHandling.LoadFromUriWithHeadersTurtle("https://fellesdatakatalog.digdir.no/api/datasets/" + url);
                }
            }
            catch (Exception ex)
            {
                return(new DatasetResponse($"Invalid import url. {ex.Message}"));
            }

            // Try to parse the dataset and save it in the database
            DatasetResponse dataset = await _graphService.AddDataset(g, categoryId);

            return(dataset);
        }