Module: ADIWG::Mdtranslator::Readers::MdJson
- Defined in:
- lib/adiwg/mdtranslator/readers/mdJson/mdJson_reader.rb,
lib/adiwg/mdtranslator/readers/mdJson/mdJson_validator.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_date.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_party.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_phone.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_scope.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_domain.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_entity.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_extent.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_format.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_locale.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_mdJson.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_medium.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_schema.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_series.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_source.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_address.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_contact.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_funding.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geoJson.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_graphic.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_keyword.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_lineage.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_measure.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_voucher.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_citation.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_dateTime.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_duration.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geodetic.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_metadata.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_taxonomy.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_algorithm.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_attribute.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_dimension.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_allocation.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_constraint.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_domainItem.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_identifier.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_processing.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_timePeriod.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_valueRange.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_boundingBox.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_dataQuality.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_distributor.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_entityIndex.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geologicAge.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_maintenance.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_processStep.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_timeInstant.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_distribution.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_metadataInfo.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_orderProcess.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_resourceInfo.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_resourceType.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_timeInterval.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_vectorObject.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_keywordObject.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_processReport.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_releasability.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_resourceUsage.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_verticalDatum.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_attributeGroup.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_coverageResult.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_dataDictionary.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geometryObject.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_onlineResource.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_temporalExtent.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_transferOption.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_verticalExtent.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_entityAttribute.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geometryFeature.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_legalConstraint.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_localProjection.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_taxonomicSystem.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_entityForeignKey.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_evaluationMethod.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geographicExtent.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_imageDescription.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_obliqueLinePoint.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_responsibleParty.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_scopeDescription.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_spatialReference.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_conformanceResult.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_dataQualityReport.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_descriptiveResult.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_featureCollection.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_nominalResolution.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_spatialResolution.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_associatedResource.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_contactPostprocess.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geometryCollection.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geometryProperties.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_gridRepresentation.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_metadataRepository.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_quantitativeResult.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_securityConstraint.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_coverageDescription.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_coordinateResolution.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geographicResolution.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_projectionParameters.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_vectorRepresentation.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_spatialRepresentation.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_additionalDocumentation.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_rangeElementDescription.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_taxonomicClassification.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_bearingDistanceResolution.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_referenceSystemParameters.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_georectifiedRepresentation.rb,
lib/adiwg/mdtranslator/readers/mdJson/modules/module_georeferenceableRepresentation.rb
Defined Under Namespace
Modules: AdditionalDocumentation, Address, Algorithm, Allocation, AssociatedResource, Attribute, AttributeGroup, BearingDistanceResolution, BoundingBox, Citation, ConformanceResult, Constraint, Contact, ContactPost, CoordinateResolution, CoverageDescription, CoverageResult, DataDictionary, DataQuality, DataQualityReport, Date, DateTime, DescriptiveResult, Dimension, Distribution, Distributor, Domain, DomainItem, Duration, Entity, EntityAttribute, EntityForeignKey, EntityIndex, EvaluationMethod, Extent, FeatureCollection, Format, Funding, GeoJson, Geodetic, GeographicExtent, GeographicResolution, GeologicAge, GeometryCollection, GeometryFeature, GeometryObject, GeometryProperties, GeorectifiedRepresentation, GeoreferenceableRepresentation, Graphic, GridRepresentation, Identifier, ImageDescription, Keyword, KeywordObject, LegalConstraint, LocalProjection, Locale, Maintenance, MdJson, Measure, Medium, Metadata, MetadataInfo, MetadataRepository, NominalResolution, ObliqueLinePoint, OnlineResource, OrderProcess, Party, Phone, ProcessStep, ProcessStepReport, Processing, ProjectionParameters, QuantitativeResult, RangeElementDescription, ReferenceSystemParameters, Releasability, ResourceInfo, ResourceLineage, ResourceType, ResourceUsage, ResponsibleParty, Schema, Scope, ScopeDescription, SecurityConstraint, Series, Source, SpatialReferenceSystem, SpatialRepresentation, SpatialResolution, TaxonomicClassification, TaxonomicSystem, Taxonomy, TemporalExtent, TimeInstant, TimeInterval, TimePeriod, TransferOption, ValueRange, VectorObject, VectorRepresentation, VerticalDatum, VerticalExtent, Voucher
Class Method Summary collapse
- .readFile(file, hResponseObj) ⇒ Object
-
.validate(file, responseObj) ⇒ Object
validate json against the adiwg-json_schemas only a single schema version is supported at this time.
Class Method Details
.readFile(file, hResponseObj) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/adiwg/mdtranslator/readers/mdJson/mdJson_reader.rb', line 34 def self.readFile(file, hResponseObj) # parse mdJson file begin hMdJson = JSON.parse(file) rescue JSON::JSONError => err hResponseObj[:readerStructureMessages] << 'ERROR: mdJson reader: Parsing mdJson Failed - see following message(s):\n' hResponseObj[:readerStructureMessages] << err.to_s.slice(0, 300) hResponseObj[:readerStructurePass] = false return {} end # file must contain an mdJson object if hMdJson.empty? hResponseObj[:readerStructureMessages] << 'ERROR: mdJson reader: object is empty' hResponseObj[:readerStructurePass] = false return {} end # schema - (required) unless hMdJson.has_key?('schema') hResponseObj[:readerStructureMessages] << 'ERROR: mdJson reader: schema definition is missing ' hResponseObj[:readerStructurePass] = false return {} end # schema - name (required) (must = 'mdJson') unless hMdJson['schema'].has_key?('name') hResponseObj[:readerStructureMessages] << 'ERROR: mdJson reader: schema element is missing' hResponseObj[:readerStructurePass] = false return {} end schemaName = hMdJson['schema']['name'] if schemaName.nil? || schemaName == '' hResponseObj[:readerStructureMessages] << 'ERROR: mdJson reader: schema name is missing' hResponseObj[:readerStructurePass] = false return {} end unless schemaName.downcase == 'mdjson' hResponseObj[:readerStructureMessages] << "ERROR: mdJson reader: schema name is '#{schemaName}', should be mdJson" hResponseObj[:readerStructurePass] = false return {} end # schema - version (required) unless hMdJson['schema'].has_key?('version') hResponseObj[:readerStructureMessages] << 'ERROR: mdJson reader: schema version element is missing' hResponseObj[:readerStructurePass] = false return {} end requestedVersion = hMdJson['schema']['version'] if requestedVersion.nil? || requestedVersion == '' hResponseObj[:readerStructureMessages] << 'ERROR: mdJson reader: schema version is missing' hResponseObj[:readerStructurePass] = false return {} end # schema - 2.0.0 =< requested version =< current version currentVersion = Gem::Specification.find_by_name('adiwg-mdjson_schemas').version.to_s hResponseObj[:readerVersionRequested] = requestedVersion hResponseObj[:readerVersionUsed] = currentVersion aCurVersion = currentVersion.split('.') aReqVersion = requestedVersion.split('.') approved = false if aReqVersion[0] == aCurVersion[0] if aReqVersion[1] <= aCurVersion[1] approved = true end end unless approved approvedVersion = aCurVersion[0] + '.0.0' hResponseObj[:readerStructureMessages] << "ERROR: mdJson reader: schema version '#{requestedVersion}' is not supported" hResponseObj[:readerStructureMessages] << "... mdTranslator supports mdJson schema version '#{approvedVersion}' through '#{currentVersion}'" hResponseObj[:readerStructurePass] = false return {} end # validate file against mdJson schema definition unless hResponseObj[:readerValidationLevel] == 'none' validate(hMdJson, hResponseObj) unless hResponseObj[:readerValidationPass] return {} end end # unpack the mdJson into the internal object return MdJson.unpack(hMdJson, hResponseObj) end |
.validate(file, responseObj) ⇒ Object
validate json against the adiwg-json_schemas only a single schema version is supported at this time
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/adiwg/mdtranslator/readers/mdJson/mdJson_validator.rb', line 25 def self.validate(file, responseObj) bStrict = false if responseObj[:readerValidationLevel] == 'strict' bStrict = true end ADIWG::MdjsonSchemas::Utils.load_schemas(false) begin aErrors = [] aErrors = JSON::Validator.fully_validate('schema.json', file, :strict => bStrict) unless aErrors.empty? responseObj[:readerValidationMessages] << 'ERROR: mdJson reader: schema validation Failed - see following message(s)' responseObj[:readerValidationMessages] << aErrors responseObj[:readerValidationPass] = false return end rescue JSON::Schema::ValidationError responseObj[:readerValidationMessages] << 'ERROR: mdJson reader: schema validation Failed - see following message(s)' responseObj[:readerValidationMessages] << $!. responseObj[:readerValidationPass] = false return end end |