From 098c4be8c0c484c50bc2ac344b0236455ed892f6 Mon Sep 17 00:00:00 2001 From: J-Oliveros <97468338+J-Oliveros@users.noreply.github.com> Date: Thu, 9 May 2024 12:12:08 -0600 Subject: [PATCH] Add bureauCode class to DCAT writer (#379) * Add bureauCode class to DCAT writer * Update logic in BureauCode. Add ProgramCode class and update references in dcat_us class --- .../dcat_us/sections/dcat_us_bureau_code.rb | 33 +++++++++++++++++++ .../dcat_us/sections/dcat_us_dcat_us.rb | 8 +++-- .../dcat_us/sections/dcat_us_program_code.rb | 33 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_bureau_code.rb create mode 100644 lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_program_code.rb diff --git a/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_bureau_code.rb b/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_bureau_code.rb new file mode 100644 index 00000000..ecf93a3d --- /dev/null +++ b/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_bureau_code.rb @@ -0,0 +1,33 @@ +require 'jbuilder' + +module ADIWG + module Mdtranslator + module Writers + module Dcat_us + module BureauCode + + def self.build(intObj) + + responsibleParties = intObj[:metadata][:resourceInfo][:citation][:responsibleParties] + contacts = [] + responsibleParties.each do |party| + contactId = party[:parties][0][:contactId] + contacts << Dcat_us.get_contact_by_id(contactId) + end + + bureauContacts = contacts&.select { |contact| contact[:externalIdentifier].any? { |id| id[:namespace] == 'bureauCode'} } + + bureauCodes = [] + bureauContacts.each do |contact| + bureauCode = contact[:externalIdentifier].find { |id| id[:namespace] == 'bureauCode' } + bureauCodes << bureauCode[:identifier] + end + + return bureauCodes + end + + end + end + end + end +end diff --git a/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_dcat_us.rb b/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_dcat_us.rb index 309aa860..1490d396 100644 --- a/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_dcat_us.rb +++ b/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_dcat_us.rb @@ -22,6 +22,8 @@ require_relative 'dcat_us_accrualPeriodicity' require_relative 'dcat_us_language' require_relative 'dcat_us_primaryITInvestmentUII' +require_relative 'dcat_us_program_code' +require_relative 'dcat_us_bureau_code' module ADIWG module Mdtranslator @@ -57,6 +59,8 @@ def self.build(intObj, responseObj) describedByType = DescribedByType.build(intObj) accrualPeriodicity = AccrualPeriodicity.build(intObj) primaryITInvestmentUII = PrimaryITInvestmentUII.build(intObj) + programCode = ProgramCode.build(intObj) + bureauCode = BureauCode.build(intObj) @Namespace = ADIWG::Mdtranslator::Writers::Dcat_us @@ -70,8 +74,8 @@ def self.build(intObj, responseObj) json.set!('contactPoint', contactPoint) json.set!('identifier', identifier) json.set!('accessLevel', accessLevel) - # json.set!('bureauCode', 'ToDo') - # json.set!('programCode', 'ToDo') + json.set!('bureauCode', bureauCode) + json.set!('programCode', programCode) json.set!('distribution', distribution) json.set!('license', license) diff --git a/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_program_code.rb b/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_program_code.rb new file mode 100644 index 00000000..765ed5d1 --- /dev/null +++ b/lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_program_code.rb @@ -0,0 +1,33 @@ +require 'jbuilder' + +module ADIWG + module Mdtranslator + module Writers + module Dcat_us + module ProgramCode + + def self.build(intObj) + + responsibleParties = intObj[:metadata][:resourceInfo][:citation][:responsibleParties] + contacts = [] + responsibleParties.each do |party| + contactId = party[:parties][0][:contactId] + contacts << Dcat_us.get_contact_by_id(contactId) + end + + programContacts = contacts&.select { |contact| contact[:externalIdentifier].any? { |id| id[:namespace] == 'programCode'} } + + programsCodes = [] + programContacts.each do |contact| + programCode = contact[:externalIdentifier].find { |id| id[:namespace] == 'programCode' } + programsCodes << programCode[:identifier] + end + + return programsCodes + end + + end + end + end + end +end