internal List <WfsLayerViewModel> CreateMetadataForFeature(string uuid, List <WfsLayerViewModel> layers, string[] keywords, string username) { SimpleMetadata parentMetadata = new SimpleMetadata(_geoNorge.GetRecordByUuid(uuid)); List <SimpleKeyword> selectedKeywordsFromParent = CreateListOfKeywords(keywords); List <string> layerIdentifiers = new List <string>(); foreach (WfsLayerViewModel layer in layers) { try { SimpleMetadata simpleLayer = createMetadataForFeature(parentMetadata, selectedKeywordsFromParent, layer); MetadataTransaction transaction = _geoNorge.MetadataInsert(simpleLayer.GetMetadata(), CreateAdditionalHeadersWithUsername(username)); if (transaction.Identifiers != null && transaction.Identifiers.Count > 0) { layer.Uuid = transaction.Identifiers[0]; layerIdentifiers.Add(layer.Uuid); } } catch (Exception e) { layer.ErrorMessage = e.Message; Log.Error("Error while creating metadata for layer: " + layer.Title, e); } } parentMetadata.OperatesOn = layerIdentifiers; _geoNorge.MetadataUpdate(parentMetadata.GetMetadata()); return(layers); }
public void SaveMetadataModel(SimpleMetadataViewModel model, string username) { SimpleMetadata metadata = new SimpleMetadata(_geoNorge.GetRecordByUuid(model.Uuid)); UpdateMetadataFromModel(model, metadata); _geoNorge.MetadataUpdate(metadata.GetMetadata(), CreateAdditionalHeadersWithUsername(username, model.Published)); }
internal string CreateMetadata(MetadataCreateViewModel model, string username) { SimpleMetadata metadata = null; if (model.Type.Equals("service")) { metadata = SimpleMetadata.CreateService(); } else { metadata = SimpleMetadata.CreateDataset(); if (model.Type.Equals("software")) { metadata.HierarchyLevel = "software"; } else if (model.Type.Equals("series")) { metadata.HierarchyLevel = "series"; } } metadata.Title = model.Title; metadata.Abstract = "..."; metadata.ContactMetadata = new SimpleContact { Name = model.MetadataContactName, Email = model.MetadataContactEmail, Organization = model.MetadataContactOrganization, Role = "pointOfContact" }; metadata.ContactPublisher = new SimpleContact { Name = model.MetadataContactName, Email = model.MetadataContactEmail, Organization = model.MetadataContactOrganization, Role = "publisher" }; metadata.ContactOwner = new SimpleContact { Name = model.MetadataContactName, Email = model.MetadataContactEmail, Organization = model.MetadataContactOrganization, Role = "owner" }; DateTime now = DateTime.Now; metadata.DateCreated = now; metadata.DatePublished = now; metadata.DateUpdated = now; SetDefaultValuesOnMetadata(metadata); _geoNorge.MetadataInsert(metadata.GetMetadata(), CreateAdditionalHeadersWithUsername(username)); return(metadata.Uuid); }
private static MD_Metadata_Type CreateDummyMetadata() { SimpleMetadata simpleMetadata = SimpleMetadata.CreateDataset(); simpleMetadata.ContactMetadata = new SimpleContact { Name = "John Smith", Email = "*****@*****.**", Organization = "Kartverket" }; return(simpleMetadata.GetMetadata()); }
private SimpleMetadata createMetadataForFeature(SimpleMetadata parentMetadata, List <SimpleKeyword> selectedKeywordsFromParent, WfsLayerViewModel layerModel) { MD_Metadata_Type parent = parentMetadata.GetMetadata(); MD_Metadata_Type layer = parent.Copy(); layer.parentIdentifier = new CharacterString_PropertyType { CharacterString = parent.fileIdentifier.CharacterString }; layer.fileIdentifier = new CharacterString_PropertyType { CharacterString = Guid.NewGuid().ToString() }; SimpleMetadata simpleLayer = new SimpleMetadata(layer); string title = layerModel.Title; if (string.IsNullOrWhiteSpace(title)) { title = layerModel.Name; } simpleLayer.Title = title; if (!string.IsNullOrWhiteSpace(layerModel.Abstract)) { simpleLayer.Abstract = layerModel.Abstract; } simpleLayer.Keywords = selectedKeywordsFromParent; if (layerModel.Keywords.Count > 0) { var existingKeywords = simpleLayer.Keywords; foreach (var keyword in layerModel.Keywords) { existingKeywords.Add(new SimpleKeyword { Keyword = keyword }); } simpleLayer.Keywords = existingKeywords; } simpleLayer.DistributionDetails = new SimpleDistributionDetails { Name = layerModel.Name, Protocol = parentMetadata.DistributionDetails.Protocol, URL = parentMetadata.DistributionDetails.URL }; if (!string.IsNullOrWhiteSpace(layerModel.BoundingBoxEast)) { string defaultWestBoundLongitude = "-20"; string defaultEastBoundLongitude = "38"; string defaultSouthBoundLatitude = "56"; string defaultNorthBoundLatitude = "90"; string parentWestBoundLongitude = defaultWestBoundLongitude; string parentEastBoundLongitude = defaultEastBoundLongitude; string parentSouthBoundLatitude = defaultSouthBoundLatitude; string parentNorthBoundLatitude = defaultNorthBoundLatitude; if (parentMetadata.BoundingBox != null) { parentWestBoundLongitude = parentMetadata.BoundingBox.WestBoundLongitude; parentEastBoundLongitude = parentMetadata.BoundingBox.EastBoundLongitude; parentSouthBoundLatitude = parentMetadata.BoundingBox.SouthBoundLatitude; parentNorthBoundLatitude = parentMetadata.BoundingBox.NorthBoundLatitude; } string WestBoundLongitude = layerModel.BoundingBoxWest; string EastBoundLongitude = layerModel.BoundingBoxEast; string SouthBoundLatitude = layerModel.BoundingBoxSouth; string NorthBoundLatitude = layerModel.BoundingBoxNorth; decimal number; if (!Decimal.TryParse(WestBoundLongitude, out number) || !Decimal.TryParse(EastBoundLongitude, out number) || !Decimal.TryParse(SouthBoundLatitude, out number) || !Decimal.TryParse(NorthBoundLatitude, out number) ) { WestBoundLongitude = parentWestBoundLongitude; EastBoundLongitude = parentEastBoundLongitude; SouthBoundLatitude = parentSouthBoundLatitude; NorthBoundLatitude = parentNorthBoundLatitude; if (!Decimal.TryParse(WestBoundLongitude, out number) || !Decimal.TryParse(EastBoundLongitude, out number) || !Decimal.TryParse(SouthBoundLatitude, out number) || !Decimal.TryParse(NorthBoundLatitude, out number) ) { WestBoundLongitude = defaultWestBoundLongitude; EastBoundLongitude = defaultEastBoundLongitude; SouthBoundLatitude = defaultSouthBoundLatitude; NorthBoundLatitude = defaultNorthBoundLatitude; } } simpleLayer.BoundingBox = new SimpleBoundingBox { EastBoundLongitude = EastBoundLongitude, WestBoundLongitude = WestBoundLongitude, NorthBoundLatitude = NorthBoundLatitude, SouthBoundLatitude = SouthBoundLatitude }; } if (!string.IsNullOrWhiteSpace(layerModel.EnglishTitle)) { simpleLayer.EnglishTitle = layerModel.EnglishTitle; } if (!string.IsNullOrWhiteSpace(layerModel.EnglishAbstract)) { simpleLayer.EnglishAbstract = layerModel.EnglishAbstract; } return(simpleLayer); }
public Task UpdateMetadata() { var datasetList = GetDatasets(); var datasets = datasetList.OrderBy(x => x.Uuid) .GroupBy(x => x.Uuid) .Select(g => new { Uuid = g.Key, Datasets = g.Select(dataset => new { dataset.Url, dataset.Organization, dataset.LastUpdated, dataset.DistributionsFormats, dataset.ReferenceSystems }) }).ToList(); foreach (var dataset in datasets) { try { var metadataInfo = new UpdateMetadataInformation(); metadataInfo.Uuid = dataset.Uuid.Trim(); metadataInfo.Distributions = new List <SimpleDistribution>(); foreach (var item in dataset.Datasets) { try { metadataInfo.DatasetDateUpdated = DateTime.Parse(item.LastUpdated, System.Globalization.CultureInfo.InvariantCulture); } catch (Exception e) { Log.Error("Error with LastUpdated: " + item.LastUpdated, e); } foreach (var distribution in item.DistributionsFormats) { SimpleDistribution simpleDistribution = new SimpleDistribution(); simpleDistribution.Organization = distribution.Organization; simpleDistribution.Protocol = "W3C:AtomFeed"; simpleDistribution.URL = item.Url; simpleDistribution.FormatName = distribution.FormatName; metadataInfo.Distributions.Add(simpleDistribution); } metadataInfo.Projections = new List <SimpleReferenceSystem>(); foreach (var projection in item.ReferenceSystems) { SimpleReferenceSystem simpleReferenceSystem = new SimpleReferenceSystem(); simpleReferenceSystem.CoordinateSystem = projection.CoordinateSystem; metadataInfo.Projections.Add(simpleReferenceSystem); } } System.Collections.Specialized.NameValueCollection settings = System.Web.Configuration.WebConfigurationManager.AppSettings; string server = settings["GeoNetworkUrl"]; string usernameGeonetwork = settings["GeoNetworkUsername"]; string password = settings["GeoNetworkPassword"]; string geonorgeUsername = settings["GeonorgeUsername"]; GeoNorge api = new GeoNorge(usernameGeonetwork, password, server); api.OnLogEventDebug += new GeoNorgeAPI.LogEventHandlerDebug(LogEventsDebug); api.OnLogEventError += new GeoNorgeAPI.LogEventHandlerError(LogEventsError); var metadata = api.GetRecordByUuid(metadataInfo.Uuid); SimpleMetadata simpleMetadata = new SimpleMetadata(metadata); List <SimpleDistribution> distributionFormats = simpleMetadata.DistributionsFormats; List <SimpleDistribution> distributionFormatsUpdated = new List <SimpleDistribution>(); if (HasAtomFeed(metadataInfo.Distributions)) { foreach (var distribution in distributionFormats) { if (distribution.Protocol != "W3C:AtomFeed") { distributionFormatsUpdated.Add(distribution); } } } else { distributionFormatsUpdated = distributionFormats; } distributionFormatsUpdated.AddRange(metadataInfo.Distributions); simpleMetadata.DistributionsFormats = distributionFormatsUpdated; simpleMetadata.DistributionDetails = new SimpleDistributionDetails { URL = distributionFormatsUpdated[0].URL, Protocol = distributionFormatsUpdated[0].Protocol, UnitsOfDistribution = distributionFormatsUpdated[0].UnitsOfDistribution }; List <SimpleReferenceSystem> simpleReferenceSystems = new List <SimpleReferenceSystem>(); foreach (var projection in metadataInfo.Projections) { SimpleReferenceSystem refsys = new SimpleReferenceSystem(); refsys.CoordinateSystem = projection.CoordinateSystem; simpleReferenceSystems.Add(refsys); } if (simpleMetadata.ReferenceSystems == null || (simpleMetadata.ReferenceSystems != null && simpleMetadata.ReferenceSystems.Count == 0)) { simpleMetadata.ReferenceSystems = simpleReferenceSystems; } simpleMetadata.DateMetadataUpdated = DateTime.Now; if (metadataInfo.DatasetDateUpdated.HasValue) { simpleMetadata.DateUpdated = metadataInfo.DatasetDateUpdated; } api.MetadataUpdate(simpleMetadata.GetMetadata(), CreateAdditionalHeadersWithUsername(geonorgeUsername, "true")); Log.Info($"Metadata updated for uuid: {metadataInfo.Uuid}"); } catch (Exception ex) { Log.Error("Error updating metadata uuid: " + dataset.Uuid + ", error: " + ex); } } return(Task.CompletedTask); }