lib/ddr/models/struct_div.rb in ddr-models-2.0.0.pre.2 vs lib/ddr/models/struct_div.rb in ddr-models-2.0.0.pre.3
- old
+ new
@@ -1,44 +1,62 @@
module Ddr
module Models
class StructDiv
- attr_accessor :id, :label, :order, :orderlabel, :type, :objs, :divs
+ attr_accessor :id, :label, :order, :orderlabel, :type, :fptrs, :divs
def initialize(structmap_or_div_node)
@id = structmap_or_div_node['ID']
@label = structmap_or_div_node['LABEL']
@order = structmap_or_div_node['ORDER']
@orderlabel = structmap_or_div_node['ORDERLABEL']
@type = structmap_or_div_node['TYPE']
- @objs = obj_pids(structmap_or_div_node) if structmap_or_div_node.node_name == "div"
+ @fptrs = fptr_pids(structmap_or_div_node) if structmap_or_div_node.node_name == "div"
@divs = subdivs(structmap_or_div_node).sort
end
def <=>(other)
self.order.to_i <=> other.order.to_i
end
- def objects?
- objs.present?
+ def pids
+ collect_pids(self)
end
- def object_pids
- objs
+ def docs
+ query = ActiveFedora::SolrService.construct_query_for_pids(pids)
+ results = ActiveFedora::SolrService.query(query, rows: 999999)
+ results.each_with_object({}) do |r, memo|
+ memo[r["id"]] = ::SolrDocument.new(r)
+ end
end
def objects
- objs.map { |pid| ActiveFedora::Base.find(pid) }
+ pids.each_with_object({}) do |pid, memo|
+ memo[pid] = ActiveFedora::Base.find(pid)
+ end
end
+ def as_json(options={})
+ super.compact
+ end
+
private
- def obj_pids(div_node)
+ def fptr_pids(div_node)
div_node.xpath('xmlns:fptr').map { |fptr_node| fptr_node["CONTENTIDS"].gsub('info:fedora/', '') }
end
def subdivs(structmap_or_div_node)
structmap_or_div_node.xpath('xmlns:div').map { |div_node| Ddr::Models::StructDiv.new(div_node) }
+ end
+
+ def collect_pids(structdiv)
+ pids = structdiv.divs.each_with_object([]) do |div, memo|
+ memo << collect_pids(div)
+ end
+ pids << structdiv.fptrs if structdiv.fptrs
+ pids.flatten
end
end
end
end
\ No newline at end of file