Class: Labimotion::UpdateTemplatePublicationMetadata

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_userObject (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

#errorObject (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

#publicationObject (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

#recordObject (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

#callObject



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.authorized?(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

Returns:

  • (Boolean)


38
39
40
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 38

def success?
  @error.nil?
end