<%@page contentType="text/html; charset=UTF-8" %> <%@page import="java.util.*" %> <%@page import="java.text.*" %> <%@page import="com.oracle.bpel.client.Locator" %> <%@page import="com.oracle.bpel.client.IInstanceHandle" %> <%@page import="com.oracle.bpel.client.IActivityHandle" %> <%@page import="com.oracle.bpel.client.util.SQLDefs" %> <%@page import="com.oracle.bpel.client.util.WhereCondition" %> <%@page import="com.oracle.bpel.client.util.WhereConditionHelper" %> <%@page import="com.collaxa.cube.fe.util.*" %> <%@page import="com.collaxa.common.util.CXStringUtils" %> <%@page import="com.collaxa.cube.fe.reports.RptConstants" %> <%@include file="initI18n.jspf" %> <%! static final String EVAL_TIME_QUERY = "((to_date(to_char(ci_modify_date, 'MM/dd/yy HH24:mi'),'MM/dd/yy HH24:mi') - " + "to_date(to_char(ci_creation_date, 'MM/dd/yy HH24:mi'),'MM/dd/yy HH24:mi'))*86400 + " + "(to_number(substr(to_char(ci_modify_date),instr(to_char(ci_modify_date),' ')+7,6)) - " + "to_number(substr(to_char(ci_creation_date),instr(to_char(ci_creation_date),' ')+7,6))))*1000"; %> <% // Initialize (parameters/attributes) String uri = request.getRequestURI( ).substring( "/BPELConsole/".length() ); boolean fromReports = "true".equals(request.getParameter( "fromReports" )); boolean showExecTime = "true".equals(request.getParameter( "showExecTime" )); // If instance id is specified, then redirect to displayInstance.jsp String referenceIdQ = request.getParameter( "referenceId" ); if ( referenceIdQ != null && ! "".equals( referenceIdQ ) ) { application.getRequestDispatcher( "/displayInstance.jsp" ) .forward( request, response ); return; } // params2 contains all the parameters except for range params Map params2 = ServletUtils.getParameters( request ); params2.remove( "rangeStart" ); params2.remove( "rangeSize" ); // params1 contains all the parameters except for sorting and range params Map params1 = new HashMap( params2 ); params1.remove( "orderBy" ); params1.remove( "order" ); // range information int rangeStartQ = 0; try { rangeStartQ = Integer.parseInt( request.getParameter( "rangeStart" ) ); } catch( Exception e ) { rangeStartQ = 0; } int rangeSizeQ = 0; try { rangeSizeQ = Integer.parseInt( request.getParameter( "rangeSize" ) ); } catch( Exception e ) { rangeSizeQ = 20; } StringBuffer buf = new StringBuffer(); WhereCondition where = null; // instanceId // String instanceIdQ = request.getParameter( "instanceId" ); // if the instanceId provided, don't mind other query parameters // if ( instanceIdQ != null ) { try { int instanceId = Integer.parseInt( instanceIdQ ); where = new WhereCondition( buf.append( SQLDefs.AL_cikey ) .append( " = ? " ) .toString() ); where.setInt( 1, instanceId ); } catch ( Exception e ) { } } //Initialise time unit divisor for Reports String timeUnit = request.getParameter("timeUnit"); double divisor = 1; if(timeUnit != null) { if("seconds".equals(timeUnit)) { divisor = 1000; } else if("minutes".equals(timeUnit)) { divisor = 60000; } else if("hours".equals(timeUnit)) { divisor = 3600000L; } else if("days".equals(timeUnit)) { divisor = 86400000L; } else if("weeks".equals(timeUnit)) { divisor = 604800000L; } } // in the case of instanceId is not provided, compose the WhereCondition // based on the query parameters // if ( where == null ) { int n = 0; WhereCondition tmpWhere = new WhereCondition(); // construct where condition step 1: instanceState // String instanceState = request.getParameter( "instanceState" ); if( "cancelled".equals( instanceState ) ) { where = WhereConditionHelper.whereInstancesCancelled(); } else if( "completed".equals( instanceState ) ) { where = WhereConditionHelper.whereInstancesCompleted(); } else if( "stale".equals( instanceState ) ) { where = WhereConditionHelper.whereInstancesStale(); } else if( "closed".equals( instanceState ) ) { where = WhereConditionHelper.whereInstancesClosed(); } else if( "active".equals( instanceState ) ) { where = WhereConditionHelper.whereInstancesOpen(); } if( where == null ) where = new WhereCondition(); else n++; // construct where condition step 2: processId // String processIdQ = request.getParameter( "processId" ); if ( processIdQ != null && ! "*".equals( processIdQ ) ) { buf.setLength( 0 ); tmpWhere.setClause( buf.append( n++ > 0 ? " AND " : "" ) .append( SQLDefs.AL_ci_process_id ) .append( " = ? " ) .toString() ); tmpWhere.setString( 1, processIdQ ); where.append( tmpWhere ); } // construct where condition step 3: revisionTag // String revisionTagQ = request.getParameter( "revisionTag" ); if ( revisionTagQ != null && ! "*".equals( revisionTagQ ) ) { buf.setLength( 0 ); tmpWhere.setClause( buf.append( n++ > 0 ? " AND " : "" ) .append( SQLDefs.AL_ci_revision_tag ) .append( " = ? " ) .toString() ); tmpWhere.setString( 1, revisionTagQ ); where.append( tmpWhere ); } // construct where condition step 4: instanceTitle // String instanceTitleQ = request.getParameter( "instanceTitle" ); if ( instanceTitleQ != null && instanceTitleQ.length( ) != 0 ) { buf.setLength( 0 ); tmpWhere.setClause( buf.append( n++ > 0 ? " AND " : "" ) .append( SQLDefs.AL_ci_title ) .append( " = ? " ) .toString() ); tmpWhere.setString( 1, instanceTitleQ ); where.append( tmpWhere ); } // construct where condition step 5: instancePriority // String instancePriorityQ = request.getParameter( "instancePriority" ); if ( instancePriorityQ != null && instancePriorityQ.length( ) != 0 ) { try { int p = Integer.parseInt( instancePriorityQ ); buf.setLength( 0 ); tmpWhere.setClause( buf.append( n++ > 0 ? " AND " : "" ) .append( SQLDefs.AL_ci_priority ) .append( " = ? " ) .toString() ); tmpWhere.setInt( 1, p ); where.append( tmpWhere ); } catch ( Exception e ) { // ignore } } // construct where condition step 6: creationDate // String creationDateQ = request.getParameter( "creationDate" ); if ( creationDateQ != null ) { try { long deltaT = Long.parseLong( creationDateQ ); Date creationDate = new Date( System.currentTimeMillis() - deltaT * 1000 ); buf.setLength( 0 ); tmpWhere.setClause( buf.append( n++ > 0 ? " AND " : "" ) .append( SQLDefs.AL_ci_creation_date ) .append( " > ? " ) .toString() ); tmpWhere.setTimestamp( 1, creationDate ); where.append( tmpWhere ); } catch ( Exception e ) { // ignore } } // construct where condition step 7: test case filter // String testCasesQ = request.getParameter( "showTestCases" ); if ( testCasesQ != null && ! "*".equals( testCasesQ ) && ! "all".equals (testCasesQ) ) { buf.setLength( 0 ); if(testCasesQ.equals("only")) { tmpWhere.setClause( buf.append( n++ > 0 ? " AND " : "" ) .append( SQLDefs.AL_ci_test_run_id ) .append( " is not null " ) .toString() ); where.append( tmpWhere ); } else if(testCasesQ.equals("hide")) { tmpWhere.setClause( buf.append( n++ > 0 ? " AND " : "" ) .append( SQLDefs.AL_ci_test_run_id ) .append( " is null " ) .toString() ); where.append( tmpWhere ); } } // list of instances upon a drill out from reports String timeInterval = request.getParameter("analysisPeriod"); String userChosenTime = request.getParameter("modifyTime"); if(fromReports && !CXStringUtils.isEmpty(userChosenTime) && !CXStringUtils.isEmpty(timeInterval)) { try { Date lmdStart, lmdEnd; // calculate the end date based on the time interval if( "DAILY".equalsIgnoreCase( timeInterval ) ) { DateFormat fmt = new SimpleDateFormat("MM/dd/yy"); // Daily reports for a particular day. End date is 24 hrs from user chosen date. lmdStart = fmt.parse(userChosenTime); Date lmdStartPlus24Hrs = new Date( (lmdStart.getTime() + 86400000L ) ); lmdEnd = lmdStartPlus24Hrs; // just to make it clear what lmdEnd here is. } else if( "HOURLY".equalsIgnoreCase( timeInterval ) ) { // Hourly reports for a particular hour in a day. // end date is 59 minutes prior end date in query section in reports String endDate = request.getParameter("endDate"); endDate += "~" + userChosenTime; DateFormat hourlyFmt = new SimpleDateFormat("MM/dd/yy~HH:mm"); lmdStart = hourlyFmt.parse(endDate); lmdEnd = new Date( (lmdStart.getTime() + 3600000L ) ); // one hr after } else // weekly report { DateFormat fmt = new SimpleDateFormat("MM/dd/yy"); // weekly reports for a particular week in a month. // End date is one week prior to user chosen date. Date timeAt1200AM = fmt.parse(userChosenTime); // end date is user chosen time At 1200AM + 24 hours = start of next // day from userChosenTime lmdEnd = new Date(timeAt1200AM.getTime() + 86400000L); Date lmdStartMinusOneWeek = new Date( (lmdEnd.getTime() - 604800000L ) ); lmdStart = lmdStartMinusOneWeek; // just to make it clear what lmdStart here is. } if("initiated".equals(instanceState)) { buf.setLength( 0 ); tmpWhere.setClause( buf.append( " AND ") .append(SQLDefs.AL_ci_creation_date) .append( " >= ? " ) .append( " AND " ) .append( SQLDefs.AL_ci_creation_date ) .append( " < ? " ) .toString() ); tmpWhere.setTimestamp( 1, lmdStart ); tmpWhere.setTimestamp( 2, lmdEnd ); where.append( tmpWhere ); } else { buf.setLength( 0 ); tmpWhere.setClause( buf.append( " AND ") .append( SQLDefs.AL_ci_modify_date ) .append( " >= ? " ) .append( " AND " ) .append( SQLDefs.AL_ci_modify_date ) .append( " < ? " ) .toString() ); tmpWhere.setTimestamp( 1, lmdStart ); tmpWhere.setTimestamp( 2, lmdEnd ); where.append( tmpWhere ); } pageContext.setAttribute("startDate", lmdStart); // one second before end date. eg. start time 12:00 end time = 13:00 // then actual time range displayed are 12:00 to 12:59. Instances within // this range are only shown including the start and the above end time. pageContext.setAttribute("endDate", new Date(lmdEnd.getTime() - 1000)); // show execution time if user clicked on any execution or sla graph String execTimeStr = request.getParameter("execTime"); String graphType = request.getParameter("graphType"); if( !CXStringUtils.isEmpty(execTimeStr) && !RptConstants.AVG.equals(graphType)) { // NumberFormat exception will be taken care in the catch block below // Time unit may be any one of milliseconds, seconds, minutes, // hours or days. According to the time unit chosen by the user, // we need to convert the exectime into milliseconds by multiplying // with the conversion factor double execTime = Double.parseDouble(execTimeStr); // check if sla has to be taken into account. String slaType = request.getParameter("slaType"); if( !CXStringUtils.isEmpty(slaType) ) { buf.setLength( 0 ); tmpWhere.setClause( buf.append( " AND ") .append( SQLDefs.AL_ci_state ) .append(" = 5 ") .toString() ); where.append( tmpWhere ); } // by default check for equality of specified evaluation time. String operator = " = "; if(RptConstants.SLA_MET.equals(slaType)) operator = " <= "; // check for instances that met the sla else if(RptConstants.SLA_NOT_MET.equals(slaType)) operator = " > "; // check for instances that violated the sla buf.setLength( 0 ); tmpWhere.setClause( buf.append( " AND ") .append("round(") .append(EVAL_TIME_QUERY) .append("/").append(divisor) .append(") ") .append(operator) .append("round( ") .append( String.valueOf(execTime) ) .append(" )") .toString() ); where.append( tmpWhere ); } } catch(Exception e) { e.printStackTrace(); } } // end of if (fromReports...) } // construct where condition final step: order // String orderBy = request.getParameter( "orderBy" ); boolean bAsc = true; if ( orderBy != null && orderBy.length( ) != 0 ) { if( orderBy.equals( SQLDefs.AL_cikey ) || orderBy.equals( SQLDefs.AL_ci_process_id ) || orderBy.equals( SQLDefs.AL_ci_modify_date ) ) { where.appendOrderBy( orderBy ); String order = request.getParameter( "order" ); if ( order != null && order.length( ) != 0 ) { where.appendOrderBy( " desc" ); bAsc = false; } } else { // Don't let user inject any arbitrary sql code here // orderBy = SQLDefs.AL_ci_modify_date; where.appendOrderBy( SQLDefs.AL_ci_modify_date ) .appendOrderBy( " desc " ); bAsc = false; } } else { orderBy = SQLDefs.AL_ci_modify_date; where.appendOrderBy( SQLDefs.AL_ci_modify_date ) .appendOrderBy( " desc " ); bAsc = false; } try { // Get the list of processes that have been deployed // get locator object from the session Locator l = ServletUtils.getLocatorWithoutUrlRewrite(request, response); // get instances IInstanceHandle[] instances = l.listInstances( where, rangeStartQ, rangeSizeQ ); String firstInstance = null; String upArrow = ""+I18nUtil.getString("sort_asc", locale)+""; String downArrow = ""+I18nUtil.getString("sort_desc", locale)+""; %> " class="DefaultTable" cellspacing="0" cellpadding="0">
<%String startRange=""; String endRange=""; if ( instances.length > 0 ) { startRange =String.valueOf(rangeStartQ + 1) ; endRange= String.valueOf(rangeStartQ + instances.length) ; } String title = I18nUtil.getString("instances_list",startRange,endRange, locale); String instancesStartDate = FormatUtils.formatDate(((Date)pageContext.getAttribute("startDate")), locale); String instancesEndDate = FormatUtils.formatDate(((Date)pageContext.getAttribute("endDate")), locale); boolean showDates = ( ! "no date".equals(instancesStartDate) || ! "no date".equals(instancesEndDate) ); if(fromReports && showDates) { String dateRange = "      " + instancesStartDate + " to " + instancesEndDate; //title += "      " + instancesStartDate + " to " + instancesEndDate; String slaType = request.getParameter("slaType"); boolean showSLA = !CXStringUtils.isEmpty(request.getParameter("execTime")); if(showExecTime && showSLA && RptConstants.SLA_MET.equals(slaType) ) { String frmStr = I18nUtil.getString("rpt_instances_satisfied_sla",locale); title = MessageFormat.format(frmStr,new Object[]{title,request.getParameter("execTime"),I18nUtil.getString("rpt_"+timeUnit,locale)}) + dateRange; //title += " that met SLA of " + request.getParameter("execTime") + "(seconds)" + dateRange; } else if(showExecTime && showSLA && RptConstants.SLA_NOT_MET.equals(slaType) ) { String frmStr = I18nUtil.getString("rpt_instances_violated_sla",locale); title = MessageFormat.format(frmStr,new Object[]{title,request.getParameter("execTime"),I18nUtil.getString("rpt_"+timeUnit,locale)}) + dateRange; //title += " that violated SLA of " + request.getParameter("execTime") + "(seconds)" + dateRange; } else title += dateRange; } %> <%=title%>
" class="DefaultTable" cellspacing="0" cellpadding="0"> <%if(fromReports) { %> <%if(showExecTime) { %> <% } else {%> <% } // end of if(showExecTime) } else {%> <% }//if(fromReports) %> <% // For each instance for( int i = 0, len1 = instances.length; i < len1; i++ ) { IInstanceHandle iH = instances[ i ]; String instanceId = iH.getReferenceId().getInstanceId( ); // in default console page, don't display instances // that don't have child activities // String instanceTitle = iH.getTitle(); if ( instanceTitle == null || instanceTitle.length( ) == 0 ) instanceTitle = I18nUtil.getString("no_title_specified", locale); %> > <%if(fromReports) {%> <%if(showExecTime) { %> <% } else {%> <% } } else {%> <% } %> <% } // End of for each instance %> <%if(fromReports) {%> <%} else {%> <% } %> <%if(fromReports) {%> <%}%>
  <%=I18nUtil.getString("instance", locale)%> <%= SQLDefs.AL_cikey.equals( orderBy )?(bAsc?downArrow:upArrow):""%> <%=I18nUtil.getString("bpel_process", locale)%> <%= SQLDefs.AL_ci_process_id.equals( orderBy )?(bAsc?downArrow:upArrow):""%> <%=I18nUtil.getString("last_modified", locale)%> <%= SQLDefs.AL_ci_modify_date.equals( orderBy )?(bAsc?downArrow:upArrow):""%> <%=MessageFormat.format(I18nUtil.getString("rpt_exec_time",locale),new Object[]{timeUnit})%> <%=I18nUtil.getString("create_date_label", locale)%> <%= SQLDefs.AL_ci_creation_date.equals( orderBy )?(bAsc?downArrow:upArrow):""%> <%=I18nUtil.getString("last_modified", locale)%> <%= SQLDefs.AL_ci_modify_date.equals( orderBy )?(bAsc?downArrow:upArrow):""%>
<% String visual = " "; if( iH.isComplete() ) { visual = ""+I18nUtil.getString("completed", locale)+""; } else if( iH.isFaulted() ) { visual = ""+I18nUtil.getString("faulted", locale)+""; } else if( iH.isCancelled() ) { visual = ""+I18nUtil.getString("cancelled", locale)+""; } %> <%= visual %>
<% // Instance is stale...show only grayed out link if( iH.isStale() ) { %> <%=I18nUtil.getString("process",iH.getReferenceId().getProcessId(),iH.getReferenceId().getRevisionTag(), locale)%> <% } else { %> " href="displayProcess.jsp?processId=<%= iH.getReferenceId().getProcessId() %>&revisionTag=<%= iH.getReferenceId().getRevisionTag() %>&mode=manage" > <%=I18nUtil.getString("process",iH.getReferenceId().getProcessId(),iH.getReferenceId().getRevisionTag(), locale)%> <% } %>
<%= FormatUtils.formatDate( iH.getModifyDate(), locale ) %>
<%= ( iH.getModifyDate().getTime() - iH.getCreationDate().getTime() ) / divisor %>
<%= FormatUtils.formatDate( iH.getCreationDate(), locale ) %>
<%= FormatUtils.formatDate( iH.getModifyDate(), locale ) %> (<%= ( iH.getModifyDate().getTime() - iH.getCreationDate().getTime() ) / divisor %> ms)
         
<% if ( rangeStartQ > 0 ) { %> <%=I18nUtil.getString("previous_page", locale)%> <% } %> - <% if ( rangeSizeQ == instances.length ) { %> <%=I18nUtil.getString("next_page", locale)%> <% } %>   <% if ( rangeSizeQ != -1 && instances.length > 0 ) { %> <%=I18nUtil.getString("show_all", locale)%> <% } else { %>   <% } %>
<% // expand first element in the list if ( firstInstance != null ) { %> <% } } catch( Throwable t ) { %> <%=I18nUtil.getString("exception_occured_description",t.getMessage(), locale)%> <% } %>