Class: Ddr::Models::Base

Inherits:
ActiveFedora::Base
  • Object
show all
Extended by:
Relation, Deprecation
Includes:
EventLoggable, FileManagement, Governable, HasAdminMetadata, HasThumbnail, Indexing, Hydra::Validations
Defined in:
lib/ddr/models/base.rb

Direct Known Subclasses

Attachment, Collection, Component, Item, Target

Constant Summary collapse

SAVE_NOTIFICATION =
"save.base.models.ddr"

Constants included from Index::Fields

Index::Fields::ACCESS_ROLE, Index::Fields::ACTIVE_FEDORA_MODEL, Index::Fields::ADMIN_SET, Index::Fields::ADMIN_SET_FACET, Index::Fields::ALL_TEXT, Index::Fields::ASPACE_ID, Index::Fields::ATTACHED_FILES, Index::Fields::ATTACHED_FILES_HAVING_CONTENT, Index::Fields::BOX_NUMBER_FACET, Index::Fields::COLLECTION_FACET, Index::Fields::COLLECTION_URI, Index::Fields::CONTENT_CREATE_DATE, Index::Fields::CONTENT_SIZE, Index::Fields::CONTENT_SIZE_HUMAN, Index::Fields::CONTRIBUTOR_FACET, Index::Fields::CREATOR_FACET, Index::Fields::DATE_FACET, Index::Fields::DATE_SORT, Index::Fields::DEPOSITOR, Index::Fields::DISPLAY_FORMAT, Index::Fields::DOI, Index::Fields::EAD_ID, Index::Fields::EXTRACTED_TEXT, Index::Fields::FCREPO3_PID, Index::Fields::FORMAT_FACET, Index::Fields::HAS_MODEL, Index::Fields::ID, Index::Fields::IDENTIFIER_ALL, Index::Fields::IS_ATTACHED_TO, Index::Fields::IS_EXTERNAL_TARGET_FOR, Index::Fields::IS_GOVERNED_BY, Index::Fields::IS_LOCKED, Index::Fields::IS_MEMBER_OF_COLLECTION, Index::Fields::IS_PART_OF, Index::Fields::LAST_FIXITY_CHECK_ON, Index::Fields::LAST_FIXITY_CHECK_OUTCOME, Index::Fields::LAST_VIRUS_CHECK_ON, Index::Fields::LAST_VIRUS_CHECK_OUTCOME, Index::Fields::LICENSE, Index::Fields::LOCAL_ID, Index::Fields::MEDIA_MAJOR_TYPE, Index::Fields::MEDIA_SUB_TYPE, Index::Fields::MEDIA_TYPE, Index::Fields::MULTIRES_IMAGE_FILE_PATH, Index::Fields::OBJECT_CREATE_DATE, Index::Fields::OBJECT_MODIFIED_DATE, Index::Fields::OBJECT_PROFILE, Index::Fields::OBJECT_STATE, Index::Fields::ORIGINAL_FILENAME, Index::Fields::PERMANENT_ID, Index::Fields::PERMANENT_URL, Index::Fields::POLICY_ROLE, Index::Fields::PUBLISHER_FACET, Index::Fields::RESEARCH_HELP_CONTACT, Index::Fields::RESOURCE_ROLE, Index::Fields::SERIES_FACET, Index::Fields::SPATIAL_FACET, Index::Fields::STRUCT_MAPS, Index::Fields::SUBJECT_FACET, Index::Fields::TECHMD_COLOR_SPACE, Index::Fields::TECHMD_CREATING_APPLICATION, Index::Fields::TECHMD_CREATION_TIME, Index::Fields::TECHMD_FILE_SIZE, Index::Fields::TECHMD_FITS_DATETIME, Index::Fields::TECHMD_FITS_VERSION, Index::Fields::TECHMD_FORMAT_LABEL, Index::Fields::TECHMD_FORMAT_VERSION, Index::Fields::TECHMD_IMAGE_HEIGHT, Index::Fields::TECHMD_IMAGE_WIDTH, Index::Fields::TECHMD_MEDIA_TYPE, Index::Fields::TECHMD_MESSAGE, Index::Fields::TECHMD_MODIFICATION_TIME, Index::Fields::TECHMD_PRONOM_IDENTIFIER, Index::Fields::TECHMD_VALID, Index::Fields::TECHMD_WELL_FORMED, Index::Fields::TITLE, Index::Fields::TYPE_FACET, Index::Fields::UNIQUE_ID, Index::Fields::WORKFLOW_STATE, Index::Fields::YEAR_FACET

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Relation

