Skip to content

Commit

Permalink
Implements Technical Metadata. Fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed May 13, 2015
1 parent 0e62250 commit edeb25d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/hydra/pcdm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module PCDM

# vocabularies
autoload :RDFVocabularies, 'hydra/pcdm/vocab/pcdm_terms'
autoload :EBUCoreVocabularies, 'hydra/pcdm/vocab/ebucore_terms'
autoload :SweetjplVocabularies, 'hydra/pcdm/vocab/sweetjpl_terms'

# models
autoload :Collection, 'hydra/pcdm/models/collection'
Expand Down
10 changes: 10 additions & 0 deletions lib/hydra/pcdm/models/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ class File < ActiveFedora::File
metadata do
configure type: RDFVocabularies::PCDMTerms.File
property :label, predicate: ::RDF::RDFS.label

property :file_name, predicate: EBUCoreVocabularies::EBUCoreTerms.filename
property :file_size, predicate: EBUCoreVocabularies::EBUCoreTerms.fileSize
property :date_created, predicate: EBUCoreVocabularies::EBUCoreTerms.dateCreated
property :has_mime_type, predicate: EBUCoreVocabularies::EBUCoreTerms.hasMimeType
property :date_modified, predicate: EBUCoreVocabularies::EBUCoreTerms.dateModified
property :byte_order, predicate: SweetjplVocabularies::SweetjplTerms.byteOrder

# This is a server-managed predicate which means Fedora does not let us change it.
property :file_hash, predicate: RDF::Vocab::PREMIS.hasMessageDigest
end
end
end
33 changes: 33 additions & 0 deletions lib/hydra/pcdm/vocab/ebucore_terms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rdf'
module EBUCoreVocabularies
class EBUCoreTerms < RDF::StrictVocabulary("http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#")
# Property definitions
property :filename,
comment: ["The name of the file containing the Resource.".freeze],
domain: "ebucore:Resource".freeze,
range: "xsd:string".freeze,
label: "File Name".freeze

property :fileSize,
comment: ["Size of a MediaResource in bytes.".freeze],
domain: "ebucore:Resource".freeze,
range: "xsd:integer".freeze,
label: "File Size".freeze

property :dateCreated,
comment: ["The date of creation of the media resource.".freeze],
domain: "ebucore:Resource".freeze,
range: "xsd:dateTime".freeze,
label: "Date Created".freeze

property :hasMimeType,
comment: ["Has Mime Type.".freeze],
range: "xsd:string".freeze,
label: "Has Mime Type".freeze

property :dateModified,
comment: ["To indicate the date at which the media resource has been modified.".freeze],
range: "xsd:dateTime".freeze,
label: "Date Modified".freeze
end
end
10 changes: 10 additions & 0 deletions lib/hydra/pcdm/vocab/sweetjpl_terms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rdf'
module SweetjplVocabularies
class SweetjplTerms < RDF::StrictVocabulary("http://sweet.jpl.nasa.gov/2.2/reprDataFormat.owl#")
# Property definitions
property :byteOrder,
comment: ["Byte Order.".freeze],
range: "xsd:string".freeze,
label: "Byte Order".freeze
end
end
31 changes: 31 additions & 0 deletions spec/hydra/pcdm/models/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,35 @@
expect(reloaded.label).to eq ['foo']
end
end

describe "technical metadata" do
let(:date_created) { Date.parse "Fri, 08 May 2015 08:00:00 -0400 (EDT)" }
let(:date_modified) { Date.parse "Sat, 09 May 2015 09:00:00 -0400 (EDT)" }
let(:content) { "hello world" }
let(:file) { Hydra::PCDM::File.new.tap { |ds| ds.content = content } }
it "saves technical metadata" do
file.file_name = "picture.jpg"
file.file_size = content.length.to_s
file.date_created = date_created
file.has_mime_type = "application/jpg"
file.date_modified = date_modified
file.byte_order = "little-endian"
expect(file.save).to be true
expect(reloaded.file_name).to eq ["picture.jpg"]
expect(reloaded.file_size).to eq [content.length.to_s]
expect(reloaded.has_mime_type).to eq ["application/jpg"]
expect(reloaded.date_created).to eq [date_created]
expect(reloaded.date_modified).to eq [date_modified]
expect(reloaded.byte_order).to eq ["little-endian"]
end

it "does not save server managed properties" do
# Currently we can't write this property because Fedora
# complains that it's a server managed property. This test
# is mostly to document this situation.
file.file_hash = "the-hash"
expect{file.save}.to raise_error(Ldp::BadRequest)
end
end

end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
ActiveFedora::Cleaner.clean!
end
end
end
end

0 comments on commit edeb25d

Please sign in to comment.