Skip to content

Commit

Permalink
Merge pull request #136 from stansmith907/dev
Browse files Browse the repository at this point in the history
Minor bug fixes and patches
  • Loading branch information
jlblcc authored Sep 14, 2017
2 parents 962658a + fc6c22b commit 8ffb0f4
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 126 deletions.
4 changes: 4 additions & 0 deletions lib/adiwg/mdtranslator/readers/fgdc/modules/module_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def self.unpack(xDetail, hDictionary, hResponseObj)
intMetadataClass = InternalMetadata.new

# entity attribute 5.1.1 (enttype) - definition and description set
# also search for (enttyp); Metavist and USGS fgdc validator use 'enttyp'
xEntity = xDetail.xpath('./enttype')
if xEntity.empty?
xEntity = xDetail.xpath('./enttyp')
end
unless xEntity.empty?

hEntity = intMetadataClass.newEntity
Expand Down
28 changes: 14 additions & 14 deletions lib/adiwg/mdtranslator/readers/fgdc/modules/module_spatialDomain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def self.unpack(xDomain, hResponseObj)
intMetadataClass = InternalMetadata.new
hExtent = intMetadataClass.newExtent
hGeoExtent = intMetadataClass.newGeographicExtent
hExtent[:geographicExtents] << hGeoExtent

# spatial domain 1.5.1 (bounding) - bounding box
xBbox = xDomain.xpath('./bounding')
Expand Down Expand Up @@ -127,46 +128,45 @@ def self.unpack(xDomain, hResponseObj)

