Exemplo n.º 1
0
        public List <MetadataViewModel> Report1()
        {
            List <MetadataViewModel> report = new List <MetadataViewModel>();

            MetadataIndexViewModel model = new MetadataIndexViewModel();
            int offset = 1;
            int limit  = 50;

            model = _metadataService.SearchMetadata("", "", offset, limit);

            foreach (var item in model.MetadataItems)
            {
                try
                {
                    MetadataViewModel md = _metadataService.GetMetadataModel(item.Uuid);
                    if (md.IsDataset())
                    {
                        report.Add(md);
                    }
                }
                catch (Exception ex) { }
            }

            int numberOfRecordsMatched = model.TotalNumberOfRecords;
            int next = model.OffsetNext();


            while (next < numberOfRecordsMatched)
            {
                model = _metadataService.SearchMetadata("", "", next, limit);

                foreach (var item in model.MetadataItems)
                {
                    try
                    {
                        MetadataViewModel md = _metadataService.GetMetadataModel(item.Uuid);
                        if (md.IsDataset())
                        {
                            report.Add(md);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.Message);
                    }
                }

                next = model.OffsetNext();
                if (next == 0)
                {
                    break;
                }
            }

            return(report);
        }
        private void PrepareViewBagForEditing(MetadataViewModel model)
        {
            ViewBag.TopicCategoryValues = new SelectList(GetListOfTopicCategories(), "Key", "Value", model.TopicCategory);
            ViewBag.SpatialRepresentationValues = new SelectList(GetListOfSpatialRepresentations(), "Key", "Value", model.SpatialRepresentation);

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

            ViewBag.predefinedDistributionProtocols = new SelectList(GetListOfpredefinedDistributionProtocols(), "Key", "Value");
            ViewBag.UnitsOfDistributionValues = new SelectList(GetListOfUnitsOfDistribution(), "Key", "Value", model.UnitsOfDistribution);
            ViewBag.MaintenanceFrequencyValues = new SelectList(GetListOfMaintenanceFrequencyValues(), "Key", "Value", model.MaintenanceFrequency);
            ViewBag.StatusValues = new SelectList(GetListOfStatusValues(), "Key", "Value", model.Status);
            ViewBag.SecurityConstraintValues = new SelectList(GetListOfClassificationValues(), "Key", "Value", model.SecurityConstraints);
            ViewBag.UseConstraintValues = new SelectList(GetListOfRestrictionValues(), "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(), "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();

            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);

            Dictionary<string, string> ReferenceSystemsList = GetListOfReferenceSystems();
            ViewBag.ReferenceSystemsValues = new SelectList(ReferenceSystemsList, "Key", "Value");

            ViewBag.NationalThemeValues = new SelectList(GetListOfNationalTheme(), "Key", "Value");
            ViewBag.NationalInitiativeValues = new SelectList(GetListOfNationalInitiative(), "Key", "Value");
            ViewBag.InspireValues = new SelectList(GetListOfInspire(), "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.ValidModel = true;
            if (Request.QueryString["metadatacreated"] == null )
            {
                ViewBag.ValidModel = TryValidateModel(model);
            }
        }
 private bool HasAccessToMetadata(MetadataViewModel model)
 {
     string organization = GetSecurityClaim("organization");
     string role = GetSecurityClaim("role");
     bool isAdmin = !string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin");
     return isAdmin || model.HasAccess(organization);
 }
        public Dictionary<string, string> GetSubRegister(string registername, MetadataViewModel model)
        {
            string role = GetSecurityClaim("role");

            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("subregisteritem");

            Dictionary<string, string> RegisterItems = new Dictionary<string, string>();

            if (cache != null)
            {
                RegisterItems = cache as Dictionary<string, string>;
            }

            if (RegisterItems.Count < 1)
            {

                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var data = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/subregister/" + registername);
                var response = Newtonsoft.Json.Linq.JObject.Parse(data);

                var items = response["containeditems"];

                foreach (var item in items)
                {
                    var id = item["id"].ToString();
                    var owner = item["owner"].ToString();
                    string organization = item["owner"].ToString();

                    if (!RegisterItems.ContainsKey(id))
                    {
                        if (!string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin") || model.HasAccess(organization))
                            RegisterItems.Add(id, item["label"].ToString());
                    }
                }
            }

            RegisterItems = RegisterItems.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);
            memCacher.Add("subregisteritem", RegisterItems, new DateTimeOffset(DateTime.Now.AddYears(1)));

            return RegisterItems;
        }
        public ActionResult Edit(string uuid, string action, MetadataViewModel model, string ignoreValidationError)
        {
            ViewBag.IsAdmin = "0";
            string role = GetSecurityClaim("role");
            if (!string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin")) {
                ViewBag.IsAdmin = "1";
            }

            ValidateModel(model);

            if (ignoreValidationError == "1" /*&& ViewBag.IsAdmin == "1"*/)
            {
                foreach (var modelValue in ModelState.Values)
                {
                    modelValue.Errors.Clear();
                }
            }

            if (ModelState.IsValid)
            {
                if (action.Equals(UI.Button_SaveAsXml))
                {
                    Stream fileStream = _metadataService.SaveMetadataAsXml(model);
                    var fileStreamResult = new FileStreamResult(fileStream, "application/xml")
                    {
                        FileDownloadName = model.Title + "_" + uuid + ".xml"
                    };

                    return fileStreamResult;
                }
                else
                {
                    SaveMetadataToCswServer(model);
                    if (action.Equals(UI.Button_Validate))
                    {
                        ValidateMetadata(uuid);
                    }

                    return RedirectToAction("Edit", new {uuid = model.Uuid});
                }
            }
            else
            {
                string messages = string.Join("; ", ModelState.Values
                                        .SelectMany(x => x.Errors)
                                        .Select(x => x.ErrorMessage));
                Log.Debug("Model for " + uuid + " is not valid: " + messages);
            }

            PrepareViewBagForEditing(model);
            return View(model);
        }
        public void SaveMetadataModel(MetadataViewModel model, string username)
        {
            SimpleMetadata metadata = new SimpleMetadata(_geoNorge.GetRecordByUuid(model.Uuid));

            metadata.Title = model.Title;
            metadata.Abstract = model.Abstract;

            if (!string.IsNullOrWhiteSpace(model.Purpose))
                metadata.Purpose = model.Purpose;

            if (!string.IsNullOrWhiteSpace(model.TopicCategory))
                metadata.TopicCategory = model.TopicCategory;

            if (!string.IsNullOrWhiteSpace(model.SupplementalDescription))
                metadata.SupplementalDescription = model.SupplementalDescription;

            if (!string.IsNullOrWhiteSpace(model.SpecificUsage))
                metadata.SpecificUsage = model.SpecificUsage;

            var contactMetadata = model.ContactMetadata.ToSimpleContact();
            if (!string.IsNullOrWhiteSpace(model.EnglishContactMetadataOrganization))
            {
                contactMetadata.OrganizationEnglish = model.EnglishContactMetadataOrganization;
            }
            metadata.ContactMetadata = contactMetadata;

            var contactPublisher = model.ContactPublisher.ToSimpleContact();
            if (!string.IsNullOrWhiteSpace(model.EnglishContactPublisherOrganization))
            {
                contactPublisher.OrganizationEnglish = model.EnglishContactPublisherOrganization;
            }
            metadata.ContactPublisher = contactPublisher;

            var contactOwner = model.ContactOwner.ToSimpleContact();
            if (!string.IsNullOrWhiteSpace(model.EnglishContactOwnerOrganization))
            {
                contactOwner.OrganizationEnglish = model.EnglishContactOwnerOrganization;
            }
            metadata.ContactOwner = contactOwner;

            // documents
            if (!string.IsNullOrWhiteSpace(model.ProductSpecificationUrl))
                metadata.ProductSpecificationUrl = model.ProductSpecificationUrl;

            if (!string.IsNullOrWhiteSpace(model.ProductSheetUrl))
                metadata.ProductSheetUrl = model.ProductSheetUrl;

            if (!string.IsNullOrWhiteSpace(model.ProductPageUrl))
                metadata.ProductPageUrl = model.ProductPageUrl;

            if (!string.IsNullOrWhiteSpace(model.LegendDescriptionUrl))
                metadata.LegendDescriptionUrl = model.LegendDescriptionUrl;

            metadata.Thumbnails = Thumbnail.ToSimpleThumbnailList(model.Thumbnails);

            // distribution
            if (!string.IsNullOrWhiteSpace(model.SpatialRepresentation))
                metadata.SpatialRepresentation = model.SpatialRepresentation;

            if (!string.IsNullOrWhiteSpace(model.ReferenceSystemCoordinateSystem))
            {
                metadata.ReferenceSystem = new SimpleReferenceSystem
                {
                    CoordinateSystem = model.ReferenceSystemCoordinateSystem,
                    Namespace = model.ReferenceSystemNamespace
                };
            }

            if (!string.IsNullOrWhiteSpace(model.DistributionFormatName) || !string.IsNullOrWhiteSpace(model.DistributionFormatVersion))
            {
                metadata.DistributionFormat = new SimpleDistributionFormat
                {
                    Name = model.DistributionFormatName,
                    Version = model.DistributionFormatVersion
                };
            }

            if (!string.IsNullOrWhiteSpace(model.DistributionUrl) || !string.IsNullOrWhiteSpace(model.DistributionProtocol) || !string.IsNullOrWhiteSpace(model.DistributionName))
            {
                metadata.DistributionDetails = new SimpleDistributionDetails
                {
                    URL = model.DistributionUrl,
                    Protocol = model.DistributionProtocol,
                    Name = model.DistributionName
                };
            }

            // quality
            if (!string.IsNullOrWhiteSpace(model.QualitySpecificationTitle)) {
                metadata.QualitySpecification = new SimpleQualitySpecification
                {
                    Title = model.QualitySpecificationTitle,
                    Date = model.QualitySpecificationDate,
                    DateType = model.QualitySpecificationDateType,
                    Explanation = model.QualitySpecificationExplanation,
                    Result = model.QualitySpecificationResult
                };
            }

            if (!string.IsNullOrWhiteSpace(model.ProcessHistory))
                metadata.ProcessHistory = model.ProcessHistory;

            if (!string.IsNullOrWhiteSpace(model.MaintenanceFrequency))
                metadata.MaintenanceFrequency = model.MaintenanceFrequency;

            if (!string.IsNullOrWhiteSpace(model.ResolutionScale))
                metadata.ResolutionScale = model.ResolutionScale;

            if (!string.IsNullOrWhiteSpace(model.Status))
                metadata.Status = model.Status;

            metadata.DateCreated = model.DateCreated;
            metadata.DatePublished = model.DatePublished;
            metadata.DateUpdated = model.DateUpdated;

            if (!string.IsNullOrWhiteSpace(model.BoundingBoxEast))
            {
                metadata.BoundingBox = new SimpleBoundingBox
                {
                    EastBoundLongitude = model.BoundingBoxEast,
                    WestBoundLongitude = model.BoundingBoxWest,
                    NorthBoundLatitude = model.BoundingBoxNorth,
                    SouthBoundLatitude = model.BoundingBoxSouth
                };
            }

            if (!string.IsNullOrWhiteSpace(model.AccessConstraints)
                || !string.IsNullOrWhiteSpace(model.OtherConstraints)
                || !string.IsNullOrWhiteSpace(model.SecurityConstraints)
                || !string.IsNullOrWhiteSpace(model.UseConstraints)
                || !string.IsNullOrWhiteSpace(model.UseLimitations))
            {
                metadata.Constraints = new SimpleConstraints
                {
                    AccessConstraints = model.AccessConstraints,
                    OtherConstraints = model.OtherConstraints,
                    SecurityConstraints = model.SecurityConstraints,
                    UseConstraints = model.UseConstraints,
                    UseLimitations = model.UseLimitations
                };
            }

            metadata.Keywords = model.GetAllKeywords();

            bool hasEnglishFields = false;
            // don't create PT_FreeText fields if it isn't necessary
            if (!string.IsNullOrWhiteSpace(model.EnglishTitle))
            {
                metadata.EnglishTitle = model.EnglishTitle;
                hasEnglishFields = true;
            }
            if (!string.IsNullOrWhiteSpace(model.EnglishAbstract))
            {
                metadata.EnglishAbstract = model.EnglishAbstract;
                hasEnglishFields = true;
            }

            if (hasEnglishFields)
                metadata.SetLocale(SimpleMetadata.LOCALE_ENG);

            SetDefaultValuesOnMetadata(metadata);

            _geoNorge.MetadataUpdate(metadata.GetMetadata(), CreateAdditionalHeadersWithUsername(username));
        }
Exemplo n.º 7
0
        private void RemoveCache(MetadataViewModel metadata)
        {
            HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create(System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogUrl"] + "thumbnail/removecache/" + metadata.Uuid);

            HttpWebResponse response = (HttpWebResponse)
            request.GetResponse();
        }
Exemplo n.º 8
0
        public MetadataViewModel GetMetadataModel(string uuid)
        {
            SimpleMetadata metadata = new SimpleMetadata(_geoNorge.GetRecordByUuid(uuid));

            var model = new MetadataViewModel()
            {
                Uuid = metadata.Uuid,
                Title = metadata.Title,
                HierarchyLevel = metadata.HierarchyLevel,
                ParentIdentifier = metadata.ParentIdentifier,
                MetadataStandard = metadata.MetadataStandard,
                Abstract = metadata.Abstract != null ? metadata.Abstract.Replace("...", "") : "",
                Purpose = metadata.Purpose,

                ContactMetadata = new Contact(metadata.ContactMetadata, "pointOfContact"),
                ContactPublisher = new Contact(metadata.ContactPublisher, "publisher"),
                ContactOwner = new Contact(metadata.ContactOwner, "owner"),

                KeywordsTheme = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, SimpleKeyword.TYPE_THEME, null)),
                KeywordsPlace = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, SimpleKeyword.TYPE_PLACE, null)),
                KeywordsNationalInitiative = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_NATIONAL_INITIATIVE)),
                KeywordsNationalTheme = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_NATIONAL_THEME)),
                KeywordsConcept = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_CONCEPT)),
                KeywordsInspire = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_GEMET_INSPIRE_V1)),
                KeywordsServiceTaxonomy = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_SERVICES_TAXONOMY)),
                KeywordsOther = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, null)),
                KeywordsEnglish = CreateDictionaryOfEnglishKeywords(metadata.Keywords),

                TopicCategory = metadata.TopicCategory,
                SupplementalDescription = metadata.SupplementalDescription,
                SpecificUsage = metadata.SpecificUsage,

                ProductPageUrl = metadata.ProductPageUrl,
                ProductSheetUrl = metadata.ProductSheetUrl,
                ProductSpecificationUrl = metadata.ProductSpecificationUrl,
                ApplicationSchema = metadata.ApplicationSchema,
                LegendDescriptionUrl = metadata.LegendDescriptionUrl,
                CoverageUrl = metadata.CoverageUrl,

                Thumbnails = Thumbnail.CreateFromList(metadata.Thumbnails),

                SpatialRepresentation = metadata.SpatialRepresentation,
                DistributionFormatName = metadata.DistributionFormat != null ? metadata.DistributionFormat.Name : null,
                DistributionFormatVersion = metadata.DistributionFormat != null ? metadata.DistributionFormat.Version : null,
                DistributionFormats = metadata.DistributionFormats != null ? metadata.DistributionFormats : new List<SimpleDistributionFormat> { new SimpleDistributionFormat() },
                DistributionUrl = metadata.DistributionDetails != null ? metadata.DistributionDetails.URL : null,
                DistributionProtocol = metadata.DistributionDetails != null ? metadata.DistributionDetails.Protocol : null,
                DistributionName = metadata.DistributionDetails != null ? metadata.DistributionDetails.Name : null,
                UnitsOfDistribution = metadata.DistributionDetails != null ? metadata.DistributionDetails.UnitsOfDistribution : null,

                ReferenceSystemCoordinateSystem = metadata.ReferenceSystem != null ? metadata.ReferenceSystem.CoordinateSystem : null,
                ReferenceSystemNamespace = metadata.ReferenceSystem != null ? metadata.ReferenceSystem.Namespace : null,
                ReferenceSystems = metadata.ReferenceSystems != null && metadata.ReferenceSystems.Count == 0 ? null : metadata.ReferenceSystems,

                //QualitySpecificationDate = (metadata.QualitySpecification != null && !string.IsNullOrWhiteSpace(metadata.QualitySpecification.Date)) ? DateTime.Parse(metadata.QualitySpecification.Date) : (DateTime?)null,
                //QualitySpecificationDateType = metadata.QualitySpecification != null ? metadata.QualitySpecification.DateType : null,
                //QualitySpecificationExplanation = metadata.QualitySpecification != null ? metadata.QualitySpecification.Explanation : null,
                //QualitySpecificationResult = metadata.QualitySpecification != null ? metadata.QualitySpecification.Result : false,
                //QualitySpecificationTitle = metadata.QualitySpecification != null ? metadata.QualitySpecification.Title : null,
                ProcessHistory = metadata.ProcessHistory,
                MaintenanceFrequency = metadata.MaintenanceFrequency,
                ResolutionScale = metadata.ResolutionScale,

                UseLimitations = metadata.Constraints != null ? metadata.Constraints.UseLimitations : null,
                EnglishUseLimitations = metadata.Constraints != null ? metadata.Constraints.EnglishUseLimitations : null,
                UseConstraints = metadata.Constraints != null ? metadata.Constraints.UseConstraints : null,
                AccessConstraints = metadata.Constraints != null ? metadata.Constraints.AccessConstraints : null,
                SecurityConstraints = metadata.Constraints != null ? metadata.Constraints.SecurityConstraints : null,
                SecurityConstraintsNote = metadata.Constraints != null ? metadata.Constraints.SecurityConstraintsNote : null,
                OtherConstraints = metadata.Constraints != null ? metadata.Constraints.OtherConstraints : null,
                EnglishOtherConstraints = metadata.Constraints != null ? metadata.Constraints.EnglishOtherConstraints : null,
                OtherConstraintsLink = metadata.Constraints != null ? metadata.Constraints.OtherConstraintsLink : null,
                OtherConstraintsLinkText = metadata.Constraints != null ? metadata.Constraints.OtherConstraintsLinkText : null,
                OtherConstraintsAccess = metadata.Constraints != null ? metadata.Constraints.OtherConstraintsAccess : null,

                DateCreated = metadata.DateCreated,
                DatePublished = metadata.DatePublished,
                DateUpdated = metadata.DateUpdated,
                DateMetadataUpdated = metadata.DateMetadataUpdated,
                DateMetadataValidFrom = string.IsNullOrEmpty(metadata.ValidTimePeriod.ValidFrom) ? (DateTime?)null : DateTime.Parse(metadata.ValidTimePeriod.ValidFrom),
                DateMetadataValidTo = string.IsNullOrEmpty(metadata.ValidTimePeriod.ValidTo) ? (DateTime?)null : DateTime.Parse(metadata.ValidTimePeriod.ValidTo),

                Status = metadata.Status,
                OrderingInstructions = (metadata.AccessProperties != null && !string.IsNullOrEmpty(metadata.AccessProperties.OrderingInstructions)) ? metadata.AccessProperties.OrderingInstructions : "",

                BoundingBoxEast = metadata.BoundingBox != null ? metadata.BoundingBox.EastBoundLongitude : null,
                BoundingBoxWest = metadata.BoundingBox != null ? metadata.BoundingBox.WestBoundLongitude : null,
                BoundingBoxNorth = metadata.BoundingBox != null ? metadata.BoundingBox.NorthBoundLatitude : null,
                BoundingBoxSouth = metadata.BoundingBox != null ? metadata.BoundingBox.SouthBoundLatitude : null,

                EnglishTitle = metadata.EnglishTitle,
                EnglishAbstract = metadata.EnglishAbstract,
                EnglishPurpose = metadata.EnglishPurpose,
                EnglishSupplementalDescription = metadata.EnglishSupplementalDescription,
                EnglishSpecificUsage = metadata.EnglishSpecificUsage,
                EnglishProcessHistory = metadata.EnglishProcessHistory,
                EnglishContactMetadataOrganization = metadata.ContactMetadata != null ? metadata.ContactMetadata.OrganizationEnglish : null,
                EnglishContactPublisherOrganization = metadata.ContactPublisher != null ? metadata.ContactPublisher.OrganizationEnglish : null,
                EnglishContactOwnerOrganization = metadata.ContactOwner != null ? metadata.ContactOwner.OrganizationEnglish : null,
            };

            if (metadata.BoundingBox != null)
            {
                model.BoundingBoxEast = ConvertCoordinateWithCommaToPoint(metadata.BoundingBox.EastBoundLongitude);
                model.BoundingBoxWest = ConvertCoordinateWithCommaToPoint(metadata.BoundingBox.WestBoundLongitude);
                model.BoundingBoxNorth = ConvertCoordinateWithCommaToPoint(metadata.BoundingBox.NorthBoundLatitude);
                model.BoundingBoxSouth = ConvertCoordinateWithCommaToPoint(metadata.BoundingBox.SouthBoundLatitude);
            }

            if (metadata.ProductSpecificationOther != null)
            {
                model.ProductSpecificationOther = new SimpleOnlineResource
                {
                    Name = metadata.ProductSpecificationOther.Name,
                    URL = metadata.ProductSpecificationOther.URL
                };
            }

            model.FixThumbnailUrls();

            model.OperatesOn = metadata.OperatesOn !=null ? metadata.OperatesOn : new List<string>();

            if (metadata.ResourceReference != null)
            {
                model.ResourceReferenceCode = metadata.ResourceReference.Code != null ? metadata.ResourceReference.Code : null;
                model.ResourceReferenceCodespace = metadata.ResourceReference.Codespace != null ? metadata.ResourceReference.Codespace : null;
            }

            getQualitySpecifications(model, metadata);

            return model;
        }
