lib/adiwg/mdtranslator/readers/sbJson/modules/module_relatedItem.rb in adiwg-mdtranslator-2.1.0 vs lib/adiwg/mdtranslator/readers/sbJson/modules/module_relatedItem.rb in adiwg-mdtranslator-2.1.1
- old
+ new
@@ -6,10 +6,11 @@
require 'json'
require 'open-uri'
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
require_relative 'module_codelists'
+require_relative 'module_browseCategory'
module ADIWG
module Mdtranslator
module Readers
module SbJson
@@ -91,10 +92,11 @@
hResponseObj[:readerExecutionMessages] << "Failed reading ScienceBase relatedItem #{resourceId} - see following message(s)"
hResponseObj[:readerExecutionMessages] << readErr.to_s.slice(0, 300)
hResponseObj[:readerExecutionMessages] << 'Either the item does not exist or the item is secured and requires authentication to access.'
break
else
+
# parse related item
begin
hRelatedItem = JSON.parse(web_contents)
rescue JSON::JSONError => parseErr
hResponseObj[:readerExecutionMessages] << 'Parsing related item failed - see following message(s):\n'
@@ -103,19 +105,11 @@
end
# create mew associated resource
hResource = intMetadataClass.newAssociatedResource
- if hRelatedItem.has_key?('browseCategories')
- aBrowse = hRelatedItem['browseCategories']
- aBrowse.each do |category|
- resourceType = Codelists.codelist_sb2adiwg('scope_sb2adiwg', category)
- resourceType = resourceType.nil? ? category : resourceType
- hResource[:resourceTypes] << resourceType
- end
- else
- hResponseObj[:readerExecutionMessages] << "Related item #{resourceId} did not have browseCategories"
- end
+ # add resource types
+ BrowseCategory.unpack(hRelatedItem, hResource[:resourceTypes], hResponseObj)
# fill in associated resource citation
hCitation = intMetadataClass.newCitation
citationTitle = nil
if hItem.has_key?('relatedItemTitle')