# make geoJson FeatureCollection from polygon
hGeometry = {
type: 'Polygon',
coordinates: polygon
'type' => 'Polygon',
'coordinates' => polygon
}
hFeature = {
type: 'Feature',
geometry: hGeometry,
properties: {
description: 'FGDC bounding polygon'
'type' => 'Feature',
'geometry' => hGeometry,
'properties' => {
'description' => 'FGDC bounding polygon'
}
}
hCollection = {
type: 'FeatureCollection',
features: [hFeature]
'type' => 'FeatureCollection',
'features' => [hFeature]
}
geoJson = hCollection.to_json
geoJson = hCollection

# make internal geometries from polygon
hIntGeo = intMetadataClass.newGeometryObject
hIntGeo[:type] = 'Polygon'
hIntGeo[:coordinates] = polygon
hIntGeo[:nativeGeoJson] = hGeometry.to_json
hIntGeo[:nativeGeoJson] = hGeometry

hIntProps = intMetadataClass.newGeometryProperties
hIntProps[:description] = 'FGDC bounding polygon'

hIntFeature = intMetadataClass.newGeometryFeature
hIntFeature[:type] = 'Feature'
hIntFeature[:geometryObject] = hIntGeo
hIntFeature[:nativeGeoJson] = hFeature.to_json
hIntFeature[:nativeGeoJson] = hFeature
hIntFeature[:properties] = hIntProps

hIntCollect = intMetadataClass.newFeatureCollection
hIntCollect[:type] = 'FeatureCollection'
hIntCollect[:features] << hIntFeature
hIntCollect[:nativeGeoJson] = hCollection.to_json
hIntCollect[:nativeGeoJson] = hCollection

hGeoExtent[:geographicElements] << hIntCollect
hGeoExtent[:nativeGeoJson] = geoJson
hGeoExtent[:nativeGeoJson] << geoJson

hExtent[:geographicExtents] << hGeoExtent
hExtent[:description] = 'FGDC spatial domain'

end
Expand Down
16 changes: 9 additions & 7 deletions lib/adiwg/mdtranslator/readers/sbJson/modules/module_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Reader - ScienceBase JSON to internal data structure

# History:
# Stan Smith 2016-06-21 original script
# Stan Smith 2017-09-13 remove fail restriction on contactType
# Stan Smith 2016-06-21 original script

require 'uuidtools'
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
Expand Down Expand Up @@ -65,20 +66,21 @@ def self.unpack(hSbJson, aContacts, hResponseObj)

hContact[:contactId] = UUIDTools::UUID.random_create.to_s

# contact - contactType (required) [ person | organization ]
# contact - contactType [ person | organization ]
if hSbContact.has_key?('contactType')
if %w(person organization).include?(hSbContact['contactType'])
if hSbContact['contactType'].nil? || hSbContact['contactType'] == ''
hResponseObj[:readerExecutionMessages] << 'Contact contactType is missing'
hContact[:isOrganization] = false
elsif %w(person organization).include?(hSbContact['contactType'])
hContact[:isOrganization] = true if hSbContact['contactType'] == 'organization'
else
hResponseObj[:readerExecutionMessages] << 'Contact contactType must be person or organization'
hResponseObj[:readerExecutionPass] = false
return nil
end
end
if hSbContact['contactType'].nil? || hSbContact['contactType'] == ''
else
hResponseObj[:readerExecutionMessages] << 'Contact contactType is missing'
hResponseObj[:readerExecutionPass] = false
return nil
hContact[:isOrganization] = false
end

# contact - name (required)
Expand Down
3 changes: 2 additions & 1 deletion lib/adiwg/mdtranslator/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# adiwg mdTranslator

# version 2 history
# 2.3.1 2017-09-13 fixed fgdc reader: removed conversion of hash to json
# 2.3.0 2017-09-11 add fgdc 1998 CSDGM reader
# 2.2.0 2017-08-31 refactor for schema changes to Lineage and Funding
# 2.1.2 2017-08-24 remove schema version from sbJson
Expand All @@ -25,7 +26,7 @@
module ADIWG
module Mdtranslator
# current mdtranslator version
VERSION = "2.3.0"
VERSION = "2.3.1"
end
end

Expand Down
12 changes: 10 additions & 2 deletions lib/adiwg/mdtranslator/writers/html/sections/html_allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,23 @@ def writeHtml(hAllocation)
unless hAllocation[:sourceId].nil?
hContact = Html_Document.getContact(hAllocation[:sourceId])
@html.em('Source Contact: ')
@html.a(hContact[:contactId], 'href' => '#CID_'+hContact[:contactId])
if hContact.empty?
@html.text!("Contact #{hAllocation[:sourceId]} not found!")
else
@html.a(hContact[:contactId], 'href' => '#CID_'+hContact[:contactId])
end
@html.br
end

# allocation - recipientId
unless hAllocation[:recipientId].nil?
hContact = Html_Document.getContact(hAllocation[:recipientId])
@html.em('Recipient Contact: ')
@html.a(hContact[:contactId], 'href' => '#CID_'+hContact[:contactId])
if hContact.empty?
@html.text!("Contact #{hAllocation[:recipientId]} not found!")
else
@html.a(hContact[:contactId], 'href' => '#CID_'+hContact[:contactId])
end
@html.br
end

Expand Down
4 changes: 2 additions & 2 deletions test/readers/fgdc/testData/entityAttribute.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
</attr>
</detailed>
<detailed>
<enttype>
<enttyp>
<enttypl>entity 2 label</enttypl>
<enttypd>entity 2 definition</enttypd>
</enttype>
</enttyp>
</detailed>
<overview>
<eaover>entity and attribute overview 1</eaover>
Expand Down
133 changes: 35 additions & 98 deletions test/readers/sbJson/tc_sbjson_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,39 @@ def test_complete_contact

# test response object
assert hResponse[:readerExecutionPass]
assert_empty hResponse[:readerExecutionMessages]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_empty_elements

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(1)
hIn0 = hIn['contacts'][0]
hIn0['oldPartyId'] = ''
hIn0['sourceId'] = ''
hIn0['organizationsPerson'] = ''
hIn0['ttyPhone'] = ''
hIn0['officePhone'] = ''
hIn0['faxPhone'] = ''
hIn0['hours'] = ''
hIn0['instructions'] = ''
hIn0['email'] = ''
hIn0['active'] = ''
hIn0['jobTitle'] = ''
hIn0['personalTitle'] = ''
hIn0['firstName'] = ''
hIn0['middleName'] = ''
hIn0['lastName'] = ''
hIn0['note'] = ''
hIn0['aliases'] = []
hIn0['fbmsCodes'] = []
hIn0['logoUrl'] = ''
hIn0['smallLogoUrl'] = ''
hIn0['organization'] = {}
hIn0['primaryLocation'] = {}
hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hContact = hIn['contacts'][0]
hContact['contactType'] = ''
hContact['oldPartyId'] = ''
hContact['sourceId'] = ''
hContact['organizationsPerson'] = ''
hContact['ttyPhone'] = ''
hContact['officePhone'] = ''
hContact['faxPhone'] = ''
hContact['hours'] = ''
hContact['instructions'] = ''
hContact['email'] = ''
hContact['active'] = ''
hContact['jobTitle'] = ''
hContact['personalTitle'] = ''
hContact['firstName'] = ''
hContact['middleName'] = ''
hContact['lastName'] = ''
hContact['note'] = ''
hContact['aliases'] = []
hContact['fbmsCodes'] = []
hContact['logoUrl'] = ''
hContact['smallLogoUrl'] = ''
hContact['organization'] = {}
hContact['primaryLocation'] = {}

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -143,8 +144,8 @@ def test_contact_empty_elements
hContact = metadata[0]
refute_nil hContact[:contactId]
refute hContact[:isOrganization]
assert_equal 'Robert N Prescott', hContact[:name]
assert_equal 'Distributor', hContact[:contactType]
assert_equal 'Jordan S Read', hContact[:name]
assert_equal 'Metadata Contact', hContact[:contactType]

# empty elements
assert_nil hContact[:positionName]
Expand All @@ -158,15 +159,15 @@ def test_contact_empty_elements
assert_nil hContact[:contactInstructions]

assert hResponse[:readerExecutionPass]
assert_empty hResponse[:readerExecutionMessages]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_missing_elements

hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -192,16 +193,16 @@ def test_contact_missing_elements
assert_nil hContact[:contactInstructions]

assert hResponse[:readerExecutionPass]
assert_empty hResponse[:readerExecutionMessages]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_name_empty

hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['name'] = ''
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -214,42 +215,10 @@ def test_contact_name_empty

def test_contact_name_missing

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0].delete('name')
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_contactType_empty

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['contactType'] = ''
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_contactType_missing

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0].delete('contactType')
hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn['contacts'][0].delete('name')

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -262,42 +231,10 @@ def test_contact_contactType_missing

def test_contact_contactType_invalid

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['contactType'] = 'badName'
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_type_empty

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['type'] = ''
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_type_missing

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0].delete('type')
hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn['contacts'][0]['contactType'] = 'badName'

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand Down
3 changes: 1 addition & 2 deletions test/readers/sbJson/testData/contact.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
},
{
"name": "Jordan S Read",
"type": "Metadata Contact",
"contactType": "person"
"type": "Metadata Contact"
}
]
}

0 comments on commit 8ffb0f4

Please sign in to comment.