package com.chenyang.nse.bussiness.engine.infa.powercenter961.createdata;

import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.ATTRIBUTE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.CONFIGREFERENCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.CONNECTIONREFERENCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.PARTITION;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SCHEDULEINFO;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SCHEDULER;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SESSION;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SESSIONEXTENSION;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SESSTRANSFORMATIONGROUP;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SESSTRANSFORMATIONINST;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TASK;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TASKINSTANCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.WORKFLOW;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.WORKFLOWLINK;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.WORKFLOWVARIABLE;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubbean.MappletBean;
import java.util.ArrayList;
import java.util.List;

public class MakeDataWorkflowUtil {
   public WORKFLOW getMakeDataWorkflow(String mappingName, String workflowname, String sourceDbname, String tragetDbname, String servername, String serverdomainname, String sqname, List<MappletBean> mapplet, String co_target, String sourcedatabasename, String paramFilepath, String source_ownername, String target_ownername) throws Exception {
      new WORKFLOW();
      WORKFLOW workflow = this.getWORKFLOW(mappingName, workflowname, sourceDbname, tragetDbname, servername, serverdomainname, sqname, mapplet, co_target, sourcedatabasename, paramFilepath, source_ownername, target_ownername);
      return workflow;
   }

   public WORKFLOW getWORKFLOW(String mappingName, String workflowname, String sourceDbname, String tragetDbname, String servername, String serverdomainname, String sqname, List<MappletBean> mapplet, String co_target, String sourcedatabasename, String paramFilepath, String source_ownername, String target_ownername) throws Exception {
      WORKFLOW workflow = new WORKFLOW();
      workflow.setDESCRIPTION("");
      workflow.setISENABLED("YES");
      workflow.setISRUNNABLESERVICE("NO");
      workflow.setISSERVICE("NO");
      workflow.setISVALID("YES");
      workflow.setNAME(workflowname);
      workflow.setREUSABLESCHEDULER("NO");
      workflow.setSCHEDULERNAME("Scheduler");
      workflow.setSERVERNAME(servername);
      workflow.setSERVERDOMAINNAME(serverdomainname);
      workflow.setSUSPENDONERROR("NO");
      workflow.setTASKSMUSTRUNONSERVER("NO");
      workflow.setVERSIONNUMBER("1");
      workflow.setSCHEDULER(this.getSCHEDULER());
      workflow.getTASK().add(this.getTASK());
      workflow.getSESSION().add(this.getSESSION(mappingName, workflowname, sourceDbname, tragetDbname, sqname, mapplet, co_target, sourcedatabasename, paramFilepath, source_ownername, target_ownername));

      for(TASKINSTANCE taskinstance : this.getTASKINSTANCE("s_M_" + mappingName)) {
         workflow.getTASKINSTANCE().add(taskinstance);
      }

      WORKFLOWLINK workflowlink = new WORKFLOWLINK();
      workflowlink.setCONDITION("");
      workflowlink.setFROMTASK("Start");
      workflowlink.setTOTASK("s_M_" + mappingName);
      workflow.getWORKFLOWLINK().add(workflowlink);

      for(WORKFLOWVARIABLE workflowvariable : this.getWORKFLOWVARIABLE(mappingName)) {
         workflow.getWORKFLOWVARIABLE().add(workflowvariable);
      }

      for(ATTRIBUTE attribute : this.getATTRIBUTE(workflowname)) {
         workflow.getATTRIBUTE().add(attribute);
      }

      return workflow;
   }

   public SCHEDULER getSCHEDULER() {
      SCHEDULER scheduler = new SCHEDULER();
      scheduler.setDESCRIPTION("");
      scheduler.setNAME("Scheduler");
      scheduler.setREUSABLE("NO");
      scheduler.setVERSIONNUMBER("1");
      SCHEDULEINFO scheduleinfo = new SCHEDULEINFO();
      scheduleinfo.setSCHEDULETYPE("ONDEMAND");
      scheduler.setSCHEDULEINFO(scheduleinfo);
      return scheduler;
   }

   public TASK getTASK() {
      TASK task = new TASK();
      task.setDESCRIPTION("");
      task.setNAME("Start");
      task.setREUSABLE("NO");
      task.setTYPE("Start");
      task.setVERSIONNUMBER("1");
      return task;
   }

