cul_scv_hydra 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/app/models/bag_aggregator.rb +3 -2
  2. data/app/models/concerns/cul.rb +7 -0
  3. data/{lib/cul_scv_hydra/active_fedora.rb → app/models/concerns/cul/scv/hydra/models.rb} +4 -5
  4. data/{lib/cul_scv_hydra/active_fedora/model → app/models/concerns/cul/scv/hydra/models}/aggregator.rb +3 -3
  5. data/{lib/cul_scv_hydra/active_fedora/model → app/models/concerns/cul/scv/hydra/models}/common.rb +36 -9
  6. data/{lib/cul_scv_hydra/active_fedora/model → app/models/concerns/cul/scv/hydra/models}/resource.rb +2 -2
  7. data/app/models/content_aggregator.rb +3 -2
  8. data/app/models/cul/scv/hydra/datastreams/dc_metadata.rb +109 -0
  9. data/app/models/cul/scv/hydra/datastreams/mods_document.rb +157 -0
  10. data/{lib/cul_scv_hydra/active_fedora/model → app/models/cul/scv/hydra/datastreams}/struct_metadata.rb +10 -4
  11. data/app/models/dcdocument.rb +2 -1
  12. data/app/models/generic_aggregator.rb +4 -3
  13. data/app/models/generic_object.rb +3 -2
  14. data/app/models/generic_resource.rb +2 -1
  15. data/app/models/jp2_image_aggregator.rb +3 -2
  16. data/app/models/mets_structured_aggregator.rb +3 -2
  17. data/app/models/resource.rb +3 -2
  18. data/app/models/static_audio_aggregator.rb +3 -2
  19. data/app/models/static_image_aggregator.rb +3 -2
  20. data/bin/rails +12 -0
  21. data/lib/cul_scv_hydra.rb +0 -1
  22. data/lib/cul_scv_hydra/engine.rb +15 -0
  23. data/lib/cul_scv_hydra/om.rb +0 -2
  24. data/lib/cul_scv_hydra/om/standard_mods.rb +8 -0
  25. data/lib/cul_scv_hydra/version.rb +1 -1
  26. data/lib/tasks/cmodel.rake +11 -2
  27. metadata +29 -61
  28. data/lib/cul_scv_hydra/active_fedora/model.rb +0 -9
  29. data/lib/cul_scv_hydra/active_fedora/model/nokogiri_datastreams.rb +0 -142
  30. data/lib/cul_scv_hydra/om/dc_metadata.rb +0 -102
  31. data/lib/cul_scv_hydra/om/scv_mods_document.rb +0 -150
@@ -1,12 +1,13 @@
1
1
  require "active-fedora"
2
2
  require "active_fedora_finders"
3
+ require "hydra-core"
3
4
  class BagAggregator < ::ActiveFedora::Base
4
5
  extend ActiveModel::Callbacks
5
6
  include ::ActiveFedora::Finders
6
7
  include ::ActiveFedora::DatastreamCollections
7
8
  include ::Hydra::ModelMethods
8
- include Cul::Scv::Hydra::ActiveFedora::Model::Common
9
- include Cul::Scv::Hydra::ActiveFedora::Model::Aggregator
9
+ include Cul::Scv::Hydra::Models::Common
10
+ include Cul::Scv::Hydra::Models::Aggregator
10
11
 
11
12
  alias :file_objects :resources
12
13
 
@@ -0,0 +1,7 @@
1
+ module Cul
2
+ extend ActiveSupport::Autoload
3
+ autoload :'Scv::Hydra::Models', 'cul/scv/hydra/models'
4
+ autoload :'Scv::Hydra::Models::Common', 'cul/scv/hydra/models/common'
5
+ autoload :'Scv::Hydra::Models::Aggregator', 'cul/scv/hydra/models/aggregator'
6
+ autoload :'Scv::Hydra::Models::Resource', 'cul/scv/hydra/models/resource'
7
+ end
@@ -3,9 +3,9 @@ require "cul_scv_hydra/om"
3
3
  require 'uri'
4
4
  require 'rdf'
5
5
  module Cul
