Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

public static void testBackground() {
	Xots.getService().submit(new UserOutput());
}

@Tasklet(session = Tasklet.Session.CLONE, context = Tasklet.Context.XSPSCOPED)
private static class UserOutput extends AbstractXotsXspRunnable {

	public UserOutput() {

    }

    public void run() {
    	try {
        	if (getContext().getSessionScope().containsKey("javaXotsOutput")) {
            	getContext().getSessionScope().put("javaXotsOutput", null);
            }
            StringBuilder sb = new StringBuilder();
            Database currDb = Factory.getSession(SessionType.CURRENT).getCurrentDatabase();
            View states = currDb.getView("AllStates");
            View people = currDb.getView("AllContactsByState");
            for (Document state : states.getAllDocuments()) {
            	String name = state.getItemValueString("Name");
                String key = state.getItemValueString("Key");
                sb.append("Processing " + name + "....<br/>");
                StringBuilder names = new StringBuilder();
                for (Document doc : people.getAllDocumentsByKey(key, true)) {
                	String personName = doc.getItemValueString("FirstName") + " "
                    	+ doc.getItemValueString("LastName");
                    names.append(personName);
                    names.append(", ");
                }
                if (names.length() > 2) {
                	sb.append(names.substring(0, names.length() - 2) + "<br/>");
                } else {
                	sb.append("No names found.<br/>");
                }
            }
            getContext().getSessionScope().put("javaXotsOutput", sb.toString());
        } catch (Throwable t) {
        	XotsUtil.handleException(t, getContext());
            getContext().getSessionScope().put("javaXotsOutput", "ERROR");
        }
    }
}
  • No labels