public/models/aeon_record_mapper.rb
def json_fields

        mappings = {}

        json = self.record.json
        if !json
            return mappings
        end

        mappings['language'] = json['language']

        if json['notes']
            json['notes'].each do |note|
                if note['type'] == 'physloc' and !note['content'].blank?
                    mappings['physical_location_note'] = note['content'].map { |cont| "#{cont}" }.join("; ")
                end
            end
        end

        if json['dates']
            json['dates']
                .select { |date| date['expression'].present? }
                .group_by { |date| date['label'] }
                .each { |label, dates|
                    mappings["#{label}_date"] = dates
                        .map { |date| date['expression'] }
                        .join("; ")
                }
        end

        mappings['restrictions_apply'] = json['restrictions_apply']
        mappings['display_string'] = json['display_string']

        instances = json.fetch('instances', false)
        if !instances
            return mappings
        end

        mappings['requests'] = instances
            .select{ |instance| !instance['digital_object'] }
            .each_with_index
            .map { |instance, i|
                request = {}

                instance_count = i + 1

                request['Request'] = "#{instance_count}"

                request["instance_is_representative_#{instance_count}"] = instance['is_representative']
                request["instance_last_modified_by_#{instance_count}"] = instance['last_modified_by']
                request["instance_instance_type_#{instance_count}"] = instance['instance_type']
                request["instance_created_by_#{instance_count}"] = instance['created_by']

                container = instance['sub_container']
                if container
                    request["instance_container_grandchild_indicator_#{instance_count}"] = container['indicator_3']
                    request["instance_container_child_indicator_#{instance_count}"] = container['indicator_2']
                    request["instance_container_grandchild_type_#{instance_count}"] = container['type_3']
                    request["instance_container_child_type_#{instance_count}"] = container['type_2']

                    request["instance_container_last_modified_by_#{instance_count}"] = container['last_modified_by']
                    request["instance_container_created_by_#{instance_count}"] = container['created_by']

                    top_container = container['top_container']
                    if top_container
                        request["instance_top_container_ref_#{instance_count}"] = top_container['ref']

                        top_container_resolved = top_container['_resolved']
                        if top_container_resolved
                            request["instance_top_container_long_display_string_#{instance_count}"] = top_container_resolved['long_display_string']
                            request["instance_top_container_last_modified_by_#{instance_count}"] = top_container_resolved['last_modified_by']
                            request["instance_top_container_display_string_#{instance_count}"] = top_container_resolved['display_string']
                            request["instance_top_container_restricted_#{instance_count}"] = top_container_resolved['restricted']
                            request["instance_top_container_created_by_#{instance_count}"] = top_container_resolved['created_by']
                            request["instance_top_container_indicator_#{instance_count}"] = top_container_resolved['indicator']
                            request["instance_top_container_barcode_#{instance_count}"] = top_container_resolved['barcode']
                            request["instance_top_container_type_#{instance_count}"] = top_container_resolved['type']
                            request["instance_top_container_uri_#{instance_count}"] = top_container_resolved['uri']

                            collection = top_container_resolved['collection']
                            if collection
                                request["instance_top_container_collection_identifier_#{instance_count}"] = collection
                                    .select { |c| c['identifier'].present? }
                                    .map { |c| c['identifier'] }
                                    .join("; ")

                                request["instance_top_container_collection_display_string_#{instance_count}"] = collection
                                    .select { |c| c['display_string'].present? }
                                    .map { |c| c['display_string'] }
                                    .join("; ")
                            end

                            series = top_container_resolved['series']
                            if series
                                request["instance_top_container_series_identifier_#{instance_count}"] = series
                                    .select { |s| s['identifier'].present? }
                                    .map { |s| s['identifier'] }
                                    .join("; ")

                                request["instance_top_container_series_display_string_#{instance_count}"] = series
                                    .select { |s| s['display_string'].present? }
                                    .map { |s| s['display_string'] }
                                    .join("; ")
                            end

                        end
                    end
                end

                request
            }

        return mappings
    end
