Class: Hyrax::Workflow::WorkflowImporter
- Inherits:
-
Object
- Object
- Hyrax::Workflow::WorkflowImporter
- Extended by:
- Forwardable
- Defined in:
- app/services/hyrax/workflow/workflow_importer.rb
Overview
Responsible for loading workflows from a data source.
Defined Under Namespace
Modules: SchemaValidator
Class Attribute Summary collapse
-
.load_errors ⇒ Object
readonly
Returns the value of attribute load_errors.
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Class Method Summary collapse
- .clear_load_errors! ⇒ Object
-
.generate_from_hash(data:, permission_template:, **keywords) ⇒ Array<Sipity::Workflow>
Responsible for generating the work type and corresponding processing entries based on given pathname or JSON document.
-
.generate_from_json_file(path:, permission_template:, **keywords) ⇒ Array<Sipity::Workflow>
Responsible for generating the work type and corresponding processing entries based on given pathname or JSON document.
-
.load_workflow_for(permission_template:, logger: default_logger) ⇒ TrueClass, FalseClass
Load all of the workflows for the given permission_template.
-
.load_workflows(permission_templates: Hyrax::PermissionTemplate.all, **kwargs) ⇒ TrueClass
Load all the workflows in config/workflows/*.json for each of the permission templates.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(data:, permission_template:, schema: default_schema, validator: default_validator, logger: default_logger) ⇒ WorkflowImporter
constructor
A new instance of WorkflowImporter.
Constructor Details
#initialize(data:, permission_template:, schema: default_schema, validator: default_validator, logger: default_logger) ⇒ WorkflowImporter
Returns a new instance of WorkflowImporter.
93 94 95 96 97 98 99 100 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 93 def initialize(data:, permission_template:, schema: default_schema, validator: default_validator, logger: default_logger) self.data = data self.schema = schema self.validator = validator self. = @logger = logger validate! end |
Class Attribute Details
.load_errors ⇒ Object
Returns the value of attribute load_errors.
19 20 21 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 19 def load_errors @load_errors end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
126 127 128 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 126 def errors @errors end |
Class Method Details
.clear_load_errors! ⇒ Object
15 16 17 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 15 def clear_load_errors! self.load_errors = [] end |
.generate_from_hash(data:, permission_template:, **keywords) ⇒ Array<Sipity::Workflow>
Responsible for generating the work type and corresponding processing entries based on given pathname or JSON document.
80 81 82 83 84 85 86 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 80 def self.generate_from_hash(data:, permission_template:, **keywords) importer = new(data: data, permission_template: , **keywords) workflows = importer.call self.load_errors ||= [] load_errors.concat(importer.errors) workflows end |
.generate_from_json_file(path:, permission_template:, **keywords) ⇒ Array<Sipity::Workflow>
Responsible for generating the work type and corresponding processing entries based on given pathname or JSON document.
67 68 69 70 71 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 67 def self.generate_from_json_file(path:, permission_template:, **keywords) contents = path.respond_to?(:read) ? path.read : File.read(path) data = JSON.parse(contents) generate_from_hash(data: data, permission_template: , **keywords) end |
.load_workflow_for(permission_template:, logger: default_logger) ⇒ TrueClass, FalseClass
I’d like to deprecate .load_workflows but for now that is beyond the scope of what I’m after. So I will use its magic instead
Load all of the workflows for the given permission_template
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 34 def self.load_workflow_for(permission_template:, logger: default_logger) workflow_config_filenames = Dir.glob(path_to_workflow_files) if workflow_config_filenames.none? logger.info("Unable to load workflows for #{.class} ID=#{.id}. No workflows were found in #{path_to_workflow_files}") return false end workflow_config_filenames.each do |config| logger.info "Loading permission_template ID=#{.id} with workflow config #{config}" generate_from_json_file(path: config, permission_template: , logger: default_logger) end true end |
.load_workflows(permission_templates: Hyrax::PermissionTemplate.all, **kwargs) ⇒ TrueClass
Load all the workflows in config/workflows/*.json for each of the permission templates
52 53 54 55 56 57 58 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 52 def self.load_workflows(permission_templates: Hyrax::PermissionTemplate.all, **kwargs) clear_load_errors! Array.wrap().each do || load_workflow_for(permission_template: , **kwargs) end true end |
Instance Method Details
#call ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 128 def call self.errors = [] Array.wrap(data.fetch(:workflows)).map do |configuration| find_or_create_from(configuration: configuration) rescue InvalidStateRemovalException => e e.states.each do |state| error = I18n.t('hyrax.workflow.load.state_error', workflow_name: state.workflow.name, state_name: state.name, entity_count: state.entities.count) Hyrax.logger.error(error) errors << error end Sipity::Workflow.find_by(name: configuration[:name]) end end |