active-fedora 10.0.0.beta1 → 10.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52036e2b5df62b1f60a9de0775f437b25c3a7007
4
- data.tar.gz: 3dfb407e63e75f71b5a4ee179ae3bb269fb9d507
3
+ metadata.gz: 07a8d037c8e741276cd1c890062704b44b83bb7f
4
+ data.tar.gz: cd0aeb9d41cc43935197ab09ad3799092efeee75
5
5
  SHA512:
6
- metadata.gz: e8f1330cc76aae3d76639026d5538c559e3b156093138f11ff736a0d0220e5bba0732b4997dc68e43f52fba756c1ebd5c77fa3d406db6ee4d9761837f3ce4cda
7
- data.tar.gz: 108479da9acacf1fef63de9d734eaa3c2aa866660b75b5363474ef1283ce04938beb0f71f04eb19cee890a5bfa46cca95f866c47ce454bee36685cc94db0045c
6
+ metadata.gz: 87513e6d099c60a8337df0583cc7b2cd00f35624bd11d5c953700752860c7f7e822814cfe0eff28398fde92c63a9ba3b22e14a2b5ef4bb269cd02774c709418a
7
+ data.tar.gz: 0cff0bacb41cb397745b83638e4d4bc42038a706cf45e3c0f26d014249f22b24d72aef3bfe7fb35beb9030b9e5f8df9f30bfd4924e0e98eefdedcc9e98a3df08
@@ -4,17 +4,13 @@ def with_test_server(&block)
4
4
  with_server('test', &block)
5
5
  end
6
6
 
7
- def with_server(environment, fcrepo_port: nil, solr_port: nil)
7
+ def with_server(environment)
8
8
  return yield if ENV["#{environment}_SERVER_STARTED"]
9
9
 
10
10
  ENV["#{environment}_SERVER_STARTED"] = 'true'
11
11
 
12
- # setting port: nil assigns a random port.
13
- solr_params = { port: solr_port, verbose: true, managed: true }
14
- fcrepo_params = { port: fcrepo_port, verbose: true, managed: true,
15
- enable_jms: false, fcrepo_home_dir: "fcrepo4-#{environment}-data" }
16
- SolrWrapper.wrap(solr_params) do |solr|
17
- ENV["SOLR_#{environment.upcase}_PORT"] = solr.port
12
+ SolrWrapper.wrap(load_config(:solr, environment)) do |solr|
13
+ ENV["SOLR_#{environment.upcase}_PORT"] = solr.port.to_s
18
14
  solr_config_path = File.join('solr', 'config')
19
15
  # Check to see if configs exist in a path relative to the working directory
20
16
  unless Dir.exist?(solr_config_path)
@@ -23,11 +19,19 @@ def with_server(environment, fcrepo_port: nil, solr_port: nil)
23
19
  solr_config_path = File.join(File.expand_path("../..", File.dirname(__FILE__)), "solr", "config")
24
20
  end
25
21
  solr.with_collection(name: "hydra-#{environment}", dir: solr_config_path) do
26
- FcrepoWrapper.wrap(fcrepo_params) do |fcrepo|
27
- ENV["FCREPO_#{environment.upcase}_PORT"] = fcrepo.port
22
+ FcrepoWrapper.wrap(load_config(:fcrepo, environment)) do |fcrepo|
23
+ ENV["FCREPO_#{environment.upcase}_PORT"] = fcrepo.port.to_s
28
24
  yield
29
25
  end
30
26
  end
31
27
  end
32
28
  ENV["#{environment}_SERVER_STARTED"] = 'false'
33
29
  end
30
+
31
+ private
32
+
33
+ def load_config(service, environment)
34
+ config_file = environment == 'test' ? "config/#{service}_wrapper_test.yml" : ".#{service}_wrapper"
35
+ return { config: config_file } if File.exist?(config_file)
36
+ {}
37
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "10.0.0.beta1".freeze
2
+ VERSION = "10.0.0.beta2".freeze
3
3
  end
@@ -4,6 +4,15 @@ module ActiveFedora
4
4
  extend ActiveSupport::Autoload
5
5
 
6
6
  autoload :MetadataNode
7
+ autoload :SweetJPLTerms
8
+ autoload :DefaultStrategy
9
+ autoload :DefaultSchema
10
+ autoload :DefaultMetadataClassFactory
11
+
12
+ included do
13
+ class_attribute :metadata_class_factory
14
+ self.metadata_class_factory = DefaultMetadataClassFactory
15
+ end
7
16
 
8
17
  def metadata_node
