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
@@ -0,0 +1,70 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class IndexingService
|
3
|
+
attr_reader :object
|
4
|
+
# Object must respond to
|
5
|
+
# create_date
|
6
|
+
# modified_date
|
7
|
+
# has_model
|
8
|
+
# id
|
9
|
+
# to_json
|
10
|
+
# attached_files
|
11
|
+
# []
|
12
|
+
# and it's class must respond to
|
13
|
+
# inspect
|
14
|
+
# outgoing_reflections
|
15
|
+
def initialize(obj)
|
16
|
+
@object = obj
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.profile_solr_name
|
20
|
+
ActiveFedora::SolrService.solr_name("object_profile", :displayable)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def generate_solr_document
|
25
|
+
solr_doc = {}
|
26
|
+
Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable)
|
27
|
+
Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
|
28
|
+
Solrizer.set_field(solr_doc, 'active_fedora_model', object.class.inspect, :stored_sortable)
|
29
|
+
solr_doc.merge!(SolrService::HAS_MODEL_SOLR_FIELD => object.has_model)
|
30
|
+
solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => object.id)
|
31
|
+
solr_doc.merge!(self.class.profile_solr_name => object.to_json)
|
32
|
+
object.attached_files.each do |name, file|
|
33
|
+
solr_doc.merge! file.to_solr(solr_doc, name: name.to_s)
|
34
|
+
end
|
35
|
+
solr_doc = solrize_relationships(solr_doc)
|
36
|
+
solr_doc
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def c_time
|
42
|
+
c_time = object.create_date.present? ? object.create_date : DateTime.now
|
43
|
+
c_time = DateTime.parse(c_time) unless c_time.is_a?(DateTime)
|
44
|
+
c_time
|
45
|
+
end
|
46
|
+
|
47
|
+
def m_time
|
48
|
+
m_time = object.modified_date.present? ? object.modified_date : DateTime.now
|
49
|
+
m_time = DateTime.parse(m_time) unless m_time.is_a?(DateTime)
|
50
|
+
m_time
|
51
|
+
end
|
52
|
+
|
53
|
+
# Serialize the datastream's RDF relationships to solr
|
54
|
+
# @param [Hash] solr_doc @deafult an empty Hash
|
55
|
+
def solrize_relationships(solr_doc = Hash.new)
|
56
|
+
object.class.outgoing_reflections.values.each do |reflection|
|
57
|
+
solr_key = reflection.solr_key
|
58
|
+
Array(object[reflection.foreign_key]).compact.each do |v|
|
59
|
+
::Solrizer::Extractor.insert_solr_field_value(solr_doc, solr_key, v )
|
60
|
+
end
|
61
|
+
end
|
62
|
+
solr_doc
|
63
|
+
end
|
64
|
+
|
65
|
+
def solr_name(*args)
|
66
|
+
ActiveFedora::SolrService.solr_name(*args)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
class LdpResource < Ldp::Resource::RdfSource
|
3
|
+
def build_empty_graph
|
4
|
+
graph_class.new(subject_uri)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.graph_class
|
8
|
+
ActiveTriples::Resource
|
9
|
+
end
|
10
|
+
|
11
|
+
def graph_class
|
12
|
+
self.class.graph_class
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# @param [RDF::Graph] original_graph The graph returned by the LDP server
|
17
|
+
# @return [RDF::Graph] A graph striped of any inlined resources present in the original
|
18
|
+
def build_graph(original_graph)
|
19
|
+
inlined_resources = get.graph.query(predicate: Ldp.contains).map { |x| x.object }
|
20
|
+
|
21
|
+
# ActiveFedora always wants to copy the resources to a new graph because it
|
22
|
+
# forces a cast to FedoraRdfResource
|
23
|
+
graph_without_inlined_resources(original_graph, inlined_resources)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module ActiveFedora
|
2
|
+
module LoadableFromJson
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class SolrBackedMetadataFile
|
6
|
+
def freeze
|
7
|
+
@hash.freeze
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@hash = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def term_values *terminology
|
15
|
+
@hash.fetch(terminology.first, [])
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_indexed_attributes hash
|
19
|
+
hash.each do |k, v|
|
20
|
+
@hash[k.first] = v
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class SolrBackedResource
|
26
|
+
def freeze
|
27
|
+
@hash.freeze
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(model)
|
31
|
+
@model = model
|
32
|
+
@hash = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
@hash.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
# It is expected that the singular filter gets applied after fetching the value from this
|
40
|
+
# resource, so cast everything back to an array.
|
41
|
+
def set_value(k, v)
|
42
|
+
@hash[k] = Array(v)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_values(k)
|
46
|
+
@hash[k]
|
47
|
+
end
|
48
|
+
|
49
|
+
# FakeQuery exists to adapt the hash to the RDF interface used by RDF associations in ActiveFedora
|
50
|
+
class FakeQuery
|
51
|
+
def initialize(values)
|
52
|
+
@values = values || []
|
53
|
+
end
|
54
|
+
|
55
|
+
def enum_statement
|
56
|
+
@values.map {|v| FakeStatement.new(v) }
|
57
|
+
end
|
58
|
+
|
59
|
+
class FakeStatement
|
60
|
+
def initialize(value)
|
61
|
+
@value = value
|
62
|
+
end
|
63
|
+
|
64
|
+
def object
|
65
|
+
@value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def query(args={})
|
71
|
+
predicate = args[:predicate]
|
72
|
+
reflection = reflection(predicate)
|
73
|
+
FakeQuery.new(get_values(reflection))
|
74
|
+
end
|
75
|
+
|
76
|
+
def rdf_subject
|
77
|
+
::RDF::URI.new(nil)
|
78
|
+
end
|
79
|
+
|
80
|
+
def insert(vals)
|
81
|
+
_, pred, val = vals
|
82
|
+
set_value(reflection(pred), [val])
|
83
|
+
end
|
84
|
+
|
85
|
+
def reflection(predicate)
|
86
|
+
@model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }.first
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# @param json [String] json to be parsed into attributes
|
91
|
+
def init_with_json(json)
|
92
|
+
attrs = JSON.parse(json)
|
93
|
+
id = attrs.delete('id')
|
94
|
+
|
95
|
+
@ldp_source = build_ldp_resource(id)
|
96
|
+
@association_cache = {}
|
97
|
+
datastream_keys = self.class.child_resource_reflections.keys
|
98
|
+
datastream_keys.each do |key|
|
99
|
+
attached_files[key] = SolrBackedMetadataFile.new
|
100
|
+
end
|
101
|
+
@resource = SolrBackedResource.new(self.class)
|
102
|
+
self.attributes = attrs.except(datastream_keys)
|
103
|
+
# TODO Should we clear the change tracking, or make this object Read-only?
|
104
|
+
|
105
|
+
run_callbacks :find
|
106
|
+
run_callbacks :initialize
|
107
|
+
freeze
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
data/lib/active_fedora/model.rb
CHANGED
@@ -5,38 +5,24 @@ module ActiveFedora
|
|
5
5
|
# This module mixes various methods into the including class,
|
6
6
|
# much in the way ActiveRecord does.
|
7
7
|
module Model
|
8
|
-
# Takes a Fedora URI for a cModel and returns classname, namespace
|
9
|
-
def self.classname_from_uri(uri)
|
10
|
-
local_path = uri.split('/')[1]
|
11
|
-
parts = local_path.split(':')
|
12
|
-
return parts[-1].split(/_/).map(&:camelize).join('::'), parts[0]
|
13
|
-
end
|
14
8
|
|
15
9
|
# Takes a Fedora URI for a cModel, and returns a
|
16
10
|
# corresponding Model if available
|
17
11
|
# This method should reverse ClassMethods#to_class_uri
|
18
12
|
# @return [Class, False] the class of the model or false, if it does not exist
|
19
|
-
def self.from_class_uri(
|
20
|
-
model_value, pid_ns = classname_from_uri(uri)
|
21
|
-
raise "model URI incorrectly formatted: #{uri}" unless model_value
|
13
|
+
def self.from_class_uri(model_value)
|
22
14
|
|
23
15
|
unless class_exists?(model_value)
|
24
|
-
ActiveFedora::Base.logger.warn "#{model_value} is not a real class" if ActiveFedora::Base.logger
|
25
|
-
return
|
26
|
-
end
|
27
|
-
result = ActiveFedora.class_from_string(model_value)
|
28
|
-
unless result.nil?
|
29
|
-
model_ns = (result.respond_to? :pid_namespace) ? result.pid_namespace : ContentModel::CMODEL_NAMESPACE
|
30
|
-
if model_ns != pid_ns
|
31
|
-
ActiveFedora::Base.logger.warn "Model class namespace '#{model_ns}' does not match uri: '#{uri}'" if ActiveFedora::Base.logger
|
32
|
-
end
|
16
|
+
ActiveFedora::Base.logger.warn "'#{model_value}' is not a real class" if ActiveFedora::Base.logger
|
17
|
+
return nil
|
33
18
|
end
|
34
|
-
|
19
|
+
ActiveFedora.class_from_string(model_value)
|
35
20
|
end
|
36
21
|
|
37
22
|
private
|
38
23
|
|
39
24
|
def self.class_exists?(class_name)
|
25
|
+
return false if class_name.empty?
|
40
26
|
klass = class_name.constantize
|
41
27
|
return klass.is_a?(Class)
|
42
28
|
rescue NameError
|
@@ -64,8 +64,8 @@ module ActiveFedora
|
|
64
64
|
attr_names.each do |association_name|
|
65
65
|
if reflection = reflect_on_association(association_name)
|
66
66
|
reflection.options[:autosave] = true
|
67
|
-
|
68
|
-
## TODO this ought to work, but doesn't seem to do the class
|
67
|
+
add_autosave_association_callbacks(reflection)
|
68
|
+
## TODO this ought to work, but doesn't seem to do the class inheritance right
|
69
69
|
|
70
70
|
nested_attributes_options = self.nested_attributes_options.dup
|
71
71
|
nested_attributes_options[association_name.to_sym] = options
|
@@ -81,8 +81,6 @@ module ActiveFedora
|
|
81
81
|
|
82
82
|
def #{association_name}_attributes=(attributes)
|
83
83
|
assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
|
84
|
-
## in lieu of autosave_association_callbacks just save all of em.
|
85
|
-
send(:#{association_name}).each {|obj| obj.marked_for_destruction? ? obj.destroy : obj.save}
|
86
84
|
end
|
87
85
|
eoruby
|
88
86
|
else
|
@@ -101,7 +99,7 @@ module ActiveFedora
|
|
101
99
|
marked_for_destruction?
|
102
100
|
end
|
103
101
|
|
104
|
-
private
|
102
|
+
private
|
105
103
|
|
106
104
|
# Attribute hash keys that should not be assigned as normal attributes.
|
107
105
|
# These hash keys are nested attributes implementation details.
|
@@ -124,13 +122,14 @@ module ActiveFedora
|
|
124
122
|
end
|
125
123
|
end
|
126
124
|
|
125
|
+
|
127
126
|
association = send(association_name)
|
128
127
|
|
129
128
|
existing_records = if association.loaded?
|
130
129
|
association.to_a
|
131
130
|
else
|
132
131
|
attribute_ids = attributes_collection.map {|a| a['id'] || a[:id] }.compact
|
133
|
-
attribute_ids.present? ? association.to_a.select{ |x| attribute_ids.include?(x.
|
132
|
+
attribute_ids.present? ? association.to_a.select{ |x| attribute_ids.include?(x.id)} : []
|
134
133
|
end
|
135
134
|
|
136
135
|
attributes_collection.each do |attributes|
|
@@ -1,35 +1,25 @@
|
|
1
1
|
require "nom"
|
2
2
|
|
3
3
|
module ActiveFedora
|
4
|
-
class NomDatastream <
|
4
|
+
class NomDatastream < File
|
5
5
|
|
6
|
-
|
6
|
+
include Datastreams::NokogiriDatastreams
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def self.terminology_options
|
14
|
-
@terminology_options
|
15
|
-
end
|
8
|
+
def self.set_terminology(options = {}, &block)
|
9
|
+
@terminology_options = options || {}
|
10
|
+
@terminology = block
|
11
|
+
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def self.terminology_options
|
14
|
+
@terminology_options
|
15
|
+
end
|
20
16
|
|
21
|
-
def self.
|
22
|
-
|
17
|
+
def self.terminology
|
18
|
+
@terminology
|
23
19
|
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
# @param [ActiveFedora::MetadataDatastream] tmpl the Datastream object that you are building @default a new instance of this class
|
28
|
-
# Careful! If you call this from a constructor, be sure to provide something 'ie. self' as the @tmpl. Otherwise, you will get an infinite loop!
|
29
|
-
def self.from_xml(xml, tmpl=nil)
|
30
|
-
ds = self.new nil, nil
|
31
|
-
ds.content = xml.to_s
|
32
|
-
ds
|
21
|
+
def self.default_attributes
|
22
|
+
super.merge(:mimeType => 'text/xml')
|
33
23
|
end
|
34
24
|
|
35
25
|
def self.decorate_ng_xml(xml)
|
@@ -37,7 +27,7 @@ module ActiveFedora
|
|
37
27
|
xml.nom!
|
38
28
|
xml
|
39
29
|
end
|
40
|
-
|
30
|
+
|
41
31
|
def serialize!
|
42
32
|
self.content = @ng_xml.to_s if @ng_xml
|
43
33
|
end
|
@@ -58,7 +48,7 @@ module ActiveFedora
|
|
58
48
|
end
|
59
49
|
end
|
60
50
|
|
61
|
-
solr_doc
|
51
|
+
solr_doc
|
62
52
|
end
|
63
53
|
|
64
54
|
def method_missing method, *args, &block
|
@@ -1,18 +1,14 @@
|
|
1
1
|
require "om"
|
2
2
|
|
3
3
|
module ActiveFedora
|
4
|
-
class OmDatastream <
|
4
|
+
class OmDatastream < File
|
5
5
|
|
6
|
-
before_save do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
6
|
+
# before_save do
|
7
|
+
# if content.blank?
|
8
|
+
# ActiveFedora::Base.logger.warn "Cowardly refusing to save a datastream with empty content: #{self.inspect}"
|
9
|
+
# false
|
10
|
+
# end
|
11
|
+
# end
|
16
12
|
|
17
13
|
include OM::XML::Document
|
18
14
|
include OM::XML::TerminologyBasedSolrizer # this adds support for calling .to_solr
|
@@ -20,177 +16,29 @@ module ActiveFedora
|
|
20
16
|
|
21
17
|
alias_method(:om_term_values, :term_values) unless method_defined?(:om_term_values)
|
22
18
|
alias_method(:om_update_values, :update_values) unless method_defined?(:om_update_values)
|
23
|
-
|
24
|
-
attr_accessor :internal_solr_doc
|
25
19
|
|
26
|
-
def
|
27
|
-
|
20
|
+
def default_mime_type
|
21
|
+
'text/xml'
|
28
22
|
end
|
29
23
|
|
30
|
-
# Indicates that this datastream has metadata content.
|
31
|
-
# @return true
|
24
|
+
# Indicates that this datastream has metadata content.
|
25
|
+
# @return true
|
32
26
|
def metadata?
|
33
27
|
true
|
34
28
|
end
|
35
29
|
|
36
|
-
# ** Experimental **
|
37
|
-
#
|
38
|
-
# This method is called by ActiveFedora::Base.load_instance_from_solr
|
39
|
-
# in order to initialize a nokogiri datastreams values from a solr document.
|
40
|
-
# This method merely sets the internal_solr_doc to the document passed in.
|
41
|
-
# Then any calls to get_values get values from the solr document on demand
|
42
|
-
# instead of directly from the xml stored in Fedora. This should be used
|
43
|
-
# for read-only purposes only, and instances where you want to improve performance by
|
44
|
-
# getting data from solr instead of Fedora.
|
45
|
-
#
|
46
|
-
# See ActiveFedora::Base.load_instance_from_solr and +get_values_from_solr+ for more information.
|
47
|
-
def from_solr(solr_doc)
|
48
|
-
#just initialize internal_solr_doc since any value retrieval will be done via lazy loading on this doc on-demand
|
49
|
-
@internal_solr_doc = solr_doc
|
50
|
-
end
|
51
|
-
|
52
30
|
# Return a hash suitable for indexing in solr. Every field name is prefixed with the
|
53
31
|
# value returned by the +prefix+ method.
|
54
|
-
def to_solr(solr_doc = {})
|
55
|
-
prefix = self.prefix
|
32
|
+
def to_solr(solr_doc = {}, opts = {})
|
33
|
+
prefix = self.prefix(opts[:name])
|
56
34
|
solr_doc.merge super({}).each_with_object({}) { |(key, value), new| new[[prefix,key].join] = value }
|
57
35
|
end
|
58
36
|
|
59
|
-
# This method is called by +get_values+ if this datastream has been initialized by calling from_solr method via
|
60
|
-
# ActiveFedora::Base.load_instance_from_solr. This method retrieves values from a preinitialized @internal_solr_doc instead of xml.
|
61
|
-
# This makes the datastream read-only and this method is not intended to be used in any other case.
|
62
|
-
#
|
63
|
-
# Values are retrieved from the @internal_solr_doc on-demand instead of via xml preloaded into memory.
|
64
|
-
# A term_pointer is passed in and if it contains hierarchical indexes it will detect which solr field values need to be returned.
|
65
|
-
#
|
66
|
-
# ====Example 1 (non-hierarchical term_pointer):
|
67
|
-
#
|
68
|
-
# term_pointer = [:image, :title_set, :title]
|
69
|
-
#
|
70
|
-
# Returns value of "image_title_set_title_t" in @internal_solr_doc
|
71
|
-
#
|
72
|
-
# ====Example 2 (hierarchical term_pointer that contains one or more indexes):
|
73
|
-
# term_pointer = [:image, {:title_set=>1}, :title]
|
74
|
-
#
|
75
|
-
# relevant xml:
|
76
|
-
# <image>
|
77
|
-
# <title_set>
|
78
|
-
# <title>Title 1</title>
|
79
|
-
# </title_set>
|
80
|
-
# </image>
|
81
|
-
# <image>
|
82
|
-
# <title_set>
|
83
|
-
# <title>Title 2</title>
|
84
|
-
# </title_set>
|
85
|
-
# <title_set>
|
86
|
-
# <title>Title 3</title>
|
87
|
-
# </title_set>
|
88
|
-
# </image>
|
89
|
-
#
|
90
|
-
# Repeating element nodes are indexed and will be stored in solr as follows:
|
91
|
-
# image_0_title_set_0_title_t = "Title 1"
|
92
|
-
# image_1_title_set_0_title_t = "Title 2"
|
93
|
-
# image_1_title_set_1_title_t = "Title 3"
|
94
|
-
#
|
95
|
-
# Even though no image element index is specified, only the second image element has two title_set elements so the expected return value is
|
96
|
-
# ["Title 3"]
|
97
|
-
#
|
98
|
-
# While loading from solr the xml hierarchy is not immediately apparent so we must detect first how many image elements with a title_set element exist
|
99
|
-
# and then check which of those elements have a second title element.
|
100
|
-
#
|
101
|
-
# As this nokogiri datastream is indexed in solr, a value at each level in the tree will be stored independently and therefore
|
102
|
-
# if 'image_0_title_set_0_title_t' exists in solr 'image_0_title_set_t' will also exist in solr.
|
103
|
-
# So, we will build up the relevant solr names incrementally for a given term_pointer. The last element in the
|
104
|
-
# solr_name will not contain an index.
|
105
|
-
#
|
106
|
-
# It then will do the following:
|
107
|
-
# Because no index is supplied for :image it will detect which indexes exist in solr
|
108
|
-
# image_0_title_set_t (found key and add 'image_0_title_set' to base solr_name list)
|
109
|
-
# image_1_title_set_t (found key and add 'image_0_title_set' to base solr_name list)
|
110
|
-
# image_2_title_set_t (not found and stop checking indexes for image)
|
111
|
-
# After iteration 1:
|
112
|
-
# bases = ["image_0_title_set","image_1_title_set"]
|
113
|
-
#
|
114
|
-
# Two image nodes were found and next sees index of 1 supplied for title_set so just uses index of 1 building off bases found in previous iteration
|
115
|
-
# image_0_title_set_1_title_t (not found remove 'image_0_title_set' from base solr_name list)
|
116
|
-
# image_1_title_set_1_title_t (found and replace 'image_1_title_set' with new base 'image_1_title_set_1_title')
|
117
|
-
#
|
118
|
-
# After iteration 2:
|
119
|
-
# bases = ["image_1_title_set_1_title"]
|
120
|
-
# It always looks ahead one element so we check if any elements are after title. There are not any other elements so we are done iterating.
|
121
|
-
# returns @internal_solr_doc["image_1_title_set_1_title_t"]
|
122
|
-
# @param [Array] term_pointer Term pointer similar to an xpath ie. [:image, :title_set, :title]
|
123
|
-
# @return [Array] If no values are found an empty Array is returned.
|
124
|
-
def get_values_from_solr(*term_pointer)
|
125
|
-
values = []
|
126
|
-
solr_doc = @internal_solr_doc
|
127
|
-
return values if solr_doc.nil?
|
128
|
-
term = self.class.terminology.retrieve_term(*OM.pointers_to_flat_array(term_pointer, false))
|
129
|
-
#check if hierarchical term pointer
|
130
|
-
if is_hierarchical_term_pointer?(*term_pointer)
|
131
|
-
# if we are hierarchical need to detect all possible node values that exist
|
132
|
-
# we do this by building up the possible solr names parent by parent and/or child by child
|
133
|
-
# if an index is supplied for any node in the pointer it will be used
|
134
|
-
# otherwise it will include all nodes and indexes that exist in solr
|
135
|
-
bases = []
|
136
|
-
#add first item in term_pointer as start of bases
|
137
|
-
# then iterate through possible nodes that might exist
|
138
|
-
term_pointer.first.kind_of?(Hash) ? bases << term_pointer.first.keys.first : bases << term_pointer.first
|
139
|
-
for i in 1..(term_pointer.length-1)
|
140
|
-
#iterate in reverse so that we can modify the bases array while iterating
|
141
|
-
(bases.length-1).downto(0) do |j|
|
142
|
-
current_last = (term_pointer[i].kind_of?(Hash) ? term_pointer[i].keys.first : term_pointer[i])
|
143
|
-
if (term_pointer[i-1].kind_of?(Hash))
|
144
|
-
#just use index supplied instead of trying possibilities
|
145
|
-
index = term_pointer[i-1].values.first
|
146
|
-
solr_name_base = OM::XML::Terminology.term_hierarchical_name({bases[j]=>index},current_last)
|
147
|
-
solr_name = generate_solr_symbol(solr_name_base, term.type)
|
148
|
-
bases.delete_at(j)
|
149
|
-
#insert the new solr name base if found
|
150
|
-
bases.insert(j,solr_name_base) if has_solr_name?(solr_name,solr_doc)
|
151
|
-
else
|
152
|
-
#detect how many nodes exist
|
153
|
-
index = 0
|
154
|
-
current_base = bases[j]
|
155
|
-
bases.delete_at(j)
|
156
|
-
solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
|
157
|
-
solr_name = generate_solr_symbol(solr_name_base, term.type)
|
158
|
-
#check for indexes that exist until we find all nodes
|
159
|
-
while has_solr_name?(solr_name,solr_doc) do
|
160
|
-
#only reinsert if it exists
|
161
|
-
bases.insert(j,solr_name_base)
|
162
|
-
index = index + 1
|
163
|
-
solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
|
164
|
-
solr_name = generate_solr_symbol(solr_name_base, term.type)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
#all existing applicable solr_names have been found and we can now grab all values and build up our value array
|
171
|
-
bases.each do |base|
|
172
|
-
field_name = generate_solr_symbol(base.to_sym, term.type)
|
173
|
-
value = (solr_doc[field_name].nil? ? solr_doc[field_name.to_s]: solr_doc[field_name])
|
174
|
-
unless value.nil?
|
175
|
-
value.is_a?(Array) ? values.concat(value) : values << value
|
176
|
-
end
|
177
|
-
end
|
178
|
-
else
|
179
|
-
#this is not hierarchical and we can simply look for the solr name created using the terms without any indexes
|
180
|
-
generic_field_name_base = OM::XML::Terminology.term_generic_name(*term_pointer)
|
181
|
-
generic_field_name = generate_solr_symbol(generic_field_name_base, term.type)
|
182
|
-
value = (solr_doc[generic_field_name].nil? ? solr_doc[generic_field_name.to_s]: solr_doc[generic_field_name])
|
183
|
-
unless value.nil?
|
184
|
-
value.is_a?(Array) ? values.concat(value) : values << value
|
185
|
-
end
|
186
|
-
end
|
187
|
-
values
|
188
|
-
end
|
189
|
-
|
190
37
|
def generate_solr_symbol(base, data_type)
|
191
|
-
ActiveFedora::SolrService.solr_name([prefix,
|
38
|
+
ActiveFedora::SolrService.solr_name([prefix,base].join, type: data_type)
|
192
39
|
end
|
193
40
|
|
41
|
+
# ** Experimental **
|
194
42
|
#@return [Boolean] true if either the key for name exists in solr or if its string value exists
|
195
43
|
#@param [String] name Name of key to look for
|
196
44
|
#@param [Solr::Document] solr_doc Solr doc to query
|
@@ -198,6 +46,7 @@ module ActiveFedora
|
|
198
46
|
!solr_doc[name].nil? || !solr_doc[name.to_s].nil?
|
199
47
|
end
|
200
48
|
|
49
|
+
# ** Experimental **
|
201
50
|
#@return true if the term_pointer contains an index
|
202
51
|
# ====Example:
|
203
52
|
# [:image, {:title_set=>1}, :title] return true
|
@@ -238,16 +87,16 @@ module ActiveFedora
|
|
238
87
|
# </mods:role>
|
239
88
|
# </mods:name>
|
240
89
|
# </mods>
|
241
|
-
def update_indexed_attributes(params={}, opts={})
|
90
|
+
def update_indexed_attributes(params={}, opts={})
|
242
91
|
if self.class.terminology.nil?
|
243
92
|
raise "No terminology is set for this OmDatastream class. Cannot perform update_indexed_attributes"
|
244
93
|
end
|
245
|
-
# remove any fields from params that this datastream doesn't recognize
|
94
|
+
# remove any fields from params that this datastream doesn't recognize
|
246
95
|
# make sure to make a copy of params so not to modify hash that might be passed to other methods
|
247
96
|
current_params = params.clone
|
248
|
-
current_params.delete_if do |term_pointer,new_values|
|
97
|
+
current_params.delete_if do |term_pointer,new_values|
|
249
98
|
if term_pointer.kind_of?(String)
|
250
|
-
ActiveFedora::Base.logger.warn "WARNING: #{
|
99
|
+
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
|
251
100
|
true
|
252
101
|
else
|
253
102
|
!self.class.terminology.has_term?(*OM.destringify(term_pointer))
|
@@ -258,10 +107,10 @@ module ActiveFedora
|
|
258
107
|
unless current_params.empty?
|
259
108
|
result = update_values( current_params )
|
260
109
|
end
|
261
|
-
|
110
|
+
|
262
111
|
return result
|
263
112
|
end
|
264
|
-
|
113
|
+
|
265
114
|
def get_values(field_key,default=[])
|
266
115
|
term_values(*field_key)
|
267
116
|
end
|
@@ -276,32 +125,12 @@ module ActiveFedora
|
|
276
125
|
#
|
277
126
|
# @example Updating multiple values with a Hash of Term pointers and values
|
278
127
|
# 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"] } )
|
279
|
-
# => {"person_0_role_text"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, "person_1_role_text"=>{"0"=>"otherrole1", "1"=>"otherrole2"}}
|
128
|
+
# => {"person_0_role_text"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, "person_1_role_text"=>{"0"=>"otherrole1", "1"=>"otherrole2"}}
|
280
129
|
def update_values(params={})
|
281
130
|
raise "can't modify frozen #{self.class}" if frozen?
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
ng_xml_will_change!
|
286
|
-
result = om_update_values(params)
|
287
|
-
return result
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
#override OM::XML::term_values so can lazy load from solr if this datastream initialized using +from_solr+
|
292
|
-
def term_values(*term_pointer)
|
293
|
-
# TODO if we can add primary_solr_name onto OmDatastream, we may be able to do away with get_values_from_solr.
|
294
|
-
if @internal_solr_doc
|
295
|
-
#lazy load values from solr on demand
|
296
|
-
get_values_from_solr(*term_pointer)
|
297
|
-
else
|
298
|
-
om_term_values(*term_pointer)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
def reset_profile_attributes
|
303
|
-
super
|
304
|
-
clear_attribute_changes([:ng_xml])
|
131
|
+
ng_xml_will_change!
|
132
|
+
result = om_update_values(params)
|
133
|
+
return result
|
305
134
|
end
|
306
135
|
|
307
136
|
end
|