active-fedora 9.13.0 → 10.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -19
  3. data/lib/active_fedora.rb +0 -17
  4. data/lib/active_fedora/associations.rb +0 -16
  5. data/lib/active_fedora/associations/builder/association.rb +3 -19
  6. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +1 -3
  7. data/lib/active_fedora/attached_files.rb +2 -108
  8. data/lib/active_fedora/attributes.rb +4 -100
  9. data/lib/active_fedora/core.rb +0 -6
  10. data/lib/active_fedora/datastreams.rb +0 -2
  11. data/lib/active_fedora/errors.rb +0 -9
  12. data/lib/active_fedora/file.rb +9 -22
  13. data/lib/active_fedora/file_configurator.rb +1 -32
  14. data/lib/active_fedora/identifiable.rb +0 -6
  15. data/lib/active_fedora/ldp_resource.rb +0 -12
  16. data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
  17. data/lib/active_fedora/query_result_builder.rb +0 -17
  18. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -11
  19. data/lib/active_fedora/rdf/indexing_service.rb +1 -1
  20. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -10
  21. data/lib/active_fedora/relation/finder_methods.rb +2 -21
  22. data/lib/active_fedora/solr_query_builder.rb +0 -16
  23. data/lib/active_fedora/solr_service.rb +2 -89
  24. data/lib/active_fedora/version.rb +1 -1
  25. data/lib/active_fedora/versionable.rb +0 -8
  26. data/spec/config_helper.rb +0 -4
  27. data/spec/integration/attached_files_spec.rb +1 -108
  28. data/spec/integration/attributes_spec.rb +14 -94
  29. data/spec/integration/direct_container_spec.rb +2 -2
  30. data/spec/integration/file_spec.rb +23 -13
  31. data/spec/integration/indexing_spec.rb +4 -4
  32. data/spec/integration/json_serialization_spec.rb +4 -57
  33. data/spec/integration/ntriples_datastream_spec.rb +77 -139
  34. data/spec/integration/relation_delegation_spec.rb +16 -18
  35. data/spec/integration/{model_spec.rb → scoping_spec.rb} +10 -14
  36. data/spec/integration/solr_hit_spec.rb +4 -20
  37. data/spec/integration/solr_instance_loader_spec.rb +1 -13
  38. data/spec/integration/versionable_spec.rb +0 -9
  39. data/spec/samples/models/mods_article.rb +1 -6
  40. data/spec/spec_helper.rb +0 -3
  41. data/spec/unit/attached_files_spec.rb +29 -127
  42. data/spec/unit/attributes_spec.rb +51 -475
  43. data/spec/unit/base_active_model_spec.rb +12 -47
  44. data/spec/unit/base_extra_spec.rb +1 -1
  45. data/spec/unit/code_configurator_spec.rb +2 -10
  46. data/spec/unit/core_spec.rb +3 -18
  47. data/spec/unit/file_configurator_spec.rb +0 -80
  48. data/spec/unit/file_spec.rb +0 -6
  49. data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -7
  50. data/spec/unit/inheritance_spec.rb +0 -12
  51. data/spec/unit/ntriples_datastream_spec.rb +2 -74
  52. data/spec/unit/property_spec.rb +0 -3
  53. data/spec/unit/query_spec.rb +0 -7
  54. data/spec/unit/querying_spec.rb +24 -0
  55. data/spec/unit/rdf/indexing_service_spec.rb +32 -20
  56. data/spec/unit/rdf_resource_datastream_spec.rb +37 -97
  57. data/spec/unit/solr_query_builder_spec.rb +0 -8
  58. data/spec/unit/solr_service_spec.rb +0 -13
  59. metadata +6 -19
  60. data/config/predicate_mappings.yml +0 -51
  61. data/lib/active_fedora/attributes/om_attribute.rb +0 -26
  62. data/lib/active_fedora/attributes/rdf_datastream_attribute.rb +0 -44
  63. data/lib/active_fedora/attributes/stream_attribute.rb +0 -43
  64. data/lib/active_fedora/datastream.rb +0 -9
  65. data/lib/active_fedora/model.rb +0 -31
  66. data/lib/active_fedora/predicates.rb +0 -122
  67. data/lib/active_fedora/simple_datastream.rb +0 -92
  68. data/spec/fixtures/rails_root/config/predicate_mappings.yml +0 -31
  69. data/spec/integration/field_to_solr_name_spec.rb +0 -36
  70. data/spec/unit/base_datastream_management_spec.rb +0 -19
  71. data/spec/unit/model_spec.rb +0 -30
  72. data/spec/unit/predicates_spec.rb +0 -126
  73. data/spec/unit/simple_datastream_spec.rb +0 -101
