
package cust.cm.report;

import java.util.*;

import wt.fc.PersistenceHelper;
import wt.fc.WTObject;
import wt.fc.QueryResult;

import wt.inf.container.WTContainerHelper;
import wt.inf.container.WTContainer;

import wt.org.WTUser;
import wt.org.WTPrincipal;
import wt.org.WTOrganization;

import wt.change2.ChangeHelper2;
import wt.change2.WTChangeIssue;
import wt.change2.WTChangeOrder2;
import wt.change2.WTChangeRequest2;
import wt.change2.WTChangeActivity2;

import wt.query.QuerySpec;

import wt.workflow.work.*;
import wt.workflow.engine.*;
import wt.workflow.definer.*;
import wt.workflow.definer.WfVariableInfo;

import wt.workflow.engine.ProcessData;

import com.ptc.netmarkets.work.*;
import com.ptc.netmarkets.work.NmWorkItemCommands;
import com.ptc.netmarkets.work.NmWfPrincipalVariableBean;
import com.ptc.netmarkets.work.NmActivityVariablesBean;

import wt.method.RemoteMethodServer;
import wt.httpgw.GatewayAuthenticator;

public class wfReport_03b {
	static String divA = "\n**************************************************";
	static String divE = "\n==================================================\n";

	public static void main(String[] args) throws Exception {
		RemoteMethodServer rms = RemoteMethodServer.getDefault();
		GatewayAuthenticator auth = new GatewayAuthenticator();
		auth.setRemoteUser("wcadmin");
		rms.setAuthenticator(auth);

		// WfProcess.class

		QueryResult resWFP=PersistenceHelper.manager.find(new QuerySpec(WfProcess.class));
		while(resWFP.hasMoreElements()) {

			WfProcess wfprocess = (WfProcess)resWFP.nextElement();
			WTContainer container = WTContainerHelper.getContainer(wfprocess);
			WTUser wfCreator = (WTUser)(wfprocess).getCreator().getPrincipal();

			System.out.println( divE + "WfProcess Creator: " + wfCreator.getName() );
			System.out.println( "Container: " + container.getName() );
			System.out.println( "WfProcess Name: " + wfprocess.getName() );
			System.out.println( "WfProcess Desc: " + wfprocess.getDescription() );
			System.out.println( "Team Name: " + wfprocess.getTeamTemplateName()	+ "\n");

			ProcessData processdata = wfprocess.getContext();
			WfVariable wfvars[] = processdata.getVariableList();
			String[] PDS = processdata.getNames();

			for (int x=0; x<PDS.length; x++) {
				System.out.println( "ProcessData: PDS["+x+"]: "+PDS[x] );
			}

			for(int z = 0; z < wfvars.length; z++) {
				String tnStg = wfvars[z].getTypeName();
				System.out.println( "TypeName: " + tnStg );

				if(tnStg.equals("boolean")||tnStg.equals("java.lang.Boolean")) {
					System.out.println( "Context Name: "+PDS[z] );
					java.lang.Boolean wfbool = (java.lang.Boolean)wfvars[z].getValue();
					System.out.println( "Value: "+wfbool + "\n" );
				}
				else if(tnStg.equals("java.lang.String")) {
					System.out.println( "Context Name: "+PDS[z] );
					System.out.println( "Value: "+(String)wfvars[z].getValue() + "\n" );
				}
				else if(tnStg.equals("java.util.Date")) {
					java.util.Date wfDate = (java.util.Date)wfvars[z].getValue();
					System.out.println( "Context Name: " + PDS[z] );
					System.out.println( "Value: " + wfDate + "\n");
				}
				else if(tnStg.equals("java.sql.Timestamp")) {
					System.out.println( "Context Name: "+PDS[z] );
					java.sql.Timestamp wfTime = (java.sql.Timestamp)wfvars[z].getValue();
					System.out.println( "Value: "+wfTime + "\n" );
				}
				else if(tnStg.equals("wt.fc.WTObject")) {
					System.out.println( "Context Name: "+PDS[z] );
					wt.fc.WTObject wfObj = (wt.fc.WTObject)wfvars[z].getValue();
					System.out.println( "Value: "+wfObj + "\n" );
				}
				else if(tnStg.equals("wt.fc.ObjectReference")) {
					System.out.println( "Context Name: "+PDS[z] );
					wt.fc.ObjectReference wfRObj = (wt.fc.ObjectReference)wfvars[z].getValue();
					System.out.println( "Value: "+wfRObj + "\n" );
				}
			}
		}
		System.out.println(divE + "Number of WorkFlow Processes: " + resWFP.size() + divE + divA);
	}
}
