module ADIWG::Mdtranslator::Readers::MdJson::AssociatedResource

Public Class Methods

unpack(hAssocRes, responseObj) click to toggle source
# File lib/adiwg/mdtranslator/readers/mdJson/modules/module_associatedResource.rb, line 28
def self.unpack(hAssocRes, responseObj)

   @MessagePath = ADIWG::Mdtranslator::Readers::MdJson::MdJson

   # return nil object if input is empty
   if hAssocRes.empty?
      @MessagePath.issueWarning(30, responseObj)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intAssocRes = intMetadataClass.newAssociatedResource

   # associated resource - resource type [] (required) {resourceType}
   if hAssocRes.has_key?('resourceType')
      hAssocRes['resourceType'].each do |item|
         unless item.empty?
            hReturn = ResourceType.unpack(item, responseObj)
            unless hReturn.nil?
               intAssocRes[:resourceTypes] << hReturn
            end
         end
      end
   end
   if intAssocRes[:resourceTypes].empty?
      @MessagePath.issueError(31, responseObj)
   end

   # associated resource - association type (required)
   if hAssocRes.has_key?('associationType')
      intAssocRes[:associationType] = hAssocRes['associationType']
   end
   if intAssocRes[:associationType].nil? || intAssocRes[:associationType] == ''
      @MessagePath.issueError(32, responseObj)
   end

   # associated resource - initiative type
   if hAssocRes.has_key?('initiativeType')
      if hAssocRes['initiativeType'] != ''
         intAssocRes[:initiativeType] = hAssocRes['initiativeType']
      end
   end

   # associated resource - resource citation (required) {CI_Citation}
   if hAssocRes.has_key?('resourceCitation')
      hObject = hAssocRes['resourceCitation']
      unless hObject.empty?
         hReturn = Citation.unpack(hObject, responseObj)
         unless hReturn.nil?
            intAssocRes[:resourceCitation] = hReturn
         end
      end
   end
   if intAssocRes[:resourceCitation].empty?
      @MessagePath.issueError(33, responseObj)
   end

   # associated resource - metadata citation
   if hAssocRes.has_key?('metadataCitation')
      hObject = hAssocRes['metadataCitation']
      unless hObject.empty?
         hReturn = Citation.unpack(hObject, responseObj)
         unless hReturn.nil?
            intAssocRes[:metadataCitation] = hReturn
         end
      end
   end

   return intAssocRes

end