private BatchData GetFormData(FormCollection batch) { BatchData data = new BatchData(); data.dataField = batch["batchField"]; string dataValue = batch["batchValue"]; if (data.dataField == "ContactMetadata_Organization" || data.dataField == "ContactPublisher_Organization" || data.dataField == "ContactOwner_Organization") { dataValue = batch["OrganizationContactMetadata"]; } else if (data.dataField == "MaintenanceFrequency") { dataValue = batch["MaintenanceFrequency"]; } data.dataValue = dataValue; if (string.IsNullOrWhiteSpace(data.dataField) || string.IsNullOrWhiteSpace(data.dataValue)) { return(null); } List <string> uuids = new List <string>(); if (batch["uuids"] != null) { uuids = batch["uuids"].Split(',').ToList(); } if (string.IsNullOrWhiteSpace(Request.Form["updateAll"]) && uuids.Count == 0) { return(null); } List <MetaDataEntry> mdList = new List <MetaDataEntry>(); foreach (var uuid in uuids) { MetaDataEntry md = new MetaDataEntry(); md.Uuid = uuid; mdList.Add(md); } data.MetaData = mdList; return(data); }
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); }
private BatchData GetFormData(FormCollection batch) { BatchData data = new BatchData(); data.dataField = batch["batchField"]; string dataValue = batch["batchValue"]; if (data.dataField == "ContactMetadata_Organization" || data.dataField == "ContactPublisher_Organization" || data.dataField == "ContactOwner_Organization") { dataValue = batch["OrganizationContactMetadata"]; } else if (data.dataField == "MaintenanceFrequency") { dataValue = batch["MaintenanceFrequency"]; } data.dataValue = dataValue; if (string.IsNullOrWhiteSpace(data.dataField) || string.IsNullOrWhiteSpace(data.dataValue)) return null; List<string> uuids = new List<string>(); if (batch["uuids"] != null) { uuids = batch["uuids"].Split(',').ToList(); } if (string.IsNullOrWhiteSpace(Request.Form["updateAll"]) && uuids.Count == 0) return null; List<MetaDataEntry> mdList = new List<MetaDataEntry>(); foreach (var uuid in uuids) { MetaDataEntry md = new MetaDataEntry(); md.Uuid = uuid; mdList.Add(md); } data.MetaData = mdList; return data; }
private void SaveValidationResult(MetaDataEntry result) { try { if (result.Status == "ERRORS" && result.ContactEmail != null && result.ContactEmail != "" && result.ContactEmail.Contains('@')) { using (var session = MvcApplication.Store.OpenSession()) { session.Store(result); session.SaveChanges(); } } } catch(Exception ex){ Log.Error(ex.Message); } }
public MetaDataEntry ValidateMetadata(string uuid) { MetaDataEntry metadata = new MetaDataEntry(); metadata.Errors = new List<Error>(); try { Kartverket.MetadataEditor.Models.MetadataService _metadataService = new Kartverket.MetadataEditor.Models.MetadataService(); Kartverket.MetadataEditor.Models.MetadataViewModel model = _metadataService.GetMetadataModel(uuid); if (model != null) { 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; }