Exemplo n.º 9
0
        private void getQualitySpecifications(MetadataViewModel model, SimpleMetadata metadata)
        {
            if (metadata.QualitySpecifications != null && metadata.QualitySpecifications.Count > 0)
            {
                foreach (var qualitySpecification in metadata.QualitySpecifications)
                {
                    string responsible = !string.IsNullOrEmpty(qualitySpecification.Responsible) ? qualitySpecification.Responsible : "";
                    responsible = responsible.ToLower();

                    string title = qualitySpecification.Title != null ? qualitySpecification.Title : "";
                    title = title.ToLower();

                    if (title.Contains("commission regulation") || title.Contains("Inspire"))
                        responsible = "inspire";
                    else if (title.Contains("sosi") && title != "sosi applikasjonsskjema")
                        responsible = "sosi";

                    if (responsible == "inspire")
                    {
                        model.QualitySpecificationDateInspire = (!string.IsNullOrWhiteSpace(qualitySpecification.Date)) ? DateTime.Parse(qualitySpecification.Date) : (DateTime?)null;
                        model.QualitySpecificationDateTypeInspire = (!string.IsNullOrWhiteSpace(qualitySpecification.DateType)) ? qualitySpecification.DateType : null;
                        model.QualitySpecificationExplanationInspire = qualitySpecification.Explanation != null ? qualitySpecification.Explanation : null;
                        model.QualitySpecificationResultInspire = qualitySpecification.Result;
                        model.QualitySpecificationTitleInspire = qualitySpecification.Title != null ? qualitySpecification.Title : null;

                    }
                    else if (responsible == "sosi")
                    {
                        model.QualitySpecificationDateSosi = (!string.IsNullOrWhiteSpace(qualitySpecification.Date)) ? DateTime.Parse(qualitySpecification.Date) : (DateTime?)null;
                        model.QualitySpecificationDateTypeSosi = (!string.IsNullOrWhiteSpace(qualitySpecification.DateType)) ? qualitySpecification.DateType : null;
                        model.QualitySpecificationExplanationSosi = qualitySpecification.Explanation != null ? qualitySpecification.Explanation : null;
                        model.QualitySpecificationResultSosi = qualitySpecification.Result;
                        model.QualitySpecificationTitleSosi = qualitySpecification.Title != null ? qualitySpecification.Title : null;
                    }
                    else if (responsible == "uml-sosi")
                    {
                        model.QualitySpecificationResultSosiConformApplicationSchema = qualitySpecification.Result;
                    }
                    else if (responsible == "uml-gml")
                    {
                        model.QualitySpecificationResultSosiConformGmlApplicationSchema = qualitySpecification.Result;
                    }
                    else
                    {
                        model.QualitySpecificationDate = (!string.IsNullOrWhiteSpace(qualitySpecification.Date)) ? DateTime.Parse(qualitySpecification.Date) : (DateTime?)null;
                        model.QualitySpecificationDateType = (!string.IsNullOrWhiteSpace(qualitySpecification.DateType)) ? qualitySpecification.DateType : null;
                        model.QualitySpecificationExplanation = qualitySpecification.Explanation != null ? qualitySpecification.Explanation : null;
                        model.QualitySpecificationResult = qualitySpecification.Result;
                        model.QualitySpecificationTitle = qualitySpecification.Title != null ? qualitySpecification.Title : null;
                    }
                }

            }
        }
