public string ServiceUrl()
        {
            StringBuilder url = new StringBuilder();

            if (IsDataset() || IsDatasetSeries())
            {
                if (string.IsNullOrWhiteSpace(ServiceDistributionProtocolForDataset) && string.IsNullOrWhiteSpace(ServiceDistributionUrlForDataset))
                {
                    foreach (var distribution in DistributionsFormats)
                    {
                        if (distribution.Protocol == SimpleMetadataUtil.OgcWms)
                        {
                            ServiceDistributionProtocolForDataset = SimpleMetadataUtil.OgcWms;
                            ServiceDistributionUrlForDataset      = distribution.URL;
                            break;
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(ServiceDistributionProtocolForDataset))
                {
                    string urlWithoutQueryString = RemoveQueryString(ServiceDistributionUrlForDataset);

                    if (!String.IsNullOrWhiteSpace(urlWithoutQueryString))
                    {
                        if (ServiceDistributionProtocolForDataset.Contains(SimpleMetadataUtil.OgcWms))
                        {
                            string commonPart = SimpleMetadataUtil.GetCommonPartOfNorgeskartUrl(SimpleMetadataUtil.OgcWms, true);

                            if (!string.IsNullOrWhiteSpace(ServiceDistributionUrlForDataset))
                            {
                                url.Append($"{commonPart}{urlWithoutQueryString}");

                                if (!string.IsNullOrWhiteSpace(ServiceDistributionNameForDataset))
                                {
                                    url.Append($"&addLayers={ServiceDistributionNameForDataset}");
                                }
                            }
                        }
                        else if (!MapOnlyWms && ServiceDistributionProtocolForDataset.Contains(SimpleMetadataUtil.OgcWfs))
                        {
                            string commonPart = SimpleMetadataUtil.GetCommonPartOfNorgeskartUrl(SimpleMetadataUtil.OgcWfs, true);

                            if (!string.IsNullOrWhiteSpace(ServiceDistributionNameForDataset) && !string.IsNullOrWhiteSpace(ServiceDistributionUrlForDataset))
                            {
                                url.Append($"{commonPart}{urlWithoutQueryString}&addLayers={ServiceDistributionNameForDataset}");
                            }
                            else if (DistributionDetails != null && !string.IsNullOrWhiteSpace(DistributionDetails.URL))
                            {
                                url.Append($"{commonPart}{urlWithoutQueryString}");
                            }
                        }
                    }
                }
            }

            return(url.ToString());
        }
Exemplo n.º 2
0
        public Metadata(SearchResultItem item, UrlHelper urlHelper)
        {
            Uuid                 = item.Uuid;
            Title                = item.Title;
            Abstract             = item.Abstract;
            Type                 = item.Type;
            TypeName             = item.TypeName;
            TypeTranslated       = TranslateType();
            Theme                = item.Theme;
            Organization         = item.Organization;
            OrganizationLogo     = item.OrganizationLogoUrl;
            ThumbnailUrl         = item.ThumbnailUrl;
            DistributionUrl      = item.DistributionUrl;
            DistributionProtocol = item.DistributionProtocol;
            DistributionName     = item.DistributionName;
            DistributionType     = item.DistributionType;
            GetCapabilitiesUrl   = GetGetCapabilitiesUrl(item);
            if (urlHelper != null)
            {
                ShowDetailsUrl = WebConfigurationManager.AppSettings["KartkatalogenUrl"] + "metadata/uuid/" + item.Uuid;
                string s = new SeoUrl(item.Organization, "").Organization;
                OrganizationUrl = WebConfigurationManager.AppSettings["KartkatalogenUrl"] + "metadata/" + s;
            }

            if (item.NationalInitiative != null && item.NationalInitiative.Contains(UI.OpenData) ||
                (!string.IsNullOrEmpty(item.DataAccess) && (item.DataAccess == UI.OpenData ||
                                                            item.DataAccess.Contains("ingen begrensninger") || item.DataAccess.Contains("no limitations"))))
            {
                IsOpenData = true;
            }
            else
            {
                IsOpenData = false;
            }

            AccessIsOpendata   = IsOpenData;
            AccessIsRestricted = SimpleMetadataUtil.IsRestricted(item.OtherConstraintsAccess);
            AccessIsProtected  = SimpleMetadataUtil.IsProtected(item.AccessConstraint);

            if (item.NationalInitiative != null && item.NationalInitiative.Contains("Det offentlige kartgrunnlaget"))
            {
                IsDokData = true;
            }
            else
            {
                IsDokData = false;
            }


            LegendDescriptionUrl           = item.LegendDescriptionUrl;
            ProductSheetUrl                = item.ProductSheetUrl;
            ProductSpecificationUrl        = item.ProductSpecificationUrl;
            DatasetServices                = item.DatasetServices;
            DatasetServicesWithShowMapLink = AddDatasetServicesWithShowMapLink(DatasetServices);
            ServiceDatasets                = item.ServiceDatasets;
            Distributions                       = item.Distributions;
            Bundles                             = item.Bundles;
            ServiceLayers                       = item.ServiceLayers;
            AccessConstraint                    = item.AccessConstraint;
            OtherConstraintsAccess              = item.OtherConstraintsAccess;
            DataAccess                          = item.DataAccess;
            ServiceDistributionUrlForDataset    = item.ServiceDistributionUrlForDataset;
            ServiceUuid                         = item.ServiceDistributionUuidForDataset;
            ServiceWfsDistributionUrlForDataset = item.ServiceWfsDistributionUrlForDataset != null ? item.ServiceWfsDistributionUrlForDataset : WfsServiceUrl();
            Date        = item.Date;
            DatasetName = item.DatasetName;

            if (Type == "dataset" || Type == "series")
            {
                if (!string.IsNullOrWhiteSpace(item.ServiceDistributionProtocolForDataset))
                {
                    string commonPart = SimpleMetadataUtil.GetCommonPartOfNorgeskartUrl(item.ServiceDistributionProtocolForDataset, true);

                    if (item.ServiceDistributionProtocolForDataset.Contains(SimpleMetadataUtil.OgcWms))
                    {
                        if (!string.IsNullOrWhiteSpace(item.ServiceDistributionUrlForDataset))
                        {
                            ServiceUrl = $"{commonPart}{RemoveQueryString(item.ServiceDistributionUrlForDataset)}";

                            if (!string.IsNullOrWhiteSpace(item.ServiceDistributionNameForDataset))
                            {
                                ServiceUrl += $"&addLayers={item.ServiceDistributionNameForDataset}";
                            }
                        }
                    }
                    else if (item.ServiceDistributionProtocolForDataset.Contains(SimpleMetadataUtil.OgcWfs))
                    {
                        if (!string.IsNullOrWhiteSpace(item.ServiceDistributionNameForDataset) && !string.IsNullOrWhiteSpace(item.ServiceDistributionUrlForDataset))
                        {
                            ServiceUrl = $"{commonPart}{RemoveQueryString(item.ServiceDistributionUrlForDataset)}&addLayers={item.ServiceDistributionNameForDataset}";
                        }
                        else if (!string.IsNullOrWhiteSpace(item.DistributionUrl))
                        {
                            ServiceUrl = $"{commonPart}{RemoveQueryString(item.DistributionUrl)}";
                        }
                    }
                }

                if (item.Serie != null)
                {
                    Serie = AddSerie(item.Serie);
                }
            }

            if (Type == "service" || Type == "servicelayer")
            {
                if (!string.IsNullOrWhiteSpace(item.DistributionProtocol) && !string.IsNullOrWhiteSpace(item.DistributionUrl))
                {
                    string commonPart = $"{SimpleMetadataUtil.GetCommonPartOfNorgeskartUrl(item.DistributionProtocol, true)}{RemoveQueryString(item.DistributionUrl)}";

                    if (item.DistributionProtocol.Contains(SimpleMetadataUtil.OgcWms) || item.DistributionProtocol.Contains(SimpleMetadataUtil.OgcWfs))
                    {
                        DownloadUrl = commonPart;

                        if (!string.IsNullOrWhiteSpace(item.DistributionName))
                        {
                            DownloadUrl += $"&addLayers={item.DistributionName}";
                        }
                    }
                }

                if (string.IsNullOrEmpty(ServiceUuid) && string.IsNullOrWhiteSpace(item.DistributionName))
                {
                    ServiceUuid = Uuid;
                }
            }

            if (Type == "series" && item.SerieDatasets != null && item.SerieDatasets.Count > 0)
            {
                SerieDatasets = AddSerieDatasets(item.SerieDatasets);
            }

            else
            {
                DownloadUrl = item.DistributionUrl;
                if (!DownloadLink())
                {
                    DownloadUrl = MakeDownloadUrlRelative();
                }
            }

            MapUrl = GetMapUrl();

            SpatialScope = item.SpatialScope;
        }
        public SearchResultItemViewModel(SearchResultItem item)
        {
            Uuid                  = item.Uuid;
            Title                 = item.Title;
            Abstract              = item.Abstract;
            Type                  = item.Type;
            Theme                 = item.Theme;
            Organization          = item.Organization;
            OrganizationShortName = !string.IsNullOrEmpty(item.OrganizationShortName) ? item.OrganizationShortName : item.Organization;
            OrganizationLogoUrl   = GetOrganizationLogoUrl(item.OrganizationLogoUrl);
            ThumbnailUrl          = item.ThumbnailUrl;
            MaintenanceFrequency  = item.MaintenanceFrequency;
            DistributionType      = item.DistributionType;
            DistributionUrl       = item.DistributionUrl;
            GetCapabilitiesUrl    = item.DistributionDetails.DistributionDetailsGetCapabilitiesUrl();
            TypeCssClass          = GetInnholdstypeCSS();
            TypeTranslated        = GetInnholdstype();
            DistributionProtocol  = item.DistributionProtocol;
            var seoUrl = new SeoUrl(Organization, Title);

            OrganizationSeoName = seoUrl.Organization;
            TitleSeo            = seoUrl.Title;

            if (!string.IsNullOrEmpty(item.OtherConstraintsAccess) && item.OtherConstraintsAccess.ToLower() == "no restrictions")
            {
                IsOpendata = true;
            }
            if (!string.IsNullOrEmpty(item.OtherConstraintsAccess) && item.OtherConstraintsAccess.ToLower() == "norway digital restricted")
            {
                IsRestricted = true;
            }
            if (item.AccessConstraint == "restricted")
            {
                IsOffline = true;
            }

            if (Type == "dataset")
            {
                if (!string.IsNullOrWhiteSpace(item.ServiceDistributionProtocolForDataset))
                {
                    string commonPart = SimpleMetadataUtil.GetCommonPartOfNorgeskartUrl(item.ServiceDistributionProtocolForDataset, true);

                    if (item.ServiceDistributionProtocolForDataset.Contains(SimpleMetadataUtil.OgcWms))
                    {
                        if (!string.IsNullOrWhiteSpace(item.ServiceDistributionUrlForDataset))
                        {
                            ServiceUrl = $"{commonPart}{RemoveQueryString(item.ServiceDistributionUrlForDataset)}";

                            if (!string.IsNullOrWhiteSpace(item.ServiceDistributionNameForDataset))
                            {
                                ServiceUrl += $"&addLayers={item.ServiceDistributionNameForDataset}";
                            }
                        }
                    }
                    else if (item.ServiceDistributionProtocolForDataset.Contains(SimpleMetadataUtil.OgcWfs))
                    {
                        if (!string.IsNullOrWhiteSpace(item.ServiceDistributionNameForDataset) && !string.IsNullOrWhiteSpace(item.ServiceDistributionUrlForDataset))
                        {
                            ServiceUrl = $"{commonPart}{RemoveQueryString(item.ServiceDistributionUrlForDataset)}&addLayers={item.ServiceDistributionNameForDataset}";
                        }
                        else if (!string.IsNullOrWhiteSpace(item.DistributionUrl))
                        {
                            ServiceUrl = $"{commonPart}{RemoveQueryString(item.DistributionUrl)}";
                        }
                    }
                }
            }

            if (Type == "service" || Type == "servicelayer")
            {
                if (!string.IsNullOrWhiteSpace(item.DistributionProtocol) && !string.IsNullOrWhiteSpace(item.DistributionUrl))
                {
                    string commonPart = $"{SimpleMetadataUtil.GetCommonPartOfNorgeskartUrl(item.DistributionProtocol, true)}{RemoveQueryString(item.DistributionUrl)}";

                    if (item.DistributionProtocol.Contains(SimpleMetadataUtil.OgcWms) || item.DistributionProtocol.Contains(SimpleMetadataUtil.OgcWfs))
                    {
                        DownloadUrl = commonPart;

                        if (!string.IsNullOrWhiteSpace(item.DistributionName))
                        {
                            DownloadUrl += $"&addLayers={item.DistributionName}";
                        }
                    }
                }
            }
            else
            {
                DownloadUrl = item.DistributionUrl;
                if (!DownloadLink())
                {
                    DownloadUrl = MakeDownloadUrlRelative();
                }
            }

            LegendDescriptionUrl    = item.LegendDescriptionUrl;
            ProductSheetUrl         = item.ProductSheetUrl;
            ProductSpecificationUrl = item.ProductSpecificationUrl;
            ServiceUuid             = item.Uuid;
            if (item.Type == "dataset")
            {
                ServiceUuid = item.ServiceDistributionUuidForDataset;
            }

            if (!string.IsNullOrEmpty(item.ParentIdentifier) && Type == "servicelayer")
            {
                ServiceUuid = item.ParentIdentifier;
            }

            ServiceDistributionAccessConstraint = item.ServiceDistributionAccessConstraint;
            MetadataLinkRouteValueDictionary    = ShowMetadataLinkRouteValueDictionary();
            MapTitleTag         = GetMapTitleTag();
            ShowDownloadService = DownloadService();
            ShowDownloadLink    = DownloadLink();
            AddToCartUrl        = GetAddToCartUrl();
            MapUrl = GetMapUrl();
        }