public void ShouldReturnOriginalThumbnailUrlWhenEmpty()
        {
            var    util         = new GeoNetworkUtil(BaseUrl);
            string thumbnailUrl = util.GetThumbnailUrl(Uuid, "");

            thumbnailUrl.Should().Be("");
        }
        public void ShouldReturnXmlDownloadUrl()
        {
            var    util           = new GeoNetworkUtil(BaseUrl);
            string xmlDownloadUrl = util.GetXmlDownloadUrl(Uuid);

            xmlDownloadUrl.Should().Be(BaseUrl + "srv/nor/xml_iso19139?uuid=" + Uuid);
        }
        public void ShouldReturnViewUrl()
        {
            var    util    = new GeoNetworkUtil(BaseUrl);
            string viewUrl = util.GetViewUrl(Uuid);

            viewUrl.Should().Be(BaseUrl + "?uuid=" + Uuid);
        }
        private void PrepareViewBagForEditing(SimpleMetadataViewModel model)
        {
            ViewBag.MaintenanceFrequencyValues = new SelectList(GetListOfMaintenanceFrequencyValues(), "Key", "Value", model.MaintenanceFrequency);

            ViewBag.CreateProductSheetUrl =
                System.Web.Configuration.WebConfigurationManager.AppSettings["ProductSheetGeneratorUrl"] + model.Uuid;
            ViewBag.DatasetUrl =
                System.Web.Configuration.WebConfigurationManager.AppSettings["DownloadDatasetUrl"];
            ViewBag.GeoNetworkViewUrl        = GeoNetworkUtil.GetViewUrl(model.Uuid);
            ViewBag.GeoNetworkXmlDownloadUrl = GeoNetworkUtil.GetXmlDownloadUrl(model.Uuid);
            var seoUrl = new SeoUrl("", model.Title);

            ViewBag.KartkatalogViewUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogUrl"] + "Metadata/" + seoUrl.Title + "/" + model.Uuid;
            ViewBag.predefinedDistributionProtocols = new SelectList(GetListOfpredefinedDistributionProtocols(), "Key", "Value");

            Dictionary <string, string> OrganizationList = GetListOfOrganizations();


            if (string.IsNullOrEmpty(model.ContactMetadata.Organization))
            {
                if (Request.Form["ContactMetadata.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactMetadata.Organization.Old"]))
                {
                    model.ContactMetadata.Organization = Request.Form["ContactMetadata.Organization.Old"].ToString();
                }
            }

            if (string.IsNullOrEmpty(model.ContactPublisher.Organization))
            {
                if (Request.Form["ContactPublisher.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactPublisher.Organization.Old"]))
                {
                    model.ContactPublisher.Organization = Request["ContactPublisher.Organization.Old"].ToString();
                }
            }


            if (string.IsNullOrEmpty(model.ContactOwner.Organization))
            {
                if (Request.Form["ContactOwner.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactOwner.Organization.Old"]))
                {
                    model.ContactOwner.Organization = Request["ContactOwner.Organization.Old"].ToString();
                }
            }

            ViewBag.OrganizationContactMetadataValues  = new SelectList(OrganizationList, "Key", "Value", model.ContactMetadata.Organization);
            ViewBag.OrganizationContactPublisherValues = new SelectList(OrganizationList, "Key", "Value", model.ContactPublisher.Organization);
            ViewBag.OrganizationContactOwnerValues     = new SelectList(OrganizationList, "Key", "Value", model.ContactOwner.Organization);

            ViewBag.NationalThemeValues      = new SelectList(GetListOfNationalTheme(), "Key", "Value");
            ViewBag.NationalInitiativeValues = new SelectList(GetListOfNationalInitiative(), "Key", "Value");
            ViewBag.InspireValues            = new SelectList(GetListOfInspire(), "Key", "Value");

            ViewBag.UseConstraintValues = new SelectList(GetListOfRestrictionValues(), "Key", "Value", model.UseConstraints);
            ViewBag.LicenseTypesValues  = new SelectList(GetListOfLicenseTypes(), "Key", "Value", model.OtherConstraintsLink);


            ViewBag.ValideringUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["ValideringUrl"] + "api/metadata/" + model.Uuid;

            ViewBag.Municipalities = new KomDataService().GetListOfMunicipalityOrganizations();
        }
        public void ShouldReturnThumbnailUrlFromGeoNetworkWhenThumbnailOnlyContainsFilename()
        {
            var    util         = new GeoNetworkUtil(BaseUrl);
            string exampleImage = "myimage.png";
            string thumbnailUrl = util.GetThumbnailUrl(Uuid, exampleImage);

            thumbnailUrl.Should().Be(BaseUrl + "srv/nor/resources.get?uuid=" + Uuid + "&access=public&fname=" + exampleImage);
        }
        public void ShouldReturnOriginalThumbnailUrlWhenUrlStartsWithHttp()
        {
            var    util         = new GeoNetworkUtil(BaseUrl);
            string exampleImage = "http://example.com/myimage.png";
            string thumbnailUrl = util.GetThumbnailUrl(Uuid, exampleImage);

            thumbnailUrl.Should().Be(exampleImage);
        }
        private static MetadataIndexViewModel ParseSearchResults(int offset, int limit, SearchResultsType results)
        {
            var model    = new MetadataIndexViewModel();
            var metadata = new Dictionary <string, MetadataItemViewModel>();

            if (results.Items != null)
            {
                foreach (var item in results.Items)
                {
                    RecordType record = (RecordType)item;

                    string title        = null;
                    string uuid         = null;
                    string publisher    = null;
                    string creator      = null;
                    string organization = null;
                    string type         = null;
                    string relation     = null;

                    for (int i = 0; i < record.ItemsElementName.Length; i++)
                    {
                        var name  = record.ItemsElementName[i];
                        var value = record.Items[i].Text != null ? record.Items[i].Text[0] : null;

                        if (name == ItemsChoiceType24.title)
                        {
                            title = value;
                        }
                        else if (name == ItemsChoiceType24.identifier)
                        {
                            uuid = value;
                        }
                        else if (name == ItemsChoiceType24.creator)
                        {
                            creator = value;
                        }
                        else if (name == ItemsChoiceType24.publisher)
                        {
                            publisher = value;
                        }
                        else if (name == ItemsChoiceType24.type)
                        {
                            type = value;
                        }
                        else if (name == ItemsChoiceType24.relation)
                        {
                            relation = value;
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(publisher))
                    {
                        organization = publisher;
                    }
                    else
                    {
                        organization = creator;
                    }

                    var metadataItem = new MetadataItemViewModel
                    {
                        Title                    = title,
                        Uuid                     = uuid,
                        Organization             = organization,
                        Type                     = type,
                        Relation                 = relation,
                        GeoNetworkViewUrl        = GeoNetworkUtil.GetViewUrl(uuid),
                        GeoNetworkXmlDownloadUrl = GeoNetworkUtil.GetXmlDownloadUrl(uuid)
                    };

                    if (uuid != null)
                    {
                        metadata.Add(uuid, metadataItem);
                    }
                }

                model.MetadataItems           = metadata.Values.ToList();
                model.Limit                   = limit;
                model.Offset                  = offset;
                model.NumberOfRecordsReturned = int.Parse(results.numberOfRecordsReturned);
                model.TotalNumberOfRecords    = int.Parse(results.numberOfRecordsMatched);
            }
            return(model);
        }
        private void PrepareViewBagForEditing(MetadataViewModel model)
        {
            ViewBag.TopicCategoryValues         = new SelectList(GetListOfTopicCategories(CultureHelper.GetCurrentCulture()), "Key", "Value", model.TopicCategory);
            ViewBag.SpatialRepresentationValues = new SelectList(GetListOfSpatialRepresentations(CultureHelper.GetCurrentCulture()), "Key", "Value", model.SpatialRepresentation);

            ViewBag.VectorFormats = new SelectList(GetListOfVectorFormats(), "Key", "Value");
            ViewBag.RasterFormats = new SelectList(GetListOfRasterFormats(), "Key", "Value");

            ViewBag.predefinedDistributionProtocols = new SelectList(GetListOfpredefinedDistributionProtocols(CultureHelper.GetCurrentCulture()), "Key", "Value");
            ViewBag.UnitsOfDistributionValues       = new SelectList(GetListOfUnitsOfDistribution(CultureHelper.GetCurrentCulture()), "Key", "Value", model.UnitsOfDistribution);
            ViewBag.MaintenanceFrequencyValues      = new SelectList(GetListOfMaintenanceFrequencyValues(CultureHelper.GetCurrentCulture()), "Key", "Value", model.MaintenanceFrequency);
            ViewBag.StatusValues             = new SelectList(GetListOfStatusValues(CultureHelper.GetCurrentCulture()), "Key", "Value", model.Status);
            ViewBag.SecurityConstraintValues = new SelectList(GetListOfClassificationValues(CultureHelper.GetCurrentCulture()), "Key", "Value", model.SecurityConstraints);
            ViewBag.UseConstraintValues      = new SelectList(GetListOfRestrictionValues(CultureHelper.GetCurrentCulture()), "Key", "Value", model.UseConstraints);
            ViewBag.LicenseTypesValues       = new SelectList(GetListOfLicenseTypes(), "Key", "Value", model.OtherConstraintsLink);
            if (!string.IsNullOrEmpty(model.OtherConstraintsAccess) && (model.OtherConstraintsAccess.ToLower() == "no restrictions" || model.OtherConstraintsAccess.ToLower() == "norway digital restricted"))
            {
                model.AccessConstraints = model.OtherConstraintsAccess;
            }
            ViewBag.AccessConstraintValues = new SelectList(GetListOfRestrictionValuesAdjusted(CultureHelper.GetCurrentCulture()), "Key", "Value", model.AccessConstraints);
            ViewBag.CreateProductSheetUrl  =
                System.Web.Configuration.WebConfigurationManager.AppSettings["ProductSheetGeneratorUrl"] + model.Uuid;
            ViewBag.ThumbnailUrl =
                System.Web.Configuration.WebConfigurationManager.AppSettings["EditorUrl"] + "thumbnails/";
            ViewBag.GeoNetworkViewUrl        = GeoNetworkUtil.GetViewUrl(model.Uuid);
            ViewBag.GeoNetworkXmlDownloadUrl = GeoNetworkUtil.GetXmlDownloadUrl(model.Uuid);
            var seoUrl = new SeoUrl("", model.Title);

            ViewBag.KartkatalogViewUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogUrl"] + "Metadata/" + seoUrl.Title + "/" + model.Uuid;

            Dictionary <string, string> OrganizationList = GetListOfOrganizations(CultureHelper.GetCurrentCulture());


            if (model.ContactMetadata != null && string.IsNullOrEmpty(model.ContactMetadata.Organization))
            {
                if (Request.Form["ContactMetadata.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactMetadata.Organization.Old"]))
                {
                    model.ContactMetadata.Organization = Request.Form["ContactMetadata.Organization.Old"].ToString();
                }
            }

            if (model.ContactPublisher != null && string.IsNullOrEmpty(model.ContactPublisher.Organization))
            {
                if (Request.Form["ContactPublisher.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactPublisher.Organization.Old"]))
                {
                    model.ContactPublisher.Organization = Request["ContactPublisher.Organization.Old"].ToString();
                }
            }


            if (model.ContactOwner != null && string.IsNullOrEmpty(model.ContactOwner.Organization))
            {
                if (Request.Form["ContactOwner.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactOwner.Organization.Old"]))
                {
                    model.ContactOwner.Organization = Request["ContactOwner.Organization.Old"].ToString();
                }
            }

            var contactMetadataOrganization  = (model.ContactMetadata != null && model.ContactMetadata.Organization != null) ? model.ContactMetadata.Organization : "";
            var contactPublisherOrganization = (model.ContactPublisher != null && model.ContactPublisher.Organization != null) ? model.ContactPublisher.Organization : "";
            var contactOwnerOrganization     = (model.ContactOwner != null && model.ContactOwner.Organization != null) ? model.ContactOwner.Organization : "";

            ViewBag.OrganizationContactMetadataValues  = new SelectList(OrganizationList, "Key", "Value", contactMetadataOrganization);
            ViewBag.OrganizationContactPublisherValues = new SelectList(OrganizationList, "Key", "Value", contactPublisherOrganization);
            ViewBag.OrganizationContactOwnerValues     = new SelectList(OrganizationList, "Key", "Value", contactOwnerOrganization);
            ViewBag.OrganizationDistributorValues      = new SelectList(OrganizationList, "Key", "Value");

            Dictionary <string, string> ReferenceSystemsList = GetListOfReferenceSystems();

            ViewBag.ReferenceSystemsValues = new SelectList(ReferenceSystemsList, "Key", "Value");

            ViewBag.NationalThemeValues      = new SelectList(GetListOfNationalTheme(CultureHelper.GetCurrentCulture()), "Key", "Value");
            ViewBag.NationalInitiativeValues = new SelectList(GetListOfNationalInitiative(), "Key", "Value");
            ViewBag.CatalogValues            = new SelectList(GetListOfCatalogs(), "Key", "Value");
            ViewBag.InspireValues            = new SelectList(GetListOfInspire(CultureHelper.GetCurrentCulture()), "Key", "Value");
            ViewBag.InspirePriorityDatasets  = new SelectList(_metadataService.GetPriorityDatasets(), "Key", "Value");

            IEnumerable <SelectListItem> conceptItems = from concept in model.KeywordsConcept
                                                        select new SelectListItem
            {
                Text     = concept.Split('|')[0].ToString(),
                Value    = concept.ToString(),
                Selected = true,
            };

            ViewBag.Concepts = new MultiSelectList(conceptItems, "Value", "Text", conceptItems.Select(c => c.Value).ToArray());

            var productspesifications = GetRegister("produktspesifikasjoner", model);

            if (!string.IsNullOrEmpty(model.ProductSpecificationUrl))
            {
                KeyValuePair <string, string> prodspecSelected = new KeyValuePair <string, string>(model.ProductSpecificationUrl, model.ProductSpecificationUrl);
                if (!productspesifications.ContainsKey(prodspecSelected.Key))
                {
                    productspesifications.Add(prodspecSelected.Key, prodspecSelected.Value);
                }
            }
            ViewBag.ProductspesificationValues = new SelectList(productspesifications, "Key", "Value", model.ProductSpecificationUrl);

            var orderingInstructions = GetSubRegister("metadata-kodelister/kartverket/norge-digitalt-tjenesteerklaering", model);

            if (!string.IsNullOrEmpty(model.OrderingInstructions))
            {
                KeyValuePair <string, string> orderingInstructionsSelected = new KeyValuePair <string, string>(model.OrderingInstructions, model.OrderingInstructions);
                if (!orderingInstructions.ContainsKey(orderingInstructionsSelected.Key))
                {
                    orderingInstructions.Add(orderingInstructionsSelected.Key, orderingInstructionsSelected.Value);
                }
            }
            ViewBag.OrderingInstructionsValues = new SelectList(orderingInstructions, "Key", "Value", model.OrderingInstructions);

            ViewBag.ProductsheetValues      = new SelectList(GetRegister("produktark", model), "Key", "Value", model.ProductSheetUrl);
            ViewBag.LegendDescriptionValues = new SelectList(GetRegister("tegneregler", model), "Key", "Value", model.LegendDescriptionUrl);

            ViewBag.ValideringUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["ValideringUrl"] + "api/metadata/" + model.Uuid;

            ViewBag.Municipalities = new KomDataService().GetListOfMunicipalityOrganizations();

            ViewBag.NewDistribution = false;

            ViewBag.IsAdmin = "0";
            string role = GetSecurityClaim("role");

            if (!string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin"))
            {
                ViewBag.IsAdmin = "1";
            }
        }