active-fedora 10.0.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +6 -7
  4. data/.rubocop_todo.yml +55 -0
  5. data/.solr_wrapper +6 -0
  6. data/README.md +1 -3
  7. data/active-fedora.gemspec +6 -11
  8. data/lib/active_fedora/aggregation/list_source.rb +2 -0
  9. data/lib/active_fedora/associations/association_scope.rb +1 -1
  10. data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
  11. data/lib/active_fedora/associations/builder/association.rb +1 -1
  12. data/lib/active_fedora/associations/builder/orders.rb +11 -3
  13. data/lib/active_fedora/associations/collection_association.rb +3 -3
  14. data/lib/active_fedora/associations/contained_finder.rb +2 -2
  15. data/lib/active_fedora/associations/has_many_association.rb +2 -2
  16. data/lib/active_fedora/associations/has_subresource_association.rb +2 -2
  17. data/lib/active_fedora/associations/orders_association.rb +4 -0
  18. data/lib/active_fedora/associations/rdf.rb +2 -0
  19. data/lib/active_fedora/attribute_assignment.rb +0 -1
  20. data/lib/active_fedora/attribute_methods/dirty.rb +1 -1
  21. data/lib/active_fedora/attributes.rb +1 -1
  22. data/lib/active_fedora/base.rb +4 -8
  23. data/lib/active_fedora/change_set.rb +6 -2
  24. data/lib/active_fedora/containers/container.rb +1 -1
  25. data/lib/active_fedora/core.rb +22 -25
  26. data/lib/active_fedora/fedora_attributes.rb +1 -1
  27. data/lib/active_fedora/file/streaming.rb +1 -1
  28. data/lib/active_fedora/file.rb +1 -9
  29. data/lib/active_fedora/indexing.rb +0 -15
  30. data/lib/active_fedora/indexing_service.rb +0 -9
  31. data/lib/active_fedora/loadable_from_json.rb +12 -1
  32. data/lib/active_fedora/nested_attributes.rb +2 -2
  33. data/lib/active_fedora/orders/list_node.rb +2 -2
  34. data/lib/active_fedora/orders/ordered_list.rb +7 -3
  35. data/lib/active_fedora/orders/target_proxy.rb +4 -0
  36. data/lib/active_fedora/querying.rb +1 -1
  37. data/lib/active_fedora/railtie.rb +2 -2
  38. data/lib/active_fedora/rake_support.rb +1 -1
  39. data/lib/active_fedora/rdf/persistence.rb +1 -0
  40. data/lib/active_fedora/rdf.rb +0 -2
  41. data/lib/active_fedora/relation/delegation.rb +4 -0
  42. data/lib/active_fedora/relation/finder_methods.rb +3 -3
  43. data/lib/active_fedora/scoping/named.rb +1 -0
  44. data/lib/active_fedora/solr_hit.rb +0 -13
  45. data/lib/active_fedora/solr_query_builder.rb +24 -13
  46. data/lib/active_fedora/version.rb +1 -1
  47. data/lib/active_fedora.rb +0 -12
  48. data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +11 -0
  49. data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +1 -1
  50. data/lib/generators/active_fedora/model/model_generator.rb +1 -1
  51. data/lib/generators/active_fedora/model/templates/model.rb.erb +4 -4
  52. data/lib/tasks/active_fedora_dev.rake +1 -9
  53. data/spec/config_helper.rb +1 -1
  54. data/spec/integration/associations_spec.rb +23 -24
  55. data/spec/integration/attached_files_spec.rb +18 -8
  56. data/spec/integration/attributes_spec.rb +12 -16
  57. data/spec/integration/autosave_association_spec.rb +6 -6
  58. data/spec/integration/base_spec.rb +3 -3
  59. data/spec/integration/basic_contains_association_spec.rb +1 -1
  60. data/spec/integration/clean_connection_spec.rb +1 -1
  61. data/spec/integration/collection_association_spec.rb +2 -5
  62. data/spec/integration/date_time_properties_spec.rb +1 -16
  63. data/spec/integration/direct_container_spec.rb +12 -12
  64. data/spec/integration/directly_contains_one_association_spec.rb +11 -13
  65. data/spec/integration/eradicate_spec.rb +1 -1
  66. data/spec/integration/fedora_solr_sync_spec.rb +2 -2
  67. data/spec/integration/file_fixity_spec.rb +6 -8
  68. data/spec/integration/file_spec.rb +32 -34
  69. data/spec/integration/generators/solr_generator_spec.rb +7 -10
  70. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +5 -5
  71. data/spec/integration/has_many_associations_spec.rb +9 -11
  72. data/spec/integration/indexing_spec.rb +2 -2
  73. data/spec/integration/indirect_container_spec.rb +11 -12
  74. data/spec/integration/json_serialization_spec.rb +4 -4
  75. data/spec/integration/query_result_builder_spec.rb +9 -21
  76. data/spec/integration/rdf_nested_attributes_spec.rb +7 -7
  77. data/spec/integration/relation_delegation_spec.rb +8 -10
  78. data/spec/integration/relation_spec.rb +13 -16
  79. data/spec/integration/scoped_query_spec.rb +4 -3
  80. data/spec/integration/solr_hit_spec.rb +4 -15
  81. data/spec/integration/versionable_spec.rb +73 -327
  82. data/spec/integration/with_metadata_spec.rb +1 -1
  83. data/spec/spec_helper.rb +52 -4
  84. data/spec/unit/active_fedora_spec.rb +1 -1
  85. data/spec/unit/aggregation/list_source_spec.rb +37 -37
  86. data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
  87. data/spec/unit/association_hash_spec.rb +17 -31
  88. data/spec/unit/attached_files_spec.rb +35 -32
  89. data/spec/unit/attributes_spec.rb +25 -25
  90. data/spec/unit/base_active_model_spec.rb +8 -8
  91. data/spec/unit/base_cma_spec.rb +1 -1
  92. data/spec/unit/base_extra_spec.rb +7 -22
  93. data/spec/unit/base_spec.rb +16 -22
  94. data/spec/unit/callback_spec.rb +2 -2
  95. data/spec/unit/change_set_spec.rb +5 -5
  96. data/spec/unit/checksum_spec.rb +2 -2
  97. data/spec/unit/code_configurator_spec.rb +1 -1
  98. data/spec/unit/core_spec.rb +62 -26
  99. data/spec/unit/default_model_mapper_spec.rb +6 -6
  100. data/spec/unit/fedora_spec.rb +3 -4
  101. data/spec/unit/file_configurator_spec.rb +96 -96
  102. data/spec/unit/file_path_builder_spec.rb +1 -1
  103. data/spec/unit/file_spec.rb +61 -61
  104. data/spec/unit/files_hash_spec.rb +9 -9
  105. data/spec/unit/filter_spec.rb +3 -3
  106. data/spec/unit/finder_methods_spec.rb +5 -5
  107. data/spec/unit/forbidden_attributes_protection_spec.rb +2 -2
  108. data/spec/unit/has_and_belongs_to_many_association_spec.rb +14 -15
  109. data/spec/unit/has_many_association_spec.rb +28 -13
  110. data/spec/unit/indexers/global_indexer_spec.rb +6 -6
  111. data/spec/unit/indexing_service_spec.rb +5 -5
  112. data/spec/unit/indexing_spec.rb +6 -6
  113. data/spec/unit/inheritance_spec.rb +11 -7
  114. data/spec/unit/loadable_from_json_spec.rb +4 -4
  115. data/spec/unit/logger_spec.rb +1 -1
  116. data/spec/unit/model_classifier_spec.rb +5 -5
  117. data/spec/unit/ordered_spec.rb +144 -146
  118. data/spec/unit/orders/list_node_spec.rb +22 -22
  119. data/spec/unit/orders/ordered_list_spec.rb +96 -96
  120. data/spec/unit/orders/reflection_spec.rb +4 -4
  121. data/spec/unit/pathing_spec.rb +4 -4
  122. data/spec/unit/persistence_spec.rb +28 -28
  123. data/spec/unit/property_spec.rb +2 -2
  124. data/spec/unit/query_spec.rb +20 -20
  125. data/spec/unit/rdf/indexing_service_spec.rb +29 -29
  126. data/spec/unit/readonly_spec.rb +5 -4
  127. data/spec/unit/reflection_spec.rb +3 -3
  128. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
  129. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
  130. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
  131. data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
  132. data/spec/unit/serializers_spec.rb +3 -4
  133. data/spec/unit/solr_config_options_spec.rb +13 -16
  134. data/spec/unit/solr_hit_spec.rb +9 -9
  135. data/spec/unit/solr_service_spec.rb +4 -10
  136. data/spec/unit/sparql_insert_spec.rb +2 -2
  137. data/spec/unit/validations_spec.rb +9 -9
  138. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
  139. data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
  140. metadata +18 -122
  141. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  142. data/lib/active_fedora/datastreams.rb +0 -6
  143. data/lib/active_fedora/nom_datastream.rb +0 -67
  144. data/lib/active_fedora/om_datastream.rb +0 -126
  145. data/lib/active_fedora/profile_indexing_service.rb +0 -11
  146. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  147. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -43
  148. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -9
  149. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -158
  150. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  151. data/lib/active_fedora/solr_instance_loader.rb +0 -47
  152. data/solr/config/_rest_managed.json +0 -3
  153. data/solr/config/admin-extra.html +0 -31
  154. data/solr/config/elevate.xml +0 -36
  155. data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
  156. data/solr/config/protwords.txt +0 -21
  157. data/solr/config/schema.xml +0 -372
  158. data/solr/config/scripts.conf +0 -24
  159. data/solr/config/solrconfig.xml +0 -311
  160. data/solr/config/spellings.txt +0 -2
  161. data/solr/config/stopwords.txt +0 -58
  162. data/solr/config/stopwords_en.txt +0 -58
  163. data/solr/config/synonyms.txt +0 -31
  164. data/solr/config/xslt/example.xsl +0 -132
  165. data/solr/config/xslt/example_atom.xsl +0 -67
  166. data/solr/config/xslt/example_rss.xsl +0 -66
  167. data/solr/config/xslt/luke.xsl +0 -337
  168. data/spec/fixtures/damsObjectModel.xml +0 -38
  169. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
  170. data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
  171. data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
  172. data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
  173. data/spec/integration/complex_rdf_datastream_spec.rb +0 -228
  174. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -179
  175. data/spec/integration/ntriples_datastream_spec.rb +0 -203
  176. data/spec/integration/om_datastream_spec.rb +0 -78
  177. data/spec/integration/solr_instance_loader_spec.rb +0 -155
  178. data/spec/samples/hydra-mods_article_datastream.rb +0 -517
  179. data/spec/samples/models/mods_article.rb +0 -9
  180. data/spec/samples/oral_history_sample.xml +0 -38
  181. data/spec/samples/oral_history_xml.xml +0 -35
  182. data/spec/samples/samples.rb +0 -2
  183. data/spec/unit/nom_datastream_spec.rb +0 -60
  184. data/spec/unit/ntriples_datastream_spec.rb +0 -170
  185. data/spec/unit/om_datastream_spec.rb +0 -325
  186. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  187. data/spec/unit/rdf_datastream_spec.rb +0 -84
  188. data/spec/unit/rdf_resource_datastream_spec.rb +0 -204
  189. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -1,67 +0,0 @@
