Class: CurationConcerns::Workflow::WorkflowImporter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
app/services/curation_concerns/workflow/workflow_importer.rb

Defined Under Namespace

Modules: SchemaValidator

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, schema: default_schema, validator: default_validator) ⇒ WorkflowImporter

Returns a new instance of WorkflowImporter.

Parameters:

  • data (#deep_symbolize_keys)

    the configuration information from which we will generate all the data entries

  • schema (#call) (defaults to: default_schema)

    The schema in which you will validate the data

  • validator (#call) (defaults to: default_validator)

    The validation service for the given data and schema



30
31
32
33
34
35
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 30

def initialize(data:, schema: default_schema, validator: default_validator)
  self.data = data
  self.schema = schema
  self.validator = validator
  validate!
end

Class Method Details

.generate_from_json_file(path:, **keywords) ⇒ Array<Sipity::Workflow>

Responsible for generating the work type and corresponding processing entries based on given pathname or JSON document.

Returns:



21
22
23
24
25
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 21

def self.generate_from_json_file(path:, **keywords)
  contents = path.respond_to?(:read) ? path.read : File.read(path)
  data = JSON.parse(contents)
  new(data: data, **keywords).call
end

.load_workflowsTrueClass

Load all the workflows in config/workflows/*.json

Returns:

  • (TrueClass)


8
9
10
11
12
13
14
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 8

def self.load_workflows
  Dir.glob(Rails.root + "config/workflows/*.json") do |config|
    Rails.logger.info "Loading workflow: #{config}"
    generate_from_json_file(path: config)
  end
  true
end

Instance Method Details

#callObject



63
64
65
66
67
# File 'app/services/curation_concerns/workflow/workflow_importer.rb', line 63

def call
  Array.wrap(data.fetch(:workflows)).map do |configuration|
    find_or_create_from(configuration: configuration)
  end
end