Class: Libis::Metadata::SharepointRecord

Inherits:
Hash
  • Object
show all
Defined in:
lib/libis/metadata/sharepoint_record.rb

Overview

Copy of the old SharepointRecord class. Needs inspection and probably a mayor update.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSharepointRecord

Returns a new instance of SharepointRecord.



18
19
20
21
22
# File 'lib/libis/metadata/sharepoint_record.rb', line 18

def initialize
  @node = nil
  self[:label_prefix] = ''
  super nil
end

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



16
17
18
# File 'lib/libis/metadata/sharepoint_record.rb', line 16

def node
  @node
end

Class Method Details

.from_xml(xml_node) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/libis/metadata/sharepoint_record.rb', line 171

def self.from_xml(xml_node)

  record = Libis::Metadata::SharepointRecord.new

  xml_node.element_children.each do |node|
    record[node.name.to_sym] = node.content
  end

  record

end

Instance Method Details

#accessright_modelObject



142
143
144
145
146
# File 'lib/libis/metadata/sharepoint_record.rb', line 142

def accessright_model
  return self[:ows_Access_x0020_rights_x0020_model] if self[:ows_Access_x0020_rights_x0020_model]
  return self.node.parent.content.accessright_model if node and node.parent and node.parent.content
  nil
end

#content_codeObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/libis/metadata/sharepoint_record.rb', line 117

def content_code
  case simple_content_type
    when :archive
      'a'
    when :map
      'm'
    when :file
      'f'
    when :mmap
      'v'
    when :mfile
      '<'
    when :unknown
      '-'
    else
      ' '
  end + (is_described? ? '*' : ' ')
end

#content_typeObject



40
41
42
# File 'lib/libis/metadata/sharepoint_record.rb', line 40

def content_type
  self[:ows_ContentType]
end

#create_dc(dir, mapping) ⇒ Object



237
238
239
240
241
242
# File 'lib/libis/metadata/sharepoint_record.rb', line 237

def create_dc(dir, mapping)
  xml_doc = to_dc mapping
  dc_file = "#{dir}/dc_#{self[:index].to_s}.xml"
  xml_doc.save dc_file
  dc_file
end

#file_nameObject



44
45
46
# File 'lib/libis/metadata/sharepoint_record.rb', line 44

def file_name
  self[:ows_FileLeafRef]
end

#file_pathObject



48
49
50
# File 'lib/libis/metadata/sharepoint_record.rb', line 48

def file_path
  self[:ows_FileRef]
end

#file_sizeObject



52
53
54
# File 'lib/libis/metadata/sharepoint_record.rb', line 52

def file_size
  self[:ows_FileSizeDisplay]
end

#ingest_modelObject



136
137
138
139
140
# File 'lib/libis/metadata/sharepoint_record.rb', line 136

def ingest_model
  return self[:ows_Ingestmodel] if self[:ows_Ingestmodel]
  return self.node.parent.content.ingest_model if node and node.parent and node.parent.content
  nil
end

#is_described?Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
# File 'lib/libis/metadata/sharepoint_record.rb', line 80

def is_described?
=begin
    self[:ows_Title1] and
  (   self[:ows_Creation_x0020_date_x0028_s_x0029_] or
      self[:ows_Startdate] or
      self[:ows_Enddate]
  )
=end
  self[:ows_Unit_of_description]
end

#is_file?Boolean

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/libis/metadata/sharepoint_record.rb', line 75

def is_file?
  return true if [:file, :mfile].include? simple_content_type
  false
end

#labelObject



32
33
34
# File 'lib/libis/metadata/sharepoint_record.rb', line 32

def label
  (self[:ows_Title1] || self[:ows_BaseName] || file_name).to_s
end

#label_prefixObject



24
25
26
# File 'lib/libis/metadata/sharepoint_record.rb', line 24

def label_prefix
  self[:label_prefix]
end

#label_prefix=(value) ⇒ Object



28
29
30
# File 'lib/libis/metadata/sharepoint_record.rb', line 28

def label_prefix=(value)
  self[:label_prefix] = value
end

#local_path(sub_dir) ⇒ Object



68
69
70
71
72
73
# File 'lib/libis/metadata/sharepoint_record.rb', line 68