   public SESSION getSESSION(String mappingName, String workflowname, String sourceDbname, String tragetDbname, String sqname, List<MappletBean> mapplet, String co_target, String sourcedatabasename, String paramFilepath, String source_ownername, String target_ownername) throws Exception {
      SESSION session = new SESSION();
      session.setDESCRIPTION("");
      session.setISVALID("YES");
      session.setMAPPINGNAME(mappingName);
      session.setNAME("s_M_" + mappingName);
      session.setREUSABLE("NO");
      session.setSORTORDER("Binary");
      session.setVERSIONNUMBER("1");

      for(SESSTRANSFORMATIONINST sesstransformationinst : this.getSESSTRANSFORMATIONINST(mappingName, sourceDbname, tragetDbname, sqname, mapplet, source_ownername, target_ownername)) {
         session.getSESSTRANSFORMATIONINST().add(sesstransformationinst);
      }

      CONFIGREFERENCE configreference = new CONFIGREFERENCE();
      configreference.setREFOBJECTNAME("default_session_config");
      configreference.setTYPE("Session config");
      session.setCONFIGREFERENCE(configreference);

      for(SESSIONEXTENSION sessionextension : this.getSESSIONEXTENSIONList(sourceDbname, tragetDbname, sqname, co_target, sourcedatabasename, mapplet)) {
         session.getSESSIONEXTENSION().add(sessionextension);
      }

      for(ATTRIBUTE attribute : this.getATTRIBUTEInfo(workflowname, paramFilepath)) {
         session.getATTRIBUTE().add(attribute);
      }

      return session;
   }

