<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="AdminException.jsp"
%><%@page import="com.fujitsu.iflow.model.workflow.WFAdminSession"
%><%@page import="com.fujitsu.iflow.model.wfcore.WFAdminSessionImpl"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessInstanceStatesEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessDefinitionStatesEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.FilterEnum"
%><%@page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessMigrationResult"
%><%@page import="java.util.Date"
%><%@page import="java.util.Enumeration"
%><%@page import="java.util.StringTokenizer"
%><%@page import="java.io.Writer"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMAdmin"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMAdminImpl"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }

    BPMAdmin bpas = bps.getAdmin();
    WFAdminSessionImpl wfSession = ((BPMAdminImpl)bpas)._wfas;

 	String processIds = request.getParameter("processId");
	String templateID = request.getParameter("planId");
	long planId = Long.parseLong(templateID);
	String markAsError = request.getParameter("markAsError");
	
    	StringTokenizer st = new StringTokenizer(processIds, ",");
    	int length = st.countTokens();
	long[] ids = new long[length];
	int i=0;
    	while (st.hasMoreTokens()){
    		ids[i] = Long.parseLong(st.nextToken());
		i++;
    	}
    	boolean markedError = false;
    	if (markAsError.equals("true"))
    	{
    		markedError = true;
    	}
    
	String[] bcolor = {"evenrow","oddrow"};
	int nextColor = 0;
	String rowColor = bcolor[nextColor];

	session.setAttribute("TabIndex","1");
	
	ProcessMigrationResult pmr = wfSession.migrateProcess(ids,planId,markedError);
	long piIds[] = pmr.getAllProcessId();	




%>


<html>
<head>
<title>Interstage Business Process Manager | Migrate Process Instances</title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
<script TYPE="text/javascript">

function getException(exception,id)
{
	var url = 'MigrationException.jsp?exception=' + exception + '&id=' + id;
	var w = '400';
	var h = '400';
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings  ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+'yes'+',';
	settings +='resizable=yes';  
	var childWindow = window.open(url,"ProcessMigrationException",settings);
	if (childWindow.opener == null)
	    childWindow.opener = self;
	
}

</script>

</head>

<body class="adminBodyClass">

<center>

<jsp:include page="AdminHeader.jsp" flush="true"/>
<br><br>

<table bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="75%" align="center">
<tr align="center" class="headrow">
    <td bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')"><font color="#000000" size="2">Migration Result</font></td>
</tr>
</table> 

<TABLE bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="75%" align="center">
<tr align="center" class="headrow"> 
	<td> Process Instance Id </td>
	<th> Process Instance Name </th>
	<th> Process Definition Id </th>
	<th> Result </th>
	<th> Exception (if any)</th>
</tr>


<%
	for (int j = 0; j < piIds.length; j++)
	{
	long piId = piIds[j];
	boolean success = pmr.isSuccess(piIds[j]);
	String result ="";
	if (success)
	{
		result = "Passed";
	}
	else
	{
		result = "Failed";
	}
	long templateId = pmr.getTemplateId(piIds[j]);
	String processName = pmr.getProcessName(piIds[j]);
	rowColor = bcolor[nextColor];
	nextColor = (nextColor + 1)%2;
	String piURL = "ProcessInstance.jsp?piId="+piId;
	String ex = "";
    

	if (success==false)
	{
		ex = pmr.getException(piId).getMessage();
%>	

<tr class="errorrow">
<%
}else
{
%>
<tr class="<%=rowColor%>">
<%
}
%>
	<td><%= piId %></td>
	<td><a href="<%=piURL%>"><%= processName %></a></td>
	<td><%= templateId%></td>
	<td><%= result %></td>
	<%
	if (!success)
	{
	%>
	<td><input type="button" onClick="getException('<%= ex.trim() %>',<%= piId%>)" value="Exception" name="exception" class="core-button"></td>
	<%
	}
	else
	{
	%>
	<td></td>
	<%
	}
	%>
	</tr>
 
<%
}
%>

</table>
</center>
</body>
</html>

<%!
    public WFAdminSessionImpl getiFlowSession(Object modelObject)
    {
    		return (WFAdminSessionImpl)(modelObject);
    }    

 

%>
