active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -1,70 +0,0 @@
|
|
1
|
-
module ActiveFedora
|
2
|
-
module ContentModel
|
3
|
-
CMODEL_NAMESPACE = "afmodel"
|
4
|
-
CMODEL_PID_SUFFIX = ""
|
5
|
-
|
6
|
-
###Override this, if you prefer your class names serialized some other way
|
7
|
-
def self.sanitized_class_name(klass)
|
8
|
-
klass.name.gsub(/(::)/, '_')
|
9
|
-
end
|
10
|
-
|
11
|
-
# list all of the models asserted by the provided object
|
12
|
-
def self.models_asserted_by(obj)
|
13
|
-
obj.relationships(:has_model)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.best_model_for(obj)
|
17
|
-
best_model_match = nil
|
18
|
-
|
19
|
-
known_models_for(obj).each do |model_value|
|
20
|
-
if model_value <= obj.class
|
21
|
-
# If there is an inheritance structure, use the most specific case.
|
22
|
-
if best_model_match.nil? || best_model_match > model_value
|
23
|
-
best_model_match = model_value
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
best_model_match
|
29
|
-
end
|
30
|
-
|
31
|
-
# returns an array of the model classes that are defined in the current
|
32
|
-
# application that the given object asserts (ie. if the object asserts
|
33
|
-
# a StreamingVideo model but the application doesn't define a
|
34
|
-
# StreamingVideo model, it will be excluded from this list.
|
35
|
-
def self.known_models_for(obj)
|
36
|
-
models_array = []
|
37
|
-
models_asserted_by( obj ).each do |model_uri|
|
38
|
-
m = uri_to_model_class(model_uri)
|
39
|
-
if m
|
40
|
-
models_array << m
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
if models_array.empty?
|
45
|
-
models_array = [default_model(obj)]
|
46
|
-
end
|
47
|
-
|
48
|
-
return models_array
|
49
|
-
end
|
50
|
-
|
51
|
-
### Returns a ruby class to use if no other class could be find to instantiate
|
52
|
-
### Override this method if you need something other than the default strategy
|
53
|
-
def self.default_model(obj)
|
54
|
-
ActiveFedora::Base
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
# Returns an ActiveFedora Model class corresponding to the given uri if one can be found.
|
59
|
-
# Returns false if no corresponding model can be found.
|
60
|
-
def self.uri_to_model_class( uri )
|
61
|
-
rc = Model.from_class_uri(uri)
|
62
|
-
if rc && (rc.superclass == ActiveFedora::Base || rc.ancestors.include?(ActiveFedora::Base))
|
63
|
-
rc
|
64
|
-
else
|
65
|
-
false
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
@@ -1,302 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module/aliasing'
|
2
|
-
module ActiveFedora
|
3
|
-
module DatastreamCollections
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
class_attribute :class_named_datastreams_desc
|
8
|
-
self.class_named_datastreams_desc = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
def inherited(kls) #:nodoc:
|
13
|
-
super
|
14
|
-
kls.class_named_datastreams_desc = kls.class_named_datastreams_desc.dup
|
15
|
-
end
|
16
|
-
|
17
|
-
# Allows for a datastream to be treated like any other attribute of a model class
|
18
|
-
# while enforcing mimeType and/or datastream type (ie. external, managed, etc.) if defined.
|
19
|
-
# ====Examples
|
20
|
-
#
|
21
|
-
# has_datastream :name=>"thumbnails",:prefix => "THUMB",:type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
22
|
-
# has_datastream :name=>"EADs", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
|
23
|
-
# has_datastream :name=>"external_images", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
24
|
-
#
|
25
|
-
# Required Keys in args
|
26
|
-
# :name - name to give this datastream (must be unique)
|
27
|
-
#
|
28
|
-
# Optional Keys in args
|
29
|
-
# :prefix - used to create the DSID plus an index ie. THUMB1, THUMB2. If :prefix is not specified, defaults to :name value in all uppercase
|
30
|
-
# :type - defaults to ActiveFedora::Datastream if you would like content specific class to be used supply it here
|
31
|
-
# :mimeType - if supplied it will ensure any datastreams added are of this type, if not supplied any mimeType is acceptabl e
|
32
|
-
# :controlGroup - possible values "X", "M", "R", or "E" (InlineXML, Managed Content, Redirect, or External Referenced) If controlGroup is 'E' or 'R' it expects a dsLocation be defined when adding the datastream.
|
33
|
-
#
|
34
|
-
# You use the datastream attribute using helper methods created for each datastream name:
|
35
|
-
#
|
36
|
-
# ====Helper Method Examples
|
37
|
-
# thumbnails_append - Append a thumbnail datastream
|
38
|
-
# thumbnails - Get array of thumbnail datastreams
|
39
|
-
# thumbnails_ids - Get array of dsid's for thumbnail datastreams
|
40
|
-
#
|
41
|
-
# When loading the list of datastreams for a name from Fedora it uses the DSID prefix to find them in Fedora
|
42
|
-
def has_datastream(args)
|
43
|
-
unless args.has_key?(:name)
|
44
|
-
return false
|
45
|
-
end
|
46
|
-
unless args.has_key?(:prefix)
|
47
|
-
args.merge!({:prefix=>args[:name].to_s.upcase})
|
48
|
-
end
|
49
|
-
unless class_named_datastreams_desc.has_key?(args[:name])
|
50
|
-
class_named_datastreams_desc[args[:name]] = {}
|
51
|
-
end
|
52
|
-
|
53
|
-
args.merge!({:mimeType=>args[:mime_type]}) if args.has_key?(:mime_type)
|
54
|
-
|
55
|
-
unless args.has_key?(:type)
|
56
|
-
#default to type ActiveFedora::Datastream
|
57
|
-
args[:type] = "ActiveFedora::Datastream"
|
58
|
-
else
|
59
|
-
# stringify class/model names
|
60
|
-
args[:type] = args[:type].name if args[:type].is_a? Class
|
61
|
-
end
|
62
|
-
class_named_datastreams_desc[args[:name]]= args
|
63
|
-
create_named_datastream_finders(args[:name],args[:prefix])
|
64
|
-
create_named_datastream_update_methods(args[:name])
|
65
|
-
end
|
66
|
-
|
67
|
-
# Creates the following helper methods for a datastream name
|
68
|
-
# [datastream_name]_append - Add a named datastream
|
69
|
-
#
|
70
|
-
# ==== Examples for "thumbnails" datastream
|
71
|
-
# thumbnails_append - Append a thumbnail datastream
|
72
|
-
# TODO: Add [datastream_name]_remove
|
73
|
-
def create_named_datastream_update_methods(name)
|
74
|
-
append_file_method_name = "#{name.to_s.downcase}_file_append"
|
75
|
-
append_method_name = "#{name.to_s.downcase}_append"
|
76
|
-
#remove_method_name = "#{name.to_s.downcase}_remove"
|
77
|
-
self.send(:define_method,:"#{append_file_method_name}") do |*args|
|
78
|
-
file,opts = *args
|
79
|
-
opts ||= {}
|
80
|
-
add_named_file_datastream(name,file,opts)
|
81
|
-
end
|
82
|
-
|
83
|
-
self.send(:define_method,:"#{append_method_name}") do |*args|
|
84
|
-
#call add_named_datastream instead of add_file_named_datastream in case not managed datastream
|
85
|
-
add_named_datastream(name,*args)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Creates the following helper methods for a datastream name
|
90
|
-
# [datastream_name] - Returns array of named datastreams
|
91
|
-
# [datastream_name]_ids - Returns array of named datastream dsids
|
92
|
-
#
|
93
|
-
# ==== Examples for "thumbnails" datastream
|
94
|
-
# thumbnails - Get array of thumbnail datastreams
|
95
|
-
# thumbnails_ids - Get array of dsid's for thumbnail datastreams
|
96
|
-
def create_named_datastream_finders(name, prefix)
|
97
|
-
class_eval <<-END, __FILE__, __LINE__
|
98
|
-
def #{name}(opts={})
|
99
|
-
id_array = []
|
100
|
-
keys = datastreams.keys
|
101
|
-
|
102
|
-
id_array = keys.select {|v| v =~ /^#{prefix}\\d+$/}
|
103
|
-
|
104
|
-
if opts[:response_format] == :id_array
|
105
|
-
return id_array
|
106
|
-
else
|
107
|
-
named_ds = []
|
108
|
-
id_array.each do |name|
|
109
|
-
if datastreams.has_key?(name)
|
110
|
-
named_ds.push(datastreams[name])
|
111
|
-
end
|
112
|
-
end
|
113
|
-
return named_ds
|
114
|
-
end
|
115
|
-
end
|
116
|
-
def #{name}_ids
|
117
|
-
#{name}(:response_format => :id_array)
|
118
|
-
end
|
119
|
-
END
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
# Accessor for class variable for hash that stores arguments passed to has_datastream calls within an
|
127
|
-
# ActiveFedora::Base child class.
|
128
|
-
#
|
129
|
-
# has_datastream :name=>"audio_file", :prefix=>"AUDIO", :type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav"
|
130
|
-
# has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
|
131
|
-
#
|
132
|
-
# The above examples result in the following hash
|
133
|
-
# {"audio_file"=>{:prefix=>"AUDIO",:type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav", :controlGroup=>'M'},
|
134
|
-
# "external_images=>{:prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'}}
|
135
|
-
#
|
136
|
-
# This hash is later used when adding a named datastream such as an "audio_file" as defined above.
|
137
|
-
def named_datastreams_desc
|
138
|
-
self.class_named_datastreams_desc ||= {}
|
139
|
-
end
|
140
|
-
|
141
|
-
# Returns array of datastream names defined for this object
|
142
|
-
def datastream_names
|
143
|
-
named_datastreams_desc.keys
|
144
|
-
end
|
145
|
-
|
146
|
-
# Calls add_named_datastream while assuming it will be managed content and sets :blob and :controlGroup values accordingly
|
147
|
-
# ====Parameters
|
148
|
-
# name: Datastream name
|
149
|
-
# file: The file to add for this datastream
|
150
|
-
# opts: Options hash. See +add_named_datastream+ for expected keys and values
|
151
|
-
def add_named_file_datastream(name, file, opts={})
|
152
|
-
opts.merge!({:blob=>file,:controlGroup=>'M'})
|
153
|
-
add_named_datastream(name,opts)
|
154
|
-
end
|
155
|
-
|
156
|
-
# This object is used by [datastream_name]_append helper to add a named datastream
|
157
|
-
# but can also be called directly.
|
158
|
-
# ====Parameters
|
159
|
-
# name: name of datastream to add
|
160
|
-
# opts: hash defining datastream attributes
|
161
|
-
# The following are expected keys in opts hash:
|
162
|
-
# :label => Defaults to the file name
|
163
|
-
# :blob or :file => Required to point to the datastream file being added if managed content
|
164
|
-
# :controlGroup => defaults to 'M' for managed, can also be 'E' external and 'R' for redirected
|
165
|
-
# :content_type => required if the file does not respond to 'content_type' and should match :mimeType in has_datastream definition if defined
|
166
|
-
# :dsLocation => holds uri location of datastream. Required only if :controlGroup is type 'E' or 'R'.
|
167
|
-
# :dsid or :dsId => Optional, and used to update an existing datastream with dsid supplied. Will throw an error if dsid does not exist and does not match prefix pattern for datastream name
|
168
|
-
def add_named_datastream(name,opts={})
|
169
|
-
unless named_datastreams_desc.has_key?(name) && named_datastreams_desc[name].has_key?(:type)
|
170
|
-
raise "Failed to add datastream. Named datastream #{name} not defined for object #{pid}."
|
171
|
-
end
|
172
|
-
|
173
|
-
if opts.has_key?(:mime_type)
|
174
|
-
opts.merge!({:content_type=>opts[:mime_type]})
|
175
|
-
elsif opts.has_key?(:mimeType)
|
176
|
-
opts.merge!({:content_type=>opts[:mimeType]})
|
177
|
-
end
|
178
|
-
opts.merge!(named_datastreams_desc[name])
|
179
|
-
|
180
|
-
label = opts.has_key?(:label) ? opts[:label] : ""
|
181
|
-
|
182
|
-
#only do these steps for managed datastreams
|
183
|
-
unless (opts.has_key?(:controlGroup)&&opts[:controlGroup]!="M")
|
184
|
-
if opts.has_key?(:file)
|
185
|
-
opts.merge!({:blob => opts[:file]})
|
186
|
-
opts.delete(:file)
|
187
|
-
end
|
188
|
-
|
189
|
-
raise "You must define parameter blob for this managed datastream to load for #{pid}" unless opts.has_key?(:blob)
|
190
|
-
|
191
|
-
#if no explicit label and is a file use original file name for label
|
192
|
-
if !opts.has_key?(:label)&&opts[:blob].respond_to?(:original_filename)
|
193
|
-
label = opts[:blob].original_filename
|
194
|
-
end
|
195
|
-
|
196
|
-
if opts[:blob].respond_to?(:content_type)&&!opts[:blob].content_type.nil? && !opts.has_key?(:content_type)
|
197
|
-
opts.merge!({:content_type=>opts[:blob].content_type})
|
198
|
-
end
|
199
|
-
|
200
|
-
raise "The blob must respond to content_type or the hash must have :content_type or :mime_type property set" unless opts.has_key?(:content_type)
|
201
|
-
|
202
|
-
#throw error for mimeType mismatch
|
203
|
-
if named_datastreams_desc[name].has_key?(:mimeType) && !named_datastreams_desc[name][:mimeType].eql?(opts[:content_type])
|
204
|
-
raise "Content type mismatch for add datastream #{name} to #{pid}. Expected: #{named_datastreams_desc[name][:mimeType]}, Actual: #{opts[:content_type]}"
|
205
|
-
end
|
206
|
-
else
|
207
|
-
label = opts[:dsLocation] if (opts.has_key?(:dsLocation))
|
208
|
-
end
|
209
|
-
|
210
|
-
opts.merge!(:dsLabel => label)
|
211
|
-
|
212
|
-
ds = create_datastream(named_datastreams_desc[name][:type], opts[:dsid], opts)
|
213
|
-
#Must be of type datastream
|
214
|
-
assert_kind_of 'datastream', ds, ActiveFedora::Datastream
|
215
|
-
#make sure dsid is nil so that it uses the prefix for mapping purposes
|
216
|
-
#check dsid works for the prefix if it is set
|
217
|
-
if ds.dsid && opts.has_key?(:prefix)
|
218
|
-
raise "dsid supplied (#{ds.dsid}) does not conform to pattern #{opts[:prefix]}[number]" unless ds.dsid =~ /#{opts[:prefix]}[0-9]/
|
219
|
-
end
|
220
|
-
|
221
|
-
add_datastream(ds,opts)
|
222
|
-
end
|
223
|
-
|
224
|
-
# Update an existing named datastream. It has same parameters as add_named_datastream
|
225
|
-
# except the :dsid key is now required.
|
226
|
-
#
|
227
|
-
# ====TODO
|
228
|
-
# Currently requires you to update file if a managed datastream
|
229
|
-
# but could change to allow metadata only updates as well
|
230
|
-
def update_named_datastream(name, opts={})
|
231
|
-
#check that dsid provided matches existing datastream with that name
|
232
|
-
raise "You must define parameter dsid for datastream to update for #{pid}" unless opts.include?(:dsid)
|
233
|
-
raise "Datastream with name #{name} and dsid #{opts[:dsid]} does not exist for #{pid}" unless self.send("#{name}_ids").include?(opts[:dsid])
|
234
|
-
add_named_datastream(name,opts)
|
235
|
-
end
|
236
|
-
|
237
|
-
# Throws an assertion failure unless the object 'o' is kind_of? class 't'
|
238
|
-
# ====Parameters
|
239
|
-
# n: Name of object
|
240
|
-
# o: The object to test
|
241
|
-
# t: The class type to check is kind_of?
|
242
|
-
def assert_kind_of(n,o,t)
|
243
|
-
raise "Assertion failure: #{n}: #{o} is not of type #{t}" unless o.kind_of?(t)
|
244
|
-
end
|
245
|
-
|
246
|
-
# Returns true if the name is a defined named datastream
|
247
|
-
def is_named_datastream?(name)
|
248
|
-
named_datastreams_desc.has_key?(name)
|
249
|
-
end
|
250
|
-
|
251
|
-
# Returns hash of datastream names defined by has_datastream calls mapped to
|
252
|
-
# array of datastream objects that have been added
|
253
|
-
# ====Example
|
254
|
-
# For the following has_datastream entries and a datastream defined for minivan only would be
|
255
|
-
# has_datastream :name=>"minivan", :prefix => "VAN", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'M'
|
256
|
-
# has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
|
257
|
-
#
|
258
|
-
# Returns
|
259
|
-
# {"external_images"=>[],"thumbnails"=>{#<ActiveFedora::Datastream:0x7ffd6512daf8 ...}}
|
260
|
-
def named_datastreams
|
261
|
-
ds_values = {}
|
262
|
-
self.class.class_named_datastreams_desc.keys.each do |name|
|
263
|
-
ds_values.merge!({name=>self.send("#{name}")})
|
264
|
-
end
|
265
|
-
return ds_values
|
266
|
-
end
|
267
|
-
|
268
|
-
# Returns hash of datastream names mapped to an array
|
269
|
-
# of dsid's for named datastream objects
|
270
|
-
# === Example
|
271
|
-
# For the following has_datastream call, assume we have added two datastreams.
|
272
|
-
#
|
273
|
-
# has_datastream :name=>"thumbnails",:prefix => "THUMB",:type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
274
|
-
#
|
275
|
-
# It would then return
|
276
|
-
# {"thumbnails=>["THUMB1", "THUMB2"]}
|
277
|
-
def named_datastreams_ids
|
278
|
-
dsids = {}
|
279
|
-
self.class.class_named_datastreams_desc.keys.each do |name|
|
280
|
-
dsid_array = self.send("#{name}_ids")
|
281
|
-
dsids[name] = dsid_array
|
282
|
-
end
|
283
|
-
return dsids
|
284
|
-
end
|
285
|
-
|
286
|
-
# Returns the hash that stores arguments passed to has_datastream calls within an
|
287
|
-
# ActiveFedora::Base child class.
|
288
|
-
#
|
289
|
-
# has_datastream :name=>"audio_file", :prefix=>"AUDIO", :type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav"
|
290
|
-
# has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
|
291
|
-
#
|
292
|
-
# The above examples result in the following hash
|
293
|
-
# {"audio_file"=>{:prefix=>"AUDIO",:type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav", :controlGroup=>'M'},
|
294
|
-
# "external_images=>{:prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'}}
|
295
|
-
#
|
296
|
-
# This hash is later used when adding a named datastream such as an "audio_file" as defined above.
|
297
|
-
def named_datastreams_desc
|
298
|
-
@named_datastreams_desc ||= self.class.class_named_datastreams_desc
|
299
|
-
end
|
300
|
-
|
301
|
-
end
|
302
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module ActiveFedora
|
4
|
-
class DatastreamHash
|
5
|
-
extend Forwardable
|
6
|
-
|
7
|
-
def_delegators :@hash, *(Hash.instance_methods(false))
|
8
|
-
|
9
|
-
def initialize (obj, &block)
|
10
|
-
@obj = obj
|
11
|
-
@hash = Hash.new &block
|
12
|
-
end
|
13
|
-
|
14
|
-
def [] (key)
|
15
|
-
if key == 'DC' && !has_key?(key)
|
16
|
-
ds = Datastream.new(@obj.inner_object, key, :controlGroup=>'X')
|
17
|
-
self[key] = ds
|
18
|
-
end
|
19
|
-
@hash[key]
|
20
|
-
end
|
21
|
-
|
22
|
-
def []= (key, val)
|
23
|
-
@obj.inner_object.datastreams[key]=val
|
24
|
-
@hash[key]=val
|
25
|
-
end
|
26
|
-
|
27
|
-
def freeze
|
28
|
-
each_value do |datastream|
|
29
|
-
datastream.freeze
|
30
|
-
end
|
31
|
-
@hash.freeze
|
32
|
-
super
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module ActiveFedora
|
2
|
-
# Helps Rubydora create datastreams of the type defined by the ActiveFedora::Base#datastream_class_for_name
|
3
|
-
class DigitalObject < Rubydora::DigitalObject
|
4
|
-
attr_accessor :original_class
|
5
|
-
|
6
|
-
module DatastreamBootstrap
|
7
|
-
def datastream_object_for dsid, options={}, ds_spec=nil
|
8
|
-
# ds_spec is nil when called from Rubydora for existing datastreams, so it should not be autocreated
|
9
|
-
ds_spec ||= (original_class.ds_specs[dsid] || {}).merge(:autocreate=>false)
|
10
|
-
ds = ds_spec.fetch(:type, ActiveFedora::Datastream).new(self, dsid, options)
|
11
|
-
attributes = {}
|
12
|
-
attributes[:asOfDateTime] ||= asOfDateTime if self.respond_to? :asOfDateTime
|
13
|
-
attributes[:dsLabel] = ds_spec[:label] if ds_spec[:label].present?
|
14
|
-
attributes[:controlGroup] = ds_spec[:control_group] if ds_spec[:control_group].present?
|
15
|
-
attributes[:versionable] = ds_spec[:versionable] unless ds_spec[:versionable].nil?
|
16
|
-
if attributes[:controlGroup]=='E'
|
17
|
-
if !ds_spec[:disseminator].present? && ds_spec[:url].present?
|
18
|
-
attributes[:dsLocation]= ds_spec[:url]
|
19
|
-
end
|
20
|
-
elsif attributes[:controlGroup]=='R'
|
21
|
-
attributes[:dsLocation]= ds_spec[:url]
|
22
|
-
end
|
23
|
-
ds.default_attributes = attributes
|
24
|
-
# would rather not load profile here in the call to .new?, so trusting :autocreate attribute
|
25
|
-
if ds_spec[:autocreate] # and ds.new?
|
26
|
-
ds.datastream_will_change!
|
27
|
-
end
|
28
|
-
ds
|
29
|
-
end
|
30
|
-
end
|
31
|
-
include DatastreamBootstrap
|
32
|
-
|
33
|
-
def self.find(original_class, pid)
|
34
|
-
raise ActiveFedora::ObjectNotFoundError.new("Unable to find #{pid.inspect} in fedora. ") unless pid.present?
|
35
|
-
conn = original_class.connection_for_pid(pid)
|
36
|
-
obj = begin
|
37
|
-
super(pid, conn)
|
38
|
-
rescue Rubydora::RecordNotFound
|
39
|
-
raise ActiveFedora::ObjectNotFoundError, "Unable to find '#{pid}' in fedora. See logger for details."
|
40
|
-
end
|
41
|
-
obj.original_class = original_class
|
42
|
-
# PID is not found, but was "well-formed" for its Fedora request. So
|
43
|
-
# an object is instantiated with that PID.
|
44
|
-
raise ActiveFedora::ObjectNotFoundError, "Unable to find '#{pid}' in fedora" if obj.new?
|
45
|
-
obj
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.find_or_initialize(original_class, pid)
|
49
|
-
conn = original_class.connection_for_pid(pid)
|
50
|
-
obj = super(pid, conn)
|
51
|
-
obj.original_class = original_class
|
52
|
-
obj
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|