Class: GeoblacklightAdmin::ImageService

Inherits:
Object
  • Object
show all
Defined in:
app/services/geoblacklight_admin/image_service.rb,
app/services/geoblacklight_admin/image_service/tms.rb,
app/services/geoblacklight_admin/image_service/wms.rb,
app/services/geoblacklight_admin/image_service/iiif.rb,
app/services/geoblacklight_admin/image_service/iiif_manifest.rb,
app/services/geoblacklight_admin/image_service/image_map_layer.rb,
app/services/geoblacklight_admin/image_service/tiled_map_layer.rb,
app/services/geoblacklight_admin/image_service/dynamic_map_layer.rb

Defined Under Namespace

Modules: DynamicMapLayer, Iiif, IiifManifest, ImageMapLayer, TiledMapLayer, Tms, Wms

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ ImageService

Returns a new instance of ImageService.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/geoblacklight_admin/image_service.rb', line 10

def initialize(document)
  @document = document

  # State Machine
  @metadata = {}
  @metadata["solr_doc_id"] = document.id
  @metadata["placeheld"] = false
  @document.thumbnail_state_machine.transition_to!(:processing, @metadata)

  # Logger
  @logger ||= ActiveSupport::TaggedLogging.new(
    Logger.new(
      Rails.root.join("log", "image_service_#{Rails.env}.log")
    )
  )
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'app/services/geoblacklight_admin/image_service.rb', line 7

def document
  @document
end

#logger=(value) ⇒ Object (writeonly)

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



8
9
10
# File 'app/services/geoblacklight_admin/image_service.rb', line 8

def logger=(value)
  @logger = value
end

#metadata=(value) ⇒ Object (writeonly)

Sets the attribute metadata

Parameters:

  • value

    the value to set the attribute metadata to.



8
9
10
# File 'app/services/geoblacklight_admin/image_service.rb', line 8

def metadata=(value)
  @metadata = value
end

Instance Method Details

#storeBoolean

Stores the document’s image in ActiveStorage

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/geoblacklight_admin/image_service.rb', line 30

def store
  # Gentle hands
  sleep(1)

  io_file = image_tempfile(@document.id)

  if io_file.nil? || @metadata["placeheld"] == true
    @metadata["IO"] = "NIL"
    @document.thumbnail_state_machine.transition_to!(:placeheld, @metadata)
  else
    attach_io(io_file)
  end

  log_output
rescue => e
  @metadata["exception"] = e.inspect
  @document.thumbnail_state_machine.transition_to!(:failed, @metadata)
  log_output
end