Saturday, June 7, 2008

requestApprovalDetailTiles.jsp

This modified file includes the customization that were done to supplement my other blog post http://rajnishbhatia19.blogspot.com/2008/06/oim-customization-for-resource.html . Please refer to that post before you dig through this code.

<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/tld/struts-nested.tld" prefix="nested"%>
<%@ page import="com.thortech.xl.webclient.util.FormField"%>
<%@ page import="com.thortech.xl.webclient.bean.*"%>
<%@ page import="com.thortech.xl.webclient.util.tcMessageResourcesUtil" %>
<%@ page import="com.thortech.xl.webclient.util.*" %>
<%@ page import="Thor.API.Operations.*" %>
<%@ page import="Thor.API.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="java.util.*"%>

<bean:define id="requestApprovalBean" name="requestApprovalDetailForm" property="requestItemListBean" />
<bean:define id="entityKey" name="requestApprovalDetailForm" property="requestKey"/>
<script>
function submitPage(pageAction){
for(var i = 0; i < document.forms[0].elements.length; i++) {
if(document.forms[0].elements[i].name=='approveDeny' && document.forms[0].elements[i].type=='hidden'){
document.forms[0].elements[i].value=pageAction;
}
}
document.forms[0].submit();
return false;
}
function getRequestDetail(htmlFormId, actionClassReference, methodName,
entityKey) {
// loop through all the forms on the page to find a match for the htmlFormId
for(var i = 0; i < document.forms.length; i++) {
if(document.forms[i].id == htmlFormId) {
document.forms[i].action=actionClassReference;
document.forms[i].entityKey.value=entityKey;
for(var j = 0; j < document.forms[i].elements.length; j++) {
if(document.forms[i].elements[j].name=='method'
&& document.forms[i].elements[j].type=='hidden') {
document.forms[i].elements[j].value=methodName;
break;
}
}
document.forms[i].submit();
return false;
}

}
}



</script>

<%!


public String getFormDataByObjectInstanceKey(String objectInstanceKey, String resourceName){
Context ctx = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

try{
String [] temp = null;
String name = "";
ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:jdbc/xlDS");
con = ds.getConnection();
con.setAutoCommit(false);
String stmt="select upper(lkv_encoded), lkv_decoded from lkv where upper(lkv_encoded)='"+resourceName.toUpperCase()+"' and lku_key =(select lku_key from lku where lku_type_string_key='Lookup.Resources.ObjectForm.FieldMappings') ";
System.out.println(stmt);
pstmt=con.prepareStatement(stmt);

rs=pstmt.executeQuery();
if(rs!=null && rs.next())
{
temp = rs.getString("LKV_DECODED").split(";");
pstmt=null;
rs=null;

String columns="";
System.out.println("------------");
for (int i = 1 ; i < temp.length ; i++) {
if(i>1)
columns=columns+" , ";
columns=columns+temp[i];
System.out.println("temp["+i+"] is "+temp[i]);
}
System.out.println("------------");

stmt="select "+columns+" from "+temp[0]+ " where obi_key= "+objectInstanceKey;
System.out.println(stmt);
pstmt = con.prepareStatement(stmt);
rs = pstmt.executeQuery();
while (rs.next()) {

for (int i = 1 ; i < temp.length ; i++) {
name =name+ " - "+rs.getString(temp[i]);
}
break;
}
System.out.println("out name : "+ name);
}
return name;
}catch(Exception exp){
exp.printStackTrace();
}finally{
try {
if(rs != null)
rs.close();

if(pstmt != null)
pstmt.close();

if(con != null )
con.close();
}catch(Exception ex)
{
ex.printStackTrace();
}
}

return "";

}



public String getResourceDetails(String requestKey, HttpSession session, String row, String resourceName){
String retVal="";
try {

retVal="Error - No Value Found for row : "+row+ " , request key : "+requestKey;
sessionContainer sessioncontainer;
sessioncontainer = (sessionContainer)session.getAttribute("Xellerate.Session");
tcRequestOperationsIntf tcrequestoperationsintf = sessioncontainer.getRequestOperationsIntf();
HashMap hashmap = new HashMap();
hashmap.put("Requests.Key", requestKey);
tcResultSet tcresultset1 = tcrequestoperationsintf.getRequestObjects(Long.parseLong(requestKey));

//System.out.println("First loop - i count = "+tcresultset1.getRowCount());

for(int i=0; i<tcresultset1.getRowCount(); i++)
{
String x=Integer.toString(i);
if ( x.equals(row)) {
tcresultset1.goToRow(i);
String value = tcresultset1.getStringValue("Object Instance.Key");
System.out.println("Object instance key is = " + value);
retVal = getFormDataByObjectInstanceKey(value, resourceName);
//System.out.println(" form data is = " + retVal);
}
}

}catch(Exception ex)
{
ex.printStackTrace();
}
return retVal;
}



