<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> index.jsp

Query Tables Sample


Query your instance data using one of the predefined query tables


Select the query table:

<%! // aux functions // add escapes needed for HTML rendering private String addEscapes(String str) { return str.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">"); } // add escapes needed for HTML rendering of Java strings: change " into \" private String addEscapes2(String str) { return addEscapes(str.replaceAll("\"", "\\\\\"")); } %> <% // List of predefined query tables as documented in // http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r2mx/topic/com.ibm.websphere.bpc.620.doc/doc/bpc/c6bpel_querytables_predef.html String predefinedTables[] = { "TASK", "PROCESS_INSTANCE", "ACTIVITY", "ACTIVITY_ATTRIBUTE", "ACTIVITY_SERVICE", "ESCALATION", "ESCALATION_CPROP", "ESCALATION_DESC", "PROCESS_ATTRIBUTE", "QUERY_PROPERTY", "TASK_CPROP", "TASK_DESC", "[OTHER]" }; String qtName = ""; // for source code snippet below String other = request.getParameter("other"); // for pre-setting text field from URL parm if (other==null) { other = ""; // avoid NullPointerException } String sel = request.getParameter("selection"); // for pre-setting radio button from URL parm if (sel==null) { sel = ""; // avoid NullPointerException } else { qtName = sel; if (sel.equals("[OTHER]")) { qtName = other; } } String attr = request.getParameter("attributes"); // for pre-setting text field from URL parm if (attr==null) { attr = ""; // avoid NullPointerException } String cond = request.getParameter("condition"); // for pre-setting text field from URL parm if (cond==null) { cond = ""; // avoid NullPointerException } %>
<% // generate HTML code like this (for example, for query table name "TASK"): // either // // or // String nam; for (int i=0; i"); } // now render the "[OTHER]" radio button with a text field nam = predefinedTables[predefinedTables.length-1]; out.println(""); %>
TASK
TASK
" + nam + "
" + nam + ": " + "
Display the following columns, separated by comma: (leave empty to get ALL defined columns displayed)
Use the following query condition: (leave empty to get ALL rows displayed)

<% // simple exception handling: if (request.getAttribute("exception") != null) { %>

Exception occurred

<%=request.getAttribute("exception")%> <% } else // no query table specified so far if (request.getAttribute("queryTable") == null) { %>

No query table selected for query.

<% // query successful; extract and render results } else { com.ibm.bpe.api.EntityResultSet ers = (com.ibm.bpe.api.EntityResultSet) request.getAttribute("result"); if (ers != null) { com.ibm.bpe.api.EntityInfo ei = ers.getEntityInfo(); java.util.List aiList = ei.getAttributeInfo(); %>

Current content of the query table <%=ers.getQueryTableName()%>:

<% out.println(""); out.println(""); for (int i = 0; i < aiList.size(); i++) { com.ibm.bpe.api.AttributeInfo ai = (com.ibm.bpe.api.AttributeInfo) aiList.get(i); out.println(""); } out.println(""); for (int i = 0; i < ers.getEntities().size(); i++) { com.ibm.bpe.api.Entity entity = (com.ibm.bpe.api.Entity) ers.getEntities().get(i); out.println(""); for (int o = 0; o < aiList.size(); o++) { com.ibm.bpe.api.AttributeInfo ai = (com.ibm.bpe.api.AttributeInfo) aiList.get(o); out.println(""); } out.println(""); } out.println("
" + ai.getName() + "
"); if (entity.getAttributeValue(ai.getName()) != null) { if (! ai.isArray()) { if (ai.getType() == com.ibm.bpe.api.AttributeType.TIMESTAMP) { out.print(((java.util.Calendar) entity.getAttributeValue(ai.getName())).getTime()); } else { out.print(entity.getAttributeValue(ai.getName())); } } else { out.print("arrays not supported"); } } else { out.print("n/a"); } out.println("
"); // finally, render source code for the successful query %>

Source code:

// java source code used for the query
BusinessFlowManagerService bfmService = getBFMService();
FilterOptions filterOpts = new FilterOptions();
filterOpts.setLocale(request.getLocale());
filterOpts.setThreshold(new Integer(20));
AdminAuthorizationOptions authOpts = null;
<%if (request.getRemoteUser().equals("admin")) { %> authOpts = new AdminAuthorizationOptions();
<% } %> <%if (! attr.trim().equals("")) { %> filterOpts.setSelectedAttributes("<%=addEscapes2(attr.trim())%>");
<% } %> <%if (! cond.trim().equals("")) { %> filterOpts.setQueryCondition("<%=addEscapes2(cond.trim())%>");
<% } %> EntityResultSet eRS = bfmService.queryEntities("<%=qtName.trim()%>", filterOpts, authOpts, null);
<% } } %>