   public List<SESSTRANSFORMATIONINST> getSESSTRANSFORMATIONINST(String mappingName, String sourcename, String targetname, String sqname, List<MappletBean> mapplet, String source_ownername, String target_ownername) throws Exception {
      List<SESSTRANSFORMATIONINST> sesstransformationinstList = new ArrayList();
      SESSTRANSFORMATIONINST s1 = new SESSTRANSFORMATIONINST();
      s1.setISREPARTITIONPOINT("YES");
      s1.setPARTITIONTYPE("PASS THROUGH");
      s1.setPIPELINE("1");
      s1.setSTAGE("1");
      s1.setSINSTANCENAME(targetname);
      s1.setTRANSFORMATIONNAME(targetname);
      s1.setTRANSFORMATIONTYPE("Target Definition");
      ATTRIBUTE a1 = new ATTRIBUTE();
      a1.setNAME("Table Name Prefix");
      a1.setVALUE(target_ownername);
      s1.getATTRIBUTE().add(a1);
      sesstransformationinstList.add(s1);
      SESSTRANSFORMATIONINST s2 = new SESSTRANSFORMATIONINST();
      s2.setISREPARTITIONPOINT("NO");
      s2.setPIPELINE("0");
      s2.setSINSTANCENAME(sourcename);
      s2.setSTAGE("0");
      s2.setTRANSFORMATIONNAME(sourcename);
      s2.setTRANSFORMATIONTYPE("Source Definition");
      ATTRIBUTE a2 = new ATTRIBUTE();
      a2.setNAME("Owner Name");
      a2.setVALUE(source_ownername);
      s2.getATTRIBUTE().add(a2);
      sesstransformationinstList.add(s2);
      SESSTRANSFORMATIONINST s3 = new SESSTRANSFORMATIONINST();
      s3.setISREPARTITIONPOINT("NO");
      s3.setPIPELINE("0");
      s3.setSINSTANCENAME("TAB_SEED");
      s3.setSTAGE("0");
      s3.setTRANSFORMATIONNAME("TAB_SEED");
      s3.setTRANSFORMATIONTYPE("Source Definition");
      sesstransformationinstList.add(s3);
      SESSTRANSFORMATIONINST s4 = new SESSTRANSFORMATIONINST();
      s4.setISREPARTITIONPOINT("NO");
      s4.setPIPELINE("2");
      s4.setSINSTANCENAME("EXPTRANS");
      s4.setSTAGE("3");
      s4.setTRANSFORMATIONNAME("EXPTRANS");
      s4.setTRANSFORMATIONTYPE("Expression");
      PARTITION part = new PARTITION();
      part.setNAME("分区编号1");
      part.setDESCRIPTION("");
      s4.getPARTITION().add(part);
      sesstransformationinstList.add(s4);
      SESSTRANSFORMATIONINST s5 = new SESSTRANSFORMATIONINST();
      s5.setISREPARTITIONPOINT("YES");
      s5.setPARTITIONTYPE("PASS THROUGH");
      s5.setPIPELINE("1");
      s5.setSINSTANCENAME(sqname);
      s5.setSTAGE("2");
      s5.setTRANSFORMATIONNAME(sqname);
      s5.setTRANSFORMATIONTYPE("Source Qualifier");
      sesstransformationinstList.add(s5);
      SESSTRANSFORMATIONINST s6 = new SESSTRANSFORMATIONINST();
      s6.setISREPARTITIONPOINT("YES");
      s6.setPARTITIONTYPE("PASS THROUGH");
      s6.setPIPELINE("2");
      s6.setSINSTANCENAME("SQ_Tab_Seed");
      s6.setSTAGE("3");
      s6.setTRANSFORMATIONNAME("SQ_Tab_Seed");
      s6.setTRANSFORMATIONTYPE("Source Qualifier");
      sesstransformationinstList.add(s6);
      SESSTRANSFORMATIONINST s7 = new SESSTRANSFORMATIONINST();
      s7.setISREPARTITIONPOINT("NO");
      s7.setPIPELINE("1");
      s7.setSINSTANCENAME("JNRTRANS");
      s7.setSTAGE("2");
      s7.setTRANSFORMATIONNAME("JNRTRANS");
      s7.setTRANSFORMATIONTYPE("Joiner");
      PARTITION part1 = new PARTITION();
      part1.setNAME("分区编号1");
      part1.setDESCRIPTION("");
      s7.getPARTITION().add(part1);
      sesstransformationinstList.add(s7);
      if (mapplet != null && mapplet.size() > 0) {
         List<String> values = new ArrayList();

         for(int i = 0; i < mapplet.size(); ++i) {
            if (i == 0) {
               SESSTRANSFORMATIONINST session = new SESSTRANSFORMATIONINST();
               session.setISREPARTITIONPOINT("NO");
               session.setPIPELINE("1");
               session.setSINSTANCENAME(((MappletBean)mapplet.get(i)).getMappletname() + ".Data_Masking");
               session.setSTAGE("2");
               session.setTRANSFORMATIONNAME(((MappletBean)mapplet.get(i)).getMappletname() + ".Data_Masking");
               session.setTRANSFORMATIONTYPE("Custom Transformation");
               SESSTRANSFORMATIONGROUP sg = new SESSTRANSFORMATIONGROUP();
               sg.setGROUP("DM_INPUT_GROUP");
               session.getSESSTRANSFORMATIONGROUP().add(sg);
               PARTITION part2 = new PARTITION();
               part2.setNAME("分区编号1");
               session.getPARTITION().add(part2);
               sesstransformationinstList.add(session);
               values.add(((MappletBean)mapplet.get(i)).getMappletname());
            } else if (values.contains(((MappletBean)mapplet.get(i)).getMappletname())) {
               SESSTRANSFORMATIONINST session = new SESSTRANSFORMATIONINST();
               session.setISREPARTITIONPOINT("NO");
               session.setPIPELINE("1");
               session.setSINSTANCENAME(((MappletBean)mapplet.get(i)).getMappletname() + 1 + ".Data_Masking");
               session.setSTAGE("2");
               session.setTRANSFORMATIONNAME(((MappletBean)mapplet.get(i)).getMappletname() + 1 + ".Data_Masking");
               session.setTRANSFORMATIONTYPE("Custom Transformation");
               SESSTRANSFORMATIONGROUP sg = new SESSTRANSFORMATIONGROUP();
               sg.setGROUP("DM_INPUT_GROUP");
               session.getSESSTRANSFORMATIONGROUP().add(sg);
               PARTITION part2 = new PARTITION();
               part2.setNAME("分区编号1");
               session.getPARTITION().add(part2);
               sesstransformationinstList.add(session);
               values.add(((MappletBean)mapplet.get(i)).getMappletname());
            } else {
               SESSTRANSFORMATIONINST session = new SESSTRANSFORMATIONINST();
               session.setISREPARTITIONPOINT("NO");
               session.setPIPELINE("1");
               session.setSINSTANCENAME(((MappletBean)mapplet.get(i)).getMappletname() + ".Data_Masking");
               session.setSTAGE("2");
               session.setTRANSFORMATIONNAME(((MappletBean)mapplet.get(i)).getMappletname() + ".Data_Masking");
               session.setTRANSFORMATIONTYPE("Custom Transformation");
               SESSTRANSFORMATIONGROUP sg = new SESSTRANSFORMATIONGROUP();
               sg.setGROUP("DM_INPUT_GROUP");
               session.getSESSTRANSFORMATIONGROUP().add(sg);
               PARTITION part2 = new PARTITION();
               part2.setNAME("分区编号1");
               session.getPARTITION().add(part2);
               sesstransformationinstList.add(session);
               values.add(((MappletBean)mapplet.get(i)).getMappletname());
            }
         }
      }

      return sesstransformationinstList;
   }

