package com.fujitsu.iflowqa.testframe;


import com.fujitsu.iflow.model.workflow.WFAdminSession;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.net.Socket;


public class WIRefresh extends BPMTestBase implements TestSet{


	/*
	 * Zero argument constructor.
	 */
	public WIRefresh() {
		super();

	}

	/*
	 * This method refreshes the workitem.
	 */
	public void tests() throws Exception {

		try {
			String response;
			String input;
			BufferedReader request = new BufferedReader(new InputStreamReader(System.in));
	
			do {
				System.out.println("###############Options For Refreshing WorkItem#################");
				System.out.println("");
				System.out.println("1. Create/Delete workitem for all roles in the server");
				System.out.println("2. Create/Delete workitem for member who added/deleted from the particular role");
				System.out.println("3. Create/Delete workitem for member who added/deleted from the particular Plan");
				System.out.println("4. Create/Delete workitem for member who added/deleted from the particular Process");
				System.out.println("");
				System.out.println("###############################################################");
				System.out.println("");
                wfSession.resetLDAPGroupsList();
                wfSession.resetLDAPUsersList();
				System.out.println("Enter your option:");
				String option = request.readLine();
                String option1;
				int opt = Integer.parseInt(option);
				switch (opt) {
				case 1:
                    System.out.println("Enter Role evaluation option (false/true) :");
                    option1 = request.readLine();
					System.out.println(wfSession.refreshWorkItems(Boolean.valueOf(option1.trim()).booleanValue()));
					System.out.println("Refreshed All Roles in the Server");
					break;
				case 2:
					System.out.println("Enter Particular Role:");
					input = request.readLine();
                    System.out.println("Enter Role evaluation option (false/true) :");
                    option1 = request.readLine();
					System.out.println(wfSession.refreshWIforGroup(input.trim(), Boolean.valueOf(option1.trim()).booleanValue()));
					System.out.println("Refreshed Role " + input + " in the server");
					break;
				case 3:
					System.out.println("Enter Particular Plan Id:");
					input = request.readLine();
					long plaan = Long.parseLong(input);
                    System.out.println("Enter Role evaluation option (false/true) :");
                    option1 = request.readLine();
					System.out.println(wfSession.refreshWIforPlan(plaan,  Boolean.valueOf(option1.trim()).booleanValue()));
					System.out.println("Refreshed Role for Plan Id " + input);
					break;
				case 4:
					System.out.println("Enter Particular Process Id:");
					input = request.readLine();
					long proc = Long.parseLong(input);
                    System.out.println("Enter Role evaluation option (false/true) :");
                    option1 = request.readLine();
					System.out.println(wfSession.refreshWIforProcess(proc, Boolean.valueOf(option1.trim()).booleanValue()));
					System.out.println("Refreshed Role for Process Id " + input);
				}
				System.out.println("Do You Want to continue Yes/No-->");
				response = request.readLine();
			} while (response.equalsIgnoreCase("Y"));


		} catch (Exception e) {
			throw e;
		}
	}


    public
    void
    logAndRethrow(
        String message,
        Exception e)
            throws Exception
    {
        tr.log(message);
        throw new ExceptionWrapper(message, e);
    }
    public
    void
    runTests(TestRecorder testRecord)
        throws Exception
    {
        try{
            init(testRecord);
            login();
			tests();
        } catch (Exception e) {
            e.printStackTrace();
           logAndRethrow("Exception caught in main Analytics Test", e);
        }finally{
            logOut();
        }
    }
	
	/**
	* TestDriver is the class that knows how to run these tests.
	* So just call it with the name of this class in there.
	*/
	public
	static
	void
	main(String[] args)
	{
	    String[] newArgs = new String[1];
	    newArgs[0] = "com.fujitsu.iflowqa.testframe.WIRefresh";
	    TestDriver.main(newArgs);
	}
}