%>


<html:form action="/requestApprovalDetail.do" styleId="requestAppDetail">
<TABLE height=66 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<TABLE>
<TR>
<TD class="PageTitle"><A class="Linktext" href="javascript:getRequestDetail('requestAppDetail','requestDetail.do','<bean:message key="request.requestDetail"/>','<%=entityKey%>')">
<bean:message key="requests.requestDetail.label.pageTitle" /> </A>
</TD>
<TD class="PageTitle"><bean:message bundle="xlDefaultAdmin" key="global.label.twoRightArrows" /></TD>
<TD class="PageTitle"><bean:message key="requests.approvalTasks.label.pageTitle" /></TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD class=PageTitle height=28><bean:message key="requests.approvalTasks.label.pageTitle" /></TD>
</TR>
<TR>
<TD class=InstructionText align=left height=18><bean:message key="requests.approvalTasks.message.instruction" /></TD>
</TR>
<TR>
<TD width=1044> </TD>
<TR>
<TD width=1044>
<P class=InstructionText align=left><B><bean:message key="request.requestID" /></B>     
<A class="Linktext" href="javascript:getRequestDetail('requestAppDetail','requestDetail.do','<bean:message key="request.requestDetail"/>','<%=entityKey%>')"> <nested:write property="requestID" /> </A></P>
</TD>
</TR>
</TBODY>
</TABLE>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>  
</td>
</tr>
</table>






<table width="100%" border="0" cellspacing="0" cellpadding="0" class="backgroundcolor">
<tr>
<td colSpan="3" width="48%" height="20" class="td_tab_header_body_fill">  
<span class="SectionTitles"><bean:message key="requests.approvalTasks.label.requestApprovalTasks" /></span>
<td>
</tr>
<tr class="backgroundcolor">
<td solSpan="3">   </td>
</tr>
<tr class="backgroundcolor">
<td>   </td>
<td>
<%
if (hasTask(requestApprovalBean)) {
%>
<TABLE class=object_list_table cellSpacing=1 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<nested:iterate indexId="indexId" id="field" property="requestItemListBean.viewTableForm.formFieldList" length="4">
<TD class=object_list_td_header><nested:message property="labelCode" /></TD>
</nested:iterate>
</TR>
<nested:iterate indexId="rowId" id="row" property="requestItemListBean.viewTableForm.formList">
<TR>
<nested:iterate id="column" indexId="columnId" name="row" length="5">
<%
if((columnId.intValue() != 3)&&(columnId.intValue() != 2)){
%>
<TD class=object_list_td_align_center vAlign=center>
<%
if (columnId.intValue() == 4){
%>
<html:multibox name="requestApprovalDetailForm" property="approvalDenyList" disabled="<%=getCheckBoxStatusValue(rowId, requestApprovalBean,request)%>">
<nested:write name="column" />
</html:multibox>
<%
}
else {
%>
<%=getValue(rowId, columnId, requestApprovalBean,column)%>
<%
}
%>
</TD>
<%
}
else {
if(columnId.intValue() == 2){
%>
<TD class=object_list_td_align_center vAlign=center>
<%=getValue(rowId, columnId, requestApprovalBean,column)%>
<%
}
else {
%>

</TD>
<%
}
}
%>
</nested:iterate>
</TR>
</nested:iterate>
<nested:iterate indexId="rowId" id="row" property="requestItemListBean.viewTableForm.formList" length="1">
<TR>
<nested:iterate id="column" indexId="columnId" name="row" length="4">
<TD class=object_list_td_align_center vAlign=center>
<%
if (columnId.intValue() == 3) {
%>
<input type="hidden" name="method" value="<bean:message key="request.requestAssignDetail"/>">
<input type="hidden" name="approveDeny" value="">
<input type="submit" class="Commandbutton" name="method" value="<bean:message key="approvals.button.approve"/>" onclick="return submitPage('approve')" />
<input type="submit" class="Commandbutton" name="method" value="<bean:message key="approvals.button.deny"/>" onclick="return submitPage('deny')" /> <input type="submit" class="Commandbutton" name="method" value="<bean:message key="approvals.button.reassign"/>" onclick="return submitPage('reassign')" />
<html:hidden property="entitySelected" value="TasksUser" />
<html:hidden property="userAction" value="new" />
<%
}
%>
</TD>
</nested:iterate>
</TR>
</nested:iterate>
</TABLE>
</td>
<td>   </td>
</tr>
<tr class="backgroundcolor">
<td solSpan="3">   </td>
</tr>
<%
}
else {
%>
<TR>
<TD class=InstructionText align=left height=18><bean:message key="requests.approvalTasks.label.noApprovalTasks" /></TD>
</TR>
</table>
<%
}
%>