   public List<SESSIONEXTENSION> getSESSIONEXTENSIONList(String sourceDbname, String tragetDbname, String sq_name, String co_target, String sourcedatabasename, List<MappletBean> mapplet) throws Exception {
      List<SESSIONEXTENSION> sessionextensionList = new ArrayList();
      SESSIONEXTENSION sessionextension = new SESSIONEXTENSION();
      sessionextension.setNAME("Relational Writer");
      sessionextension.setSINSTANCENAME(tragetDbname);
      sessionextension.setSUBTYPE("Relational Writer");
      sessionextension.setTRANSFORMATIONTYPE("Target Definition");
      sessionextension.setTYPE("WRITER");
      CONNECTIONREFERENCE connectionreference = new CONNECTIONREFERENCE();
      connectionreference.setCNXREFNAME("DB Connection");
      connectionreference.setCONNECTIONNAME(co_target);
      connectionreference.setCONNECTIONNUMBER("1");
      connectionreference.setCONNECTIONSUBTYPE("Oracle");
      connectionreference.setCONNECTIONTYPE("Relational");
      connectionreference.setVARIABLE("");
      sessionextension.getCONNECTIONREFERENCE().add(connectionreference);
      String[] attributeStr = new String[]{"Target load type@Normal", "Insert@YES", "Update as Update@YES", "Update as Insert@NO", "Update else Insert@NO", "Delete@YES", "Truncate target table option@NO", "Reject file directory@$PMBadFileDir", "Reject filename@1.bad"};
      String[] tmpAttr = null;
      ATTRIBUTE[] attribute = new ATTRIBUTE[attributeStr.length];

      for(int i = 0; i < attributeStr.length; ++i) {
         tmpAttr = attributeStr[i].split("@");
         attribute[i] = new ATTRIBUTE();
         attribute[i].setNAME(tmpAttr[0]);
         if (tmpAttr.length > 1) {
            attribute[i].setVALUE(tmpAttr[1]);
         } else {
            attribute[i].setVALUE("");
         }

         sessionextension.getATTRIBUTE().add(attribute[i]);
      }

      sessionextensionList.add(sessionextension);
      SESSIONEXTENSION sessionextension3 = new SESSIONEXTENSION();
      sessionextension3.setDSQINSTNAME(sq_name);
      sessionextension3.setDSQINSTTYPE("Source Qualifier");
      sessionextension3.setNAME("Relational Reader");
      sessionextension3.setSINSTANCENAME(sourceDbname);
      sessionextension3.setSUBTYPE("Relational Reader");
      sessionextension3.setTRANSFORMATIONTYPE("Source Definition");
      sessionextension3.setTYPE("READER");
      sessionextensionList.add(sessionextension3);
      SESSIONEXTENSION sessionextension4 = new SESSIONEXTENSION();
      sessionextension4.setDSQINSTNAME("SQ_Tab_Seed");
      sessionextension4.setDSQINSTTYPE("Source Qualifier");
      sessionextension4.setNAME("Relational Reader");
      sessionextension4.setSINSTANCENAME("TAB_SEED");
      sessionextension4.setSUBTYPE("Relational Reader");
      sessionextension4.setTRANSFORMATIONTYPE("Source Definition");
      sessionextension4.setTYPE("READER");
      sessionextensionList.add(sessionextension4);
      SESSIONEXTENSION sessionextension1 = new SESSIONEXTENSION();
      sessionextension1.setNAME("Relational Reader");
      sessionextension1.setSINSTANCENAME(sq_name);
      sessionextension1.setSUBTYPE("Relational Reader");
      sessionextension1.setTRANSFORMATIONTYPE("Source Qualifier");
      sessionextension1.setTYPE("READER");
      CONNECTIONREFERENCE connectionreference1 = new CONNECTIONREFERENCE();
      connectionreference1.setCNXREFNAME("DB Connection");
      connectionreference1.setCONNECTIONNAME(sourcedatabasename);
      connectionreference1.setCONNECTIONNUMBER("1");
      connectionreference1.setCONNECTIONSUBTYPE("Oracle");
      connectionreference1.setCONNECTIONTYPE("Relational");
      connectionreference1.setVARIABLE("");
      sessionextension1.getCONNECTIONREFERENCE().add(connectionreference1);
      sessionextensionList.add(sessionextension1);
      SESSIONEXTENSION sessionextension2 = new SESSIONEXTENSION();
      sessionextension2.setNAME("Relational Reader");
      sessionextension2.setSINSTANCENAME("SQ_Tab_Seed");
      sessionextension2.setSUBTYPE("Relational Reader");
      sessionextension2.setTRANSFORMATIONTYPE("Source Qualifier");
      sessionextension2.setTYPE("READER");
      CONNECTIONREFERENCE connectionreference2 = new CONNECTIONREFERENCE();
      connectionreference2.setCNXREFNAME("DB Connection");
      connectionreference2.setCONNECTIONNAME("DBD_Tab_Seed");
      connectionreference2.setCONNECTIONNUMBER("1");
      connectionreference2.setCONNECTIONSUBTYPE("Oracle");
      connectionreference2.setCONNECTIONTYPE("Relational");
      connectionreference2.setVARIABLE("");
      sessionextension2.getCONNECTIONREFERENCE().add(connectionreference2);
      sessionextensionList.add(sessionextension2);
      if (mapplet != null && mapplet.size() > 0) {
         for(int i = 0; i < mapplet.size(); ++i) {
            SESSIONEXTENSION sessionextension6 = new SESSIONEXTENSION();
            sessionextension6.setCOMPONENTVERSION("5000000");
            sessionextension6.setNAME("Data Masking Extension");
            sessionextension6.setSINSTANCENAME(((MappletBean)mapplet.get(i)).getMappletname() + ".Data_Masking");
            sessionextension6.setSUBTYPE("Data Masking Extension");
            sessionextension6.setTRANSFORMATIONTYPE("Custom Transformation");
            sessionextension6.setTYPE("TEMPLATEEXTENSION");
            CONNECTIONREFERENCE c1 = new CONNECTIONREFERENCE();
            c1.setCNXREFNAME("IDM_Dictionary");
            c1.setCONNECTIONNAME("");
            c1.setCONNECTIONNUMBER("1");
            c1.setCONNECTIONSUBTYPE("");
            c1.setCONNECTIONTYPE("");
            c1.setVARIABLE("");
            CONNECTIONREFERENCE c2 = new CONNECTIONREFERENCE();
            c2.setCNXREFNAME("IDM_Storage");
            c2.setCONNECTIONNAME("");
            c2.setCONNECTIONNUMBER("2");
            c2.setCONNECTIONSUBTYPE("");
            c2.setCONNECTIONTYPE("");
            c2.setVARIABLE("");
            CONNECTIONREFERENCE c3 = new CONNECTIONREFERENCE();
            c3.setCNXREFNAME("IDM_Email_Dictionary");
            c3.setCONNECTIONNAME("");
            c3.setCONNECTIONNUMBER("3");
            c3.setCONNECTIONSUBTYPE("");
            c3.setCONNECTIONTYPE("");
            c3.setVARIABLE("");
            sessionextension6.getCONNECTIONREFERENCE().add(c1);
            sessionextension6.getCONNECTIONREFERENCE().add(c2);
            sessionextension6.getCONNECTIONREFERENCE().add(c3);
            String[] attributeStr1 = new String[]{"SSN High Group file@$PMSourceFileDir/highgroup.txt", "Cache Directory@$PMCacheDir/", "Cache Size@8388608", "Shared Storage Table@NO", "Storage Commit Interval@100000", "Encrypt Storage@NO", "Storage Encryption Key@INFA"};
            String[] tmpAttr1 = null;
            ATTRIBUTE[] attribute1 = new ATTRIBUTE[attributeStr1.length];

            for(int j = 0; j < attributeStr1.length; ++j) {
               tmpAttr1 = attributeStr1[j].split("@");
               attribute1[j] = new ATTRIBUTE();
               attribute1[j].setNAME(tmpAttr1[0]);
               if (tmpAttr1.length > 1) {
                  attribute1[j].setVALUE(tmpAttr1[1]);
               } else {
                  attribute1[j].setVALUE("");
               }

               sessionextension6.getATTRIBUTE().add(attribute1[j]);
            }

            sessionextensionList.add(sessionextension6);
         }
      }

      return sessionextensionList;
   }

