Class: SubContainerToAspaceJsonMapper

Inherits:
Object
  • Object
show all
Includes:
JSONModel
Defined in:
backend/app/lib/subcontainer_to_aspace_json_mapper.rb

Overview

Take our record containing managed containers and generate corresponding ArchivesSpace container records.

Instance Method Summary (collapse)

Methods included from JSONModel

JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_repository, strict_mode, strict_mode?, with_repository

Constructor Details

- (SubContainerToAspaceJsonMapper) initialize(instance_json, instance_obj)

Returns a new instance of SubContainerToAspaceJsonMapper



7
8
9
10
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 7

def initialize(instance_json, instance_obj)
  @instance_json = instance_json
  @instance_obj = instance_obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args)



52
53
54
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 52

def method_missing(method, *args)
  nil
end

Instance Method Details

- (Object) barcode_1



33
34
35
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 33

def barcode_1
  top_container.barcode
end

- (Object) container_locations



38
39
40
41
42
43
44
45
46
47
48
49
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 38

def container_locations
  relationship = TopContainer.find_relationship(:top_container_housed_at)

  relationship.find_by_participant(top_container).map {|container_location|
    properties = container_location.values.merge('ref' => Location.uri_for(:location, container_location[:location_id]))
    properties[:jsonmodel_type] ||= "container_location"
    properties[:start_date] = properties[:start_date].strftime('%Y-%m-%d') if properties[:start_date]
    properties[:end_date] = properties[:end_date].strftime('%Y-%m-%d') if properties[:end_date]

    JSONModel(:container_location).from_hash(properties, true, true).to_hash(:trusted)
  }
end

- (Object) indicator_1



28
29
30
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 28

def indicator_1
  top_container.indicator
end

- (Object) lock_version



19
20
21
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 19

def lock_version
      top_container.lock_version
end

- (Object) to_hash



13
14
15
16
17
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 13

def to_hash
  result = Hash[JSONModel(:container).schema['properties'].map {|property, _| [property, self.send(property.intern)]}]

  result
end

- (Object) type_1



23
24
25
# File 'backend/app/lib/subcontainer_to_aspace_json_mapper.rb', line 23

def type_1
  top_container.type || 'box'
end