def local_path(sub_dir)
  return relative_path unless sub_dir
  sub_dir += '/' unless sub_dir[-1] == '/'
  return relative_path.gsub(/^#{sub_dir}/, '') if relative_path
  nil
end


248
249
250
251
252
253
254
255
256
257
# File 'lib/libis/metadata/sharepoint_record.rb', line 248

def (f, mapping)
  f.printf "%6d -------------------------------------------------------------------------\n", self[:index].to_i
  self.each do |label, value|
    next if label == :node
#      next if label == :index
    name = mapping.fancy_label(label)
    f.printf " %40s : %s\n", name, value
  end

end

#relative_pathObject



63
64
65
66
# File 'lib/libis/metadata/sharepoint_record.rb', line 63

def relative_path
  return file_path.gsub(/^sites\/lias\/Gedeelde documenten\//, '') if file_path
  nil
end

#simple_content_typeObject



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
# File 'lib/libis/metadata/sharepoint_record.rb', line 91

def simple_content_type
  case content_type
    when /^Archief/i
      return :archive
    when /^Bestanddeel \(folder\)/i
      return :map
    when /^Bestanddeel of stuk \(document\)/i
      return :file
    when /^Meervoudige beschrijving \(folder\)/i
      return :mmap
    when /^Meervoudige beschrijving \(document\)/i
      return :mfile
    when /^Tussenniveau/i
      return :map
    when /^Film/i
      return :file
    when /^Object/i
      return :file
    when /^Document/i
      return :file
    else
      # type code here
  end
  :unknown
end

#titleObject



36
37
38
# File 'lib/libis/metadata/sharepoint_record.rb', line 36

def title
  self[:label_prefix] + ' ' + self.label
end

#to_dc(mapping) ⇒ Object

Parameters:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/libis/metadata/sharepoint_record.rb', line 184

def to_dc(mapping)

  return nil unless mapping and mapping.is_a? Hash

  xml_doc = Libis::Tools::XmlDocument.new

  #noinspection RubyStringKeysInHashInspection
  xml_doc.root = xml_doc.create_node(
      'record',
      namespaces: {
          'dc' => 'http://purl.org/dc/elements/1.1/',
          'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
          'dcterms' => 'http://purl.org/dc/terms/'})

  self.each do |label, value|
    dc_tag = mapping.dc_tag(label)
    next unless dc_tag
    dc_value = (mapping.dc_prefix(label) || '') + value.to_s + (mapping.dc_postfix(label) || '')
    #noinspection RubyResolve
    xml_doc.root << xml_doc.create_text_node(dc_tag, dc_value)
  end

  if xml_doc.xpath('//dc:title').size == 0
    xml_doc.root << xml_doc.create_text_node('dc:title', self[:ows_BaseName])
  end

  xml_doc

end

#to_rawObject



148
149
150
# File 'lib/libis/metadata/sharepoint_record.rb', line 148

def to_raw
  self
end

#to_sObject



244
245
246
# File 'lib/libis/metadata/sharepoint_record.rb', line 244

def to_s
  super
end

#to_sql(mapping) ⇒ Object

Parameters:



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/libis/metadata/sharepoint_record.rb', line 215

def to_sql(mapping)
  sql_fields = []
  sql_values = []

  self.each do |label, value|
    db_column = mapping.db_column(label)
    next unless db_column
    db_value = mapping.db_value(label, value)
    next unless db_value and db_value != "''"
    sql_fields << db_column
    sql_values << db_value.escape_for_sql
  end

  sql_fields.each_with_index { |element, index| (index % 10 == 0) && (sql_fields[index] = "\n    " + element)
  }
  sql_values.each_with_index { |element, index| (index % 10 == 0) && (sql_values[index] = "\n    " + element)
  }

  'INSERT INTO @TABLE_NAME@ (' + sql_fields.join(',') + ")\n  VALUES (" + sql_values.join(',') + ');'

end

#to_xmlObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/libis/metadata/sharepoint_record.rb', line 152

def to_xml

  xml_doc = Libis::Tools::XmlDocument.new

  xml_doc.root = xml_doc.create_node('record')

  self.each do |label, value|

    unless label == :node
      #noinspection RubyResolve
      xml_doc.root << xml_doc.create_text_node(label.to_s, value.to_s)
    end

  end

  xml_doc

end

#urlObject



56
57
58
59
60
61
# File 'lib/libis/metadata/sharepoint_record.rb', line 56

def url
#    self[:ows_EncodedAbsUrl]
#    'https://www.groupware.kuleuven.be' + CGI.escape(self[:ows_ServerUrl], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
#    'https://www.groupware.kuleuven.be' + CGI.escape(self[:ows_ServerUrl])
  CGI.escape(CGI.unescape(self[:ows_EncodedAbsUrl]))
end