Module: Cul::Scv::Hydra::Models::Common

Extended by:
ActiveSupport::Concern
Included in:
DcDocument, GenericAggregator, GenericObject, GenericResource, METSStructuredAggregator, Resource, ResourceAggregator
Defined in:
app/models/concerns/cul/scv/hydra/models/common.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#cmodel_pid(klass) ⇒ Object



37
38
39
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 37

def cmodel_pid(klass)
  klass.pid_namespace + ":" + klass.name.split("::")[-1]
end

#createObject



31
32
33
34
35
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 31

def create
  run_callbacks :create do
    super
  end
end

#datastreams_in_fedoraObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 41

def datastreams_in_fedora
  mds = {}
  self.datastreams_xml['datastream'].each do |ds|
    dsid = ds["dsid"]
    ds.merge!({:pid => self.pid, :dsID => dsid, :dsLabel => ds["label"]})
    if dsid == "RELS-EXT"
      mds.merge!({dsid => ActiveFedora::RelsExtDatastream.new(ds)})
    else
      if self.class.ds_specs.has_key? dsid
        mds.merge!({dsid => self.class.ds_specs[dsid][0].new(ds)})
      else
        mds.merge!({dsid => ActiveFedora::Datastream.new(ds)})
      end
    end
    mds[dsid].new_object = false
  end
  mds
end

#has_desc?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 64

def has_desc?
  has_desc = false
  begin
    has_desc = self.datastreams.include? "descMetadata"
    has_desc = has_desc and self.inner_object.datastreams["descMetadata"].content.length > 0
    has_desc = has_desc and self.datastreams["descMetadata"].term_values(:identifier).length > 0
  rescue
    has_desc = false
  end
  has_desc
end

#initialize(attrs = nil) ⇒ Object



25
26
27
28
29
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 25

def initialize(attrs = nil)
  attrs = {} if attrs.nil?
  attrs[:namespace] = self.class.pid_namespace unless attrs[:namespace]
  super
end

#rdf_typeObject



21
22
23
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 21

def rdf_type
  relationships[:rdf_type]
end

#route_asObject



60
61
62
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 60

def route_as
  "default"
end

#thumbnail_infoObject



146
147
148
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 146

def thumbnail_info
  {:asset=>("cul_scv_hydra/crystal/kmultiple.png"),:mime_type=>"image/png"}
end

#to_solr(solr_doc = Hash.new, opts = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 76

def to_solr(solr_doc = Hash.new, opts={})
  solr_doc = super(solr_doc, opts)

  if has_desc?
    solr_doc["descriptor_ssi"] = ["mods"]
  else
    solr_doc["descriptor_ssi"] = ["dublin core"]
  end
  # if no mods, pull some values from DC
  if (solr_doc["title_display_ssm"].nil? or solr_doc["title_display_ssm"].length == 0)
    if self.datastreams["DC"].term_values(:dc_title).first
      solr_doc["title_display_ssm"] = self.datastreams["DC"].term_values(:dc_title)
    else
      solr_doc["title_display_ssm"] = self.datastreams["DC"].term_values(:dc_identifier).reject {|dcid| dcid.eql? self.id}
    end
    solr_doc["title_si"] = self.datastreams["DC"].term_values(:dc_title).first
    if self.datastreams["DC"].term_values(:dc_relation).first
      self.datastreams["DC"].term_values(:dc_relation).each {|val|
        if val =~ /clio:/
          solr_doc["clio_ssim"] ||= []
          solr_doc["clio_ssim"] << val.split(':')[-1]
        end
      }
    end
  end
  if (solr_doc["identifier_ssim"].nil? or solr_doc["identifier_ssim"].length == 0)
      solr_doc["identifier_ssim"] = self.datastreams["DC"].term_values(:dc_identifier).reject {|dcid| dcid.eql? self.id}
  end
  if (solr_doc["title_display_ssm"].length > 1)
    solr_doc["title_display_ssm"].uniq!
  end
  solr_doc["format_ssi"] = [self.route_as]
  solr_doc["index_type_label_ssi"] = [self.index_type_label]

  solr_doc.each_pair {|key, value|
    if value.is_a? Array
      value.each {|v| v.strip! unless v.nil? }
    elsif value.is_a? String
      value.strip!
    end
  }
  solr_doc[:structured_bsi] = 'false' unless solr_doc.has_key? :structured_bsi

  solr_doc
end

#update_datastream_attributes(params = {}, opts = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/models/concerns/cul/scv/hydra/models/common.rb', line 122

def update_datastream_attributes(params={}, opts={})
  logger.debug "Common.update_datastream_attributes"
  result = params.dup
  params.each_pair do |dsid, ds_params|
    if datastreams.include?(dsid)
      verify_params = ds_params.dup
      changed = false
      verify_params.each { |pointer, values|
        changed ||= value_changed?(datastreams[dsid],pointer,values)
      }
      if changed
        logger.debug "Common.update_datastream_attributes calling update_indexed_attributes"
        result[dsid] = datastreams[dsid].update_indexed_attributes(ds_params)
      else
        result[dsid] = no_update(ds_params)
      end
      logger.debug "change detected? #{changed} digital_object? #{datastreams[dsid].changed?}"
    else
      result.delete(dsid)
    end
  end
  return result
end