having_local_id, in_collection

Methods included from HasAdminMetadata

#assign_permanent_id!, #copy_resource_roles_from, #effective_license, #effective_permissions, #finding_aid, #grant_roles_to_creator, #inherited_license, #inherited_roles, #lock, #lock!, #locked?, #permanent_id_manager, #research_help, #roles, #unlock, #unlock!, #workflow

Methods included from Indexing

#admin_set_facet, #all_identifiers, #associated_collection, #collection_facet, const_missing, #date_sort, #index_fields, #title_display, #to_solr, #year_facet

Methods included from Index::Fields

const_missing, descmd, get, techmd

Methods included from FileManagement

#add_file

Methods included from EventLoggable

#events, #has_events?, #notify_event, #update_events

Methods included from HasThumbnail

#copy_thumbnail_from, #thumbnail_changed?

Methods included from Governable

#copy_admin_policy_from

Class Method Details

.find_by_unique_id(unique_id) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ddr/models/base.rb', line 30

def self.find_by_unique_id(unique_id)
  if result = where(Ddr::Index::Fields::UNIQUE_ID => unique_id).first
    result
  else
    raise ActiveFedora::ObjectNotFoundError,
          "#{self} not found having unique id #{unique_id.inspect}."
  end
end

Instance Method Details

#admin_metadataObject



71
72
73
# File 'lib/ddr/models/base.rb', line 71

def 
  @admin_metadata ||= AdministrativeMetadata.new(self)
end

#adminMetadataObject



66
67
68
69
# File 'lib/ddr/models/base.rb', line 66

def 
  Deprecation.warn(Base, "`adminMetadata` is deprecated; use `admin_metadata` instead.")
  
end

#attached_files_having_contentObject



147
148
149
150
151
152
153
# File 'lib/ddr/models/base.rb', line 147

def attached_files_having_content
  Hash.new.tap do |h|
    attached_files.each do |file_id, file|
      h[file_id] = file if !file.destroyed? && file.has_content?
    end
  end
end

#attached_files_profileObject



129
130
131
# File 'lib/ddr/models/base.rb', line 129

def attached_files_profile
  AttachedFilesProfile.new(self)
end

#check_fixityObject Also known as: fixity_check



159
160
161
162
163
164
165
166
# File 'lib/ddr/models/base.rb', line 159

def check_fixity
  FixityCheckResults.new.tap do |results|
    attached_files_having_content.each_with_object(results) do |(file_id, file), memo|
      results[file_id] = !!file.check_fixity
    end
    notify_event(:fixity_check, results: results)
  end
end

#copy_admin_policy_or_roles_from(other) ⇒ Object



133
134
135
# File 'lib/ddr/models/base.rb', line 133

def copy_admin_policy_or_roles_from(other)
  copy_admin_policy_from(other) || copy_resource_roles_from(other)
end

#datastreams_to_validateObject



141
142
143
144
145
# File 'lib/ddr/models/base.rb', line 141

def datastreams_to_validate
  Deprecation.warn(FixityCheckable, "`datastreams_to_validate` is deprecated." \
                                    " Use `attached_files_having_content` instead.")
  attached_files_having_content
end

#desc_metadataObject



80
81
82
# File 'lib/ddr/models/base.rb', line 80

def 
  @desc_metadata ||= DescriptiveMetadata.new(self)
end

#desc_metadata_terms(*args) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ddr/models/base.rb', line 84

