Class: Labimotion::UpdateTemplatePublicationMetadata
- Inherits:
-
Object
- Object
- Labimotion::UpdateTemplatePublicationMetadata
- Includes:
- TemplateDoiHelpers
- Defined in:
- lib/labimotion/usecases/update_template_publication_metadata.rb
Overview
Merges a normalized "publication" sub-object into the template's properties_template jsonb. Keeps the rest of the jsonb untouched so the labimotion gem's runtime shape stays intact.
Constant Summary collapse
- ALLOWED_KEYS =
%w[title description authors contributors references license].freeze
- REFERENCE_KEYS =
%w[doi title url].freeze
- PERSON_KEYS =
Authors and contributors are the same shape: a DataCite personal name plus the identifiers that make it resolvable — ORCID for the person, ROR for their organisation. Contributors carry a contributorType on top.
%w[givenName familyName orcid affiliation affiliation_id ror_id].freeze
Constants included from TemplateDoiHelpers
TemplateDoiHelpers::CONTRIBUTOR_TYPES, TemplateDoiHelpers::DEFAULT_CONTRIBUTOR_TYPE, TemplateDoiHelpers::GENERIC_ADMIN_KEY, TemplateDoiHelpers::HOST_ENV_KEYS, TemplateDoiHelpers::KLASS_BY_TYPE
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#publication ⇒ Object
readonly
Returns the value of attribute publication.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(record, current_user, publication) ⇒ UpdateTemplatePublicationMetadata
constructor
A new instance of UpdateTemplatePublicationMetadata.
- #success? ⇒ Boolean
Methods included from TemplateDoiHelpers
authorized?, klass_type_for, new_version_available?, public_host, template_url
Constructor Details
#initialize(record, current_user, publication) ⇒ UpdateTemplatePublicationMetadata
Returns a new instance of UpdateTemplatePublicationMetadata.
19 20 21 22 23 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 19 def initialize(record, current_user, publication) @record = record @current_user = current_user @publication = publication end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
17 18 19 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 17 def current_user @current_user end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
17 18 19 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 17 def error @error end |
#publication ⇒ Object (readonly)
Returns the value of attribute publication.
17 18 19 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 17 def publication @publication end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
17 18 19 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 17 def record @record end |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 25 def call return failure('record is required') if record.nil? return failure('unauthorized') unless TemplateDoiHelpers.(record, current_user) return failure('publication payload must be a hash') unless publication.is_a?(Hash) merged = normalized_publication props = (record.properties_template || {}).dup props['publication'] = merged record.update!(properties_template: props) @publication = merged self end |
#success? ⇒ Boolean
38 39 40 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 38 def success? @error.nil? end |