9
18
  @metadata_node ||= self.class.metadata_schema.new(self)
@@ -17,19 +26,11 @@ module ActiveFedora
17
26
 
18
27
  module ClassMethods
19
28
  def metadata(&block)
20
- metadata_schema.exec_block(&block)
29
+ @metadata_schema = metadata_class_factory.build(self, &block)
21
30
  end
22
31
 
23
32
  def metadata_schema
24
- @metadata_schema ||= MetadataNode(self)
25
- end
26
-
27
- # Make a subclass of MetadataNode named GeneratedMetadataSchema and set its
28
- # parent_class attribute to have the value of the current class.
29
- def MetadataNode(parent_klass)
30
- klass = const_set(:GeneratedMetadataSchema, Class.new(MetadataNode))
31
- klass.parent_class = parent_klass
32
- klass
33
+ @metadata_schema ||= metadata_class_factory.build(self)
33
34
  end
34
35
  end
35
36
  end
@@ -0,0 +1,31 @@
1
+ # This builds classes for metadata nodes (nodes that describe a binary)
2
+ module ActiveFedora::WithMetadata
3
+ class DefaultMetadataClassFactory
4
+ class_attribute :metadata_base_class, :file_metadata_schemas, :file_metadata_strategy
5
+ self.metadata_base_class = MetadataNode
6
+ self.file_metadata_schemas = [DefaultSchema]
7
+ self.file_metadata_strategy = DefaultStrategy
8
+
9
+ class << self
10
+ def build(parent, &block)
11
+ create_class(parent).tap do |resource_class|
12
+ file_metadata_schemas.each do |schema|
13
+ resource_class.apply_schema(schema, file_metadata_strategy)
14
+ end
15
+ resource_class.exec_block(&block) if block_given?
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ # Make a subclass of MetadataNode named GeneratedMetadataSchema and set its
22
+ # parent_class attribute to have the value of the current class.
23
+ def create_class(parent_klass)
24
+ Class.new(metadata_base_class).tap do |klass|
25
+ parent_klass.const_set(:GeneratedMetadataSchema, klass)
26
+ klass.parent_class = parent_klass
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ # These are the default properties defined on a resource that has WithMetadata
2
+ # added to it. This is most commonly used with ActiveFedora::File, when we want
3
+ # to add rdf triples to a non-rdf resource and have them persisted.
4
+ module ActiveFedora::WithMetadata
5
+ class DefaultSchema < ActiveTriples::Schema
6
+ property :label, predicate: ::RDF::RDFS.label
7
+ property :file_name, predicate: ::RDF::Vocab::EBUCore.filename
8
+ property :file_size, predicate: ::RDF::Vocab::EBUCore.fileSize
9
+ property :date_created, predicate: ::RDF::Vocab::EBUCore.dateCreated
10
+ property :has_mime_type, predicate: ::RDF::Vocab::EBUCore.hasMimeType
11
+ property :date_modified, predicate: ::RDF::Vocab::EBUCore.dateModified
12
+ property :byte_order, predicate: SweetJPLTerms.byteOrder
13
+ # This is a server-managed predicate which means Fedora does not let us change it.
14
+ property :file_hash, predicate: ::RDF::Vocab::PREMIS.hasMessageDigest
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveFedora::WithMetadata
2
+ class DefaultStrategy < ActiveTriples::ExtensionStrategy
3
+ # override apply method to check if property already exists or reciever already has predicate defined.
4
+ # Do not add property if the rdf_resource already responds to the property name
5
+ # Do not add property if the rdf_resource already has a property with the same predicate.
6
+ def self.apply(resource, property)
7
+ return if resource.respond_to?(property.name)
8
+ return if resource.properties.any? { |p| p[1].predicate == property.predicate }
9
+ resource.property property.name, property.to_h
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'rdf'
2
+ module ActiveFedora::WithMetadata
3
+ class SweetJPLTerms < RDF::StrictVocabulary('http://sweet.jpl.nasa.gov/2.2/reprDataFormat.owl#')
4
+ # Property definitions
5
+ property :byteOrder,
6
+ comment: ['Byte Order.'.freeze],
7
+ range: 'xsd:string'.freeze,
8
+ label: 'Byte Order'.freeze
9
+ end
10
+ end
@@ -2,6 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::WithMetadata do
4
4
  before do
5
+ class AdditionalSchema < ActiveTriples::Schema
6
+ property :new_property, predicate: ::RDF::URI("http://my.new.property/")
7
+ end
8
+
9
+ ActiveFedora::WithMetadata::DefaultMetadataClassFactory.file_metadata_schemas << AdditionalSchema
10
+
5
11
  class SampleFile < ActiveFedora::File