   public List<ATTRIBUTE> getATTRIBUTEInfo(String workflowname, String paramFilepath) {
      List<ATTRIBUTE> ATTRIBUTEList = new ArrayList();
      String[] attruInfo = new String[]{"General Options@", "Write Backward Compatible Session Log File@NO", "Session Log File Name@" + workflowname + ".log", "Session Log File directory@$PMSessionLogDir\\", "Parameter Filename@" + paramFilepath, "Enable Test Load@NO", "$Source connection value@", "$Target connection value@", "Treat source rows as@Insert", "Commit Type@Target", "Commit Interval@10000", "Commit On End Of File@YES", "Rollback Transactions on Errors@NO", "Recovery Strategy@Fail task and continue workflow", "Java Classpath@", "Performance@", "DTM buffer size@Auto", "Collect performance data@NO", "Write performance data to repository@NO", "Incremental Aggregation@NO", "Enable high precision@NO", "Session retry on deadlock@NO", "Pushdown Optimization@None", "Allow Temporary View for Pushdown@NO", "Allow Temporary Sequence for Pushdown@NO", "Allow Pushdown for User Incompatible Connections@NO"};
      String[] tmpAttr = null;
      ATTRIBUTE[] attribute1 = new ATTRIBUTE[attruInfo.length];

      for(int i = 0; i < attruInfo.length; ++i) {
         tmpAttr = attruInfo[i].split("@");
         attribute1[i] = new ATTRIBUTE();
         attribute1[i].setNAME(tmpAttr[0]);
         if (tmpAttr.length > 1) {
            attribute1[i].setVALUE(tmpAttr[1]);
         } else {
            attribute1[i].setVALUE("");
         }

         ATTRIBUTEList.add(attribute1[i]);
      }

      return ATTRIBUTEList;
   }