1
- require "nom"
2
-
3
- module ActiveFedora
4
- class NomDatastream < File
5
- include Datastreams::NokogiriDatastreams
6
-
7
- def self.set_terminology(options = {}, &block)
8
- @terminology_options = options || {}
9
- @terminology = block
10
- end
11
-
12
- class << self
13
- attr_reader :terminology_options
14
- end
15
-
16
- class << self
17
- attr_reader :terminology
18
- end
19
-
20
- def self.decorate_ng_xml(xml)
21
- xml.set_terminology terminology_options, &terminology
22
- xml.nom!
23
- xml
24
- end
25
-
26
- def serialize!
27
- self.content = @ng_xml.to_s if @ng_xml
28
- end
29
-
30
- def to_solr
31
- solr_doc = {}
32
-
33
- ng_xml.terminology.flatten.select { |x| x.options[:index] }.each do |term|
34
- term.values.each do |v|
35
- Array(term.options[:index]).each do |index_as|
36
- solr_doc[index_as] ||= []
37
- solr_doc[index_as] << if v.is_a? Nokogiri::XML::Node
38
- v.text
39
- else
40
- v
41
- end
42
- end
43
- end
44
- end
45
-
46
- solr_doc
47
- end
48
-
49
- def method_missing(method, *args, &block)
50
- if ng_xml.respond_to? method
51
- ng_xml.send(method, *args, &block)
52
- else
53
- super
54
- end
55
- end
56
-
57
- def respond_to?(*args)
58
- super || self.class.terminology.respond_to?(*args)
59
- end
60
-
61
- protected
62
-
63
- def default_mime_type
64
- 'text/xml'
65
- end
66
- end
67
- end
@@ -1,126 +0,0 @@
1
- require "om"
2
-
3
- module ActiveFedora
4
- class OmDatastream < File
5
- # before_save do
6
- # if content.blank?
7
- # ActiveFedora::Base.logger.warn "Cowardly refusing to save a datastream with empty content: #{self.inspect}"
8
- # false
9
- # end
10
- # end
11
-
12
- include OM::XML::Document
13
- include OM::XML::TerminologyBasedSolrizer # this adds support for calling .to_solr
14
- include Datastreams::NokogiriDatastreams
15
-
16
- alias om_term_values term_values unless method_defined?(:om_term_values)
17
- alias om_update_values update_values unless method_defined?(:om_update_values)
18
-
19
- def default_mime_type
20
- 'text/xml'
21
- end
22
-
23
- # Indicates that this datastream has metadata content.
24
- # @return true
25
- def metadata?
26
- true
27
- end
28
-
29
- # Return a hash suitable for indexing in solr. Every field name is prefixed with the
30
- # value returned by the +prefix+ method.
31
- def to_solr(solr_doc = {}, opts = {})
32
- prefix = self.prefix(opts[:name])
33
- solr_doc.merge super({}).each_with_object({}) { |(key, value), new| new[[prefix, key].join] = value }
34
- end
35
-
36
- # ** Experimental **
37
- # @return [Boolean] true if either the key for name exists in solr or if its string value exists
38
- # @param [String] name Name of key to look for
39
- # @param [Solr::Document] solr_doc Solr doc to query
40
- def has_solr_name?(name, solr_doc = {})
41
- !solr_doc[name].nil? || !solr_doc[name.to_s].nil?
42
- end
43
-
44
- # ** Experimental **
45
- # @return true if the term_pointer contains an index
46
- # ====Example:
47
- # [:image, {:title_set=>1}, :title] return true
48
- # [:image, :title_set, :title] return false
49
- def is_hierarchical_term_pointer?(*term_pointer)
50
- if term_pointer.length > 1
51
- term_pointer.each do |pointer|
52
- return true if pointer.is_a?(Hash)
53
- end
54
- end
55
- false
56
- end
57
-
58
- # Update field values within the current datastream using {#update_values}, which is a wrapper for {http://rdoc.info/gems/om/1.2.4/OM/XML/TermValueOperators#update_values-instance_method OM::TermValueOperators#update_values}
59
- # Ignores any fields from params that this datastream's Terminology doesn't recognize
60
- #
61
- # @param [Hash] params The params specifying which fields to update and their new values. The syntax of the params Hash is the same as that expected by
62
- # term_pointers must be a valid OM Term pointers (ie. [:name]). Strings will be ignored.
63
- # @param [Hash] _opts This is not currently used by the datastream-level update_indexed_attributes method
64
- #
65
- # Example:
66
- # @mods_ds.update_indexed_attributes( {[{":person"=>"0"}, "role"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} })
67
- # => {"person_0_role"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}}
68
- #
69
- # @mods_ds.to_xml # (the following is an approximation)
70
- # <mods>
71
- # <mods:name type="person">
72
- # <mods:role>
73
- # <mods:roleTerm>role1</mods:roleTerm>
74
- # </mods:role>
75
- # <mods:role>
76
- # <mods:roleTerm>role2</mods:roleTerm>
77
- # </mods:role>
78
- # <mods:role>
79
- # <mods:roleTerm>role3</mods:roleTerm>
80
- # </mods:role>
81
- # </mods:name>
82
- # </mods>
83
- def update_indexed_attributes(params = {}, _opts = {})
84
- if self.class.terminology.nil?
85
- raise "No terminology is set for this OmDatastream class. Cannot perform update_indexed_attributes"
86
- end
87
- # remove any fields from params that this datastream doesn't recognize
88
- # make sure to make a copy of params so not to modify hash that might be passed to other methods
89
- current_params = params.clone
90
- current_params.delete_if do |term_pointer, new_values|
91
- if term_pointer.is_a?(String)
92
- ActiveFedora::Base.logger.warn "WARNING: #{self.class.name} ignoring {#{term_pointer.inspect} => #{new_values.inspect}} because #{term_pointer.inspect} is a String (only valid OM Term Pointers will be used). Make sure your html has the correct field_selector tags in it." if ActiveFedora::Base.logger
93
- true
94
- else
95
- !self.class.terminology.has_term?(*OM.destringify(term_pointer))
96
- end
97
- end
98
-
99
- result = {}
100
- result = update_values(current_params) unless current_params.empty?
101
-
102
- result
103
- end
104
-
105
- def get_values(field_key, _default = [])
106
- term_values(*field_key)
107
- end
108
-
109
- def find_by_terms(*termpointer)
110
- super
111
- end
112
-
113
- # Update values in the datastream's xml
114
- # This wraps {http://rdoc.info/gems/om/1.2.4/OM/XML/TermValueOperators#update_values-instance_method OM::TermValueOperators#update_values} so that returns an error if we have loaded from solr since datastreams loaded that way should be read-only
115
- #
116
- # @example Updating multiple values with a Hash of Term pointers and values
117
- # ds.update_values( {[{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, [{:person=>1}, :family_name]=>"Andronicus", [{"person"=>"1"},:given_name]=>["Titus"],[{:person=>1},:role,:text]=>["otherrole1","otherrole2"] } )
118
- # => {"person_0_role_text"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, "person_1_role_text"=>{"0"=>"otherrole1", "1"=>"otherrole2"}}
119
- def update_values(params = {})
120
- raise "can't modify frozen #{self.class}" if frozen?
121
- ng_xml_will_change!
122
- result = om_update_values(params)
123
- result
124
- end
125
- end
126
- end
@@ -1,11 +0,0 @@
1
- module ActiveFedora
2
- class ProfileIndexingService
3
- def initialize(object)
4
- @object = object
5
- end
6
-
7
- def export
8
- @object.serializable_hash.to_json
9
- end
10
- end
11
- end
@@ -1,158 +0,0 @@
1
- module ActiveFedora
2
- # This class represents a Qualified Dublin Core Datastream. A special case of ActiveFedora::OmDatastream
3
- # The implementation of this class defines the terms from the Qualified Dublin Core specification.
4
- # This implementation features customized xml generators and deserialization routines to handle the
5
- # Fedora Dublin Core XML datastreams structure.
6
- #
7
- # Fields can still be overridden if more specificity is desired (see ActiveFedora::File#fields method).
8
- class QualifiedDublinCoreDatastream < OmDatastream
9
- attr_accessor :fields
10
- class_attribute :class_fields
11
- self.class_fields = []
12
-
13
- set_terminology do |t|
14
- t.root(path: "dc", xmlns: "http://purl.org/dc/terms/")
15
- end
16
-
17
- define_template :creator do |xml, name|
18
- xml.creator do
19
- xml.text(name)
20
- end
21
- end
22
-
23
- # A frozen array of Dublincore Terms.
24
- DCTERMS = [
25
- :abstract,
26
- :accessRights,
27
- :accrualMethod,
28
- :accrualPeriodicity,
29
- :accrualPolicy,
30
- :alternative,
31
- :audience,
32
- :available,
33
- :bibliographicCitation,
34
- :conformsTo,
35
- :contributor,
36
- :coverage,
37
- :created,
38
- :creator,
39
- :date,
40
- :dateAccepted,
41
- :dateCopyrighted,
42
- :dateSubmitted,
43
- :description,
44
- :educationLevel,
45
- :extent,
46
- :hasFormat,
47
- :hasPart,
48
- :hasVersion,
49
- :identifier,
50
- :instructionalMethod,
51
- :isFormatOf,
52
- :isPartOf,
53
- :isReferencedBy,
54
- :isReplacedBy,
55
- :isRequiredBy,
56
- :isVersionOf,
57
- :issued,
58
- :language,
59
- :license,
60
- :mediator,
61
- :medium,
62
- :modified,
63
- :provenance,
64
- :publisher,
65
- :references,
66
- :relation,
67
- :replaces,
68
- :requires,
69
- :rights,
70
- :rightsHolder,
71
- :source,
72
- :spatial,
73
- :subject,
74
- :tableOfContents,
75
- :temporal,
76
- :title,
77
- :type,
78
- :valid
79
- ].freeze # removed :format
80
- DCTERMS.freeze
81
-
82
- # Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
83
- # when this method returns. Each term is marked as a multivalue string.
84
- def initialize(string_or_url = nil)
85
- super
86
- self.fields = {}
87
- DCTERMS.each do |el|
88
- field el, :string, multiple: true
89
- end
90
- end
91
-
92
- # This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
93
- # each field will have the 2 magic methods:
94
- # name=(arg)
95
- # name
96
- #
97
- #
98
- # Calling any of the generated methods marks self as dirty.
99
- #
100
- # 'tupe' is a datatype, currently :string, :text and :date are supported.
101
- #
102
- # opts is an options hash, which will affect the generation of the xml representation of this datastream.
103
- #
104
- # Currently supported modifiers:
105
- # For +QualifiedDublinCorDatastreams+:
106
- # :element_attrs =>{:foo=>:bar} - hash of xml element attributes
107
- # :xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
108
- # :encoding=>foo, or encodings_scheme - causes an xsi:type attribute to be set to 'foo'
109
- # :multiple=>true - mark this field as a multivalue field (on by default)
110
- #
111
- #
112
- # There is quite a good example of this class in use in spec/examples/oral_history.rb
113
- #
114
- # !! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
115
- # you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
116
- # whenever you edit the field's values.
117
- def field(name, tupe = nil, opts = {})
118
- @fields[name.to_s.to_sym] = { type: tupe, values: [] }.merge(opts)
119
- # add term to template
120
- self.class.class_fields << name.to_s
121
- # add term to terminology
122
- return if self.class.terminology.has_term?(name.to_sym)
123
- om_term_opts = { xmlns: "http://purl.org/dc/terms/", namespace_prefix: "dcterms", path: opts[:path] }
124
- term = OM::XML::Term.new(name.to_sym, om_term_opts, self.class.terminology)
125
- self.class.terminology.add_term(term)
126
- term.generate_xpath_queries!
127
- end
128
-
129
- def update_indexed_attributes(params = {}, opts = {})
130
- # if the params are just keys, not an array, make then into an array.
131
- new_params = {}
132
- params.each do |key, val|
133
- if key.is_a? Array
134
- new_params[key] = val
135
- else
136
- new_params[[key.to_sym]] = val
137
- end
138
- end
139
- super(new_params, opts)
140
- end
141
-
142
- def self.xml_template
143
- Nokogiri::XML::Document.parse("<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>")
144
- end
145
-
146
- def to_solr(solr_doc = {}, _opts = {}) # :nodoc:
147
- @fields.each do |field_key, field_info|
148
- things = send(field_key)
149
- next unless things
150
- field_symbol = ActiveFedora.index_field_mapper.solr_name(field_key, type: field_info[:type])
151
- things.val.each do |val|
152
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val)
153
- end
154
- end
155
- solr_doc
156
- end
157
- end
158
- end
@@ -1,43 +0,0 @@
1
- module ActiveFedora::RDF
2
- module DatastreamIndexing
3
- extend ActiveSupport::Concern
4
-
5
- def to_solr(solr_doc = {}, opts = {}) # :nodoc:
6
- super.tap do |new_doc|
7
- solrize_rdf_assertions(opts[:name], new_doc)
8
- end
9
- end
10
-
11
- module ClassMethods
12
- def indexer
13
- ActiveFedora::RDF::IndexingService
14
- end
15
-
16
- def index_config
17
- @index_config ||= ActiveFedora::Indexing::Map.new
18
- end
19
- end
20
-
21
- protected
22
-
23
- def indexing_service
24
- @indexing_service ||= self.class.indexer.new(self)
25
- end
26
-
27
- # Serialize the datastream's RDF relationships to solr
28
- # @param [String] file_path used to prefix the keys in the solr document
29
- # @param [Hash] solr_doc @default an empty Hash
30
- def solrize_rdf_assertions(file_path, solr_doc = {})
31
- solr_doc.merge! indexing_service.generate_solr_document(prefix_method(file_path))
32
- end
33
-
34
- # Returns a function that takes field name and returns a solr document key
35
- def prefix_method(file_path)
36
- ->(field_name) { apply_prefix(field_name, file_path) }
37
- end
38
-
39
- def apply_prefix(name, file_path)
40
- prefix(file_path) + name.to_s
41
- end
42
- end
43
- end
@@ -1,9 +0,0 @@
1
- require 'rdf/ntriples'
2
-
3
- module ActiveFedora
4
- class NtriplesRDFDatastream < RDFDatastream
5
- def serialization_format
6
- :ntriples
7
- end
8
- end
9
- end
@@ -1,158 +0,0 @@
1
- module ActiveFedora
2
- class RDFDatastream < File
3
- include ActiveTriples::NestedAttributes
4
- include RDF::DatastreamIndexing
5
- include ActiveTriples::Properties
6
- include ActiveTriples::Reflection
7
-
8
- delegate :rdf_subject, :set_value, :get_values, :attributes=, to: :resource
9
-
10
- class << self
11
- def rdf_subject(&block)
12
- return @subject_block = block if block_given?
13
-
14
- @subject_block ||= ->(ds) { parent_uri(ds) }
15
- end
16
-
17
- # Trim the last segment off the URI to get the parents uri
18
- def parent_uri(ds)
19
- m = /^(.*)\/[^\/]*$/.match(ds.uri)
20
- if m
21
- m[1]
22
- else
23
- ::RDF::URI.new(nil)
24
- end
25
- end
26
-
27
- ##
28
- # @param [Class] klass an object to set as the resource class, Must be a descendant of
29
- # ActiveTriples::Resource and include ActiveFedora::RDF::Persistence.
30
- #
31
- # @return [Class] the object resource class
32
- def resource_class(klass = nil)
33
- if klass
34
- raise ArgumentError, "#{self} already has a resource_class #{@resource_class}, cannot redefine it to #{klass}" if @resource_class && klass != @resource_class
35
- raise ArgumentError, "#{klass} must be a subclass of ActiveTriples::Resource" unless klass < ActiveTriples::Resource
36
- end
37
-
38
- @resource_class ||= begin
39
- klass = Class.new(klass || ActiveTriples::Resource)
40
- klass.send(:include, RDF::Persistence)
41
- klass
42
- end
43
- end
44
- end
45
-
46
- before_save do
47
- if content.blank?
48
- ActiveFedora::Base.logger.warn "Cowardly refusing to save a datastream with empty content: #{inspect}" if ActiveFedora::Base.logger
49
- false
50
- end
51
- end
52
-
53
- def parent_uri
54
- self.class.parent_uri(self)
55
- end
56
-
57
- def metadata?
58
- true
59
- end
60
-
61
- def content
62
- serialize
63
- end
64
-
65
- def content=(new_content)
66
- resource.clear!
67
- resource << deserialize(new_content)
68
- content
69
- end
70
-
71
- def uri=(uri)
72
- super
73
- resource.set_subject!(parent_uri) if empty_or_blank_subject?
74
- end
75
-
76
- def content_changed?
77
- return false unless instance_variable_defined? :@resource
78
- return true if empty_or_blank_subject? # can't be serialized because a subject hasn't been assigned yet.
79
- @content = serialize
80
- super
81
- end
82
-
83
- def empty_or_blank_subject?
84
- resource.rdf_subject.node? || resource.rdf_subject.value.blank?
85
- end
86
-
87
- def freeze
88
- @resource.freeze
89
- end
90
-
91
- ##
92
- # The resource is the RdfResource object that stores the graph for
93
- # the datastream and is the central point for its relationship to
94
- # other nodes.
95
- #
96
- # set_value, get_value, and property accessors are delegated to this object.
97
- def resource
98
- @resource ||= begin
99
- klass = self.class.resource_class
100
- klass.properties.merge(self.class.properties).each do |_prop, config|
101
- klass.property(config.term,
102
- predicate: config.predicate,
103
- class_name: config.class_name)
104
- end
105
- klass.accepts_nested_attributes_for(*nested_attributes_options.keys) unless nested_attributes_options.blank?
106
- uri_stub = self.class.rdf_subject.call(self)
107
-
108
- r = klass.new(uri_stub)
109
- r.datastream = self
110
- r << deserialize
111
- r
112
- end
113
- end
114
-
115
- alias graph resource
116
-
117
- def refresh_attributes
118
- @resource = nil
119
- end
120
-
121
- ##
122
- # This method allows for delegation.
123
- # This patches the fact that there's no consistent API for allowing delegation - we're matching the
124
- # OmDatastream implementation as our "consistency" point.
125
- # @TODO: We may need to enable deep RDF delegation at one point.
126
- def term_values(*values)
127
- send(values.first)
128
- end
129
-
130
- def update_indexed_attributes(hash)
131
- hash.each do |fields, value|
132
- fields.each do |field|
133
- send("#{field}=", value)
134
- end
135
- end
136
- end
137
-
138
- def serialize
139
- resource.set_subject!(parent_uri) if parent_uri && rdf_subject.node?
140
- resource.dump serialization_format
141
- end
142
-
143
- def deserialize(data = nil)
144
- return ::RDF::Graph.new if new_record? && data.nil?
145
- data ||= remote_content
146
-
147
- # Because datastream_content can return nil, we should check that here.
148
- return ::RDF::Graph.new if data.nil?
149
-
150
- data.force_encoding('utf-8')
151
- ::RDF::Graph.new << ::RDF::Reader.for(serialization_format).new(data)
152
- end
153
-
154
- def serialization_format
155
- raise "you must override the `serialization_format' method in a subclass"
156
- end
157
- end
158
- end
@@ -1,13 +0,0 @@
1
- require 'rdf/rdfxml'
2
-
3
- module ActiveFedora
4
- class RDFXMLDatastream < RDFDatastream
5
- def serialization_format
6
- :rdfxml
7
- end
8
-
9
- def mime_type
10
- 'text/xml'
11
- end
12
- end
13
- end
@@ -1,47 +0,0 @@
1
- module ActiveFedora
2
- class FedoraSolrMismatchError < ActiveFedora::ObjectNotFoundError
3
- def initialize(fedora_id, solr_document_id)
4
- super("Solr ID and Fedora ID do not match; Solr ID=#{solr_document_id}, Fedora ID=#{fedora_id}")
5
- end
6
- end
7
-
8
- # Responsible for loading an ActiveFedora::Base proxy from a Solr document.
9
- class SolrInstanceLoader
10
- attr_reader :context, :id
11
- private :context, :id
12
- def initialize(context, id, solr_doc = nil)
13
- @context = context
14
- @id = id
15
- self.solr_doc = solr_doc
16
- end
17
-
18
- def object
19
- return @object if @object
20
- @object = solr_doc.instantiate_with_json
21
- @object.readonly!
22
- @object.freeze
23
- @object
24
- end
25
-
26
- private
27
-
28
- def solr_doc
29
- @solr_doc ||= begin
30
- self.solr_doc = context.search_by_id(id)
31
- end
32
- end
33
-
34
- def solr_doc=(solr_doc)
35
- unless solr_doc.nil?
36
- solr_doc = ActiveFedora::SolrHit.for(solr_doc)
37
- validate_solr_doc_and_id!(solr_doc)
38
- @solr_doc = solr_doc
39
- end
40
- end
41
-
42
- def validate_solr_doc_and_id!(document)
43
- return if id == document.id
44
- raise ActiveFedora::FedoraSolrMismatchError, id, document.id
45
- end
46
- end
47
- end
@@ -1,3 +0,0 @@
1
- {
2
- "initArgs":{},
3
- "managedList":[]}
@@ -1,31 +0,0 @@
1
- <!--
2
- Licensed to the Apache Software Foundation (ASF) under one or more
3
- contributor license agreements. See the NOTICE file distributed with
4
- this work for additional information regarding copyright ownership.
5
- The ASF licenses this file to You under the Apache License, Version 2.0
6
- (the "License"); you may not use this file except in compliance with
7
- the License. You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software
12
- distributed under the License is distributed on an "AS IS" BASIS,
13
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- See the License for the specific language governing permissions and
15
- limitations under the License.
16
- -->
17
-
18
- <!-- The content of this page will be statically included into the top
19
- of the admin page. Uncomment this as an example to see there the content
20
- will show up.
21
-
22
- <hr>
23
- <i>This line will appear before the first table</i>
24
- <tr>
25
- <td colspan="2">
26
- This row will be appended to the end of the first table
27
- </td>
28
- </tr>
29
- <hr>
30
-
31
- -->