Class: Rdomino::Database

Inherits:
Object
  • Object
show all
Includes:
Enumerable, DatabaseHelper, DbDcDoc, DomObject
Defined in:
lib/rdomino/database.rb

Constant Summary collapse

FLAGS =
{
  '4' => :allow_soft_deletes_,
  'Z' => :enable_lz1_compression,
  'f' => :do_not_allow_stored_forms,
  'z' => :do_not_maintain_unread_marks,
  'h' => :mark_parent_document_on_reply_or_forward,
  'J' => :use_javascript_when_generating_web_pages,
  'n' => :never_show_policy_never_show_about_database_when_first_opened,
  '7' => :large_unk_table_allow_more_fields_in_database,
  '6' => :allow_design_locking,
  'K' => :restore_as_lasted_viewed_by_user,
  'c' => :show_about_database_if_modified,
  'Q' => :replicate_unread_marks_to_clustered_servers_only,
  'U' => :replicate_unread_marks_to_all_servers_appears_with_q_set,
  '2' => :optimise_document_table_bitmap,
  '3' => :maintain_lastaccessed_property,
  '1' => :dont_support_specialised_response_hierarchy,
  'M' => :multilingual_database,
  'X' => :web_access_requires_ssl_connection,
  '8' => :web_access_dont_allow_url_open,
  'i' => :display_images_after_loading,
  '5' => :allow_document_locking,
  'g' => :database_type_library,
  'j' => :database_type_personal_journal,
  'b' => :database_type_domino_directory,
  'B' => :database_type_directory_catalog,
  'm' => :database_type_multi_db_search,
  'u' => :database_type_portfolio,
  'A' => :database_type_mailbox,
  'r' => :database_type_mailfile,
  'p' => :always_show_about_database_document_when_opened_in_the_client_property,
  'F' => :launch_designated_frameset,
  'l' => :launch_designated_navigator,
  's' => :launch_designated_navigator_in_own_window_used_in_conjuction_with_l_above,
  'a' => :launch_first_attachment_in_about_database_document,
  'd' => :launch_first_doclink_in_about_database_document,
  'P' => :web_launch_show_about_database_document,
  'S' => :web_launch_open_designated_frameset,
  'E' => :web_launch_open_designated_page,
  'L' => :web_launch_open_designated_navigator_in_its_own_window,
  'D' => :web_launch_open_first_doclink_in_about_database_document,
  'T' => :web_launch_open_designated_doclink,
  'V' => :web_launch_open_first_document_in_designated_view
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DomObject

#empty?, #method_missing, #obj

Methods included from DbDcDoc

#dxl, #dxl_to_file

Methods included from DatabaseHelper

#is_replica_id?

Constructor Details

#initialize(name, obj) ⇒ Database

server,path or object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rdomino/database.rb', line 42

def initialize(name,obj)
  m = Rdomino::Databases.const_get(name.to_s.camelize) rescue nil
  self.extend(m) if m
  @name = name
  case obj
  when String
    @server_path = obj
    server, path = obj.split("!!") 
    @obj = Session.session.getDatabase(server, path)
    flag = @obj.OpenByReplicaID( server, path ) if is_replica_id?(path)
  else
    @obj = obj
    @server_path = "#{obj.server}!!#{obj.filepath}"
  end
  print "\ndb.open:#{self}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rdomino::DomObject

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rdomino/database.rb', line 7

def name
  @name
end

#server_pathObject (readonly)

Returns the value of attribute server_path.



7
8
9
# File 'lib/rdomino/database.rb', line 7

def server_path
  @server_path
end

Instance Method Details

#[](view_string) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/rdomino/database.rb', line 28

def [](view_string)
  if view_string =~ /^search:(.*)/
    search( $1 )
  else 
    v = get_view( view_string )
    v.obj ? v : nil
  end
end

#all_documentsObject Also known as: all

contains deleted documents



75
76
77
# File 'lib/rdomino/database.rb', line 75

def all_documents
  DocumentCollection.new(@obj.allDocuments)
end

#by(f = :Form, s = nil) ⇒ Object



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/rdomino/database.rb', line 307

def by( f=:Form, s=nil)
  field = f.to_s  
  h = Hash.new { |hash, key| hash[key] = 0 }
  (s ? search(s) : all_documents).each do |d| 
    h[d.getItemValue(field)[0]] += 1 unless d.isDeleted
  end
  puts "-----------------------------"
  h.keys.sort.each{|k| puts "%10s %10d"%[k,h[k]]}  
  h
#      while dc.count > 0
#        doc = dc.GetFirstDocument
#        value = doc.getitemValue(field)[0] 
#        dc_sub = search("#{field}='#{value}'")
#        h[field] = dc_sub.count
#        dc.obj.Subtract( dc_sub ) # doesn't work 
#      end
end

#copy(destination) ⇒ Object



286
287
288
289
# File 'lib/rdomino/database.rb', line 286

def copy(destination)
  server, path = destination.split("!!")       
  new(obj.CreateReplica( server, path ))
end

#countObject



80
81
82
# File 'lib/rdomino/database.rb', line 80

def count
  all_documents.count
end

#create_document(attributes = {}) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/rdomino/database.rb', line 91

def create_document(attributes={})
  doc = Document.new( obj.CreateDocument )
  attributes.each do |field,value|
    doc.replaceItemValue(field.to_s,value)
  end
  doc.save(true, false)
  doc
end

#create_meeting(start_time, subject, p = {}) ⇒ Object

defaults :duration => 1, :location => ” , :body => nil



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/rdomino/database.rb', line 245

def create_meeting(start_time,subject,p={})
  end_time = start_time + (p[:duration]||1) * 3600
  sdt = Datetime.new(start_time)    
  edt = Datetime.new(end_time)  
  date_range = Daterange.new(sdt,edt)    
  target = create_document( 
    :form => 'Appointment',
    :subject => subject,
    :chair => 'CN=Frank Behrens/OU=IMBEH/OU=BBS/O=BAYER',
    :principal => 'CN=Frank Behrens/OU=IMBEH/OU=BBS/O=BAYER',
    :location => p[:location]||'' ,
    :appointmentType => '3',
    :KLCategories_2 => "",   
    :Alarms => "0",
    :Logo => "StdNotesLtr14",
    :BookFreeTime => "",
    :Duration => 105,
    :SequenceNum => 1,
    :OrgTable => "CO",
    :tmpOwnerHW => "1",
    :WebDateTimeInit => "1",
    :TimeRange => date_range.obj,
    :CalendarDateTime => sdt.obj,
    :startDate => sdt.obj,
    :startDateTime => sdt.obj,
    :startTime => sdt.obj,
    :endDate => edt.obj,
    :endDateTime => edt.obj,
    :endTime => edt.obj,
    :_ViewIcon => 9,
    :Org_Table=> "")
#        Call doc.ReplaceItemValue("Org_Table", ORS_ITEM_PLANNER)   
#        Set newitem = New NotesItem(doc,"_ViewIcon",9)
#        newitem.issummary = True
#        doc.PostedDate = Now
  target.obj.CopyItem( p[:body], "" )       if p[:body]
  target.ComputeWithForm false, false
  target.save(true, false)
  target
end

#cut_off_intervallObject



14
15
16
# File 'lib/rdomino/database.rb', line 14

def cut_off_intervall
  replication.cutoffInterval
end

#cut_off_intervall=(v) ⇒ Object



18
19
20
21
# File 'lib/rdomino/database.rb', line 18

def cut_off_intervall=(v)
  replication.cutoffInterval = v
  replication.save() 
end

#default_framesetObject

underscored will be omitted (as in selection list)



214
215
216
# File 'lib/rdomino/database.rb', line 214

def default_frameset
  icon.g(:$DefaultFrameset)
end

#default_frameset=(value) ⇒ Object



218
219
220
221
# File 'lib/rdomino/database.rb', line 218

def default_frameset=(value)
  icon.replace :$DefaultFrameset => value
  icon.save
end

#delete_documents(*form) ⇒ Object

returns number al deleted documents



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rdomino/database.rb', line 145

def delete_documents(*form)
  if form.empty?
    dc = allDocuments
  else
    filter = "Form='#{form.map{|i| i.to_s}.join("':'")}'"
    dc = search( filter )
  end
  c = dc.count
  dc.removeAll true
  c == 0 ? nil : c
end

#design_documents(*elements) ⇒ Object

multiple Documents are yielded to a block returns the number of documents found

ReplicationFormulas Actions DataConnections Documents
Agents Folders Forms ScriptLibraries Subforms Views
FrameSets Navigators Pages Outlines     
ImageResources JavaResources MiscCodeElements MiscFormatElements MiscIndexElements
Profiles SharedFields StyleSheetResources


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/rdomino/database.rb', line 173

def design_documents(*elements)
  elements.map!{|e| "#{e}=" }  
  elements << :alldesignelements if elements.empty?
  # its nv.alldesignelements(true)
  # but nv.views = true
  nc = @obj.CreateNoteCollection false
  elements.each{|v| 
    nc.send("select#{v}",true)}
  nc.BuildCollection
  id = nc.GetFirstNoteId
  # check if its a single element which doesn't end with 's'
  if elements.length == 1 && elements[0].to_s !~ /s=?$/
    find(id)
  else  
    while id != '' 
      yield find(id) 
      id = nc.GetNextNoteId(id)
    end
    nc.count
  end 
end

#dumpObject



135
136
137
# File 'lib/rdomino/database.rb', line 135

def dump
  all_documents.dxl_to_file( fixture_file )
end

#dxl_import(s) ⇒ Object



157
158
159
160
161
162
163
164
# File 'lib/rdomino/database.rb', line 157

def dxl_import(s)
  imp = Session.session.createDXLImporter
  imp.replaceDBProperties = false
  imp.replicaRequiredForReplaceOrUpdate = false
  imp.aCLImportOption = 5 # DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
  imp.designImportOption = 2 # DXLIMPORTOPTION_CREATE
  imp.import(s, obj)
end

#each(&b) ⇒ Object



23
24
25
26
# File 'lib/rdomino/database.rb', line 23

def each(&b)
  dc = DocumentCollection.new(@obj.allDocuments)
  dc.each(&b) 
end

#find(id) ⇒ Object

finds document by noteid or unid



299
300
301
302
303
304
305
# File 'lib/rdomino/database.rb', line 299

def find(id)
  if id.length == 32
    Document.new(obj.getdocumentbyunid(id))
  else
    Document.new(obj.getdocumentbyid(id))
  end
end

#firstObject



325
326
327
# File 'lib/rdomino/database.rb', line 325

def first
  all.first
end

#fixture_fileObject



131
132
133
# File 'lib/rdomino/database.rb', line 131

def fixture_file
  File.dirname(__FILE__)+"/../../test/fixtures/#{name}.xml"
end

#fixturesObject



100
101
102
# File 'lib/rdomino/database.rb', line 100

def fixtures
  Session.get.configuration[name][:fixtures]
end

#flagsObject



206
207
208
209
210
211
# File 'lib/rdomino/database.rb', line 206

def flags
  f = icon.g(:$flags)
  r =[f]
  (f.length).times {|i| c = f[i].chr;  r << "#{c} - #{FLAGS[c]}" }
  r  
end

#get_agent(v) ⇒ Object



70
71
72
# File 'lib/rdomino/database.rb', line 70

def get_agent(v)
   Agent.new(obj.getAgent(v))
end

#get_view(v) ⇒ Object



66
67
68
# File 'lib/rdomino/database.rb', line 66

def get_view(v)
  View.new(@obj,v)
end

#iconObject



202
203
204
# File 'lib/rdomino/database.rb', line 202

def icon
  find('FFFF0010')
end

#import_all_documents_by_dxl(db) ⇒ Object



139
140
141
142
# File 'lib/rdomino/database.rb', line 139

def import_all_documents_by_dxl(db)
  d = db.all_documents.dxl
  dxl_import(d)
end

#lastObject



329
330
331
# File 'lib/rdomino/database.rb', line 329

def last
  all.last
end

#load_fixtures(p = :xml) ⇒ Object

:xml from test/fixtures/db.xml :yml from config.yml [db] hash or Array of tabular text: f1|f2nv1|v2



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rdomino/database.rb', line 108

def load_fixtures(p=:xml)
  delete_documents
  p = ( [] << p ) if p.kind_of? Hash
  p = fixtures if p == :yml
  case p
  when String
    f,*d = p.split("\n")
    fields = f.split("|")
    d.each do |line|
      hash = {}
      values = line.split("|")
      values.each_index{ |i| hash[fields[i]] = values[i] }
      create_document(hash)
    end
  when Array
    p.map{|h|
      create_document(h) }[0]
  else
    dxl_import(IO.read(fixture_file))
  end
  self
end

#move(destination) ⇒ Object



291
292
293
294
295
296
# File 'lib/rdomino/database.rb', line 291

def move(destination)
  target = copy(destination)       
  obj.Remove
  @obj = nil
  target
end

#open!Object



59
60
61
62
63
64
# File 'lib/rdomino/database.rb', line 59

def open!
  unless isopen
    @obj = Session.session.getDatabase(@obj.server, @obj.filepath)
  end
  self
end

#refresh_view_design(template_view, options = {}) ⇒ Object

options(:open => true) => :no_action, :refreshed, :pasted



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/rdomino/database.rb', line 224

def refresh_view_design(template_view,options={})
  view_name = template_view.name
  view = get_view( view_name )
  if view.obj
    if view == template_view
      remove,paste,result = false,false, :no_action
    else
      remove,paste,result = true,true,:refreshed
    end
  else
    remove,paste,result = false,true,:pasted
  end
  view.document.removepermanently(true) if remove
  if paste
    template_view.document.copytodatabase(@obj)
    get_view( view_name ).refresh if options[:open]
  end  
  result
end

#replicationObject



10
11
12
# File 'lib/rdomino/database.rb', line 10

def replication
  @replication ||= self.replicationInfo 
end

#search(filter, since = Time.local(1980,1,1,0,0,0), count = 0) ⇒ Object

search(:Memo) => all Memos

only documents modified within cutoff_days



86
87
88
89
# File 'lib/rdomino/database.rb', line 86

def search(filter,since=Time.local(1980,1,1,0,0,0),count=0)
  filter = "Form='#{filter}'" if filter.kind_of? Symbol
  DocumentCollection.new(@obj.search(filter,Datetime.new(since).obj,count))
end

#to_sObject



37
38
39
# File 'lib/rdomino/database.rb', line 37

def to_s
  "#{obj.title} (#{server_path})"
end