public Models.v0_2.Metadata Convert( Models.v0_1_0alpha3.Metadata metadata) { Models.v0_2.Metadata result = new Models.v0_2.Metadata { CreationDate = DateTime.Parse( metadata.File.CreationDate), ModifiedDate = DateTime.UtcNow }; Models.v0_2.Dataset d; if (metadata.Dataset != null) { d = new Models.v0_2.Dataset() { Zone = metadata.Dataset.Zone.ToString(), Project = metadata.Dataset.Project, Name = metadata.Dataset.Name, Description = metadata.Dataset.Description, Format = metadata.Dataset.Format, FilePathTemplate = metadata.Dataset.FilePathTemplate, FilePathDescriptor = metadata.Dataset.FilePathDescriptor, Structure = metadata.Dataset.Structure, Tags = metadata.Dataset.Tags, Contacts = ConvertContacts(metadata.Dataset.Contacts), Geometry = metadata.Dataset.Geometry, Methods = metadata.Dataset.Methods, TemporalResolution = metadata.Dataset.TemporalResolution, TemporalExtent = $"{metadata.Dataset.StartDate}/{metadata.Dataset.EndDate}", SpatialRepeats = metadata.Dataset.SpatialRepeats, Variables = ConvertVariables(metadata.Dataset.Variables) }; } else { d = new Models.v0_2.Dataset(); } result.Dataset = d; return(result); }
public Models.v0_2.Metadata Parse( string json) { string version = GetVersion(json); Models.v0_2.Metadata result = version switch { "v0.1.0-alpha1" or "v0.1.0-alpha2" or "v0.1.0-alpha3" => Deserialize_v0_1_0alpha3(json), "v0.1.0-alpha4" or "v0.1" or "v0.2" => Deserialize_v0_2(json), _ => throw new ArgumentException("Unable to parse JSON"), }; return(result); }
private Models.v0_2.Metadata Deserialize_v0_2( string json) { JsonSerializerOptions options = new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, WriteIndented = true, Converters = { new JsonStringEnumConverter() }, Encoder = System.Text.Encodings.Web .JavaScriptEncoder .UnsafeRelaxedJsonEscaping }; Models.v0_2.Metadata m = JsonSerializer.Deserialize <Models.v0_2.Metadata>( json, options); Models.v0_2.Metadata result = converter.Convert(m); return(result); }
public Models.v0_2.Metadata Convert( Models.v0_2.Metadata metadata) { return(metadata); }
public void Convert_v0_1_0alpha3WithVals_ConvertsProperly() { var creationDate = "2020-12-20"; var contactName = "TestUser"; var startDate = "1999-20-01"; var tempExtent = $"{startDate}/{startDate}"; List <string> expectedQC = new List <string>() { "Assurance", "Point", "Review" }; Models.v0_1_0alpha3.Metadata input = new Models.v0_1_0alpha3.Metadata() { File = new Models.v0_1_0alpha3.File() { CreationDate = creationDate }, Dataset = new Models.v0_1_0alpha3.Dataset() { Zone = Models.v0_1_0alpha3.Zones.Production, Project = "UnitTest", Name = "Convert_v0_1_0alpha3WithVals_ConvertsProperly", Description = "Pleh", Format = "geotiff", Contacts = new List <Models.v0_1_0alpha3.Person>() { new Models.v0_1_0alpha3.Person() { Name = contactName, Email = "*****@*****.**", Role = "Tool" } }, StartDate = startDate, EndDate = startDate, Variables = new List <Models.v0_1_0alpha3.Variable>() { new Models.v0_1_0alpha3.Variable() { Name = "value", IsQCSpecified = false, ProcessingLevel = Models.v0_1_0alpha3.ProcessingLevels.Calculated }, new Models.v0_1_0alpha3.Variable() { Name = "value2", IsQCSpecified = true, QCApplied = new Models.v0_1_0alpha3.QCApplied() { Assurance = true, Point = true, Review = true }, StartDate = startDate, EndDate = startDate } } } }; var sut = new MetadataConverter(); Models.v0_2.Metadata actual = sut.Convert(input); Assert.Equal(creationDate, actual.CreationDate.ToString()); Assert.Equal(contactName, actual.Dataset.Contacts[0].Name); Assert.Equal(tempExtent, actual.Dataset.TemporalExtent); Assert.False(actual.Dataset.Variables[0].IsQCSpecified); Assert.Equal("Calculated", actual.Dataset.Variables[0].ProcessingLevel); Assert.Equal(expectedQC, actual.Dataset.Variables[1].QCApplied); Assert.Equal(tempExtent, actual.Dataset.Variables[1].TemporalExtent); }