6
- module Scv
7
- module Hydra
8
- module ActiveFedora
6
+ module Scv
7
+ module Hydra
8
+ module Models
9
9
  AGGREGATOR_TYPE = (URI.parse("http://purl.oclc.org/NET/CUL/Aggregator"))
10
10
  RESOURCE_TYPE = (URI.parse("http://purl.oclc.org/NET/CUL/Resource"))
11
11
  MEMBER_QUERY = <<-SPARQL
@@ -14,5 +14,4 @@ module Cul
14
14
  end
15
15
  end
16
16
  end
17
- end
18
- require 'cul_scv_hydra/active_fedora/model.rb'
17
+ end
@@ -1,15 +1,15 @@
1
- module Cul::Scv::Hydra::ActiveFedora::Model
1
+ module Cul::Scv::Hydra::Models
2
2
  module Aggregator
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- has_metadata :name => "structMetadata", :type=>Cul::Scv::Hydra::ActiveFedora::Model::StructMetadata, :versionable => true, :controlGroup => 'M'
6
+ has_metadata :name => "structMetadata", :type=>Cul::Scv::Hydra::Datastreams::StructMetadata, :versionable => true, :controlGroup => 'M'
7
7
  has_many :parts, :property => :cul_member_of, :class_name=>'ActiveFedora::Base'
8
8
  after_create :aggregator!
9
9
  end
10
10
 
11
11
  def aggregator!
12
- add_relationship(:rdf_type, Cul::Scv::Hydra::ActiveFedora::AGGREGATOR_TYPE.to_s)
12
+ add_relationship(:rdf_type, Cul::Scv::Hydra::Models::AGGREGATOR_TYPE.to_s)
13
13
  @metadata_is_dirty = true
14
14
  self.save
15
15
  end
@@ -1,15 +1,18 @@
1
1
  require 'active-fedora'
2
2
  require 'uri'
3
- module Cul::Scv::Hydra::ActiveFedora::Model
3
+ module Cul::Scv::Hydra::Models
4
4
  module Common
5
5
  extend ActiveSupport::Concern
6
-
6
+ DC_SPEC = {
7
+ :name => "DC", :type=>Cul::Scv::Hydra::Datastreams::DCMetadata,
8
+ :versionable => true, :label => 'Dublin Core Record for this object'
9
+ }
7
10
  included do
8
11
  define_model_callbacks :create
9
-
10
12
  has_and_belongs_to_many :containers, :property=>:cul_member_of, :class_name=>'ActiveFedora::Base'
11
- has_metadata :name => "DC", :type=>Cul::Scv::Hydra::Om::DCMetadata, :versionable => true
12
- has_metadata :name => "descMetadata", :type=>Cul::Scv::Hydra::Om::ModsDocument, :versionable => true
13
+ has_metadata :name => "DC", :type=>Cul::Scv::Hydra::Datastreams::DCMetadata, :versionable => true
14
+ #self.ds_specs['DC'] = DC_SPEC
15
+ has_metadata :name => "descMetadata", :type=>Cul::Scv::Hydra::Datastreams::ModsDocument, :versionable => true
13
16
  has_metadata :name => "rightsMetadata", :type=>::Hydra::Datastream::RightsMetadata, :versionable => true
14
17
 
15
18
  end
@@ -18,6 +21,31 @@ module Common
18
21
  def pid_namespace
19
22
  'ldpd'
20
23
  end
24
+
25
+ # override a buggy impl in AF
26
+ def has_datastream(args)
27
+ unless args.has_key?(:name)
28
+ return false
29
+ end
30
+ unless args.has_key?(:prefix)
31
+ args.merge!({:prefix=>args[:name].to_s.upcase})
32
+ end
33
+ unless class_named_datastreams_desc.has_key?(args[:name])
34
+ class_named_datastreams_desc[args[:name]] = {}
35
+ end
36
+
37
+ args.merge!({:mimeType=>args[:mime_type]}) if args.has_key?(:mime_type)
38
+
39
+ unless class_named_datastreams_desc[args[:name]].has_key?(:type)
40
+ #default to type ActiveFedora::Datastream
41
+ args[:type] ||= ActiveFedora::Datastream
42
+ end
43
+ args[:type] = args[:type].constantize if args[:type].is_a? String
44
+ raise args[:type] unless args[:type].name
45
+ class_named_datastreams_desc[args[:name]]= args
46
+ create_named_datastream_finders(args[:name],args[:prefix])
47
+ create_named_datastream_update_methods(args[:name])
48
+ end
21
49
  end