<bean:define id="objectListBean" name="requestApprovalDetailForm" property="resourceList"/>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>  <td>
</tr>
</table>
<%
if(hasApprovalTask(objectListBean)){
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="backgroundcolor">
<tr>
<td colSpan="3" width="48%" height="20" class="td_tab_header_body_fill">
  <span class="SectionTitles"><bean:message key="requests.approvalTasks.label.resourceApprovalTasks" /></span>
<td>
</tr>
<%
int index = 0;
%>
<nested:iterate indexId="indexId" id="resource" property="resourceList">
<tr class="backgroundcolor">
<td solSpan="3">   </td>
</tr>
<tr class="backgroundcolor">
<td>   </td>
<td>
<%// Integer indexIdInteger = new Integer(indexId);
//System.out.println("New thing");
//System.out.println("Index ID " + indexId);
//System.out.println("Integer indexIdInteger"+ indexIdInteger);
%>
<nested:iterate id="resourceName" name="requestApprovalDetailForm" property="resourceNameList" length="1" offset="<%=indexId.toString()%>">
<% String resName= (String) resourceName; %>
<P class=InstructionText align=left><B><nested:write name="resourceName"/> <%= getResourceDetails(entityKey.toString(), session,indexId.toString(), resName) %></B></P>
</nested:iterate>
</td>
<td>   </td>
</tr>
<tr class="backgroundcolor">
<td>   </td>
<td>
<TABLE class=object_list_table cellSpacing=1 width="100%" border=0 >
<TBODY>
<%
if(hasApprovalTask(objectListBean, index)){
%>
<TR vAlign=top>
<nested:iterate id="field" name="resource" property="viewTableForm.formFieldList" length="4">
<TD class=object_list_td_header>
<nested:message property="labelCode"/>
</TD>
</nested:iterate>
</TR>
<nested:iterate indexId="rowId" id="row" name="resource" property="viewTableForm.formList" >
<TR>
<nested:iterate id="column" indexId="columnId" name="row" length="5">
<%
if((columnId.intValue() != 3)&&(columnId.intValue() != 2)){
%>
<TD class=object_list_td_align_center vAlign=center>
<%
if (columnId.intValue() == 4){
%>
<html:multibox name="requestApprovalDetailForm" property="approvalDenyList" disabled="<%=getCheckBoxStatusValue(rowId, resource,request)%>">
<nested:write name="column" />
</html:multibox>
<%
}
else {
%>
<%=getValue(rowId,columnId,resource,column)%>
<%
}
%>
</TD>
<%
}
else {
if(columnId.intValue() == 2){
%>
<TD class=object_list_td_align_center vAlign=center>
<%=getValue(rowId,columnId,resource,column)%>
<%
}
else {
%>

</TD>
<%
}
}
%>
</nested:iterate>
</TR>
</nested:iterate>
<nested:iterate indexId="rowId" id="row" property="viewTableForm.formList" length="1">
<TR>
<nested:iterate id="column" indexId="columnId" name="row" length="4">
<TD class=object_list_td_align_center vAlign=center>
<%
if (columnId.intValue() == 3) {
%>
<input type="hidden" name="method" value="<bean:message key="request.requestAssignDetail"/>">
<input type="hidden" name="approveDeny" value="">
<input type="submit" class="Commandbutton" name="method" value="<bean:message key="approvals.button.approve"/>" onclick="return submitPage('approve')" />
<input type="submit" class="Commandbutton" name="method" value="<bean:message key="approvals.button.deny"/>" onclick="return submitPage('deny')" /> <input type="submit" class="Commandbutton" name="method" value="<bean:message key="approvals.button.reassign"/>" onclick="return submitPage('reassign')" />
<html:hidden property="entitySelected" value="TasksUser" />
<html:hidden property="userAction" value="new" />
<%
}
%>
</TD>
</nested:iterate>
</TR>
</nested:iterate>
</TABLE>
</td>
<td>   </td>
</tr>
<tr class="backgroundcolor">
<td solSpan="3">   </td>
</tr>
<%
}
else{
%>
<TABLE height=66 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=InstructionText align=left height=18><bean:message key="requests.approvalTasks.label.noApprovalTasks" />
</TD>
</TR>
</TBODY>
</TABLE>
<%
}
index++;
%>
</nested:iterate>
</table>
<%
}
%>
<input type="hidden" name="method" value=""/>
<input type="hidden" name="entityKey" value=""/>
<html:hidden property="requestKey"/>
<html:hidden property="requestID"/>