@@ -1,51 +0,0 @@
1
- # The default namespace maps to the default namespace for generating relationships from solr
2
- :default_namespace: info:fedora/fedora-system:def/relations-external#
3
-
4
- # namespace mappings---
5
- # you can add specific mappings for your institution by providing the following:
6
- # namespace_uri:
7
- # :relationship_symbol: relationship_identifier
8
- #
9
- # For example, if you have the following element in your relationships:
10
- #
11
- # <oai:itemID>oai:example.edu:changeme:500</oai:itemID>
12
- #
13
- # With the last two lines of this file uncommented, the relationships hash of your object will include:
14
- # :oai_item_id => ["info:fedora/oai:example.edu:changeme:500"]
15
- #
16
- :predicate_mapping:
17
- info:fedora/fedora-system:def/relations-external#:
18
- :conforms_to: conformsTo
19
- :has_annotation: hasAnnotation
20
- :has_collection_member: hasCollectionMember
21
- :has_constituent: hasConstituent
22
- :has_dependent: hasDependent
23
- :has_derivation: hasDerivation
24
- :has_description: hasDescription
25
- :has_equivalent: hasEquivalent
26
- :has_metadata: hasMetadata
27
- :has_member: hasMember
28
- :has_model: hasModel
29
- :has_part: hasPart
30
- :has_subset: hasSubset
31
- :has_topic: hasTopic
32
- :is_annotation_of: isAnnotationOf
33
- :is_constituent_of: isConstituentOf
34
- :is_dependent_of: isDependentOf
35
- :is_derivation_of: isDerivationOf
36
- :is_description_of: isDescriptionOf
37
- :is_member_of: isMemberOf
38
- :is_member_of_collection: isMemberOfCollection
39
- :is_metadata_for: isMetadataFor
40
- :is_part_of: isPartOf
41
- :is_subset_of: isSubsetOf
42
- :is_topic_of: isTopicOf
43
- http://fedora.info/definitions/v4/model#:
44
- :is_contractor_of: isContractorOf
45
- :is_deployment_of: isDeploymentOf
46
- :has_service: hasService
47
- :has_model: hasModel
48
- http://www.openarchives.org/OAI/2.0/:
49
- :oai_item_id: itemID
50
- http://projecthydra.org/ns/relations#:
51
- :is_governed_by: isGovernedBy
@@ -1,26 +0,0 @@
1
- module ActiveFedora
2
- # Class for attributes that are delegated to an OmDatastream
3
-
4
- class OmAttribute < StreamAttribute
5
- # @param [ActiveFedora::Base] obj the object that has the attribute
6
- # @param [Object] v value to write to the attribute
7
- def writer(obj, v)
8
- ds = file_for_attribute(obj, delegate_target)
9
- obj.mark_as_changed(field) if obj.value_has_changed?(field, v)
10
- terminology = at || [field]
11
- ds.send(:update_indexed_attributes, terminology => v)
12
- end
13
-
14
- # @param [ActiveFedora::Base] obj the object that has the attribute
15
- # @param [Object] opts extra options that are passed to the target reader
16
- def reader(obj, *opts)
17
- ds = file_for_attribute(obj, delegate_target)
18
- terminology = at || [field]
19
- if terminology.length == 1 && opts.present?
20
- ds.send(terminology.first, *opts)
21
- else
22
- ds.send(:term_values, *terminology)
23
- end
24
- end
25
- end
26
- end
@@ -1,44 +0,0 @@
1
- module ActiveFedora
2
- # Class for attributes that are delegated to a RDFDatastream
3
-
4
- class RdfDatastreamAttribute < StreamAttribute
5
- # @param [ActiveFedora::Base] obj the object that has the attribute
6
- # @param [Object] v value to write to the attribute
7
- def writer(obj, v)
8
- node = file_for_attribute(obj, delegate_target)
9
- obj.mark_as_changed(field) if obj.value_has_changed?(field, v)
10
- term = if at
11
- vals = at.dup
12
- while vals.length > 1
13
- node = node.send(vals.shift)
14
- node = node.build if node.empty?
15
- node = node.first
16
- end
17
- vals.first
18
- else
19
- field
20
- end
21
- node.send("#{term}=", v)
22
- end
23
-
24
- # @param [ActiveFedora::Base] obj the object that has the attribute
25
- def reader(obj)
26
- node = file_for_attribute(obj, delegate_target)
27
- term = if at
28
- vals = at.dup
29
- while vals.length > 1
30
- node = node.send(vals.shift)
31
- node = if node.empty?
32
- node.build
33
- else
34
- node.first
35
- end
36
- end
37
- vals.first
38
- else
39
- field
40
- end
41
- node.send(term)
42
- end
43
- end
44
- end
@@ -1,43 +0,0 @@
1
- module ActiveFedora
2
- # Abstract class for attributes that are delegated to a serialized representation such as a NonRDFSource
3
- #
4
- # @abstract
5
- # @attr [String] delegate_target
6
- # @attr [String] at
7
- # @attr [String] target_class
8
-
9
- class StreamAttribute < DelegatedAttribute
10
- attr_accessor :delegate_target, :at, :target_class
11
-
12
- # @param [Symbol] field the field to find or create
13
- # @param [Hash] args
14
- # @option args [String] :delegate_target the path to the delegate
15
- # @option args [Class] :klass the class to create
16
- # @option args [true,false] :multiple (false) true for multi-value fields
17
- # @option args [Array<Symbol>] :at path to a deep node
18
- def initialize(field, args = {})
19
- super
20
- self.delegate_target = args.fetch(:delegate_target)
21
- self.target_class = args.fetch(:klass)
22
- self.at = args.fetch(:at, nil)
23
- end
24
-
25
- # Gives the primary solr name for a column. If there is more than one indexer on the field definition, it gives the first
26
- def primary_solr_name
27
- @datastream ||= target_class.new
28
- raise NoMethodError, "the file '#{target_class}' doesn't respond to 'primary_solr_name'" unless @datastream.respond_to?(:primary_solr_name)
29
- @datastream.primary_solr_name(field, delegate_target)
30
- end
31
-
32
- def type
33
- raise NoMethodError, "the file '#{target_class}' doesn't respond to 'type'" unless target_class.respond_to?(:type)
34
- target_class.type(field)
35
- end
36
-
37
- private
38
-
39
- def file_for_attribute(obj, delegate_target)
40
- obj.attached_files[delegate_target] || raise(ArgumentError, "Undefined file: `#{delegate_target}' in property #{field}")
41
- end
42
- end
43
- end
@@ -1,9 +0,0 @@
1
- module ActiveFedora
2
- class Datastream < File
3
- extend Deprecation
4
-
5
- def self.inherited(child)
6
- Deprecation.warn child, "ActiveFedora::Datastream is deprecated and will be removed in active-fedora 10.0. Use ActiveFedora::File instead"
7
- end
8
- end
9
- end
@@ -1,31 +0,0 @@
1
- module ActiveFedora
2
- # = ActiveFedora
3
- # This module mixes various methods into the including class,
4
- # much in the way ActiveRecord does.
5
- module Model
6
- # @deprecated
7
- # Convenience method for getting class constant based on a string
8
- # @example
9
- # ActiveFedora::Model.class_from_string("Om")
10
- # => Om
11
- # ActiveFedora::Model.class_from_string("ActiveFedora::RdfNode::TermProxy")
12
- # => ActiveFedora::RdfNode::TermProxy
13
- # @example Search within ActiveFedora::RdfNode for a class called "TermProxy"
14
- # ActiveFedora::Model.class_from_string("TermProxy", ActiveFedora::RdfNode)
15
- # => ActiveFedora::RdfNode::TermProxy
16
- def self.class_from_string(*args)
17
- Deprecation.warn("ActiveFedora::Model.class_from_string has been deprecated and will be removed in ActiveFedora 10.0. Use ActiveFedora::ModelClassifier.class_from_string instead")
18
- ActiveFedora::ModelClassifier.class_from_string(*args)
19
- end
20
-
21
- # @deprecated
22
- # Takes a Fedora URI for a cModel, and returns a
23
- # corresponding Model if available
24
- # This method should reverse ClassMethods#to_class_uri
25
- # @return [Class, False] the class of the model or false, if it does not exist
26
- def self.from_class_uri(model_value)
27
- Deprecation.warn("ActiveFedora::Model.from_class_uri has been deprecated and will be removed in ActiveFedora 10.0. Use ActiveFedora::ModelClassifier.from_class_uri instead")
28
- ActiveFedora::ModelClassifier.new(Array(model_value)).best_model
29
- end
30
- end
31
- end
@@ -1,122 +0,0 @@
1
- module ActiveFedora
2
- module Predicates
3
- def self.short_predicate(predicate)
4
- # for this regex to short-circuit correctly, namespaces must be sorted into descending order by length
5
- if match = /^(#{Predicates.predicate_mappings.keys.sort.reverse.join('|')})(.+)$/.match(predicate.to_str)
6
- namespace = match[1]
7
- predicate = match[2]
8
- Predicates.predicate_mappings[namespace].invert[predicate]
9
- elsif predicate.is_a? ::RDF::URI
10
- predicate.to_s.split('/', 4).last.gsub(/(\/|#)/, '_').underscore
11
- else
12
- raise "Unable to parse predicate: #{predicate}"
13
- end
14
- end
15
-
16
- def self.find_graph_predicate(predicate)
17
- Deprecation.warn("find_graph_predicate has been deprecated and will be removed in ActiveFedora 10.0")
18
- # TODO, these could be cached
19
- case predicate
20
- when :has_model, "hasModel", :hasModel
21
- xmlns = "http://fedora.info/definitions/v4/model#"
22
- begin
23
- rel_predicate = predicate_lookup(predicate, xmlns)
24
- rescue UnregisteredPredicateError
25
- xmlns = nil
26
- rel_predicate = nil
27
- end
28
- else
29
- xmlns = "info:fedora/fedora-system:def/relations-external#"
30
- begin
31
- rel_predicate = predicate_lookup(predicate, xmlns)
32
- rescue UnregisteredPredicateError
33
- xmlns = nil
34
- rel_predicate = nil
35
- end
36
- end
37
-
38
- unless xmlns && rel_predicate
39
- rel_predicate, xmlns = find_predicate(predicate)
40
- end
41
-
42
- vocabularies[xmlns][rel_predicate]
43
- end
44
-
45
- def self.vocabularies(vocabs = {})
46
- Deprecation.warn("vocabularies has been deprecated and will be removed in ActiveFedora 10.0")
47
- @vocabularies ||= vocabs
48
- predicate_mappings.keys.each do |ns|
49
- @vocabularies[ns] = ::RDF::Vocabulary.new(ns) unless @vocabularies.key? ns
50
- end
51
- @vocabularies
52
- end
53
-
54
- # If predicate is a symbol, looks up the predicate in the predicate_mappings
55
- # If predicate is not a Symbol, returns the predicate untouched
56
- # @raise UnregisteredPredicateError if the predicate is a symbol but is not found in the predicate_mappings
57
- def self.predicate_lookup(predicate, namespace = "info:fedora/fedora-system:def/relations-external#")
58
- if predicate.class == Symbol
59
- if predicate_mappings[namespace].key?(predicate)
60
- return predicate_mappings[namespace][predicate]
61
- else
62
- raise ActiveFedora::UnregisteredPredicateError
63
- end
64
- end
65
- predicate
66
- end
67
-
68
- def self.predicate_config=(value)
69
- unless value.nil? || (value.is_a?(Hash) && [:predicate_mapping, :default_namespace].all? { |key| value.key? key })
70
- raise TypeError, "predicate_config must specify :predicate_mapping and :default_namespace"
71
- end
72
- @@predicate_config = value
73
- end
74
-
75
- def self.predicate_config
76
- @@predicate_config ||= ActiveFedora.predicate_config
77
- end
78
-
79
- def self.predicate_namespaces
80
- Deprecation.warn("predicate_namespaces has been deprecated and will be removed in ActiveFedora 10.0")
81
- predicate_config[:predicate_namespaces] ||= {}
82
- end
83
-
84
- def self.predicate_mappings
85
- predicate_config[:predicate_mapping]
86
- end
87
-
88
- def self.default_predicate_namespace
89
- predicate_config[:default_namespace]
90
- end
91
-
92
- def self.find_predicate(predicate)
93
- predicate_mappings.each do |namespace, predicates|
94
- if predicates.fetch(predicate, nil)
95
- return predicates[predicate], namespace
96
- end
97
- end
98
- raise ActiveFedora::UnregisteredPredicateError, "Unregistered predicate: #{predicate.inspect}"
99
- end
100
-
101
- # Add/Modify predicates without destroying the other predicate configs
102
- #
103
- # @example
104
- # ActiveFedora::Predicates.set_predicates({
105
- # "http://projecthydra.org/ns/relations#"=>{has_profile:"hasProfile"},
106
- # "info:fedora/fedora-system:def/relations-external#"=>{
107
- # references:"references",
108
- # has_derivation: "cameFrom"
109
- # },
110
- # })
111
- def self.set_predicates(new_predicates)
112
- predicate_config = ActiveFedora::Predicates.predicate_config
113
- new_predicates.each_pair do |ns, predicate_confs|
114
- predicate_config[:predicate_mapping][ns] ||= {}
115
- predicate_confs.each_pair do |property, value|
116
- predicate_config[:predicate_mapping][ns][property] = value
117
- end
118
- end
119
- predicate_config
120
- end
121
- end
122
- end
@@ -1,92 +0,0 @@
1
- module ActiveFedora
2
- # This class represents a simple xml datastream.
3
- class SimpleDatastream < OmDatastream
4
- extend Deprecation
5
- class_attribute :class_fields
6
- attr_accessor :fields
7
- self.class_fields = []
8
-
9
- set_terminology do |t|
10
- t.root(path: "fields", xmlns: nil)
11
- end
12
-
13
- define_template :creator do |xml, name|
14
- xml.creator do
15
- xml.text(name)
16
- end
17
- end
18
-
19
- # Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
20
- # when this method returns. Each term is marked as a multivalue string.
21
- def initialize(digital_object = nil, dsid = nil, options = {}, &block)
22
- Deprecation.warn(SimpleDatastream, "ActiveFedora::SimpleDatastream is deprecated and will be removed in ActiveFedora 10.0")
23
- self.fields = {}
24
- super
25
- end
26
-
27
- # This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
28
- # each field will have the 2 magic methods:
29
- # name=(arg)
30
- # name
31
- #
32
- #
33
- # 'datatype' is a datatype, currently :string, :integer and :date are supported.
34
- #
35
- # opts is an options hash, which will affect the generation of the xml representation of this datastream.
36
- #
37
- # Currently supported modifiers:
38
- # For +SimpleDatastream+:
39
- # :element_attrs =>{:foo=>:bar} - hash of xml element attributes
40
- # :xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
41
- # :encoding=>foo, or encodings_scheme - causes an xsi:type attribute to be set to 'foo'
42
- # :multiple=>true - mark this field as a multivalue field (on by default)
43
- #
44
- #
45
- # There is quite a good example of this class in use in spec/examples/oral_history.rb
46
- #
47
- # !! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
48
- # you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
49
- # whenever you edit the field's values.
50
- def field(name, datatype = :string, opts = {})
51
- @fields[name.to_s.to_sym] = { type: datatype, values: [] }.merge(opts)
52
- # add term to template
53
- self.class.class_fields << name.to_s
54
- # add term to terminology
55
- return if self.class.terminology.has_term?(name.to_sym)
56
- term = OM::XML::Term.new(name.to_sym, { type: datatype }, self.class.terminology)
57
- self.class.terminology.add_term(term)
58
- term.generate_xpath_queries!
59
- end
60
-
61
- def update_indexed_attributes(params = {}, opts = {})
62
- raise "can't modify frozen #{self.class}" if frozen?
63
- # if the params are just keys, not an array, make then into an array.
64
- new_params = {}
65
- params.each do |key, val|
66
- if key.is_a? Array
67
- new_params[key] = val
68
- else
69
- new_params[[key.to_sym]] = val
70
- end
71
- end
72
- super(new_params, opts)
73
- end
74
-
75
- def self.xml_template
76
- Nokogiri::XML::Document.parse("<fields/>")
77
- end
78
-
79
- def to_solr(solr_doc = {}, _opts = {}) # :nodoc:
80
- @fields.each do |field_key, field_info|
81
- next if field_key == :location ## FIXME HYDRA-825
82
- things = send(field_key)
83
- next unless things
84
- field_symbol = ActiveFedora.index_field_mapper.solr_name(field_key, type: field_info[:type])
85
- things.val.each do |val|
86
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val.to_s)
87
- end
88
- end
89
- solr_doc
90
- end
91
- end
92
- end
@@ -1,31 +0,0 @@
1
- :default_namespace: info:fedora/fedora-system:def/relations-external#
2
-
3
- :predicate_mapping:
4
- info:fedora/fedora-system:def/relations-external#:
5
- :is_derivation_of: isDerivationOf
6
- :is_metadata_for: isMetadataFor
7
- :is_member_of_collection: isMemberOfCollection
8
- :has_derivation: hasDerivation
9
- :is_annotation_of: isAnnotationOf
10
- :is_constituent_of: isConstituentOf
11
- :is_dependent_of: isDependentOf
12
- :has_collection_member: hasCollectionMember
13
- :has_annotation: hasAnnotation
14
- :has_constituent: hasConstituent
15
- :has_dependent: hasDependent
16
- :is_part_of: isPartOf
17
- :has_equivalent: hasEquivalent
18
- :is_subset_of: isSubsetOf
19
- :is_description_of: isDescriptionOf
20
- :is_member_of: isMemberOf
21
- :has_model: hasModel
22
- :conforms_to: conformsTo
23
- :has_metadata: hasMetadata
24
- :has_subset: hasSubset
25
- :has_description: hasDescription
26
- :has_part: hasPart
27
- :has_member: hasMember
28
- http://fedora.info/definitions/v4/model#:
29
- :has_model: hasModel
30
- # http://www.openarchives.org/OAI/2.0/:
31
- # :oai_item_id: itemID