   public List<TASKINSTANCE> getTASKINSTANCE(String sessionname) {
      List<TASKINSTANCE> taskinstanceList = new ArrayList();
      TASKINSTANCE taskinstance = new TASKINSTANCE();
      taskinstance.setDESCRIPTION("");
      taskinstance.setISENABLED("YES");
      taskinstance.setNAME("Start");
      taskinstance.setREUSABLE("NO");
      taskinstance.setTASKNAME("Start");
      taskinstance.setTASKTYPE("Start");
      taskinstanceList.add(taskinstance);
      TASKINSTANCE taskinstance1 = new TASKINSTANCE();
      taskinstance1.setDESCRIPTION("");
      taskinstance1.setFAILPARENTIFINSTANCEDIDNOTRUN("NO");
      taskinstance1.setFAILPARENTIFINSTANCEFAILS("YES");
      taskinstance1.setISENABLED("YES");
      taskinstance1.setREUSABLE("NO");
      taskinstance1.setNAME(sessionname);
      taskinstance1.setTASKNAME(sessionname);
      taskinstance1.setTASKTYPE("Session");
      taskinstance1.setTREATINPUTLINKASAND("YES");
      taskinstanceList.add(taskinstance1);
      return taskinstanceList;
   }

   public List<WORKFLOWVARIABLE> getWORKFLOWVARIABLE(String mappingName) {
      List<WORKFLOWVARIABLE> workflowvariableList = new ArrayList();
      String name = "s_M_" + mappingName;
      String[] workflowvariableStr = new String[]{"date/time@The time this task started@NO@NO@$Start.StartTime@NO", "date/time@The time this task completed@NO@NO@$Start.EndTime@NO", "integer@Status of this task&apos;s execution@NO@NO@$Start.Status@NO", "integer@Status of the previous task that is not disabled@NO@NO@$Start.PrevTaskStatus@NO", "integer@Error code for this task&apos;s execution@NO@NO@$Start.ErrorCode@NO", "string@Error message for this task&apos;s execution@NO@NO@$Start.ErrorMsg@NO", "date/time@The time this task started@NO@NO@$" + name + ".StartTime@NO", "date/time@The time this task completed@NO@NO@$" + name + ".EndTime@NO", "integer@Status of this task&apos;s execution@NO@NO@$" + name + ".Status@NO", "integer@Status of the previous task that is not disabled@NO@NO@$" + name + ".PrevTaskStatus@NO", "integer@Error code for this task&apos;s execution@NO@NO@$" + name + ".ErrorCode@NO", "string@Error message for this task&apos;s execution@NO@NO@$" + name + ".ErrorMsg@NO", "integer@Rows successfully read@NO@NO@$" + name + ".SrcSuccessRows@NO", "integer@Rows failed to read@NO@NO@$" + name + ".SrcFailedRows@NO", "integer@Rows successfully loaded@NO@NO@$" + name + ".TgtSuccessRows@NO", "integer@Rows failed to load@NO@NO@$" + name + ".TgtFailedRows@NO", "integer@Total number of transformation errors@NO@NO@$" + name + ".TotalTransErrors@NO", "integer@First error code@NO@NO@$" + name + ".FirstErrorCode@NO", "string@First error message@NO@NO@$" + name + ".FirstErrorMsg@NO"};
      String[] splitArry = null;
      WORKFLOWVARIABLE[] workflowvariable = new WORKFLOWVARIABLE[workflowvariableStr.length];

      for(int i = 0; i < workflowvariableStr.length; ++i) {
         workflowvariable[i] = new WORKFLOWVARIABLE();
         splitArry = workflowvariableStr[i].split("@");
         workflowvariable[i].setDATATYPE(splitArry[0]);
         workflowvariable[i].setDEFAULTVALUE("");
         workflowvariable[i].setDESCRIPTION(splitArry[1]);
         workflowvariable[i].setISNULL(splitArry[2]);
         workflowvariable[i].setISPERSISTENT(splitArry[3]);
         workflowvariable[i].setNAME(splitArry[4]);
         workflowvariable[i].setUSERDEFINED(splitArry[5]);
         workflowvariableList.add(workflowvariable[i]);
      }

      return workflowvariableList;
   }