6
12
  include ActiveFedora::WithMetadata
7
13
 
@@ -13,6 +19,8 @@ describe ActiveFedora::WithMetadata do
13
19
 
14
20
  after do
15
21
  Object.send(:remove_const, :SampleFile)
22
+ Object.send(:remove_const, :AdditionalSchema)
23
+ ActiveFedora::WithMetadata::DefaultMetadataClassFactory.file_metadata_schemas = [ActiveFedora::WithMetadata::DefaultSchema]
16
24
  end
17
25
 
18
26
  let(:file) { SampleFile.new }
@@ -28,6 +36,18 @@ describe ActiveFedora::WithMetadata do
28
36
  it "tracks changes" do
29
37
  expect(file.title_changed?).to be true
30
38
  end
39
+
40
+ context "with defaults" do
41
+ subject { file }
42
+ it { is_expected.to respond_to(:label) }
43
+ it { is_expected.to respond_to(:file_name) }
44
+ it { is_expected.to respond_to(:file_size) }
45
+ it { is_expected.to respond_to(:date_created) }
46
+ it { is_expected.to respond_to(:has_mime_type) }
47
+ it { is_expected.to respond_to(:date_modified) }
48
+ it { is_expected.to respond_to(:byte_order) }
49
+ it { is_expected.to respond_to(:file_hash) }
50
+ end
31
51
  end
32
52
 
33
53
  describe "#save" do
@@ -83,4 +103,9 @@ describe ActiveFedora::WithMetadata do
83
103
  expect(reloaded_file.metadata_node.query(predicate: ::RDF.type).map(&:object)).to include book
84
104
  end
85
105
  end
106
+
107
+ context "when using additional schema" do
108
+ subject { SampleFile.new }
109
+ it { is_expected.to respond_to(:new_property) }
110
+ end
86
111
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::WithMetadata::DefaultMetadataClassFactory do
4
+ let(:parent) { double("Parent") }
5
+
6
+ describe "default class attributes" do
7
+ its(:metadata_base_class) { is_expected.to eq(ActiveFedora::WithMetadata::MetadataNode) }
8
+ its(:file_metadata_schemas) { is_expected.to eq([ActiveFedora::WithMetadata::DefaultSchema]) }
9
+ its(:file_metadata_strategy) { is_expected.to eq(ActiveFedora::WithMetadata::DefaultStrategy) }
10
+ end
11
+
12
+ describe "::build" do
13
+ it "sets MetadataNode to the default schema using the default strategy" do
14
+ expect(parent).to receive(:const_set)
15
+ expect(parent).to receive(:delegate).at_least(8).times
16
+ subject.class.build(parent)
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0.beta1
4
+ version: 10.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-10 00:00:00.000000000 Z
13
+ date: 2016-05-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -553,7 +553,11 @@ files:
553
553
  - lib/active_fedora/versionable.rb
554
554
  - lib/active_fedora/versions_graph.rb
555
555
  - lib/active_fedora/with_metadata.rb
556
+ - lib/active_fedora/with_metadata/default_metadata_class_factory.rb
557
+ - lib/active_fedora/with_metadata/default_schema.rb
558
+ - lib/active_fedora/with_metadata/default_strategy.rb
556
559
  - lib/active_fedora/with_metadata/metadata_node.rb
560
+ - lib/active_fedora/with_metadata/sweet_jpl_terms.rb
557
561
  - lib/generators/active_fedora/config/USAGE
558
562
  - lib/generators/active_fedora/config/config_generator.rb
559
563
  - lib/generators/active_fedora/config/fedora/fedora_generator.rb
@@ -751,6 +755,7 @@ files:
751
755
  - spec/unit/solr_service_spec.rb
752
756
  - spec/unit/sparql_insert_spec.rb
753
757
  - spec/unit/validations_spec.rb
758
+ - spec/unit/with_metadata/default_metadata_class_factory_spec.rb
754
759
  - spec/unit/with_metadata/metadata_node_spec.rb
755
760
  homepage: https://github.com/projecthydra/active_fedora
756
761
  licenses:
@@ -772,7 +777,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
772
777
  version: 1.3.1
773
778
  requirements: []
774
779
  rubyforge_project:
775
- rubygems_version: 2.5.1
780
+ rubygems_version: 2.6.4
776
781
  signing_key:
777
782
  specification_version: 4
778
783
  summary: A convenience libary for manipulating documents in the Fedora Repository.