Module RemoteEntryMixin.pkg
1//****************************************************************************//
2// //
3// $File name : RemoteEntry_MX.pkg //
4// $File title : RemoteEntryMixin class //
5// Notice : //
6// $Author(s) : John Tuohy //
7// //
8// Confidential Trade Secret. //
9// Copyright 1998-1999 Data Access Corporation, Miami FL, USA //
10// All Rights reserved //
11// DataFlex is a registered trademark of Data Access Corporation. //
12// $Rev History //
13// //
14// $Rev History //
15// JJT 8/1/99 Added RequestDDUpdate function //
16// JJT 7/30/99 Added peFieldMultiUser for field level change checking //
17// JJT 7/26/99 Added pbAllowxxx to disable save, delete, clear,find //
18// //
19// JJT 9/15/98 Added pbReportErrors, if false errors are not displayed //
20// allowing developer to control how errors are reported. //
21// Added ErrorQueueStart/End. //
22// HasErrors changed to ErrorCount //
23// JJT 8/27/98 Changed messages to functions (doRequestSave, etc) //
24// which return non-zero error status values //
25// JJT 8/6/98 Added support to pbShowEntryError. Only saves will ask //
26// the DD to return errors (all others just ignore the data) //
27// JW 1998-06-27 Source Merge for Internet by Janne Wassberg //
28// //
29//****************************************************************************//
30
31
32// Pkg: RemoteEntry_mx.pkg
33//
34// Class: RemoteEntryMixin
35// This provides mixin support to add save, delete, clear, find logic
36// to a BPO. This could have been sub-classed. Creating a mixin gives
37// us a bit more flexibility.
38//
39// These methods assume that there is no permanance in these BPO processes. When
40// a process is started (e.g. a save) all DD data is cleared and it is expected
41// that all information will be provided by the remote object. The remote object
42// will refind any existing records (the remote object must know what those
43// records are) and will update any changed data. Once this is completed, the BPO
44// will take over and process the data as needed.
45//
46// Usage:
47//
48// Use RemoteEntry_mx.pkg
49// Class RemoteEntryProcess is an DistributedBusinessProcess
50// Procedure Construct_Object
51// Forward Send Construct_Object
52// Send Define_RemoteEntryMixin
53// End_procedure
54// Import_Class_Protocol RemoteEntryMixin
55// End_Class
56//
57//
58// Remote BPO requests
59//
60// The following Public Request Functions are supported below
61// In all cases they return an integer error status. If 0, operation
62// was successful, if not zero the Stat_code for the last operation is returned
63//
64// DoRequestSave sFileName
65// DoRequestClear sFileName bClearAll
66// DoRequestDelete sFileName
67// DoRequestFind sFileName sFieldName iFindMode
68// DoRequestDDUpdate sFileName bShowErrors
69//
70// Properties
71//
72// pbAllowSaveNew Boolean - If false, DoRequestSave for new records is disabled
73// pbAllowSaveEdit Boolean - If false, DoRequestSave for old (edited) records is disabled
74// pbAllowClear Boolean - If false, DoRequestClear is disabled
75// pbAllowDelete Boolean - If false, DoRequestDelete is disabled
76// pbAllowFind Boolean - If false, DoRequestFindSave is disabled
77// pbAllowDDupdate Boolean - if false, DoRequestDDUpdate is disabled
78// peFieldMultiUser mode - 0-don't check, 1-check required, 2-check desired
79// pbClearAfterSave Boolean - determines is a clear should occur after save
80// pbReportErrors Boolean - should errors be reported after process?
81// phREO_MainDD - these are set during request and can be queried
82// piREO_OperationStatus to determine what happened.
83//
84// The Following messages are suitable for augmentation
85//
86// OnReportSaveStatus by default, the report status messages
87// OnReportDeleteStatus report errors by sending ReportAllErrors
88// OnReportClearStatus
89// OnReportFindStatus
90// OnReportValidateStatus
91//
92// Get SaveConfirmation The confirmation messages do nothing and are
93// Get DeleteConfirmation supplied for future augmentation.
94// Get ClearConfirmation
95//
96// All of these messages send an error status reporting procedure passing the
97// error status. Those messages are ReportxxxxStatus where xxxx is "save",
98// "clear", "delete" and "find". By default they report all errors. These are
99// intended to be augmentation points where you can add custom code concerning
100// the result of operation
101
102// These messages require the additional following Support from the class they
103// are mixed into:
104//
105// Get MapFileNametoDD - return DD object ID of passed filename
106// Get MaptoFileNumber - return file number from fieldname
107// Get MaptoFieldNumber - return field number from file number and field name
108// Get RequestUpdateData - Update all records & data to DD. Refind recs/update values
109// Get RequestUpdateRecords - loads all records to DD and finds as needed
110// Get RequestUpdateFileFieldValues - Load all data into DDs
111// Send ReportAllErrors - Report all errors in the handler queue
112// Get ErrorCount - return true, if errors exist in queue
113// Send ErrorQueueStart - start queueing of errors
114// Send ErrorQueueEnd - end queueing of errors
115//
116use VDFBase.pkg
117
118//
119// possible Process Status (PS_) conditions that can occur during BPO request
120//
121
122Enumeration_list // Save Status Values
123 Define PS_SaveNoChange // no errors, but nothing to do (yawn)
124 Define PS_SaveNewRecord // A new record was saved
125 Define PS_saveOldRecord // An old Record was altered
126 Define PS_SaveNotConfirmed // save not approved from user confirmation (for future use)
127 Define PS_SaveError // Some kind of error occurred. errors are logged
128End_Enumeration_list
129
130Enumeration_list // Clear/Clear_All Status Values
131 Define PS_ClearOk
132 Define PS_ClearAllOk
133 Define PS_ClearNotConfirmed
134 Define PS_ClearError
135End_Enumeration_list
136
137Enumeration_list // Find Status Values
138 Define PS_FindOk
139 Define PS_FindError
140End_Enumeration_list
141
142Enumeration_list // Delete Status Values
143 Define PS_DeleteOk
144 Define PS_DeleteNoRec
145 Define PS_DeleteNotConfirmed
146 Define PS_DeleteError
147End_Enumeration_list
148
149
150{ ClassLibrary=WebApp }
151{ OverrideProperty=peNeighborhood DesignTime=False }
152Class RemoteEntryMixin is a Mixin
153
154 { Visibility=Private }
155 Procedure Define_RemoteEntryMixin
156 // after a save, should we clear the data?
157 { Category=Data }
158 { PropertyType=Boolean }
159 Property Integer pbClearAfterSave True
160
161 // these disable operations. This can used to increase security within a WBO
162 { Category=Data }
163 { PropertyType=Boolean }
164 Property Integer pbAllowSaveNew True // disables saving of new records
165 { Category=Data }
166 { PropertyType=Boolean }
167 Property Integer pbAllowSaveEdit True // disables editing of existing records.
168 { Category=Data }
169 { PropertyType=Boolean }
170 Property Integer pbAllowClear True
171 { Category=Data }
172 { PropertyType=Boolean }
173 Property Integer pbAllowDelete True
174 { Category=Data }
175 { PropertyType=Boolean }
176 Property Integer pbAllowFind True
177 { Category=Data }
178 { PropertyType=Boolean }
179 Property Integer pbAllowDDUpdate True
180 // this determines if errors are reported automatically. If shut off you
181 // can do a process and then check for errors and report them
182 // manually
183 { Category="Error Handling" }
184 { PropertyType=Boolean }
185 Property Integer pbReportErrors True
186
187 // This determines if the WBO will use multi-user field changed checking and how strict
188 // we want to be. Note that in all cases, M/U integrity is maintained. When relaxed we
189 // assume that all fields submitted from the browswer are changed. To support this the browswer
190 // must supply a properly formatted changed field string. Note that the check is only needed
191 // during a save of an existing record.
192 // 0 = Never check for field change (always assume all submitted fields are changed)
193 // 1 = Check required. Error if we can't check
194 // 2 = Check desired. If the browser provides the proper information, use it.
195 Enum_list
196 Define C_fmuNone for 0
197 Define C_fmuRequired for 1
198 Define C_fmuDesired for 2
199 End_Enum_List
200
201 { Category=Data }
202 { EnumList="C_fmuNone, C_fmuRequired, C_fmuDesired" }
203 Property Integer peFieldMultiUser C_fmuNone
204
205 // the request operations should set those allowing other
206 // messages to use this information as needed
207 { DesignTime=False }
208 Property integer phREO_MainDD 0 // current main DD of operation
209 { DesignTime=False }
210 Property integer piREO_OperationStatus 0 // what happended?
211
212 End_Procedure
213
214// #IFDEF SUPPORT$OLD$INTERFACE
215
216// // Old public messages. These support the version 1 WebApp interface
217// // don't use these
218// Procedure Set ClearAfterSave_state integer bState
219// Set pbClearAfterSave to bState
220// End_Procedure
221
222// Function ClearAfterSave_state Returns integer
223// Function_Return (pbClearAfterSave(self))
224// End_Function
225
226// Procedure Set ReportErrors_state integer bState
227// Set pbReportErrors to bState
228// End_Procedure
229
230// Function ReportErrors_state Returns integer
231// Function_Return (pbReportErrors(self))
232// End_Function
233
234// #ENDIF SUPPORT$OLD$INTERFACE
235
236
237 // these are for user confirmation of an operation.
238 // They do nothing and return 0 which means OK.
239 // These are provided for augmentation.
240
241 Function SaveConfirmation Returns integer
242 Function_Return 0
243 End_Function
244
245 Function DeleteConfirmation Returns integer
246 Function_Return 0
247 End_Function
248
249 Function ClearConfirmation Returns integer
250 Function_Return 0
251 End_Function
252
253
254 Function DoRequestSave String sFileName returns integer
255 Integer iStat
256 Integer hDD
257 integer bErr bNewRec bAllowSaveNew bAllowSaveEdit
258 Get pbAllowSaveNew to bAllowSaveNew
259 Get pbAllowSaveEdit to bAllowSaveEdit
260
261 Send ClearErrors
262 // if saves are completely disabled...end it
263 If (not(bAllowSaveNew) AND not(bAllowSaveEdit)) Function_Return 1
264
265 Send ErrorQueueStart // Start report queue, clear error reporting system
266
267 Get MapFileNametoDD sFileName True to hDD // this is the save DD
268 Move (hDD=0) to bErr
269 Set phREO_MainDD to hDD
270
271 If Not bErr Begin
272 // use check field change?
273 Set piUseChanged to (peFieldMultiUser(self)<>C_fmuNone)
274 Set pbShowEntryError to True // show entry errors for saves
275 Get RequestUpdateData hDD to bErr // refind all records and data from ASP file
276
277 If not bErr Begin
278 If (Should_Save(hDD)) Begin // Only Save if changes exist
279
280 Move (not(HasRecord(hDD))) to bNewRec
281
282 // if new save not allowed and it is a new record or
283 // if edit not allowed and it is an old record...don't allow
284 If ( ( bNewRec AND not(bAllowSaveNew) ) OR ;
285 ( not(bNewRec) AND not(bAllowSaveEdit) ) ) ;
286 function_return 1
287
288 If (SaveConfirmation(self)) ; // non-zero is a failed confirmation
289 Move PS_SaveNotConfirmed to iStat
290 Else Begin
291 // (at some point we may want to add a user verification)
292 Get Request_Validate_All of hDD to bErr // Validate-All Fields (includes FindReq)
293 If Not bErr Begin
294 // a new save, or an edit?
295 Move (if( bNewRec, PS_SaveNewRecord, PS_SaveOldRecord)) to iStat
296 Send Request_Save to hDD // Ask DD to save the Record
297 Move (Err) to bErr // Err indicator is returned if failure
298 End
299 End
300 End
301 else ;
302 Move PS_SaveNoChange to iStat // no save, nothing to do.
303 End
304 Set piUseChanged to False
305 End
306
307 If bErr Move PS_SaveError to iStat // else iStat is already set!
308 Set piREO_OperationStatus to iStat
309
310 Send OnReportSaveStatus iStat hDD // report what happened!
311
312 Send ErrorQueueEnd
313
314 If (Not(bErr) AND pbClearAfterSave(Self)) ; // should we clear after the save
315 Send Clear to hDD
316 Function_Return (If(bErr, iStat, 0))
317 End_function
318
319 // good for augmentation!
320 { MethodType=Event }
321 Procedure OnReportSaveStatus integer iSaveStat integer hSaveDD
322 If (iSaveStat=PS_SaveError AND pbReportErrors(self) ) ;
323 Send ReportAllErrors C_$ErrorsDuringSave
324 End_Procedure
325
326
327
328 Function DoRequestClear String sFileName Integer bClearAll returns integer
329 Integer iStat
330 Integer hDD
331 integer bErr
332
333 Send ClearErrors
334 If (not(pbAllowClear(self))) Function_Return 1
335
336 Send ErrorQueueStart // Start report queue, clear error reporting system
337
338 Get MapFileNametoDD sFileName True to hDD // this is the clear DD
339 Move (hDD=0) to bErr
340 Set phREO_MainDD to hDD
341
342 If Not bErr Begin
343
344 // we actually have to refind records for a clear. A clear may not clear
345 // parents and we want them to be around. We resynch the data because it is
346 // possible to have a changed parent which should remain changed. Also, the synch
347 // change lets us ask for data-loss (in the future)
348
349 Set pbShowEntryError to False // do not show entry errors for clears
350 Get RequestUpdateData hDD to bErr // refind all records and data from ASP file
351
352 If not bErr Begin
353 If (Should_Save(hDD) AND ClearConfirmation(self)) Begin // non-zero is a failed confirmation
354 Move PS_ClearNotConfirmed to iStat
355 End
356 Else Begin
357 If bClearAll Send Clear_All to hDD
358 Else Send Clear to hDD
359 Move (if(bClearAll, PS_ClearAllOk, PS_ClearOk)) to iStat
360 end
361 end
362 End
363
364 If bErr Move PS_ClearError to iStat // else iStat is already set!
365 Set piREO_OperationStatus to iStat
366
367 Send OnReportClearStatus iStat hDD // report what happened!
368
369 Send ErrorQueueEnd
370
371 Function_Return (If(bErr, iStat, 0))
372 End_Function
373
374 // good for augmentation!
375 { MethodType=Event }
376 Procedure OnReportClearStatus integer iClearStat integer hClearDD
377 If (iClearStat=PS_ClearError AND pbReportErrors(self)) ;
378 Send ReportAllErrors C_$ErrorsDuringClear
379 End_Procedure
380
381
382 Function DoRequestDelete String sFileName returns integer
383 Integer iStat // keep track of delete process status
384 Integer hDD
385 integer bErr
386
387 Send ClearErrors
388 If (not(pbAllowDelete(self))) Function_Return 1
389
390 Send ErrorQueueStart // Start report queue, clear error reporting system
391
392 Get MapFileNametoDD sFileName True to hDD // this is the delete DD
393 Move (hDD=0) to bErr
394 Set phREO_MainDD to hDD
395
396 If Not bErr Begin
397
398 // We must synch all data, in case the user does not delete the record
399 // we can restore all of the DD info, included changes
400 Set pbShowEntryError to False // do not show entry errors for deletes
401 Get RequestUpdateData hDD to bErr // refind all records and data from ASP file
402
403 If not bErr Begin
404 If (not(HasRecord(hDD))) Begin
405 Move PS_DeleteNoRec to iStat
406 End
407 Else If (DeleteConfirmation(self)) ; // non-zero is a failed confirmation
408 Move PS_DeleteNotConfirmed to iStat
409 Else Begin
410 Send Request_delete to hDD // attempt the delete. (Errors happen)
411 If (Err) Move 1 to bErr // Err indicator is returned if failure
412 Else Move PS_DeleteOK to iStat
413 End
414 end
415 End
416
417 If bErr Move PS_DeleteError to iStat // else iStat is already set!
418 Set piREO_OperationStatus to iStat
419
420 Send OnReportDeleteStatus iStat hDD // report what happened!
421 Send ErrorQueueEnd
422
423 If (Not(bErr)) ; // If no errors, we should clear after delete
424 Send Clear to hDD
425
426 Function_Return (If(bErr, iStat, 0))
427 End_Function
428
429 // good for augmentation!
430 { MethodType=Event }
431 Procedure OnReportDeleteStatus integer iDeleteStat integer hDeleteDD
432 If (iDeleteStat=PS_DeleteError AND pbReportErrors(self)) ;
433 Send ReportAllErrors C_$ErrorsDuringDelete
434 End_Procedure
435
436
437 Function DoRequestFind String sFileName String sFieldName Integer iFindMode returns integer
438 Integer iStat // keep track of delete process status
439 Integer hDD
440 integer iFile iField iIndex
441 integer bErr bIsIndex
442
443 Send ClearErrors
444 If (not(pbAllowFind(self))) Function_Return 1
445
446 Send ErrorQueueStart // Start report queue, clear error reporting system
447
448 Get MapFileNametoDD sFileName True to hDD // this is the find DD
449 Move (hDD=0) to bErr
450 Set phREO_MainDD to hDD
451
452 Get Main_file of hDD to iFile // this is the file#
453 if Not bErr Begin
454 Move (trim(sFieldName)) to sFieldName
455 If (sFieldName='') Begin
456 Move 1 to iIndex
457 Move 1 to bIsIndex
458 end
459 else If ("0123456789" contains left(sFieldName,1)) Begin
460 Move sFieldName to iIndex
461 Move 1 to bIsIndex
462 end
463 Else Begin
464 Get MaptoFieldNumber iFile sFieldName To iField
465 If (iField<0) Move 1 to bErr
466 end
467 End
468
469 If Not bErr Begin
470
471 Set pbShowEntryError to False // do not show entry errors for Finds
472 Get RequestUpdateData hDD to bErr // refind all records and data from ASP file
473 If not bErr Begin
474 If bIsIndex ;
475 Send File_Index_Find to hDD iFindMode iFile iIndex True True False
476 else ;
477 Send File_Field_Find to hDD iFindMode iFile iField True True False
478 Get ErrorCount to bErr
479 End
480 End
481
482 Move (if(bErr, PS_FindError, PS_FindOk)) to iStat
483 Set piREO_OperationStatus to iStat
484
485 Send OnReportFindStatus iStat hDD // report what happened!
486 Send ErrorQueueEnd
487
488 Function_Return (If(bErr, iStat, 0))
489 End_Function
490
491
492 // good for augmentation!
493 { MethodType=Event }
494 Procedure OnReportFindStatus integer iFindStat integer hDD
495 If (iFindStat=PS_FindError AND pbReportErrors(self)) ;
496 Send ReportAllErrors C_$ErrorsDuringFind
497 End_Procedure
498
499 Function DoRequestDDUpdate String sFileName integer bShowErrors integer iExtra returns integer
500 Integer hDD
501 integer bErr
502
503 Send ClearErrors
504 If (not(pbAllowDDUpdate(self))) Function_Return 1
505
506 // currently iExtra is not used.
507 Send ErrorQueueStart // Start report queue, clear error reporting system
508
509 Get MapFileNametoDD sFileName True to hDD // this is the save DD
510 Move (hDD=0) to bErr
511 Set phREO_MainDD to hDD
512
513 If Not bErr Begin
514 // use check field change?
515 Set piUseChanged to (peFieldMultiUser(self)<>C_fmuNone)
516 Set pbShowEntryError to True // show entry errors for saves
517 Get RequestUpdateData hDD to bErr // refind all records and data from ASP file
518 Set piUseChanged to False
519 If not bErr Begin
520 Get Request_Validate_All of hDD to bErr // Validate-All Fields (includes FindReq)
521 End
522 End
523
524 If bShowErrors Send OnReportValidateStatus bErr hDD // report what happened!
525
526 Send ErrorQueueEnd
527 Indicate Err False
528 Function_Return bErr
529 End_function
530
531 // good for augmentation!
532 { MethodType=Event }
533 Procedure OnReportValidateStatus integer iValStat integer hValDD
534 If (iValStat AND pbReportErrors(self) ) ;
535 Send ReportAllErrors C_$ErrorsDuringValidate
536 End_Procedure
537
538End_Class // remote_entry_mixin
539