22
50
 
23
51
  def rdf_type
@@ -102,15 +130,15 @@ module Common
102
130
  end
103
131
 
104
132
  def index_type_label
105
- riquery = Cul::Scv::Hydra::ActiveFedora::MEMBER_QUERY.gsub(/%PID%/, self.pid)
133
+ riquery = Cul::Scv::Hydra::Models::MEMBER_QUERY.gsub(/%PID%/, self.pid)
106
134
  begin
107
135
  docs = ::ActiveFedora::Base.connection_for_pid(self.pid).find_by_sparql riquery
108
136
  rescue Exception=>e
109
137
  docs = self.parts
110
138
  end
111
- if docs.length == 0
139
+ if docs.size == 0
112
140
  label = "EMPTY"
113
- elsif docs.length == 1
141
+ elsif docs.size == 1
114
142
  label = "SINGLE PART"
115
143
  else
116
144
  label = "MULTIPART"
@@ -180,7 +208,6 @@ module Common
180
208
  params.each_pair do |dsid, ds_params|
181
209
  if datastreams.include?(dsid)
182
210
  verify_params = ds_params.dup
183
- current_indexed_attributes = {}
184
211
  changed = false
185
212
  verify_params.each { |pointer, values|
186
213
  changed ||= value_changed?(datastreams[dsid],pointer,values)
@@ -1,4 +1,4 @@
1
- module Cul::Scv::Hydra::ActiveFedora::Model
1
+ module Cul::Scv::Hydra::Models
2
2
  module Resource
3
3
  extend ActiveSupport::Concern
4
4
  # constants #
@@ -35,7 +35,7 @@ module Resource
35
35
  end
36
36
 
37
37
  def resource!
38
- add_relationship(:rdf_type, Cul::Scv::Hydra::ActiveFedora::RESOURCE_TYPE.to_s)
38
+ add_relationship(:rdf_type, Cul::Scv::Hydra::Models::RESOURCE_TYPE.to_s)
39
39
  @metadata_is_dirty = true
40
40
  update
41
41
  end
@@ -1,11 +1,12 @@
1
1
  require "active-fedora"
2
+ require "active_fedora_finders"
2
3
  class ContentAggregator < ::ActiveFedora::Base
3
4
  extend ActiveModel::Callbacks
4
5
  include ::ActiveFedora::Finders
5
6
  include ::ActiveFedora::DatastreamCollections
6
7
  include ::Hydra::ModelMethods
7
- include Cul::Scv::Hydra::ActiveFedora::Model::Common
8
- include Cul::Scv::Hydra::ActiveFedora::Model::Aggregator
8
+ include Cul::Scv::Hydra::Models::Common
9
+ include Cul::Scv::Hydra::Models::Aggregator
9
10
 
10
11
  alias :file_objects :resources
11
12
 
@@ -0,0 +1,109 @@
1
+ require 'active-fedora'
2
+ module Cul
3
+ module Scv
4
+ module Hydra
5
+ module Datastreams
6
+ class DCMetadata < ::ActiveFedora::OmDatastream
7
+
8
+ after_save :action_after_save
9
+ set_terminology do |t|
10
+ t.root(:path=>"dc", :namespace_prefix=>"oai_dc",
11
+ "xmlns:oai_dc"=>"http://www.openarchives.org/OAI/2.0/oai_dc/",
12
+ "xmlns:dc"=>"http://purl.org/dc/elements/1.1/",
13
+ :schema=>"http://www.openarchives.org/OAI/2.0/oai_dc.xsd")
14
+ t.dc_contributor(:path=>"contributor",
15
+ :namespace_prefix=>"dc",
16
+ :index_as=>[:displayable, :searchable])
17
+ t.dc_coverage(:path=>"coverage",
18
+ :namespace_prefix=>"dc",
19
+ :index_as=>[:displayable, :searchable])
20
+ t.dc_creator(:path=>"creator",
21
+ :namespace_prefix=>"dc",
22
+ :index_as=>[:displayable, :searchable])
23
+ t.dc_date(:path=>"date",
24
+ :namespace_prefix=>"dc",
25
+ :index_as=>[:displayable, :searchable])
26
+ t.dc_description(:path=>"description",
27
+ :namespace_prefix=>"dc",
28
+ :index_as=>[:displayable, :searchable])
29
+ t.dc_format(:path=>"format",
30
+ :namespace_prefix=>"dc",
31
+ :index_as=>[:displayable, :searchable])
32
+ t.dc_identifier(:path=>"identifier",
33
+ :namespace_prefix=>"dc",
34
+ :type=>:string,
35
+ :index_as=>[:symbol])
36
+ t.dc_language(:path=>"language",
37
+ :namespace_prefix=>"dc",
38
+ :index_as=>[:displayable, :searchable])
39
+ t.dc_publisher(:path=>"publisher",
40
+ :namespace_prefix=>"dc",
41
+ :index_as=>[:displayable, :searchable])
42
+ t.dc_relation(:path=>"relation",
43
+ :namespace_prefix=>"dc",
44
+ :index_as=>[:displayable, :searchable])
45
+ t.dc_rights(:path=>"rights",
46
+ :namespace_prefix=>"dc",
47
+ :index_as=>[:displayable, :searchable])
48
+ t.dc_source(:path=>"source",
49
+ :namespace_prefix=>"dc",
50
+ :index_as=>[:displayable, :searchable])
51
+ t.dc_subject(:path=>"subject",
52
+ :namespace_prefix=>"dc",
53
+ :index_as=>[:displayable, :searchable])
54
+ t.dc_title(:path=>"title",
55
+ :namespace_prefix=>"dc",
56
+ :index_as=>[:displayable, :searchable])
57
+ t.dc_type(:path=>"type",
58
+ :namespace_prefix=>"dc",
59
+ :index_as=>[:displayable, :searchable])
60
+ end
61
+
62
+ def self.xml_template
63
+
64
+ Nokogiri::XML::Document.parse(<<-src
65
+ <oai_dc:dc
66
+ xmlns:oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/'
67
+ xmlns:dc='http://purl.org/dc/elements/1.1/'
68
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
69
+ xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'></oai_dc:dc>
70
+ src
71
+ )
72
+ end
73
+ # Because FCRepo 3.5+ modifies DC on saves (to ensure that PID is a dc:identifier value),
74
+ # this datastream's content must be reloaded after saves
75
+ def action_after_save
76
+ @content = nil
77
+ @ng_xml = nil
78
+ remove_instance_variable(:@ng_xml)
79
+ end
80
+
81
+ def prefix
82
+ if ::ActiveFedora::VERSION >= '8'
83
+ Rails.logger.warn("the prefix method of #{self.class.name} was overriden to maintain backwards compatibility")
84
+ end
85
+ ''
86
+ end
87
+
88
+ def method_missing method, *args
89
+ query = false
90
+ _mname = method.id2name
91
+ if _mname[-1,1] == '?'
92
+ query = true
93
+ _mname = _mname[0,_mname.length-1]
94
+ end
95
+ _msym = _mname.to_sym
96
+ has_term = self.class.terminology.has_term?(_msym)
97
+ return false if query and not has_term
98
+ _r = super(_mname.to_sym, *args)
99
+ if query
100
+ _r.length > 0
101
+ else
102
+ _r
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,157 @@
1
+ require 'active-fedora'
2
+ require 'solrizer'
3
+ require 'cul_scv_hydra/solrizer'
4
+ module Cul
5
+ module Scv
6
+ module Hydra
7
+ module Datastreams
8
+ class ModsDocument < ::ActiveFedora::OmDatastream
9
+ include ::OM::XML::TerminologyBasedSolrizer
10
+ include Cul::Scv::Hydra::Solrizer::TerminologyBasedSolrizer
11
+ include Cul::Scv::Hydra::Solrizer::ScvModsFieldable
12
+
13
+ map_field("lib_repo_sim", :marc_to_facet)
14
+ map_field("lib_repo_ssm", :marc_to_display)
15
+ map_field("lib_project_sim", :project_to_facet)
16
+
17
+ set_terminology do |t|
18
+ t.root(:path=>"mods",
19
+ :xmlns=>"http://www.loc.gov/mods/v3",
20
+ :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-4.xsd") {
21
+ }
22
+
23
+ t.main_title_info(:path=>'titleInfo', :index_as=>[], :attributes=>{:type=>:none}){
24
+ t.non_sort(:path=>"nonSort", :index_as=>[])
25
+ t.main_title(:path=>"title", :index_as=>[])
26
+ }
27
+
28
+ t.title(:proxy=>[:mods, :main_title_info, :main_title], :type=>:string,
29
+ :index_as=>[:searchable, :sortable, :textable])
30
+ t.title_display(:proxy=>[:mods, :main_title_info], :type=>:string,
31
+ :index_as=>[:displayable])
32
+
33
+ t.search_title_info(:path=>'titleInfo', :index_as=>[]){
34
+ t.search_title(:path=>'title', :index_as=>[:searchable])
35
+ }
36
+ t.project(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Project"}, :index_as=>[]){
37
+ t.project_title_info(:path=>'titleInfo', :index_as=>[]){
38
+ t.lib_project(:path=>'title',:index_as=>[])
39
+ }
40
+ }
41
+ t.collection(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Collection"}, :index_as=>[]){
42
+ t.collection_title_info(:path=>'titleInfo', :index_as=>[:facetable, :displayable]){
43
+ t.lib_collection(:path=>'title', :index_as=>[])
44
+ }
45
+ }
46
+ t.lib_project(:proxy=>[:project,:project_title_info],
47
+ :index_as=>[:displayable, :searchable, :project_facetable, :textable])
48
+ t.lib_collection(:proxy=>[:collection,:collection_title_info])
49
+ # pattern matches
50
+ t.identifier(:path=>"identifier", :attributes=>{:type=>"local"}, :type=>:string, :index_as=>[:symbol, :textable])
51
+ t.clio(:path=>"identifier", :attributes=>{:type=>"CLIO"}, :data_type=>:symbol, :index_as=>[:symbol, :textable])
52
+ t.abstract
53
+ t.subject {
54
+ t.topic
55
+ }
56
+ t.type_of_resource(:path=>"typeOfResource", :index_as=>[:displayable])
57
+ t.physical_description(:path=>"physicalDescription", :index_as=>[]){
58
+ t.form_marc(:path=>"form", :attributes=>{:authority=>"marcform"}, :index_as=>[:displayable])
59
+ t.form_aat(:path=>"form", :attributes=>{:authority=>"aat"}, :index_as=>[:displayable])
60
+ t.form(:attributes=>{:authority=>:none}, :index_as=>[:displayable])
61
+ t.form_nomarc(:path=>"form[@authority !='marcform']", :index_as=>[])
62
+ t.extent(:path=>"extent", :index_as=>[:searchable, :displayable])
63
+ t.reformatting_quality(:path=>"reformattingQuality", :index_as=>[:displayable])
64
+ t.internet_media_type(:path=>"internetMediaType", :index_as=>[:displayable])
65
+ t.digital_origin(:path=>"digitalOrigin", :index_as=>[:displayable])
66
+ }
67
+ t.lib_format(:proxy=>[:physical_description, :form_nomarc], :index_as=>[:displayable, :facetable])
68
+ t.location(:path=>"location", :index_as=>[]){
69
+ t.repo_text(:path=>"physicalLocation",:attributes=>{:authority=>:none}, :index_as=>[])
70
+ t.lib_repo(:path=>"physicalLocation",
71
+ :attributes=>{:authority=>"marcorg"},
72
+ :index_as=>[])
73
+ t.shelf_locator(:path=>"shelfLocator", :index_as=>[:textable])
74
+ }
75
+ t.lib_repo(:proxy=>[:location, :lib_repo], :type=>:text,
76
+ :index_as=>[:marc_code_facetable, :marc_code_displayable, :marc_code_textable])
77
+ t.lib_name(
78
+ :path=>'name',:attributes=>{:type=>'personal'},
79
+ :index_as=>[:facetable, :displayable, :searchable, :textable]){
80
+ t.name_part(:path=>'namePart', :index_as=>[])
81
+ }
82
+ t.name_corporate(
83
+ :path=>'name',:attributes=>{:type=>'corporate'},
84
+ :index_as=>[:facetable, :displayable, :searchable],
85
+ :variant_of=>{:field_base=>:lib_name}){
86
+ t.name_part(
87
+ :path=>'namePart',
88
+ :index_as=>[])
89
+ }
90
+ t.note(:path=>"note", :index_as=>[:textable])
91
+ t.access_condition(:path=>"accessCondition",
92
+ :attributes=>{:type=>"useAndReproduction"},
93
+ :index_as => [:searchable, :symbol])
94
+ t.record_info(:path=>"recordInfo", :index_as=>[]) {
95
+ t.record_creation_date(:path=>"recordCreationDate",:attributes=>{:encoding=>"w3cdtf"}, :index_as=>[])
96
+ t.record_content_source(:path=>"recordContentSource",:attributes=>{:authority=>"marcorg"}, :index_as=>[])
97
+ t.language_of_cataloging(:path=>"languageOfCataloging", :index_as=>[]){
98
+ t.language_term(:path=>"languageTerm", :index_as=>[], :attributes=>{:type=>:none})
99
+ t.language_code(:path=>"languageTerm",:attributes=>{:type=>'code',:authority=>"iso639-2b"}, :index_as=>[])
100
+ }
101
+ t.record_origin(:path=>"recordOrigin", :index_as=>[])
102
+ }
103
+ t.language_term(:proxy=>[:record_info, :language_of_cataloging, :language_term])
104
+ t.language_code(:proxy=>[:record_info, :language_of_cataloging, :language_code])
105
+
106
+ t.origin_info(:path=>"originInfo", :index_as=>[]){
107
+ t.date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf'}, :index_as=>[])
108
+ t.lib_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes'},
109
+ :index_as=>[:date_sortable])
110
+ t.start_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes',:point=>'start'}, :index_as=>[])
111
+ t.end_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:point=>'end'}, :index_as=>[])
112
+ }
113
+ end
114
+
115
+ def self.xml_template
116
+ builder = Nokogiri::XML::Builder.new do |xml|
117
+ xml.mods(:version=>"3.4",
118
+ "xmlns"=>"http://www.loc.gov/mods/v3",
119
+ "xmlns:xlink"=>"http://www.w3.org/1999/xlink",
120
+ "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance"){
121
+ }
122
+ end
123
+ builder.doc.encoding = 'UTF-8'
124
+ # for some reason, this is the only way to get an equivalent nokogiri root node; the attribute can't be in the original builder call
125
+ builder.doc.root["xsi:schemaLocation"] = 'http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd'
126
+ return builder.doc
127
+ end
128
+
129
+ def prefix
130
+ if ::ActiveFedora::VERSION >= '8'
131
+ Rails.logger.warn("the prefix method of #{self.class.name} was overriden to maintain backwards compatibility")
132
+ end
133
+ ''
134
+ end
135
+
136
+ def method_missing method, *args
137
+ query = false
138
+ _mname = method.id2name
139
+ if _mname[-1,1] == '?'
140
+ query = true
141
+ _mname = _mname[0,_mname.length-1]
142
+ end
143
+ _msym = _mname.to_sym
144
+ has_term = self.class.terminology.has_term?(_msym)
145
+ return false if query and not has_term
146
+ _r = super(_mname.to_sym, *args)
147
+ if query
148
+ _r.length > 0
149
+ else
150
+ _r
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end