Exemplo n.º 1
0
        public Dataset FetchDatasetFromKartkatalogen(string uuid)
        {
            Dataset metadata = new Dataset();

            string url = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogenUrl"] + "api/getdata/" + uuid;

            System.Net.WebClient c = new System.Net.WebClient();
            c.Encoding = System.Text.Encoding.UTF8;
            try
            {
                var json = c.DownloadString(url);

                dynamic data = Newtonsoft.Json.Linq.JObject.Parse(json);
                if (data != null)
                {
                    metadata.name                    = data.Title;
                    metadata.description             = data.Abstract;
                    metadata.PresentationRulesUrl    = data.LegendDescriptionUrl;
                    metadata.ProductSheetUrl         = data.ProductSheetUrl;
                    metadata.ProductSpecificationUrl = data.ProductSpecificationUrl;
                    metadata.SpecificUsage           = data.SpecificUsage;
                    var thumbnails = data.Thumbnails;
                    if (thumbnails != null && thumbnails.Count > 0)
                    {
                        metadata.datasetthumbnail = thumbnails[0].URL.Value;
                    }

                    metadata.datasetownerId = mapOrganizationNameToId(data.ContactOwner != null && data.ContactOwner.Organization != null ? data.ContactOwner.Organization.Value : "Kartverket");
                    metadata.ThemeGroupId   = AddTheme(data.KeywordsNationalTheme != null && data.KeywordsNationalTheme.Count > 0 ? data.KeywordsNationalTheme[0].KeywordValue.Value : "Annen");

                    if (data.ServiceUuid != null)
                    {
                        metadata.UuidService = data.ServiceUuid;
                    }

                    if (data.ServiceDistributionUrlForDataset != null)
                    {
                        metadata.WmsUrl = data.ServiceDistributionUrlForDataset;
                    }
                }

                if (data.DistributionDetails != null)
                {
                    metadata.DistributionUrl = data.DistributionDetails.URL;
                }

                if (data.UnitsOfDistribution != null)
                {
                    metadata.DistributionArea = data.UnitsOfDistribution.Value;
                }

                var distributionFormat = data.DistributionFormat;
                if (distributionFormat != null)
                {
                    if (distributionFormat.Name != null)
                    {
                        metadata.DistributionFormat = distributionFormat.Name.Value;
                    }
                }

                metadata.restricted = false;

                var constraints = data.Constraints;

                if (constraints != null)
                {
                    string accessConstraint = constraints.AccessConstraints.Value;
                    if (!string.IsNullOrEmpty(accessConstraint) && accessConstraint == "Beskyttet")
                    {
                        metadata.restricted = true;
                    }
                }

                var    englishTitle    = data.EnglishTitle;
                var    englishAbstract = data.EnglishAbstract;
                string keywordsNationalThemeEnglish = "";
                if (data.KeywordsNationalTheme.Count > 0)
                {
                    keywordsNationalThemeEnglish = data.KeywordsNationalTheme[0].EnglishKeyword;
                }
                metadata.Translations.Add(new DatasetTranslation
                {
                    CultureName  = Culture.EnglishCode,
                    Name         = englishTitle,
                    Description  = englishAbstract,
                    ThemeGroupId = keywordsNationalThemeEnglish
                });

                metadata.AddMissingTranslations();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                System.Diagnostics.Debug.WriteLine(url);
                return(null);
            }

            return(metadata);
        }