def (*args)
  return DescriptiveMetadata.unqualified_names.sort if args.empty?
  arg = args.pop
  terms = case arg.to_sym
          when :empty
            .select { |t| .values(t).empty? }
          when :present
            .select { |t| .values(t).present? }
          when :defined_attributes
             & MetadataMapping.dc11.unqualified_names
          when :required
            (:defined_attributes).select {|t| required? t}
          when :dcterms
            MetadataMapping.dc11.unqualified_names +
              (MetadataMapping.dcterms.unqualified_names - MetadataMapping.dc11.unqualified_names)
          when :dcterms_elements11
            Ddr::Vocab::Vocabulary.term_names(::RDF::DC11)
          when :duke
            Ddr::Vocab::Vocabulary.term_names(Ddr::Vocab::DukeTerms)
          else
            raise ArgumentError, "Invalid argument: #{arg.inspect}"
          end
  if args.empty?
    terms
  else
    terms | (*args)
  end
end

#desc_metadata_values(term) ⇒ Object



113
114
115
116
# File 'lib/ddr/models/base.rb', line 113

def (term)
  Deprecation.warn(Base, "`desc_metadata_values` is deprecated; use `desc_metadata.values` instead.")
  .values(term)
end

#descMetadataObject



75
76
77
78
# File 'lib/ddr/models/base.rb', line 75

def 
  Deprecation.warn(Base, "`descMetadata` is deprecated; use `desc_metadata` instead.")
  
end

#fixity_checksObject



155
156
157
# File 'lib/ddr/models/base.rb', line 155

def fixity_checks
  Ddr::Events::FixityCheckEvent.for_object(self)
end

#has_extracted_text?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/ddr/models/base.rb', line 137

def has_extracted_text?
  false
end

#inspectObject



43
44
45
# File 'lib/ddr/models/base.rb', line 43

def inspect
  "#<#{model_and_id}, uri: \"#{uri}\">"
end

#last_fixity_checkObject



170
171
172
# File 'lib/ddr/models/base.rb', line 170

def last_fixity_check
  fixity_checks.last
end

#last_fixity_check_onObject



174
175
176
# File 'lib/ddr/models/base.rb', line 174

def last_fixity_check_on
  last_fixity_check && last_fixity_check.event_date_time
end

#last_fixity_check_outcomeObject



178
179
180
# File 'lib/ddr/models/base.rb', line 178

def last_fixity_check_outcome
  last_fixity_check && last_fixity_check.outcome
end

#model_and_idObject

Cf. github.com/duke-libraries/ddr-models/issues/586 def to_key

(key = permanent_id_suffix) ? [key] : super

end

See Also:

  • ActiveModel::Conversion


57
58
59
# File 'lib/ddr/models/base.rb', line 57

def model_and_id
  "#{self.class} id: #{id.inspect || '[NEW]'}"
end

#model_pidObject



61
62
63
64
# File 'lib/ddr/models/base.rb', line 61

def model_pid
  Deprecation.warn(Base, "`model_pid` is deprecated; use `model_and_id` instead.")
  model_and_id
end

#permanent_id_suffixObject



47
48
49
# File 'lib/ddr/models/base.rb', line 47

def permanent_id_suffix
  permanent_id && permanent_id.sub(/\Aark:\/\d+\//, "")
end

#publishable?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


182
183
184
# File 'lib/ddr/models/base.rb', line 182

def publishable?
  raise NotImplementedError, "Must be implemented by subclasses"
end

#set_desc_metadata(term_values_hash) ⇒ Object

Update all desc_metadata terms with values in hash Note that term not having key in hash will be set to nil!



125
126
127
# File 'lib/ddr/models/base.rb', line 125

def (term_values_hash)
  .each { |t| .set_values(t, term_values_hash[t]) }
end

#set_desc_metadata_values(term, values) ⇒ Object



118
119
120
121
# File 'lib/ddr/models/base.rb', line 118

def (term, values)
  Deprecation.warn(Base, "`set_desc_metadata_values` is deprecated; use `desc_metadata.set_values` instead.")
  .set_values(term, values)
end

#unique_idsObject



39
40
41
# File 'lib/ddr/models/base.rb', line 39

def unique_ids
  [id, permanent_id, permanent_id_suffix].compact
end

#version_nameObject

Override AF::Versionable

Examples:

=> "version.20160205153424.643252000"


189
190
191
# File 'lib/ddr/models/base.rb', line 189

def version_name
  "version.#{Time.now.utc.strftime('%Y%m%d%H%M%S.%N')}"
end