</html:form>

<%!
public String getValue(Integer rowId, Integer columnId,
Object itemListBean, Object columnValueBean) {

String returnValue = (String) columnValueBean;

int rowIdx = rowId.intValue();
int columnIdx = columnId.intValue();
tcItemListBean itemList = (tcItemListBean) itemListBean;
String columnValue = (String) columnValueBean;

FormField formField = (FormField) itemList.getViewTableForm()
.getFormFieldList().get(columnIdx);
String type = formField.getType();
String assignType = ((String[]) itemList.getViewTableForm()
.getFormList().get(rowIdx))[3];
if (type != null) {
if (type.equals("IMG")) {

if (returnValue.equals("C")) {
returnValue = "<img src='images/checkw.gif'/>";
} else if (returnValue.equals("R")) {
returnValue = "<img src='images/stoppedw.gif'/>";
} else if (returnValue.equals("W")) {
returnValue = "<img src='images/pausedw.gif'/>";
} else if (returnValue.equals("P")) {
returnValue = "<img src='images/runningtrans.gif'/>";
}
} else if (type.equals("IMG_VALUE")) {
if (columnValueBean != null) {
if (assignType.equals("User")) {
returnValue = "<img src='images/user.gif'/>"
+ returnValue;
} else if (assignType.equals("Group")) {
returnValue = "<img src='images/user_group.gif'/>"
+ returnValue;
} else if (assignType.equals("UserProxy")) {
returnValue = "<img src='images/assign_to_proxy_user.gif'/>"
+ returnValue;
} else if (assignType.equals("GroupProxy")) {
returnValue = "<img src='images/assign_to_proxy_group.gif'/>"
+ returnValue;
}
}
}
}

itemList.getViewTableForm().getFormList().get(rowIdx);
return returnValue;
}
public boolean getCheckBoxStatusValue(Integer rowId,
Object itemListBean, HttpServletRequest request) {

int rowIdx = rowId.intValue();

tcItemListBean itemList = (tcItemListBean) itemListBean;

String status = ((String[]) itemList.getViewTableForm()
.getFormList().get(rowIdx))[1];
String statusAdminRole = ((String[]) itemList.getViewTableForm()
.getFormList().get(rowIdx))[5];

java.util.Locale locale = (java.util.Locale)request.getSession(true).getAttribute(org.apache.struts.Globals.LOCALE_KEY);
org.apache.struts.util.MessageResources message = (org.apache.struts.util.MessageResources) request.getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
if(status.equalsIgnoreCase(tcMessageResourcesUtil.getMessage(message,locale, "global.Lookup.WebClient.Open-Task.Status.Pending")) && statusAdminRole.equalsIgnoreCase("true"))
{
return false;
}
else return true;
}

public boolean hasTask(Object requestApprovalBean) {
boolean hasTask = false;
tcItemListBean itemList = (tcItemListBean) requestApprovalBean;
if (itemList.getViewTableForm().getFormList().size() != 0) {
hasTask = true;
}
return hasTask;

}

public boolean hasApprovalTask(Object objectListBean) {
boolean hasTask = false;

ArrayList resourceList = (ArrayList) objectListBean;
if (resourceList.size() != 0) {
hasTask = true;
}

return hasTask;

}

public boolean hasApprovalTask(Object objectListBean, int objIndex) {
boolean hasTask = false;

ArrayList resourceList = (ArrayList) objectListBean;

tcItemListBean itemList = (tcItemListBean) resourceList.get(objIndex);

ArrayList taskList = itemList.getViewTableForm().getFormList();

if (taskList.size() > 0) {
hasTask = true;
}

return hasTask;

}
%>

No comments: