Class: AspaceJsonToManagedContainerMapper
- Inherits:
-
Object
- Object
- AspaceJsonToManagedContainerMapper
- Includes:
- JSONModel
- Defined in:
- backend/app/lib/aspace_json_to_managed_container_mapper.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ContainerProfileMismatchException, LocationMismatchException
Instance Method Summary (collapse)
-
- (Object) call
-
- (AspaceJsonToManagedContainerMapper) initialize(json, new_record)
constructor
A new instance of AspaceJsonToManagedContainerMapper.
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
- (AspaceJsonToManagedContainerMapper) initialize(json, new_record)
Returns a new instance of AspaceJsonToManagedContainerMapper
5 6 7 8 9 |
# File 'backend/app/lib/aspace_json_to_managed_container_mapper.rb', line 5 def initialize(json, new_record) @json = json @new_record = new_record @new_top_containers = [] end |
Instance Method Details
- (Object) call
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'backend/app/lib/aspace_json_to_managed_container_mapper.rb', line 20 def call @json['instances'].each do |instance| # Make sure we're dealing with a hash, not a JSONModel instance = instance.is_a?(JSONModelType) ? instance.to_hash(:raw) : instance if instance['sub_container'] || instance['digital_object'] # Just need to make sure there are no conflicting ArchivesSpace containers # instance.delete('container') next end if !instance['container'] # This instance must be empty. No sub container, digital object or aspace container! Log.warn("Empty instance found. Skipped!") next end top_container = get_or_create_top_container(instance) begin ensure_harmonious_values(top_container, instance['container']) rescue LocationMismatchException => e if @json.is_a?(JSONModel(:accession)) # We handle this case specially because the AT migrator sends multiple # locations attached to an accession as containers with identical # indicator_1 values but differing locations. # # For an accession, match on indicator_1 but mismatch on location # means we're really talking about different Top Containers. container = instance['container'] top_container = create_top_container({'indicator' => get_default_indicator(container['indicator_1']), 'type' => container['type_1'], 'container_locations' => container['container_locations']}) else raise e end end subcontainer = { 'top_container' => {'ref' => top_container.uri}, } instance['container']['jsonmodel_type'] ||= 'container' [2, 3].each do |level| # ArchivesSpace containers allow type_2/3 to be set without # indicator_2/3. Provide a default if it's missing. if instance['container']["type_#{level}"] subcontainer["type_#{level}"] = instance['container']["type_#{level}"] subcontainer["indicator_#{level}"] = instance['container']["indicator_#{level}"] || get_default_indicator end end if instance['container']["type_3"] && !instance['container']["type_2"] # Promote type_3 to type_2 to stop validation blowing up subcontainer["type_2"] = instance['container']["type_3"] subcontainer["indicator_2"] = instance['container']["indicator_3"] || get_default_indicator subcontainer["type_3"] = nil subcontainer["indicator_3"] = nil end instance['sub_container'] = subcontainer # No need for the original value now. instance.delete('container') end end |