   public List<ATTRIBUTE> getATTRIBUTE(String workflowname) {
      List<ATTRIBUTE> attributeList = new ArrayList();
      String[] attributeStr = new String[]{"Parameter Filename@", "Write Backward Compatible Workflow Log File@NO", "Workflow Log File Name@" + workflowname + ".log", "Workflow Log File Directory@$PMWorkflowLogDir\\", "Save Workflow log by@By runs", "Save workflow log for these runs@0", "Service Name@", "Service Timeout@0", "Is Service Visible@NO", "Is Service Protected@NO", "Enable HA recovery@NO", "Automatically recover terminated tasks@NO", "Service Level Name@Default", "Allow concurrent run with unique run instance name@NO", "Allow concurrent run with same run instance name@NO", "Maximum number of concurrent runs@0", "Assigned Web Services Hubs@", "Maximum number of concurrent runs per Hub@1000", "Expected Service Time@1"};
      String[] splitArry = null;
      ATTRIBUTE[] attribute = new ATTRIBUTE[attributeStr.length];

      for(int i = 0; i < attributeStr.length; ++i) {
         attribute[i] = new ATTRIBUTE();
         splitArry = attributeStr[i].split("@");
         attribute[i].setNAME(splitArry[0]);
         if (splitArry.length > 1) {
            attribute[i].setVALUE(splitArry[1]);
         } else {
            attribute[i].setVALUE("");
         }

         attributeList.add(attribute[i]);
      }

      return attributeList;
   }
}