Exemplo n.º 10
0
 public Stream SaveMetadataAsXml(MetadataViewModel model)
 {
     var simpleMetadata = new SimpleMetadata(_geoNorge.GetRecordByUuid(model.Uuid));
     UpdateMetadataFromModel(model, simpleMetadata);
     return SerializeUtil.SerializeToStream(simpleMetadata.GetMetadata());
 }
Exemplo n.º 11
0
        public void SaveMetadataModel(MetadataViewModel model, string username)
        {
            SimpleMetadata metadata = new SimpleMetadata(_geoNorge.GetRecordByUuid(model.Uuid));

            UpdateMetadataFromModel(model, metadata);

            var transaction = _geoNorge.MetadataUpdate(metadata.GetMetadata(), CreateAdditionalHeadersWithUsername(username, model.Published));
            if (transaction.TotalUpdated == "0")
                throw new Exception("Kunne ikke lagre endringene - kontakt systemansvarlig");

            Task.Run(() => ReIndexOperatesOn(model));
            Task.Run(() => RemoveCache(model));
        }
Exemplo n.º 12
0
        private void UpdateMetadataFromModel(MetadataViewModel model, SimpleMetadata metadata)
        {
            metadata.Title = model.Title;
            metadata.Abstract = model.Abstract;

            if (!string.IsNullOrEmpty(model.ParentIdentifier))
                metadata.ParentIdentifier = model.ParentIdentifier;

            metadata.Purpose = !string.IsNullOrWhiteSpace(model.Purpose) ? model.Purpose : " ";

            if (!string.IsNullOrWhiteSpace(model.TopicCategory))
                metadata.TopicCategory = model.TopicCategory;
            if(!string.IsNullOrWhiteSpace(model.SupplementalDescription))
                metadata.SupplementalDescription = model.SupplementalDescription;

            metadata.SpecificUsage = !string.IsNullOrWhiteSpace(model.SpecificUsage) ? model.SpecificUsage : " ";

            var contactMetadata = model.ContactMetadata.ToSimpleContact();
            if (!string.IsNullOrWhiteSpace(model.EnglishContactMetadataOrganization))
            {
                contactMetadata.OrganizationEnglish = model.EnglishContactMetadataOrganization;
            }
            metadata.ContactMetadata = contactMetadata;

            var contactPublisher = model.ContactPublisher.ToSimpleContact();
            if (!string.IsNullOrWhiteSpace(model.EnglishContactPublisherOrganization))
            {
                contactPublisher.OrganizationEnglish = model.EnglishContactPublisherOrganization;
            }
            metadata.ContactPublisher = contactPublisher;

            var contactOwner = model.ContactOwner.ToSimpleContact();
            if (!string.IsNullOrWhiteSpace(model.EnglishContactOwnerOrganization))
            {
                contactOwner.OrganizationEnglish = model.EnglishContactOwnerOrganization;
            }
            metadata.ContactOwner = contactOwner;

            // documents
            metadata.ProductSpecificationUrl = model.ProductSpecificationUrl;

            metadata.ApplicationSchema = model.ApplicationSchema;

            if (metadata.IsDataset()) {
                metadata.ProductSpecificationOther = new SimpleOnlineResource
                {
                    Name = model.ProductSpecificationOther.Name,
                    URL = model.ProductSpecificationOther.URL
                };
            }

            metadata.ProductSheetUrl = model.ProductSheetUrl;
                metadata.ProductPageUrl = model.ProductPageUrl;
                metadata.LegendDescriptionUrl = model.LegendDescriptionUrl;
                metadata.CoverageUrl = model.CoverageUrl;

            metadata.Thumbnails = Thumbnail.ToSimpleThumbnailList(model.Thumbnails);

            // distribution
            //if (!string.IsNullOrWhiteSpace(model.SpatialRepresentation))
                metadata.SpatialRepresentation = model.SpatialRepresentation;

            //if (!string.IsNullOrWhiteSpace(model.ReferenceSystemCoordinateSystem))
            //{
            //    metadata.ReferenceSystem = new SimpleReferenceSystem
            //    {
            //        CoordinateSystem = model.ReferenceSystemCoordinateSystem,
            //        Namespace = model.ReferenceSystemNamespace
            //    };
            //}
                var refsys = model.GetReferenceSystems();
                if (refsys != null)
                    metadata.ReferenceSystems = refsys;

            //Upgraded to multiple distribution formats
            //if (!string.IsNullOrWhiteSpace(model.DistributionFormatName) ||
            //    !string.IsNullOrWhiteSpace(model.DistributionFormatVersion))
            //{
            //    metadata.DistributionFormat = new SimpleDistributionFormat
            //    {
            //        Name = model.DistributionFormatName,
            //        Version = model.DistributionFormatVersion
            //    };
            //}

            metadata.DistributionFormats = model.GetDistributionFormats();

            metadata.DistributionDetails = new SimpleDistributionDetails
            {
                URL = model.DistributionUrl,
                Protocol = model.DistributionProtocol,
                Name = model.DistributionName,
                UnitsOfDistribution = model.UnitsOfDistribution
            };

            // quality
            List<SimpleQualitySpecification> qualityList = new List<SimpleQualitySpecification>();
            if (!string.IsNullOrWhiteSpace(model.QualitySpecificationTitleInspire))
            {
                qualityList.Add(new SimpleQualitySpecification
                {
                    Title = model.QualitySpecificationTitleInspire,
                    Date = string.Format("{0:yyyy-MM-dd}", model.QualitySpecificationDateInspire),
                    DateType = model.QualitySpecificationDateTypeInspire,
                    Explanation = model.QualitySpecificationExplanationInspire,
                    Result = model.QualitySpecificationResultInspire,
                    Responsible = "inspire"
                });
            }
            if (!string.IsNullOrWhiteSpace(model.QualitySpecificationTitleSosi))
            {
                qualityList.Add(new SimpleQualitySpecification
                {
                    Title = model.QualitySpecificationTitleSosi,
                    Date = string.Format("{0:yyyy-MM-dd}", model.QualitySpecificationDateSosi),
                    DateType = model.QualitySpecificationDateTypeSosi,
                    Explanation = model.QualitySpecificationExplanationSosi,
                    Result = model.QualitySpecificationResultSosi,
                    Responsible = "sosi"
                });
            }
            if (model.QualitySpecificationResultSosiConformApplicationSchema)
            {
                qualityList.Add(new SimpleQualitySpecification
                {
                    Title = "Sosi applikasjonsskjema",
                    Date = string.Format("{0:yyyy-MM-dd}", model.QualitySpecificationDateSosi),
                    DateType = model.QualitySpecificationDateTypeSosi,
                    Explanation = "SOSI-filer er i henhold til applikasjonsskjema",
                    Result = true,
                    Responsible = "uml-sosi"
                });
            }
            if (model.QualitySpecificationResultSosiConformGmlApplicationSchema)
            {
                qualityList.Add(new SimpleQualitySpecification
                {
                    Title = "Sosi applikasjonsskjema",
                    Date = string.Format("{0:yyyy-MM-dd}", model.QualitySpecificationDateSosi),
                    DateType = model.QualitySpecificationDateTypeSosi,
                    Explanation = "GML-filer er i henhold til applikasjonsskjema",
                    Result = true,
                    Responsible = "uml-gml"
                });
            }
            if (!string.IsNullOrWhiteSpace(model.QualitySpecificationTitle))
            {
                qualityList.Add(new SimpleQualitySpecification
                {
                    Title = model.QualitySpecificationTitle,
                    Date = string.Format("{0:yyyy-MM-dd}", model.QualitySpecificationDate),
                    DateType = model.QualitySpecificationDateType,
                    Explanation = model.QualitySpecificationExplanation,
                    Result = model.QualitySpecificationResult,
                    Responsible = "other"
                });
            }

            metadata.QualitySpecifications = qualityList;

            metadata.ProcessHistory = !string.IsNullOrWhiteSpace(model.ProcessHistory) ? model.ProcessHistory : " ";

            if (!string.IsNullOrWhiteSpace(model.MaintenanceFrequency))
                metadata.MaintenanceFrequency = model.MaintenanceFrequency;

            if (!model.IsService())
                metadata.ResolutionScale = !string.IsNullOrWhiteSpace(model.ResolutionScale) ? model.ResolutionScale : " ";

            if (!string.IsNullOrWhiteSpace(model.Status))
                metadata.Status = model.Status;

            metadata.DateCreated = model.DateCreated;
            metadata.DatePublished = model.DatePublished;
            metadata.DateUpdated = model.DateUpdated;

            DateTime? DateMetadataValidFrom = model.DateMetadataValidFrom;
            DateTime? DateMetadataValidTo = model.DateMetadataValidTo;

                metadata.ValidTimePeriod = new SimpleValidTimePeriod()
                {
                    ValidFrom = DateMetadataValidFrom != null ? String.Format("{0:yyyy-MM-dd}", DateMetadataValidFrom) : "",
                    ValidTo = DateMetadataValidTo != null ? String.Format("{0:yyyy-MM-dd}", DateMetadataValidTo) : ""
                };

            if (!string.IsNullOrWhiteSpace(model.BoundingBoxEast))
            {
                metadata.BoundingBox = new SimpleBoundingBox
                {
                    EastBoundLongitude = model.BoundingBoxEast,
                    WestBoundLongitude = model.BoundingBoxWest,
                    NorthBoundLatitude = model.BoundingBoxNorth,
                    SouthBoundLatitude = model.BoundingBoxSouth
                };
            }

            var accessConstraintsSelected = model.AccessConstraints;
            string otherConstraintsAccess = model.OtherConstraintsAccess;

            if (!string.IsNullOrEmpty(accessConstraintsSelected))
            {
                if (accessConstraintsSelected.ToLower() == "no restrictions" || accessConstraintsSelected.ToLower() == "norway digital restricted")
                {
                    otherConstraintsAccess = accessConstraintsSelected;
                    accessConstraintsSelected = "otherRestrictions";

                }
            }

            metadata.Constraints = new SimpleConstraints
            {
                AccessConstraints = !string.IsNullOrWhiteSpace(accessConstraintsSelected) ? accessConstraintsSelected : "",
                OtherConstraints = !string.IsNullOrWhiteSpace(model.OtherConstraints) ? model.OtherConstraints : "",
                EnglishOtherConstraints = !string.IsNullOrWhiteSpace(model.EnglishOtherConstraints) ? model.EnglishOtherConstraints : "",
                OtherConstraintsLink = !string.IsNullOrWhiteSpace(model.OtherConstraintsLink) ? model.OtherConstraintsLink : null,
                OtherConstraintsLinkText = !string.IsNullOrWhiteSpace(model.OtherConstraintsLinkText) ? model.OtherConstraintsLinkText : null,
                SecurityConstraints = !string.IsNullOrWhiteSpace(model.SecurityConstraints) ? model.SecurityConstraints : "",
                SecurityConstraintsNote = !string.IsNullOrWhiteSpace(model.SecurityConstraintsNote) ? model.SecurityConstraintsNote : "",
                UseConstraints = !string.IsNullOrWhiteSpace(model.UseConstraints) ? model.UseConstraints : "",
                UseLimitations = !string.IsNullOrWhiteSpace(model.UseLimitations) ? model.UseLimitations : "",
                EnglishUseLimitations = !string.IsNullOrWhiteSpace(model.EnglishUseLimitations) ? model.EnglishUseLimitations : "",
                OtherConstraintsAccess = !string.IsNullOrWhiteSpace(otherConstraintsAccess) ? otherConstraintsAccess : "",
            };

            if(model.IsService() && !string.IsNullOrEmpty(model.DistributionProtocol))
            {
                model.KeywordsOther = AddKeywordForService(model.DistributionProtocol, model.KeywordsOther);
                metadata.ServiceType = GetServiceType(model.DistributionProtocol);
            }
            metadata.Keywords = model.GetAllKeywords();

            bool hasEnglishFields = false;
            // don't create PT_FreeText fields if it isn't necessary
            if (!string.IsNullOrWhiteSpace(model.EnglishTitle))
            {
                metadata.EnglishTitle = model.EnglishTitle;
                hasEnglishFields = true;
            }
            if (!string.IsNullOrWhiteSpace(model.EnglishAbstract))
            {
                metadata.EnglishAbstract = model.EnglishAbstract;
                hasEnglishFields = true;
            }

            if (!string.IsNullOrWhiteSpace(model.EnglishPurpose))
            {
                metadata.EnglishPurpose = model.EnglishPurpose;
                hasEnglishFields = true;
            }

            if (!string.IsNullOrWhiteSpace(model.EnglishSupplementalDescription))
            {
                metadata.EnglishSupplementalDescription = model.EnglishSupplementalDescription;
                hasEnglishFields = true;
            }

            if (!string.IsNullOrWhiteSpace(model.EnglishSpecificUsage))
            {
                metadata.EnglishSpecificUsage = model.EnglishSpecificUsage;
                hasEnglishFields = true;
            }

            if (!string.IsNullOrWhiteSpace(model.EnglishProcessHistory))
            {
                metadata.EnglishProcessHistory = model.EnglishProcessHistory;
                hasEnglishFields = true;
            }

            if (hasEnglishFields)
                metadata.SetLocale(SimpleMetadata.LOCALE_ENG);

            if (model.OperatesOn != null)
                metadata.OperatesOn = model.OperatesOn;

            if (!string.IsNullOrWhiteSpace(model.ResourceReferenceCode) || !string.IsNullOrWhiteSpace(model.ResourceReferenceCodespace))
            {
                metadata.ResourceReference = new SimpleResourceReference
                {
                 Code = model.ResourceReferenceCode != null ? model.ResourceReferenceCode : null,
                 Codespace = model.ResourceReferenceCodespace != null ? model.ResourceReferenceCodespace : null
                };
            }

            if (model.IsService())
                metadata.AccessProperties = new SimpleAccessProperties { OrderingInstructions = model.OrderingInstructions }  ;

            SetDefaultValuesOnMetadata(metadata);
        }
