Domino Extended 1.1
I was working on some updates to Open Audit, specifically the ability to delete audit logs when a document is deleted and archive audit logs when the document is archived. One thing that I did not want to have to worry about when I was deleting or archiving (deleting -because it is being moved to another database) is if the audit log was already deleted. Yes, I have in the past always gotten the next document before deleting the current document but I did not want have to worry about this and I know I would have to worry about it twice (archive & delete).
So I created a new Domino Extended class to handle it. This will be called NoteDocumentCollectionExtended, not a fancy name but it does all the necessary error checking!!! I also included an example of the test code for your enjoyment.
Along the way I have updated the other Domino Extended (NotesSystem and NotesDocumentExtended) classes so I have include them also nothing major but a couple of improvements.
NotesSystem oveview
Class NotesSystem Public SubNew() Public Function hasWorkspace() As Boolean Public Function ThisWorkspace() As NotesUIWorkspace Public Function ThisDatabase() As NotesDatabase Public Function hasDocument() As Boolean Public Function ThisDocument() As NotesDocument Public Function hasUIDocument() As Boolean Public Function ThisUIDocument() As NotesUIDocument Public Function ThisSession() As NotesSession Public Function CurrentUser() As NotesName Public Function CurrentUserCommon() As String Public Function CurrentUserAbbreviated() As String EndClass
NotesDocumentExtended oveview
Public Class NotesDocumentExtended Public Function getFieldValues ( fieldName As String) AsVariant Public Function getFieldItem ( fieldName As String) As NotesItem Public Sub replaceField ( fieldName As String , Var As Variant) Public Function getFieldText ( fieldName As String) As String Public Function getFieldAbstraction ( fieldName As String)As String Public Function getFieldUnformattedText ( fieldName As String) As String Public Function getFieldFormattedText ( fieldName As String, tabstrip As Boolean, lineLength As Integer )As String Public Function Public Function hasField ( fieldName AsString )As Boolean Public Function hasFieldText ( fieldName As String) AsBoolean Public Function hasDoc ( )As Boolean Public Function hasDocument () As Boolean Public Sub setDoc ( Doc As NotesDocument ) Public Function Doc() As NotesDocument Public Sub setDocument ( Document As NotesDocument ) Public Function Document As NotesDocument EndClass
NotesDocumentCollectionExtended oveview
Public Class NotesDocumentCollectionExtended Public SubNew() Public SubClear() Public Sub LoadCollection ( docCollection As NotesDocumentCollection ) Public Function getNavFirst () As NotesDocument Public Function getNavLast () As NotesDocument Public Function getNavNext () As NotesDocument Public Function getNavPrev () As NotesDocument Public Function getCurrentDocument( )As NotesDocument Public Function getPrevDocument( )As NotesDocument Public Function getNextDocument( )As NotesDocument Public Function hasCurrentDocument( )As Boolean Public Function hasPrevDocument( )As Boolean Public Function hasNextDocument( )As Boolean Public Function hasCollection( )As Boolean EndClass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 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 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | 'Domino_Extended: Option Public Option Declare Dim System As Variant '/** ' * A basic class to extend the NotesDocument class to reduce ' * code and improve error checking ' * ' * @author Tim Tripcony http://www.timtripcony.com ' * @author Chad Schelfhout http://www.chadsmiley.com.previewdns.com/ ' * ' * @version 1.0 Created by Tim ' * @version 1.1 Split intialization, each object is initalized only when it is needed ' * @version 1.2 Converted NotesDocument to NotesDocumentExtended ' * @version 1.3 Converted properties to Function so it is easily ported to Java ' */ Private Class NotesSystem 'Used to determine if each object has been initalized. Private boolSession As Boolean Private boolDatabase As Boolean Private boolWorkspace As Boolean Private boolUIDocument As Boolean Private boolDocumentExtended As Boolean Private boolName As Boolean 'Possible objects that can be loaded Private sessionCurrent As NotesSession Private databaseCurrent As NotesDatabase Private workspaceCurrent As NotesUIWorkspace Private uiDocumentCurrent As NotesUIDocument Private documentExtendedCurrent As NotesDocumentExtended Private nameCurrent As NotesName '/** ' * Constructor, but nothing else is intialized until it is used. ' */ Public Sub New() Let boolSession = False Let boolDatabase = False Let boolWorkspace = False Let boolUIDocument = False Let boolDocumentExtended = False Let boolName = False End Sub '/** ' * IntializeSession ' */ Private Sub intializeSession( ) If Not boolSession Then Set SessionCurrent = New NotesSession() Let boolSession = True End If End Sub '/** ' * Intialize Database ' */ Private Sub intializeDatabase( ) If Not boolDatabase Then Call intializeSession() Set databaseCurrent = sessionCurrent.CurrentDatabase() Let boolDatabase = True End If End Sub '/** ' * Intialize Document ' */ Private Sub intializeDocument( ) If Not boolDocumentExtended Then Call intializeDatabase() Set documentExtendedCurrent = New NotesDocumentExtended() If isOnServer Then Call documentExtendedCurrent.setDocument ( sessionCurrent.DocumentContext() ) Else Call intializeUIDocument() If hasUIDocument() Then Call documentExtendedCurrent.setDocument( uiDocumentCurrent.Document() ) End If End If Let boolDocumentExtended = True End If End Sub '/** ' * Determines if the object was loaded through the UI ' */ Private Function isOnServer () As Boolean Call intializeSession() Let isOnServer = sessionCurrent.IsOnServer() End Function '/** ' * Intialize Workspace ' */ Private Sub intializeWorkspace( ) If Not boolWorkspace Then If Not isOnServer Then 'Skip workspace initialization if the code is running on a server because NotesUIWorkspace would be unavailable Set workspaceCurrent = New NotesUIWorkspace() End If Let boolWorkspace = True End If End Sub '/** ' * Intialize UI Document ' */ Private Sub intializeUIDocument( ) If Not boolUIDocument Then If Not isOnServer Then Call intializeWorkspace() If hasWorkspace() Then Set uiDocumentCurrent = workspaceCurrent.CurrentDocument() End If End If Let boolUIDocument = True End If End Sub '/** ' * Intialize Name ' */ Private Sub intializeName() If Not boolName Then Call intializeSession() Set nameCurrent = New NotesName( sessionCurrent.EffectiveUserName ()) Let boolName = True End If End Sub '/** ' * Determines if a UI Workspace is available ' */ Public Function hasWorkspace() As Boolean Call intializeWorkspace() Let hasWorkspace = Not workspaceCurrent Is Nothing End Function '/** ' * Returns the UI Workspace ' * @return UI Workspace ' */ Public Function ThisWorkspace() As NotesUIWorkspace Call intializeWorkspace() Set ThisWorkspace = workspaceCurrent End Function '/** ' * Returns the current database ' * @return current database ' */ Public Function ThisDatabase() As NotesDatabase Call intializeDatabase() Set ThisDatabase = databaseCurrent End Function '/** ' * determines if there is a current document ' * @return True/False ' */ Public Function hasDocument() As Boolean Call intializeDocument() Let hasDocument = documentExtendedCurrent.hasDocument() End Function '/** ' * Returns the current document ' * @return current document ' */ Public Function ThisDocument() As NotesDocument Call intializeDocument() Set ThisDocument = documentExtendedCurrent.Document() End Function '/** ' * Returns the current ui document ' * @return current ui document ' */ Public Function ThisUIDocument() As NotesUIDocument Call intializeDocument() Set ThisUIDocument = uiDocumentCurrent End Function '/** ' * Determines if a ui document is available ' * @return True/False ' */ Public Function hasUIDocument() As Boolean Call intializeUIDocument() Let hasUIDocument = Not ( uiDocumentCurrent Is Nothing ) End Function '/** ' * Returns the current Session ' * @return current Session ' */ Public Function ThisSession() As NotesSession Call intializeSession() Set ThisSession = sessionCurrent End Function '/** ' * Returns the current Users Name object ' * @return current user Name object ' */ Public Function CurrentUser() As NotesName Call intializeName() Set CurrentUser = nameCurrent End Function '/** ' * Returns the current users common name ' * @return current users common name ' */ Public Function CurrentUserCommon() As String Call intializeName() Let CurrentUserCommon = nameCurrent.Common End Function '/** ' * Returns the current users abbreviated name ' * @return current users abbreviated name ' */ Public Function CurrentUserAbbreviated() As String Call intializeName() Let CurrentUserAbbreviated = nameCurrent.Abbreviated End Function End Class '/** ' * A basic class to extend the NotesDocument class to reduce ' * code and improve error checking ' * ' * @author Chad Schelfhout http://www.chadsmiley.com.previewdns.com/ ' * @version 1.1 ' * ' * @history 1.0 Created ' * 1.1 converted properties to function/subs and ported to Java ' */ Class NotesDocumentExtended Private pDoc As NotesDocument '/** ' * Constructor ' */ Public Sub New() End Sub '/** ' * Returns the Values ofthe field if it is availabe ' * @param fieldName The name of the field on the document ' * @return the values of the field, or nothing ' */ Public Function getFieldValues ( fieldName As String ) As Variant Set getFieldValues = Nothing If hasDocument() Then If pDoc.hasItem( fieldName ) Then Let getFieldValues = pDoc.getFirstItem( fieldName).Values End If End If End Function '/** ' * Returns the Values ofthe field if it is availabe ' * @param fieldName The name of the field on the document ' * @return the notes item of the field, or nothing ' */ Public Function getFieldItem ( fieldName As String ) As NotesItem Set getFieldItem = Nothing If hasDocument() Then If pDoc.hasItem( fieldName ) Then Set getFieldItem = pDoc.getFirstItem( fieldName) End If End If End Function '/** ' * Replaces the fields value with the new one supplied ' * @param fieldName The name of the field on the document ' * @param Item the new value for the field ' */ Public Sub replaceField ( fieldName As String , Var As Variant ) If hasDocument() Then Call pDoc.ReplaceItemValue( fieldName , Var ) End If End Sub '/** ' * Returns the text representation of fields value ' * @param fieldName The name of the field on the document ' * @return the fields value as a string ' */ Public Function getFieldText ( fieldName As String ) As String Let getFieldText = "" If hasDocument() Then If pDoc.hasItem( fieldName ) Then Let getFieldText = pDoc.getFirstItem( fieldName).text End If End If End Function '/** ' * Returns the text representation of fields value as an abstraction ' * @param fieldName The name of the field on the document ' * @return the fields value as a string ' */ Public Function getFieldAbstraction ( fieldName As String ) As String Let getFieldAbstraction = "" If hasDocument() Then If pDoc.hasItem( fieldName ) Then Let getFieldAbstraction = pDoc.getFirstItem( fieldName).abstract( 64994 , False ,False ) End If End If End Function '/** ' * Returns the text representation of fields value as unformatted text ' * @param fieldName The name of the field on the document ' * @return the fields value as a string ' */ Public Function getFieldUnformattedText ( fieldName As String ) As String Let getFieldUnformattedText = "" If hasDocument() Then If pDoc.hasItem( fieldName ) Then If ( pDoc.GetFirstItem( fieldName ).Type = RICHTEXT ) Then Dim rti As NotesRichTextItem Set rti = pDoc.GetFirstItem( fieldName ) Let getFieldUnformattedText = rti.GetUnformattedText() Else Let getFieldUnformattedText = getFieldText( fieldName ) End If End If End If End Function '/** ' * Returns the text representation of fields value as formatted text ' * @param fieldName The name of the field on the document ' * @return the fields value as a string ' */ Public Function getFieldFormattedText ( fieldName As String , tabstrip As Boolean , lineLength As Integer ) As String Let getFieldFormattedText = "" If hasDocument() Then If pDoc.hasItem( fieldName ) Then If ( pDoc.GetFirstItem( fieldName ).Type = RICHTEXT ) Then Dim rti As NotesRichTextItem Set rti = pDoc.GetFirstItem( fieldName ) Let getFieldFormattedText = rti.GetFormattedText( tabstrip , lineLength ) Else Let getFieldFormattedText = getFieldText( fieldName ) End If End If End If End Function '/** ' * Determines if the field exists on the document ' * @param fieldName The name of the field on the document ' * @return weather the field exists ' */ Public Function hasField ( fieldName As String ) As Boolean Let hasField = False If hasDocument() Then Let hasField = pDoc.hasItem( fieldName ) End If End Function '/** ' * Determines if the field has text. by converting all values to text and checking the length ' * @param fieldName The name of the field on the document ' * @return weather the text length is zero ' */ Public Function hasFieldText ( fieldName As String ) As Boolean Let hasFieldText = False If hasDocument() Then Let hasFieldText = ( Len( getFieldText( fieldName ) ) > 0 ) End If End Function '/** ' * Determines if a document exists ' * @return weather there is a document ' */ Public Function hasDoc ( ) As Boolean Let hasDoc = Not ( pDoc Is Nothing ) End Function '/** ' * Determines if a document exists ' * @return weather there is a document ' */ Public Function hasDocument ( ) As Boolean Let hasDocument = Not ( pDoc Is Nothing ) End Function '/** ' * Returns the true NotesDocument ' * @return the NotesDocument ' */ Public Sub setDoc ( Doc As NotesDocument ) Set pDoc = Doc End Sub '/** ' * Returns the true NotesDocument ' * @return the NotesDocument ' */ Public Function Doc() As NotesDocument Set Doc = pDoc End Function '/** ' * Sets the true NotesDocument ' * @param the NotesDocument ' */ Public Sub setDocument ( Document As NotesDocument ) Set pDoc = Document End Sub '/** ' * Returns the true NotesDocument ' * @return the NotesDocument ' */ Public Function Document As NotesDocument Set Document = pDoc End Function End Class '/** ' * A basic class to extend the NotesDocumentCollection class to reduce ' * navigation issues. When trying to navigate through documents and deleting ' * some documents the developer trys to navigate to could be deleted ' * this class is intended to remove that possibility. ' * ' * @author Chad Schelfhout http://www.chadsmiley.com.previewdns.com/ ' * ' * @version 1.0 Created ' */ Public Class NotesDocumentCollectionExtended prevDoc As NotesDocument curDoc As NotesDocument nxtDoc As NotesDocument colDocs As NotesDocumentCollection Public Sub new() Call clear() End Sub '/** ' * Clears everything ' */ Public Sub clear() Set prevDoc = Nothing Set curDoc = Nothing Set nxtDoc = Nothing Set colDocs = Nothing End Sub '/** ' * Loads the document collection ' */ Public Sub LoadCollection ( docCollection As NotesDocumentCollection ) Set colDocs = docCollection Call getNavFirst() End Sub '/** ' * Navigates to the first document and returns the current document ' * @return the NotesDocument ' */ Public Function getNavFirst () As NotesDocument Set prevDoc = Nothing If hasCollection Then Set curDoc = colDocs.GetFirstDocument Set nxtDoc = colDocs.GetNextDocument(curDoc) End If Set getNavFirst = getCurrentDocument End Function Public Function getNavLast () As NotesDocument If hasCollection Then Set curDoc = colDocs.GetLastDocument Set prevDoc = colDocs.GetPrevDocument(curDoc) Set nxtDoc = Nothing End If Set getNavLast = getCurrentDocument End Function '/** ' * Navigates to the next document and returns the current document ' * @return the NotesDocument ' */ Public Function getNavNext () As NotesDocument If hasCollection Then If hasNextDocument Then Set curDoc = nxtDoc Call setPrevDocument() Call setNextDocument() Elseif hasCurrentDocument Then Call setPrevDocument() Call setNextDocument() Set curDoc = Nothing End If End If Set getNavNext = getCurrentDocument End Function '/** ' * Navigates to the previous document and returns the current document ' * @return the NotesDocument ' */ Public Function getNavPrev() As NotesDocument If hasCollection Then If hasPrevDocument Then Set curDoc = prevDoc Call setPrevDocument() Call setNextDocument() Elseif hasCurrentDocument Then Call setPrevDocument() Call setNextDocument() Set curDoc = Nothing End If End If Set getNavPrev = getCurrentDocument End Function '/** ' * Navigates to the next document if it is available otherwise try the ' * document after the next until a document is found or the next document is nothing ' */ Private Sub setNextDocument() If hasCollection Then If hasCurrentDocument Then If Not colDocs.GetNextDocument( curDoc ) Is Nothing Then If colDocs.GetNextDocument( curDoc ).isDeleted Then ' Print "Next Document Deleted" Set nxtDoc = colDocs.GetNextDocument( nxtDoc ) Else Set nxtDoc = colDocs.GetNextDocument( curDoc ) End If If hasNextDocument Then If nxtDoc.IsDeleted Then ' Print "Found Deleted document Move next" Call setNextDocument() End If End If Else Set nxtDoc = Nothing End If Else Set nxtDoc = Nothing End If Else Set nxtDoc = Nothing End If End Sub '/** ' * Navigates to the previous document if it is available otherwise try the ' * document before the previous until a document is found or the previous document is nothing ' */ Private Sub setPrevDocument() If hasCollection Then If hasCurrentDocument Then If Not colDocs.GetPrevDocument( curDoc ) Is Nothing Then If colDocs.GetPrevDocument( curDoc ).isDeleted Then ' Print "Previous Document Deleted" Set prevDoc = colDocs.GetPrevDocument( prevDoc ) Else Set prevDoc = colDocs.GetPrevDocument( curDoc ) End If If hasPrevDocument Then If prevDoc.IsDeleted Then ' Print "Found Deleted document Move previous" Call setPrevDocument() End If End If Else Set prevDoc = Nothing End If Else Set prevDoc = Nothing End If Else Set prevDoc = Nothing End If End Sub '/** ' * Returns the current document ' * @return the NotesDocument ' */ Public Function getCurrentDocument() As NotesDocument Set getCurrentDocument = curDoc End Function '/** ' * Returns the previous document ' * @return the NotesDocument ' */ Public Function getPrevDocument() As NotesDocument Set getPrevDocument = prevDoc End Function '/** ' * Returns the next document ' * @return the NotesDocument ' */ Public Function getNextDocument() As NotesDocument Set getNextDocument = nxtDoc End Function '/** ' * Returns weather the current document exists ' * @return the True/False ' */ Public Function hasCurrentDocument() As Boolean Let hasCurrentDocument = Not curDoc Is Nothing End Function '/** ' * Returns weather the next document exists ' * @return the True/False ' */ Public Function hasNextDocument() As Boolean Let hasNextDocument = Not nxtDoc Is Nothing End Function '/** ' * Returns weather the previous document exists ' * @return the True/False ' */ Public Function hasPrevDocument() As Boolean Let hasPrevDocument = Not prevDoc Is Nothing End Function '/** ' * Returns weather a collection exists ' * @return the True/False ' */ Public Function hasCollection() As Boolean Let hasCollection = Not colDocs Is Nothing End Function End Class </textarea> |
February 2nd, 2007 - 07:37
How about including a method ‘DBColumn’ in the class NotesDocumentCollectionExtended, to retrieve the values of a fields from all the documents in that collection?
February 2nd, 2007 - 20:57
I will look into adding this but until then consider some work that Jerry has done:{ Link }