private static void ValidateName(Vocabulary vocab, ValidationResult<Vocabulary> result) { if (String.IsNullOrWhiteSpace(vocab.Name)) { result.Errors.Add("The name must not be blank", v => v.Name); } }
public ValidationResult<Vocabulary> Validate(Vocabulary vocab) { var result = new ValidationResult<Vocabulary>(); ValidateId(vocab, result); ValidateName(vocab, result); return result; }
private void ValidateId(Vocabulary vocab, ValidationResult<Vocabulary> result) { if (String.IsNullOrWhiteSpace(vocab.Id)) { result.Errors.Add("The Id must not be blank", v => v.Id); } if (vocab.Id.EndsWith("/")) { result.Errors.Add("The Id must not end with a slash", v => v.Id); } //todo: validate ID format }
public VocabularyServiceResult Insert(Vocabulary vocab) { var existingVocab = db.Load<Vocabulary>(vocab.Id); if (existingVocab == null) { return Upsert(vocab); } else { var validation = new ValidationResult<Vocabulary>(); validation.Errors.Add("Vocabulary already exists", v => v.Id); return new VocabularyServiceResult { Vocab = vocab, Validation = validation }; } }
public VocabularyServiceResult Upsert(Vocabulary vocab) { vocab.Keywords = (from k in vocab.Keywords group k by k.Value.ToLower().Trim() into g // distinct by Value select g.First() into n orderby n.Value select n).ToList(); var validation = validator.Validate(vocab); if (!validation.Errors.Any()) db.Store(vocab); return new VocabularyServiceResult { Vocab = vocab, Validation = validation }; }
public VocabularyServiceResult Update(Vocabulary vocab) { return Upsert(vocab); }
void AddVocabularies() { var jnccDomain = new Vocabulary { Id = "http://vocab.jncc.gov.uk/jncc-domain", Name = "JNCC Domain", Description = "Groups metadata records into broad areas.", PublicationDate = "2015", Publishable = true, Controlled = true, Keywords = new List<VocabularyKeyword> { new VocabularyKeyword { Value = "Marine" }, new VocabularyKeyword { Value = "Freshwater" }, new VocabularyKeyword { Value = "Terrestrial" }, new VocabularyKeyword { Value = "Atmosphere" }, } }; db.Store(jnccDomain); var jnccCategory = new Vocabulary { Id = "http://vocab.jncc.gov.uk/jncc-category", Name = "JNCC Category", Description = "Groups metadata records into collections.", PublicationDate = "2015", Publishable = true, Controlled = true, Keywords = new List<VocabularyKeyword> { new VocabularyKeyword { Value = "Seabed Habitat Maps", Description = "Geospatial datasets from the Mapping European Seabed Habitats (MESH) project."}, new VocabularyKeyword { Value = "Human Activities", Description = "Geospatial datasets of activities undertaken by humans in the UK marine environment."}, new VocabularyKeyword { Value = "JNCC Publications", Description = "Official publications produced by Joint Nature Conservation Committee (JNCC)."}, new VocabularyKeyword { Value = "Natural Capital Library", Description = "Reports, briefings and publications related to the Natural Capital concept."}, new VocabularyKeyword { Value = "Example Collection", Description = "A collection of example records for development and testing."}, } }; db.Store(jnccCategory); var metadataAdmin = new Vocabulary { Id = "http://vocab.jncc.gov.uk/metadata-admin", Name = "Metadata Admin", Description = "Tags for managing Topcat records.", PublicationDate = "2015", Publishable = false, Controlled = true, Keywords = new List<VocabularyKeyword> { new VocabularyKeyword { Value = "Delete" }, new VocabularyKeyword { Value = "Improve" }, new VocabularyKeyword { Value = "Suspect" }, } }; db.Store(metadataAdmin); var referenceManagerCode = new Vocabulary { Id = "http://vocab.jncc.gov.uk/reference-manager-code", Name = "JNCC Reference Manager Code", Description = "A field for the Reference Manager code used within JNCC.", PublicationDate = "2013", Publishable = false, Controlled = false, Keywords = new List<VocabularyKeyword>() }; db.Store(referenceManagerCode); var meshOriginalSeabedClassification = new Vocabulary { Id = "http://vocab.jncc.gov.uk/original-seabed-classification-system", Name = "Original Seabed Classification", Description = "Used by MESH", PublicationDate = "2013", Publishable = false, Controlled = true, Keywords = new List<VocabularyKeyword>() }; db.Store(meshOriginalSeabedClassification); var meshSeabedMapStatus = new Vocabulary { Id = "http://vocab.jncc.gov.uk/seabed-map-status", Name = "Seabed Map Status", Description = "Used by MESH", PublicationDate = "2013", Publishable = false, Controlled = true, Keywords = new List<VocabularyKeyword>() }; db.Store(meshSeabedMapStatus); var meshSeabedSurveyPurpose = new Vocabulary { Id = "http://vocab.jncc.gov.uk/seabed-survey-purpose", Name = "Seabed Survey Purpose", Description = "Used by MESH", PublicationDate = "2013", Publishable = false, Controlled = true, Keywords = new List<VocabularyKeyword>() }; db.Store(meshSeabedSurveyPurpose); var meshSeabedSurveyTechnique = new Vocabulary { Id = "http://vocab.jncc.gov.uk/seabed-survey-technique", Name = "Seabed Survey Technique", Description = "Used by MESH", PublicationDate = "2013", Publishable = false, Controlled = true, Keywords = new List<VocabularyKeyword>() }; db.Store(meshSeabedSurveyTechnique); }