# Pulls relevant data from the record's JSON property
Pulls relevant data from the record's JSON property
Pulls relevant data from the record ' s JSON property
def json_fields
        mappings = {}
        json = self.record.json
        if !json
            return mappings
        end
        mappings['language'] = json['language']
        if json['notes']
            json['notes'].each do |note|
                if note['type'] == 'physloc' and !note['content'].blank?
                    mappings['physical_location_note'] = note['content'].map { |cont| "#{cont}" }.join("; ")
                end
            end
        end
        if json['dates']
            json['dates']
                .select { |date| date['expression'].present? }
                .group_by { |date| date['label'] }
                .each { |label, dates|
                    mappings["#{label}_date"] = dates
                        .map { |date| date['expression'] }
                        .join("; ")
                }
        end
        mappings['restrictions_apply'] = json['restrictions_apply']
        mappings['display_string'] = json['display_string']
        instances = json.fetch('instances', false)
        if !instances
            return mappings
        end
        mappings['requests'] = instances
            .select{ |instance| !instance['digital_object'] }
            .each_with_index
            .map { |instance, i|
                request = {}
                instance_count = i + 1
                request['Request'] = "#{instance_count}"
                request["instance_is_representative_#{instance_count}"] = instance['is_representative']
                request["instance_last_modified_by_#{instance_count}"] = instance['last_modified_by']
                request["instance_instance_type_#{instance_count}"] = instance['instance_type']
                request["instance_created_by_#{instance_count}"] = instance['created_by']
                container = instance['sub_container']
                if container
                    request["instance_container_grandchild_indicator_#{instance_count}"] = container['indicator_3']
                    request["instance_container_child_indicator_#{instance_count}"] = container['indicator_2']
                    request["instance_container_grandchild_type_#{instance_count}"] = container['type_3']
                    request["instance_container_child_type_#{instance_count}"] = container['type_2']
                    request["instance_container_last_modified_by_#{instance_count}"] = container['last_modified_by']
                    request["instance_container_created_by_#{instance_count}"] = container['created_by']
                    top_container = container['top_container']
                    if top_container
                        request["instance_top_container_ref_#{instance_count}"] = top_container['ref']
                        top_container_resolved = top_container['_resolved']
                        if top_container_resolved
                            request["instance_top_container_long_display_string_#{instance_count}"] = top_container_resolved['long_display_string']
                            request["instance_top_container_last_modified_by_#{instance_count}"] = top_container_resolved['last_modified_by']
                            request["instance_top_container_display_string_#{instance_count}"] = top_container_resolved['display_string']
                            request["instance_top_container_restricted_#{instance_count}"] = top_container_resolved['restricted']
                            request["instance_top_container_created_by_#{instance_count}"] = top_container_resolved['created_by']
                            request["instance_top_container_indicator_#{instance_count}"] = top_container_resolved['indicator']
                            request["instance_top_container_barcode_#{instance_count}"] = top_container_resolved['barcode']
                            request["instance_top_container_type_#{instance_count}"] = top_container_resolved['type']
                            request["instance_top_container_uri_#{instance_count}"] = top_container_resolved['uri']
                            collection = top_container_resolved['collection']
                            if collection
                                request["instance_top_container_collection_identifier_#{instance_count}"] = collection
                                    .select { |c| c['identifier'].present? }
                                    .map { |c| c['identifier'] }
                                    .join("; ")
                                request["instance_top_container_collection_display_string_#{instance_count}"] = collection
                                    .select { |c| c['display_string'].present? }
                                    .map { |c| c['display_string'] }
                                    .join("; ")
                            end
                            series = top_container_resolved['series']
                            if series
                                request["instance_top_container_series_identifier_#{instance_count}"] = series
                                    .select { |s| s['identifier'].present? }
                                    .map { |s| s['identifier'] }
                                    .join("; ")
                                request["instance_top_container_series_display_string_#{instance_count}"] = series
                                    .select { |s| s['display_string'].present? }
                                    .map { |s| s['display_string'] }
                                    .join("; ")
                            end
                        end
                    end
                end
                request
            }
        return mappings
    end
