Lines 1-3 are a utility method to trigger the Xots task. It creates a new instance of the
UserOutput class and passes it to the Xots service.
Lines 6 onwards are the
UserOutput class. Note that it extends the
Line 5 contains annotations that determine two aspects that Xots applies to the object. The first tells it to clone the current user session, so
SessionType.CURRENT will be the same as
SessionType.NATIVE will still be available if required. The second tells it the scope is XSPSCOPED, which means all the XPages-related objects - scope maps, FacesContext and XSPContext - will be made available to the tasklet.
Lines 8 - 10 are the constructor for the class. In this scenario, the scopes have everything required. But if there was additional information required - for example a UNID of a document to run against - that could be passed into the constructor. Obviously Domino objects cannot be passed into the constructor of a Xots tasklet. So you would need to pass distinguishing information and retrieve the Domino object during the
Lines 12 onwards are the
run method. A class that implements Runnable will need to have this method, it's the one that is triggered when Xots runs the tasklet. Because this is a Runnable - a background task that is just kicked off and allowed to complete - it doesn't return anything.
Lines 14 - 16 show how to get a handle on scoped variables and other objects passed into the Xots context object. Here the code checks whether the sessionScope variable already exists and if so clears it.
Lines 17 - 20 get the database as the current user and two views, one of states and one of contacts by state.
Lines 21 onwards iterate each state in the view of states. A message is added to the StringBuilder giving the name of the state being processed.
Lines 26 - 31 iterate all contacts for that state, creating a comma-separated string of names for all contacts in that state.
Lines 32 - 36 add the names (or a message saying there were no names) and a carriage return.
Lines 39 - 41 contain the error handling. This shows how to output the error to OpenLog using
XotsUtil. By passing the context, the logging will be able to output the current database and the Xots class the error is triggered from.