Exemplo n.º 13
0
        public MetaDataEntry ValidateMetadata(string uuid)
        {
            MetaDataEntry metadata = new MetaDataEntry();

            metadata.Errors = new List <Error>();

            try
            {
                Kartverket.MetadataEditor.Models.MetadataViewModel model = _metadataService.GetMetadataModel(uuid);


                if (model != null)
                {
                    string role = GetSecurityClaim("role");
                    if (!string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin"))
                    {
                        model.ValidateAllRequirements = true;
                    }

                    metadata.Uuid             = model.Uuid;
                    metadata.Title            = model.Title;
                    metadata.OrganizationName = model.ContactMetadata.Organization != null ? model.ContactMetadata.Organization : "";
                    metadata.ContactEmail     = model.ContactMetadata.Email != null ? model.ContactMetadata.Email : "";

                    if (model.MetadataStandard == "ISO19115:Norsk versjon")
                    {
                        Kartverket.MetadataEditor.Models.SimpleMetadataService   _simpleMetadataService = new Kartverket.MetadataEditor.Models.SimpleMetadataService();
                        Kartverket.MetadataEditor.Models.SimpleMetadataViewModel modelSimple            = _simpleMetadataService.GetMetadataModel(uuid);

                        Validate(modelSimple);

                        var errors = ModelState.Where(n => n.Value.Errors.Count > 0).ToList();

                        foreach (var error in errors)
                        {
                            metadata.Errors.Add(new Error {
                                Key = error.Key.ToString(), Message = error.Value.Errors[0].ErrorMessage
                            });
                        }
                    }

                    else
                    {
                        var thumb = model.Thumbnails.Where(t => t.Type == "thumbnail" || t.Type == "miniatyrbilde");
                        if (thumb.Count() == 0)
                        {
                            ModelState.AddModelError("ThumbnailMissing", "Det er påkrevd å fylle ut illustrasjonsbilde");
                        }
                        else if (thumb.Count() > 0)
                        {
                            try
                            {
                                //Disable SSL sertificate errors
                                System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                                    delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                             System.Security.Cryptography.X509Certificates.X509Chain chain,
                                             System.Net.Security.SslPolicyErrors sslPolicyErrors)
                                {
                                    return(true); // **** Always accept
                                };
                                using (var client = new HttpClient())
                                {
                                    client.DefaultRequestHeaders.Accept.Clear();
                                    string Url = thumb.Select(t => t.URL).FirstOrDefault().ToString();
                                    HttpResponseMessage response = client.GetAsync(new Uri(Url)).Result;
                                    if (response.StatusCode != HttpStatusCode.OK)
                                    {
                                        metadata.Errors.Add(new Error {
                                            Key = "ThumbnailNotFound", Message = "Feil ressurslenke til illustrasjonsbilde"
                                        });
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                metadata.Errors.Add(new Error {
                                    Key = "Error", Message = ex.Message
                                });
                            }
                        }

                        Validate(model);

                        var errors = ModelState.Where(n => n.Value.Errors.Count > 0).ToList();

                        foreach (var error in errors)
                        {
                            metadata.Errors.Add(new Error {
                                Key = error.Key.ToString(), Message = error.Value.Errors[0].ErrorMessage
                            });
                        }
                    }
                }
            }
            catch (Exception ex) {
                metadata.Errors.Add(new Error {
                    Key = "Error", Message = ex.Message
                });
            }

            if (metadata.Errors.Count > 0)
            {
                metadata.Status = "ERRORS";
            }
            else
            {
                metadata.Status = "OK";
            }

            return(metadata);
        }
Exemplo n.º 14
0
        public MetadataViewModel GetMetadataModel(string uuid)
        {
            SimpleMetadata metadata = new SimpleMetadata(_geoNorge.GetRecordByUuid(uuid));

            var model = new MetadataViewModel() {
                Uuid = metadata.Uuid,
                Title = metadata.Title,
                HierarchyLevel = metadata.HierarchyLevel,
                Abstract = metadata.Abstract,
                Purpose = metadata.Purpose,

                ContactMetadata = new Contact(metadata.ContactMetadata, "pointOfContact"),
                ContactPublisher = new Contact(metadata.ContactPublisher, "publisher"),
                ContactOwner = new Contact(metadata.ContactOwner, "owner"),

                KeywordsTheme = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, SimpleKeyword.TYPE_THEME, null)),
                KeywordsPlace = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, SimpleKeyword.TYPE_PLACE, null)),
                KeywordsNationalInitiative = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_NATIONAL_INITIATIVE)),
                KeywordsInspire = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_GEMET_INSPIRE_V1)),
                KeywordsServiceTaxonomy = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, SimpleKeyword.THESAURUS_SERVICES_TAXONOMY)),
                KeywordsOther = CreateListOfKeywords(SimpleKeyword.Filter(metadata.Keywords, null, null)),
                KeywordsEnglish = CreateDictionaryOfEnglishKeywords(metadata.Keywords),

                TopicCategory = metadata.TopicCategory,
                SupplementalDescription = metadata.SupplementalDescription,
                SpecificUsage = metadata.SpecificUsage,

                ProductPageUrl = metadata.ProductPageUrl,
                ProductSheetUrl = metadata.ProductSheetUrl,
                ProductSpecificationUrl = metadata.ProductSpecificationUrl,
                LegendDescriptionUrl = metadata.LegendDescriptionUrl,

                Thumbnails = Thumbnail.CreateFromList(metadata.Thumbnails),

                SpatialRepresentation = metadata.SpatialRepresentation,
                DistributionFormatName = metadata.DistributionFormat != null ? metadata.DistributionFormat.Name : null,
                DistributionFormatVersion = metadata.DistributionFormat != null ? metadata.DistributionFormat.Version : null,
                DistributionUrl = metadata.DistributionDetails != null ? metadata.DistributionDetails.URL : null,
                DistributionProtocol = metadata.DistributionDetails != null ? metadata.DistributionDetails.Protocol : null,
                DistributionName = metadata.DistributionDetails != null ? metadata.DistributionDetails.Name : null,

                ReferenceSystemCoordinateSystem = metadata.ReferenceSystem != null ? metadata.ReferenceSystem.CoordinateSystem : null,
                ReferenceSystemNamespace = metadata.ReferenceSystem != null ? metadata.ReferenceSystem.Namespace: null,

                QualitySpecificationDate = metadata.QualitySpecification != null ? metadata.QualitySpecification.Date : null,
                QualitySpecificationDateType = metadata.QualitySpecification != null ? metadata.QualitySpecification.DateType : null,
                QualitySpecificationExplanation = metadata.QualitySpecification != null ? metadata.QualitySpecification.Explanation : null,
                QualitySpecificationResult = metadata.QualitySpecification != null ? metadata.QualitySpecification.Result : false,
                QualitySpecificationTitle = metadata.QualitySpecification != null ? metadata.QualitySpecification.Title : null,
                ProcessHistory = metadata.ProcessHistory,
                MaintenanceFrequency = metadata.MaintenanceFrequency,
                ResolutionScale = metadata.ResolutionScale,

                UseLimitations = metadata.Constraints != null ? metadata.Constraints.UseLimitations : null,
                UseConstraints = metadata.Constraints != null ? metadata.Constraints.UseConstraints : null,
                AccessConstraints = metadata.Constraints != null ? metadata.Constraints.AccessConstraints : null,
                SecurityConstraints = metadata.Constraints != null ? metadata.Constraints.SecurityConstraints : null,
                OtherConstraints = metadata.Constraints != null ? metadata.Constraints.OtherConstraints : null,

                DateCreated = metadata.DateCreated,
                DatePublished = metadata.DatePublished,
                DateUpdated = metadata.DateUpdated,
                DateMetadataUpdated = metadata.DateMetadataUpdated,

                Status = metadata.Status,

                BoundingBoxEast = metadata.BoundingBox != null ? metadata.BoundingBox.EastBoundLongitude : null,
                BoundingBoxWest = metadata.BoundingBox != null ? metadata.BoundingBox.WestBoundLongitude : null,
                BoundingBoxNorth = metadata.BoundingBox != null ? metadata.BoundingBox.NorthBoundLatitude : null,
                BoundingBoxSouth = metadata.BoundingBox != null ? metadata.BoundingBox.SouthBoundLatitude : null,

                EnglishTitle = metadata.EnglishTitle,
                EnglishAbstract = metadata.EnglishAbstract,
                EnglishContactMetadataOrganization = metadata.ContactMetadata != null ? metadata.ContactMetadata.OrganizationEnglish : null,
                EnglishContactPublisherOrganization = metadata.ContactPublisher != null ? metadata.ContactPublisher.OrganizationEnglish : null,
                EnglishContactOwnerOrganization = metadata.ContactOwner != null ? metadata.ContactOwner.OrganizationEnglish : null,
            };

            model.FixThumbnailUrls();
            return model;
        }
