From fb95081b383f75e4f2b68b5c7b66029f749eced1 Mon Sep 17 00:00:00 2001 From: Johnathan Date: Thu, 25 Jan 2024 15:11:08 -0700 Subject: [PATCH] Bugfix/unit tests (#329) * Update Internal Object * Fix Data Quality Order * Fix Data Quality Order * Fixing Legal Constraint Order * Fix Allocation Order * Fix Funding Order * Fix Data Quality Order * Update Data Quality Object * And standaloneQualityReportDetails to mdJson Reader * Fix Order * Fix Standalone Quality Report * Update Version for mdJson-schemas * Add Quality Result File to Coverage Result * Update Gemfile.lock * Update nokogiri * Rename standaloneQualityReport.rb Need to fix naming case. * Fix File Name * Fix Typo * Fix Internal Object resultContent --> resultContentDescription and { } not [ ] --- Gemfile.lock | 14 +- adiwg-mdtranslator.gemspec | 4 +- .../internal/internal_metadata_obj.rb | 25 ++-- .../modules/module_dataQualityReport.rb | 4 + .../mdJson/modules/module_legalConstraint.rb | 16 +-- .../mdJson/sections/mdJson_allocation.rb | 2 +- .../mdJson/sections/mdJson_dataQuality.rb | 4 +- .../writers/mdJson/sections/mdJson_funding.rb | 4 +- .../mdJson/sections/mdJson_legalConstraint.rb | 2 +- .../mdJson/sections/mdJson_metadata.rb | 2 +- .../mdJson_standaloneQualityReport.rb | 31 +++++ test/helpers/mdJson_hash_functions.rb | 122 +++++++++--------- test/helpers/mdJson_hash_objects.rb | 29 ++--- test/writers/mdJson/tc_mdjson_metadata.rb | 11 +- 14 files changed, 159 insertions(+), 111 deletions(-) create mode 100644 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_standaloneQualityReport.rb diff --git a/Gemfile.lock b/Gemfile.lock index cd1728fca..8c8d131e7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,14 +3,14 @@ PATH specs: adiwg-mdtranslator (2.18.5) adiwg-mdcodes (= 2.8.4) - adiwg-mdjson_schemas (= 2.8.1) + adiwg-mdjson_schemas (= 2.8.2) builder (~> 3.2) coderay (~> 1.1) jbuilder (~> 2.5) json (~> 2.0) json-schema (~> 2.7) kramdown (>= 1.13, < 3.0) - nokogiri (~> 1.7) + nokogiri (~> 1.15) thor (~> 0.19) uuidtools (~> 2.1) @@ -32,7 +32,7 @@ GEM public_suffix (>= 2.0.2, < 6.0) adiwg-mdcodes (2.8.4) json (~> 2.0) - adiwg-mdjson_schemas (2.8.1) + adiwg-mdjson_schemas (2.8.2) builder (3.2.4) coderay (1.1.3) concurrent-ruby (1.2.2) @@ -51,11 +51,13 @@ GEM loofah (2.21.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mini_portile2 (2.4.0) minitest (5.20.0) - nokogiri (1.10.10) - mini_portile2 (~> 2.4.0) + nokogiri (1.15.5-arm64-darwin) + racc (~> 1.4) + nokogiri (1.15.5-x86_64-linux) + racc (~> 1.4) public_suffix (4.0.7) + racc (1.7.3) rails-dom-testing (2.1.1) activesupport (>= 5.0.0) minitest diff --git a/adiwg-mdtranslator.gemspec b/adiwg-mdtranslator.gemspec index 5b0890048..88a269592 100644 --- a/adiwg-mdtranslator.gemspec +++ b/adiwg-mdtranslator.gemspec @@ -34,11 +34,11 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "thor", "~> 0.19" spec.add_runtime_dependency "uuidtools", "~> 2.1" spec.add_runtime_dependency "json-schema", "~> 2.7" - spec.add_runtime_dependency "adiwg-mdjson_schemas", "2.8.1" + spec.add_runtime_dependency "adiwg-mdjson_schemas", "2.8.2" spec.add_runtime_dependency "adiwg-mdcodes", "2.8.4" spec.add_runtime_dependency "jbuilder", "~> 2.5" spec.add_runtime_dependency "kramdown", ">= 1.13", "< 3.0" spec.add_runtime_dependency "coderay", "~> 1.1" - spec.add_runtime_dependency "nokogiri", "~> 1.7" + spec.add_runtime_dependency "nokogiri", "~> 1.15" end \ No newline at end of file diff --git a/lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb b/lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb index 7bf476c90..0e837ad44 100644 --- a/lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb +++ b/lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb @@ -650,7 +650,7 @@ def newDataQuality def newConformanceResult { - dateTime: [], + dateTime: nil, scope: {}, specification: {}, explanation: nil, @@ -658,21 +658,30 @@ def newConformanceResult } end + def newQualityResultFile + { + fileName: nil, + fileType: nil, + fileDescription: nil, + fileFormat: {} + } + end + def newCoverageResult { - dateTime: [], + dateTime: nil, scope: {}, spatialRepresentationType: nil, spatialRepresentation: {}, - resultContent: [], - resourceFormat: nil, - resultFile: nil + resultContentDescription: {}, + resourceFormat: {}, + resultFile: {} } end def newDescriptiveResult { - dateTime: [], + dateTime: nil, scope: {}, statement: nil } @@ -695,7 +704,7 @@ def newEvaluationMethod def newQuantitativeResult { - dateTime: [], + dateTime: nil, scope: {}, values: [], valueUnits: nil, @@ -727,8 +736,8 @@ def newDataQualityReport def newStandaloneReport { - reportReference: {}, abstract: nil, + reportReference: {}, } end diff --git a/lib/adiwg/mdtranslator/readers/mdJson/modules/module_dataQualityReport.rb b/lib/adiwg/mdtranslator/readers/mdJson/modules/module_dataQualityReport.rb index 986e735ba..6b6bd7498 100644 --- a/lib/adiwg/mdtranslator/readers/mdJson/modules/module_dataQualityReport.rb +++ b/lib/adiwg/mdtranslator/readers/mdJson/modules/module_dataQualityReport.rb @@ -28,6 +28,10 @@ def self.unpack(hReport, responseObj, inContext = nil) intReport[:type] = hReport["type"] + if hReport.has_key?('standaloneQualityReportDetails') + intReport[:standaloneQualityReportDetails] = hReport['standaloneQualityReportDetails'] + end + if hReport.has_key?('conformanceResult') hReport['conformanceResult'].each do |item| hReturn = ConformanceResult.unpack(item, responseObj) diff --git a/lib/adiwg/mdtranslator/readers/mdJson/modules/module_legalConstraint.rb b/lib/adiwg/mdtranslator/readers/mdJson/modules/module_legalConstraint.rb index 0a0517ac4..f81faa911 100644 --- a/lib/adiwg/mdtranslator/readers/mdJson/modules/module_legalConstraint.rb +++ b/lib/adiwg/mdtranslator/readers/mdJson/modules/module_legalConstraint.rb @@ -34,21 +34,21 @@ def self.unpack(hLegalCon, responseObj, inContext = nil) haveLegal = false - # legal constraint - use constraint [] - if hLegalCon.has_key?('useConstraint') - hLegalCon['useConstraint'].each do |item| + # legal constraint - access constraint [] + if hLegalCon.has_key?('accessConstraint') + hLegalCon['accessConstraint'].each do |item| unless item == '' - intLegalCon[:useCodes] << item + intLegalCon[:accessCodes] << item haveLegal = true end end end - # legal constraint - access constraint [] - if hLegalCon.has_key?('accessConstraint') - hLegalCon['accessConstraint'].each do |item| + # legal constraint - use constraint [] + if hLegalCon.has_key?('useConstraint') + hLegalCon['useConstraint'].each do |item| unless item == '' - intLegalCon[:accessCodes] << item + intLegalCon[:useCodes] << item haveLegal = true end end diff --git a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_allocation.rb b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_allocation.rb index c10a2317d..eb6768648 100644 --- a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_allocation.rb +++ b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_allocation.rb @@ -28,8 +28,8 @@ def self.build(hAllocation) json.recipientId hAllocation[:recipientId] json.responsibleParty @Namespace.json_map(hAllocation[:responsibleParties], ResponsibleParty) json.matching hAllocation[:matching] - json.onlineResource @Namespace.json_map(hAllocation[:onlineResources], OnlineResource) json.comment hAllocation[:comment] + json.onlineResource @Namespace.json_map(hAllocation[:onlineResources], OnlineResource) end end # build diff --git a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dataQuality.rb b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dataQuality.rb index 92e3fc1e6..afd9a8975 100644 --- a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dataQuality.rb +++ b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_dataQuality.rb @@ -3,6 +3,8 @@ require 'jbuilder' require_relative 'mdJson_scope' require_relative 'mdJson_dataQualityReport' +require_relative 'mdJson_citation' +require_relative 'mdJson_standaloneQualityReport' module ADIWG module Mdtranslator @@ -17,7 +19,7 @@ def self.build(hDataQuality) Jbuilder.new do |json| json.scope Scope.build(hDataQuality[:scope]) json.systemIdentifier hDataQuality[:systemIdentifier] - json.standaloneQualityReport hDataQuality[:standaloneQualityReport] + json.standaloneQualityReport StandaloneQualityReport.build(hDataQuality[:standaloneReport]) unless hDataQuality[:standaloneReport].nil? json.report @Namespace.json_map(hDataQuality[:report], DataQualityReport) end diff --git a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_funding.rb b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_funding.rb index 59d66841a..70247a4bc 100644 --- a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_funding.rb +++ b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_funding.rb @@ -20,9 +20,9 @@ module Funding def self.build(hFunding) Jbuilder.new do |json| - json.description hFunding[:description] - json.timePeriod TimePeriod.build(hFunding[:timePeriod]) unless hFunding[:timePeriod].empty? json.allocation @Namespace.json_map(hFunding[:allocations], Allocation) + json.timePeriod TimePeriod.build(hFunding[:timePeriod]) unless hFunding[:timePeriod].empty? + json.description hFunding[:description] end end # build diff --git a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_legalConstraint.rb b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_legalConstraint.rb index 30ed6c303..75f5c4c87 100644 --- a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_legalConstraint.rb +++ b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_legalConstraint.rb @@ -15,8 +15,8 @@ module LegalConstraint def self.build(hLegal) Jbuilder.new do |json| - json.useConstraint hLegal[:useCodes] unless hLegal[:useCodes].empty? json.accessConstraint hLegal[:accessCodes] unless hLegal[:accessCodes].empty? + json.useConstraint hLegal[:useCodes] unless hLegal[:useCodes].empty? json.otherConstraint hLegal[:otherCons] unless hLegal[:otherCons].empty? end diff --git a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_metadata.rb b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_metadata.rb index 06971d11e..5a6469553 100644 --- a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_metadata.rb +++ b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_metadata.rb @@ -28,12 +28,12 @@ def self.build(hMetadata) Jbuilder.new do |json| json.metadataInfo MetadataInfo.build(hMetadata[:metadataInfo]) json.resourceInfo ResourceInfo.build(hMetadata[:resourceInfo]) + json.dataQuality @Namespace.json_map(hMetadata[:dataQuality], DataQuality) json.resourceLineage @Namespace.json_map(hMetadata[:lineageInfo], LineageInfo) json.resourceDistribution @Namespace.json_map(hMetadata[:distributorInfo], Distribution) json.associatedResource @Namespace.json_map(hMetadata[:associatedResources], AssociatedResource) json.additionalDocumentation @Namespace.json_map(hMetadata[:additionalDocuments], AdditionalDocument) json.funding @Namespace.json_map(hMetadata[:funding], Funding) - json.dataQuality @Namespace.json_map(hMetadata[:dataQuality], DataQuality) end end # build diff --git a/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_standaloneQualityReport.rb b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_standaloneQualityReport.rb new file mode 100644 index 000000000..bb4f1a43e --- /dev/null +++ b/lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_standaloneQualityReport.rb @@ -0,0 +1,31 @@ +# mdJson 2.0 writer - dataQuality + +require 'jbuilder' +require_relative 'mdJson_citation' + +module ADIWG + module Mdtranslator + module Writers + module MdJson + + module StandaloneQualityReport + + @Namespace = ADIWG::Mdtranslator::Writers::MdJson + + def self.build(hStandaloneReport) + reportReference = hStandaloneReport[:reportReference] + Jbuilder.new do |json| + json.reportReference Citation.build(reportReference) + json.abstract hStandaloneReport[:abstract] + end + + end + + end + + end + end + end +end + + diff --git a/test/helpers/mdJson_hash_functions.rb b/test/helpers/mdJson_hash_functions.rb index 071915334..de31be79f 100644 --- a/test/helpers/mdJson_hash_functions.rb +++ b/test/helpers/mdJson_hash_functions.rb @@ -62,6 +62,68 @@ def build_dataDictionary return hDictionary end + def build_dataQuality + hDataQuality = dataQuality + hDataQuality[:scope] = build_scope_full + hDataQuality[:standaloneQualityReport] = { + reportReference: build_citation('standalone quality report 1'), + abstract: "standalone quality report 1" + } + + hDataQuality[:report] = [ + { + type: 'DQ_AbsoluteExternalPositionalAccuracy', + standaloneQualityReportDetails: "standalone quality report details 1", + qualityMeasure: { + identifier: { + identifier: 'identifier', + namespace: 'namespace', + version: 'version', + description: 'description' + }, + name: ['name of measure'], + description: 'description' + }, + evaluationMethod: { + type: 'DQ_EvaluationMethod', + dateTime: ['2019-06-11T08:35:00', '2019-06-11T09:00:00'], + methodDescription: 'evaluation method description', + evaluationProcedure: { title: 'EP Title' }, + referenceDocument: [ ], + evaluationMethodType: 'DQ_EvaluationMethodTypeCode', + deductiveSource: 'deductive source', + samplingScheme: 'sampling scheme', + lotDescription: 'lot description', + samplingRatio: 'sampling ratio' + }, + quantitativeResult: [ + { + dateTime: "2019-06-11T09:00:00", + scope: build_scope_full, + value: [9.99, 9.0], + valueUnits: "value units", + valueRecordType: "value record type" + } + ], + descriptiveResult: [{ + dateTime: "2019-06-11T09:00:00", + scope: build_scope_full, + statement: "statement" + }], + conformanceResult: [{ + dateTime: "2019-06-11T09:00:00", + scope: build_scope_full, + specification: build_citation('alternate metadata title one'), + explanation: "conformance result explanation", + pass: false + }], + # derivedElementReports: [], + } + ] + + return hDataQuality + end + def build_date(dateTime, type = 'none') hDate = date hDate[:date] = dateTime @@ -157,66 +219,6 @@ def build_funding(id = nil, amount = nil, description = nil) hFunding[:description] = description unless description.nil? return hFunding end - - def build_dataQuality - hDataQuality = dataQuality - hDataQuality[:scope] = build_scope_full - hDataQuality[:standaloneQualityReport] = { - abstract: "standalone quality report 1" - } - - hDataQuality[:report] = [ - { - conformanceResult: [{ - dateTime: "2019-06-11T09:00:00", - scope: build_scope_full, - specification: build_citation('alternate metadata title one'), - explanation: "conformance result explanation", - pass: false - }], - descriptiveResult: [{ - dateTime: "2019-06-11T09:00:00", - scope: build_scope_full, - statement: "statement" - }], - qualityMeasure: { - identifier: { - identifier: 'identifier', - description: 'description', - namespace: 'namespace', - version: 'version' - }, - name: ['name of measure'], - description: 'description' - }, - evaluationMethod: { - type: 'evaluation method type - enumerated', - dateTime: '2019-06-11T08:35:00', - methodDescription: 'evaluation method description', - evaluationProcedure: { title: 'EP Title' }, - referenceDocument: [ ], - evaluationMethodType: 'DQ_EvaluationMethodTypeCode', - deductiveSource: 'deductive source', - samplingScheme: 'sampling scheme', - lotDescription: 'lot description', - samplingRatio: 'sampling ratio' - }, - quantitativeResult: [ - { - dateTime: "2019-06-11T09:00:00", - scope: build_scope_full, - value: [9.99, 9.0], - valueUnits: "value units", - valueRecordType: "value record type" - } - ], - # derivedElementReports: [], - # relatedElementReports: [] - } - ] - - return hDataQuality - end def build_geoJson aGeoJson = [] diff --git a/test/helpers/mdJson_hash_objects.rb b/test/helpers/mdJson_hash_objects.rb index c4a157e20..e088d4eb7 100644 --- a/test/helpers/mdJson_hash_objects.rb +++ b/test/helpers/mdJson_hash_objects.rb @@ -148,6 +148,16 @@ def base status: [ 'status 1' ], + pointOfContact: [ + { + role: 'pointOfContact', + party: [ + { + contactId: 'CID001' + } + ] + } + ], extent: [ geographicExtent: [ { @@ -162,16 +172,6 @@ def base } ] ], - pointOfContact: [ - { - role: 'pointOfContact', - party: [ - { - contactId: 'CID001' - } - ] - } - ], keyword: [ { keyword: [ @@ -245,14 +245,14 @@ def additionalDocumentation # associated resource --------------------- def associatedResource { + associationType: 'association type', + initiativeType: 'initiative type', resourceType: [ { type: 'resource type', name: 'resource name' } ], - associationType: 'association type', - initiativeType: 'initiative type', resourceCitation: { title: 'citation title', date: [ @@ -1054,9 +1054,8 @@ def funding def dataQuality { scope: scope, - report: [{ - qualityMeasure: qualityMeasure - }] + standaloneQualityReport: {}, + report: [] } end diff --git a/test/writers/mdJson/tc_mdjson_metadata.rb b/test/writers/mdJson/tc_mdjson_metadata.rb index 8b66b2adb..4c0d4fd7d 100644 --- a/test/writers/mdJson/tc_mdjson_metadata.rb +++ b/test/writers/mdJson/tc_mdjson_metadata.rb @@ -17,6 +17,11 @@ class TestWriterMdJsonMetadata < TestWriterMdJsonParent # build mdJson test file in hash mdHash = TDClass.base + # data quality [] + mdHash[:metadata][:dataQuality] = [] + mdHash[:metadata][:dataQuality] << TDClass.build_dataQuality + mdHash[:metadata][:dataQuality] << TDClass.build_dataQuality + # lineage [] mdHash[:metadata][:resourceLineage] = [] mdHash[:metadata][:resourceLineage] << TDClass.build_lineage @@ -42,12 +47,6 @@ class TestWriterMdJsonMetadata < TestWriterMdJsonParent mdHash[:metadata][:funding] << TDClass.build_funding mdHash[:metadata][:funding] << TDClass.build_funding - # data quality [] - mdHash[:metadata][:dataQuality] = [] - mdHash[:metadata][:dataQuality] << TDClass.build_dataQuality - mdHash[:metadata][:dataQuality] << TDClass.build_dataQuality - - TDClass.removeEmptyObjects(mdHash) @@mdHash = mdHash