def json_fields mappings = { } json = self . record . json if ! json return mappings end mappings [ 'language' ] = json [ 'language' ] if json [ 'notes' ] json [ 'notes' ] . each do | note | if note [ 'type' ] == 'physloc' and ! note [ 'content' ] . blank? mappings [ 'physical_location_note' ] = note [ 'content' ] . map { | cont | "#{cont}" } . join ( "; " ) end end end if json [ 'dates' ] json [ 'dates' ] . select { | date | date [ 'expression' ] . present? } . group_by { | date | date [ 'label' ] } . each { | label , dates | mappings [ "#{label}_date" ] = dates . map { | date | date [ 'expression' ] } . join ( "; " ) } end mappings [ 'restrictions_apply' ] = json [ 'restrictions_apply' ] mappings [ 'display_string' ] = json [ 'display_string' ] instances = json . fetch ( 'instances' , false ) if ! instances return mappings end mappings [ 'requests' ] = instances . select { | instance | ! instance [ 'digital_object' ] } . each_with_index . map { | instance , i | request = { } instance_count = i + 1 request [ 'Request' ] = "#{instance_count}" request [ "instance_is_representative_#{instance_count}" ] = instance [ 'is_representative' ] request [ "instance_last_modified_by_#{instance_count}" ] = instance [ 'last_modified_by' ] request [ "instance_instance_type_#{instance_count}" ] = instance [ 'instance_type' ] request [ "instance_created_by_#{instance_count}" ] = instance [ 'created_by' ] container = instance [ 'sub_container' ] if container request [ "instance_container_grandchild_indicator_#{instance_count}" ] = container [ 'indicator_3' ] request [ "instance_container_child_indicator_#{instance_count}" ] = container [ 'indicator_2' ] request [ "instance_container_grandchild_type_#{instance_count}" ] = container [ 'type_3' ] request [ "instance_container_child_type_#{instance_count}" ] = container [ 'type_2' ] request [ "instance_container_last_modified_by_#{instance_count}" ] = container [ 'last_modified_by' ] request [ "instance_container_created_by_#{instance_count}" ] = container [ 'created_by' ] top_container = container [ 'top_container' ] if top_container request [ "instance_top_container_ref_#{instance_count}" ] = top_container [ 'ref' ] top_container_resolved = top_container [ '_resolved' ] if top_container_resolved request [ "instance_top_container_long_display_string_#{instance_count}" ] = top_container_resolved [ 'long_display_string' ] request [ "instance_top_container_last_modified_by_#{instance_count}" ] = top_container_resolved [ 'last_modified_by' ] request [ "instance_top_container_display_string_#{instance_count}" ] = top_container_resolved [ 'display_string' ] request [ "instance_top_container_restricted_#{instance_count}" ] = top_container_resolved [ 'restricted' ] request [ "instance_top_container_created_by_#{instance_count}" ] = top_container_resolved [ 'created_by' ] request [ "instance_top_container_indicator_#{instance_count}" ] = top_container_resolved [ 'indicator' ] request [ "instance_top_container_barcode_#{instance_count}" ] = top_container_resolved [ 'barcode' ] request [ "instance_top_container_type_#{instance_count}" ] = top_container_resolved [ 'type' ] request [ "instance_top_container_uri_#{instance_count}" ] = top_container_resolved [ 'uri' ] collection = top_container_resolved [ 'collection' ] if collection request [ "instance_top_container_collection_identifier_#{instance_count}" ] = collection . select { | c | c [ 'identifier' ] . present? } . map { | c | c [ 'identifier' ] } . join ( "; " ) request [ "instance_top_container_collection_display_string_#{instance_count}" ] = collection . select { | c | c [ 'display_string' ] . present? } . map { | c | c [ 'display_string' ] } . join ( "; " ) end series = top_container_resolved [ 'series' ] if series request [ "instance_top_container_series_identifier_#{instance_count}" ] = series . select { | s | s [ 'identifier' ] . present? } . map { | s | s [ 'identifier' ] } . join ( "; " ) request [ "instance_top_container_series_display_string_#{instance_count}" ] = series . select { | s | s [ 'display_string' ] . present? } . map { | s | s [ 'display_string' ] } . join ( "; " ) end end end end request } return mappings end
Pulls relevant data from the record's JSON property
Pulls relevant data from the record ' s JSON property