Exemplo n.º 15
0
 private void SaveMetadataToCswServer(MetadataViewModel model)
 {
     try
     {
         _metadataService.SaveMetadataModel(model, GetUsername());
         TempData["success"] = UI.Metadata_Edit_Saved_Success;
     }
     catch (Exception e)
     {
         Log.Error("Error while editing metadata with uuid = " + model.Uuid, e);
         TempData["failure"] = String.Format(UI.Metadata_Edit_Saved_Failure, e.Message);
     }
 }
Exemplo n.º 16
0
        private void ReIndexOperatesOn(MetadataViewModel metadata)
        {
            if (metadata.OperatesOn != null)
            {
                System.Collections.Specialized.NameValueCollection settings = System.Web.Configuration.WebConfigurationManager.AppSettings;
                string username = settings["KartkatalogUsername"];
                string password = settings["KartkatalogPassword"];

                foreach (var uuid in metadata.OperatesOn)
                {
                    string url = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogUrl"] + "api/metadataupdated";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = WebRequestMethods.Http.Post;
                    request.ContentType = "application/x-www-form-urlencoded";
                    using (var writer = new StreamWriter(request.GetRequestStream()))
                    {
                        writer.Write("uuid="+ uuid);
                        writer.Write("&action=post");
                    }
                    NetworkCredential networkCredential = new NetworkCredential(username, password);
                    CredentialCache myCredentialCache = new CredentialCache { { new Uri(url), "Basic", networkCredential } };
                    request.PreAuthenticate = true;
                    request.Credentials = myCredentialCache;
                    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
                }
            }
        }
Exemplo n.º 17
0
 private void ValidateModel(MetadataViewModel model)
 {
     ViewBag.thumbnailMissingCSS = "";
     var thumb = model.Thumbnails.Where(t => t.Type == "thumbnail" || t.Type == "miniatyrbilde");
     if (thumb.Count() == 0)
     {
         ModelState.AddModelError("thumbnailMissing", "Det er påkrevd å fylle ut illustrasjonsbilde");
         ViewBag.thumbnailMissingCSS = "input-validation-error";
         }
 }
        public ActionResult Edit(MetadataViewModel model)
        {
            bool saved = true;
            string errorMessage = null;
            try
            {
                _metadataService.SaveMetadataModel(model, GetUsername());
            }
            catch (Exception e)
            {
                saved = false;
                errorMessage = e.Message;
                Log.Error("Error while editing metadata with uuid = " + model.Uuid, e);

            }

            return RedirectToAction("Edit", new { uuid = model.Uuid, saved});
        }