Class: ImportGblv1

Inherits:
Import show all
Defined in:
app/models/import_gblv1.rb

Overview

Import GBLv1

Instance Method Summary collapse

Methods inherited from Import

#all_mapping_keys, #check_if_mapped, #convert_data, #mappings_valid?, #run!, #set_csv_file_attributes, #state_machine

Instance Method Details

#assumed_mappingsObject

Copy Value from Field to Field



23
24
25
26
27
28
29
30
# File 'app/models/import_gblv1.rb', line 23

def assumed_mappings
  # No longer assuming identfier == slug
  # [
  #   { 'dc_identifier_s': 'layer_slug_s' }
  # ]
  # Return empty array
  []
end

#default_mappingsObject

Solr Field => Hard Value



16
17
18
19
20
# File 'app/models/import_gblv1.rb', line 16

def default_mappings
  [
    {geoblacklight_version: "1.0"}
  ]
end

#derived_mappingsObject

Derived Values



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/import_gblv1.rb', line 33

def derived_mappings
  [
    {dct_references_s:
      {
        field: "dct_references_s",
        method: "geomg_dct_references_s"
      }},
    {b1g_date_range_drsim:
      {
        field: "b1g_date_range_drsim",
        method: "geomg_b1g_date_range_drsim"
      }}
  ]
end

#geomg_b1g_date_range_drsim(args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'app/models/import_gblv1.rb', line 61

def geomg_b1g_date_range_drsim(args)
  data_hash = args[:data_hash]
  field = args[:field]

  # Ex. [2020 TO 2020], [* TO 2020], [2020 TO *]
  date_range = nil
  date_range = data_hash[field][0] unless data_hash[field].empty?
  date_range = date_range[1..12]&.gsub(" TO ", "-") unless date_range.nil?
  date_range
end

#geomg_dct_references_s(args) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/import_gblv1.rb', line 72

def geomg_dct_references_s(args)
  data_hash = args[:data_hash]
  field = args[:field]
  references = []

  unless data_hash[field].empty?
    dct_references = data_hash[field][0]
    json_data = JSON.parse(dct_references[:value])

    json_data.each do |key, value|
      reference = {
        value: value,
        category: GeoblacklightAdmin::FieldMappingsGblv1.uri_2_category_references_mappings[key]
      }
      references << reference
    end
  end

  references
end

#klass_delimiterObject



11
12
13
# File 'app/models/import_gblv1.rb', line 11

def klass_delimiter
  "|"
end

#mapping_configurationObject

validations, constants and methods



7
8
9
# File 'app/models/import_gblv1.rb', line 7

def mapping_configuration
  GeoblacklightAdmin::Schema.instance.importable_fields
end

#required_mappingsObject

Required Values Key / Default Value



50
51
52
53
54
# File 'app/models/import_gblv1.rb', line 50

def required_mappings
  [
    {b1g_status_s: "Active"}
  ]
end

#solr_geom_mapping(geom) ⇒ Object



56
57
58
59
# File 'app/models/import_gblv1.rb', line 56

def solr_geom_mapping(geom)
  # Example: "ENVELOPE(-87\\, -85.76\\, 39.78\\, 37.96)"
  geom&.delete("\\")
end