%REM Created by Joacim Boive 070507 - 060523-21 Note! All classes should declare their public values in alphabetical order, or else strange events may occur. (Like data loss!) Best Practices states that each class should be contained in a separate library. However this wasn't possible as the Notes Client would crash every time. This is probably a bug and is just tested on 7.01 and COULD work in a never version (7.02FP1 is the latest as of this writing). But since this probably is the version that will be used in production we are force to live with this. %END REM Private s As NotesSession Private db As NotesDatabase Private m_key As String Const V_ISAVAILABLE="vIsAvailable" 'view used by entry.hasErrands Const V_LIST="vLstXMLGrid" 'view used by wsInfo.getList Const V_DETAILS="vLstXMLDetail" 'view used by wsInfo.getDetails Const ALOG="alog.nsf" 'AgentLog database that stores error messages. Const SEPARATOR="#%" 'Separator used by the views to separate data fields. Class Skeleton 'Base class that other classes inherits some function from. Private result As Variant Private strErrMsg As String Private Sub throwFault (fault As WS_FAULT, faultText As String) 'Generates a SOAP-errormessage with the supplied errormessage in return to the request. Call fault.setFault(True) Call fault.setFaultString(faultText) End Sub Private Function chkElements(isNo As Integer, ShouldBe As Integer, returnFault As WS_FAULT) As Boolean 'Verfyfies that the expected number of elements are available. If(isNo=shouldBe) Then chkElements=True Else strErrMsg=m_key & " - Returned " & isNo+1 & " elements, but should have returned: " & shouldBe+1 & " elements" Dim logIt As New logError(Lsi_info(2), Lsi_info(12), "Unexpected number of elements", strErrMsg, Lsi_info(1)) Call throwFault(returnFault, strErrMsg) chkElements=False End If End Function Private Function strIsEmpty(strInfo As String, returnFault As WS_FAULT) As Boolean 'Checks to see if the supplied string is empty. If(strInfo="") Then strErrMsg=m_key & " - doesn't contain any data!" Dim logIt As New logError(Lsi_info(2), Lsi_info(12), "Missing Data", strErrMsg, Lsi_info(1)) Call throwFault(returnFault, strErrMsg) strIsEmpty=True Else strIsEmpty=False End If End Function Private Function viewIsAvailable(view As NotesView, viewName As String, returnFault As WS_FAULT) As Boolean 'Check if the supplied view exists. If(view Is Nothing) Then strErrMsg=viewName & " - doesn't exist in database " & db.FilePath &"!" Dim logIt As New logError(Lsi_info(2), Lsi_info(12), "Missing Data", strErrMsg, Lsi_info(1)) Call throwFault(returnFault, strErrMsg) viewIsAvailable=False Else viewIsAvailable=True End If End Function Private Function entryIsAvailable(obj As Variant, key As String, returnFault As WS_FAULT) As Boolean 'Checks if an entry, like a document or viewentry, exists. If(obj Is Nothing) Then strErrMsg=key & " - doesn't exist!" Dim logIt As New logError(Lsi_info(2), Lsi_info(12), "Missing Data", strErrMsg, Lsi_info(1)) Call throwFault(returnFault, strErrMsg) entryIsAvailable=False Else entryIsAvailable=True End If End Function Private Function getdate(strDate As String) As XSD_DATETIME 'Used to return a strDate value in the proper SOAP format. If(strDate<>"") Then Dim dt As New NotesDateTime(strDate) Set getdate = New XSD_DATETIME Call getdate.SetValueFromNotesDateTime(dt) End If End Function End Class Class Detail As Skeleton 'Object to return details about selected errand. Public action_comment As String Public action_cost As String Public action_responsible As String Public complainer_adress As String Public complainer_epost As String Public complainer_fnr As String Public complainer_namn As String Public complainer_postadress As String Public complainer_tele As String Public doc_action As String Public doc_description As String Public doc_loggedby As String Public doc_recap As String Public doc_rubrik As String Public end_datefinished As XSD_DATETIME Public end_terminatedby As String Public info_category As String Public info_complaint_date As XSD_DATETIME Public info_complaint_nr As String Public info_state As String Public info_subcategory As String Public info_type As String Public other_info As String Function setItems(strInfo As Variant, key As String, returnFault As WS_FAULT) As Detail 'Set the value of the object and returns it to the calling function. Const NO_ELEMENTS=22 'Number of expected object that strInfo should contain after processing. On Error Goto handler If(strIsEmpty(Cstr(strInfo), returnFault)=False) Then result=Split(strInfo, SEPARATOR) If(chkElements(Ubound(result), NO_ELEMENTS, returnFault)) Then action_comment=result(17) action_cost=result(18) action_responsible=result(19) complainer_adress=result(3) complainer_epost=result(6) complainer_fnr=result(7) complainer_namn=result(2) complainer_postadress=result(4) complainer_tele=result(5) doc_action=result(15) doc_description=result(14) doc_loggedby=result(12) doc_recap=result(16) doc_rubrik=result(13) Set end_datefinished=getDate(result(20)) end_terminatedby=result(21) info_category=result(9) Set info_complaint_date=getDate(result(0)) info_complaint_nr=result(11) info_state=result(1) info_subcategory=result(10) info_type=result(8) other_info=result(22) End If End If exitFunc: Exit Function handler: Dim NotesError As New NotesError(Lsi_info(2),Lsi_info(12), returnFault) Resume exitFunc End Function End Class Class Entry As Skeleton 'Object that returns a few details about the errand. Intended use is to build a view/list/grid of many entrys. Public complaint_date As XSD_DATETIME Public complaint_number As String Public complaint_type As String Public headline As String Public logged_by As String Function setItems(strInfo As Variant, key As String, returnFault As WS_FAULT) As Integer Const NO_ELEMENTS=4 m_key=key On Error Goto handler If(strIsEmpty(Cstr(strInfo), returnFault)=False) Then result=Split(strInfo, SEPARATOR) If(chkElements(Ubound(result), NO_ELEMENTS, returnFault)) Then 'date+";"+KlagomalsNr+";"+typ+";"+inskrivare+";"+rubrik Set complaint_date=getDate(result(0)) complaint_number=result(1) complaint_type=result(2) logged_by=result(3) headline=result(4) End If End If setItems=1 exitFunc: Exit Function handler: Dim NotesError As New NotesError(Lsi_info(2),Lsi_info(12), returnFault) Resume exitFunc End Function End Class Class wsInfo As Skeleton 'The WebService! Sub New Set s = New NotesSession Set db=s.CurrentDatabase End Sub Public Function hasErrands(fNr As Double, returnFault As WS_FAULT) As Boolean 'Check to see if the supplied insurance number has any errands. Dim view As NotesView Dim doc As NotesDocument Dim response As Boolean On Error Goto handler Set db=s.CurrentDatabase Set view=db.GetView(V_ISAVAILABLE) m_key=Cstr(fNr) response=False If viewIsAvailable(view, V_ISAVAILABLE, returnFault) Then Set doc=view.GetDocumentByKey(m_key, True) If(Not doc Is Nothing) Then If(doc.IsValid) Then response=True End If End If Else End If hasErrands=response exitFunc: Exit Function handler: Dim NotesError As New NotesError(Lsi_info(2),Lsi_info(12), returnFault) Resume exitFunc End Function Public Function getDetails(errandNr As String, returnFault As WS_FAULT) As Detail 'Get the details of the supplied errandnumber Dim view As NotesView Dim ve As NotesViewEntry Dim response As New Detail Set view=db.GetView(V_DETAILS) m_key=errandNr If(viewIsAvailable(view, V_DETAILS, returnFault)) Then Set ve=view.GetEntryByKey(m_key, True) If(entryIsAvailable(ve, m_key, returnFault)) Then Call response.setItems(ve.ColumnValues(2), m_key, returnFault) End If Set getDetails=response End Function Public Function getList(fNr As Double, returnFault As WS_FAULT) As VARIANTARRAY_HOLDER 'Create a list of existing errands that the supplied insurancenumber has. Dim view As NotesView Dim doc As NotesDocument Dim vc As NotesViewEntryCollection Dim ve As NotesViewEntry Dim response As Entry Dim reply As New VARIANTARRAY_HOLDER Dim i As Integer On Error Goto handler Set view=db.GetView(V_LIST) m_key=fNr If(viewIsAvailable(view, V_LIST, returnFault)) Then Set vc=view.GetAllEntriesByKey(m_key, True) Set ve=vc.GetFirstEntry If(entryIsAvailable(ve, m_key, returnFault)) Then Redim reply.Value(vc.Count) While Not ve Is Nothing If(ve.IsValid) Then Set response=New Entry Call response.setItems(ve.ColumnValues(2), m_key, returnFault) Set reply.Value(i)=response i=i+1 End If Set ve=vc.GetNextEntry(ve) Wend End If End If Set getList=reply exitFunc: Exit Function handler: Dim NotesError As New NotesError(Lsi_info(2), Lsi_info(12), returnFault) Resume exitFunc End Function End Class Class logError As Skeleton 'Object that is used to store messages to a log-database. Private s As NotesSession Private db As NotesDatabase Sub new(location As String, caller As String, strErr As String, strError As String, strErl As String) Set s=New NotesSession Set db=New NotesDatabase("", ALOG ) If(db.IsOpen) Then Dim currentLog As New NotesLog(s.CurrentAgent.ServerName & " - " & s.CurrentDatabase.FileName & " / " & s.CurrentAgent.Name) Call currentLog.OpenNotesLog( "", ALOG) Call currentLog.LogError(1001, caller & " / " & location & " - Error: " & strErr & " - " & strError & " at line: " & strErl & " - "_ & "Memory allocated: " & Lsi_info(50) & " / Memory from OS: " & Lsi_info(51) & " / Memory blocks used: " & Lsi_info(52)) Call currentLog.Close Else Msgbox |ERROR: Database - "| & ALOG & |" needs to be created for agent error logging to work...| End If End Sub End Class Class notesError As Skeleton 'The error handling object. Sub new(location As String, caller As String, returnFault As WS_FAULT) 'Store the error message to the logdatabase. Dim logIt As New logError(location ,caller, Str(Err), Error$, Cstr(Erl)) 'Return a SOAP-formatted error message to the requester. Call throwFault(returnFault, caller & " / " & location & " - Error: " & Str(Err) & " - " & Error$ & " at line: " & Cstr(Erl)) 'Log an error to the server console and log file of the server. Msgbox caller & " / " & location & " - Error: " & Str(Err) & " - " & Error$ & " at line: " & Cstr(Erl) & Chr(10)_ & "Memory allocated: " & Lsi_info(50) & " / Memory from OS: " & Lsi_info(51) & " / Memory blocks used: " & Lsi_info(52), 0+48, "Error" End Sub End Class
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.