package com.teamcenter.rac.workflow.commands.digitalsign;

//import com.teamcenter.net.tcserverproxy.client.TSPException;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.InterfaceAIFOperationListener;
import com.teamcenter.rac.kernel.TCCRDecision;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentActionHandler;
import com.teamcenter.rac.kernel.TCComponentSignoff;
import com.teamcenter.rac.kernel.TCComponentTask;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCTaskState;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.workflow.commands.complete.CompleteOperation;
import com.teamcenter.rac.workflow.commands.failure.FailureOperation;
import com.teamcenter.rac.workflow.commands.newperformsignoff.DecisionDialog;
import com.teamcenter.rac.workflow.commands.newperformsignoff.SignoffDecisionOperation;
import com.teamcenter.soa.client.PKCS7;
import java.awt.Window;
import java.io.IOException;
import org.eclipse.core.runtime.jobs.Job;

public class PerformTaskUtil {
  private TCComponentTask task = null;
  
  private String commentsStr = null;
  
  private String passwordStr = null;
  
  private Window m_window = null;
  
  private String resultStr = null;
  
  private String operationType = null;
  
  TCComponent supportObject = null;
  
  TCCRDecision decision = null;
  
  TCSession session = null;
  
  AbstractAIFOperation m_operation = null;
  
  TCComponent[] attachments = null;
  
  DecisionDialog dialog = null;
  
  public static final String APPLY_DS_HANDLER = "EPM-apply-digital-signature";
  
  public static final String REQUEST_PKI_AUTHENTICATION_HANDLER = "EPM-request-PKI-authentication";
  
  public static final String COMPLETE_OPERATION = "COMPLETE_OPERATION";
  
  public static final String FAILURE_OPERATION = "FAILURE_OPERATION";
  
  public static final String SIGNOFF_DECISION_OPERATION = "SIGNOFF_DECISION_OPERATION";
  
  InterfaceAIFOperationListener m_lsnr;
  
  public PerformTaskUtil(Window paramWindow, TCComponentTask paramTCComponentTask, String paramString1, String paramString2, String paramString3) {
    this.m_window = paramWindow;
    this.task = paramTCComponentTask;
    this.commentsStr = paramString1;
    this.passwordStr = paramString2;
    this.resultStr = paramString3;
    this.session = this.task.getSession();
  }
  
  public PerformTaskUtil(Window paramWindow, TCComponentTask paramTCComponentTask, String paramString1, String paramString2, String paramString3, InterfaceAIFOperationListener paramInterfaceAIFOperationListener, String paramString4) {
    this(paramWindow, paramTCComponentTask, paramString1, paramString2, paramString3);
    this.m_lsnr = paramInterfaceAIFOperationListener;
    this.operationType = paramString4;
  }
  
  public PerformTaskUtil(DecisionDialog paramDecisionDialog, TCComponentTask paramTCComponentTask, TCComponent paramTCComponent, TCCRDecision paramTCCRDecision, String paramString1, String paramString2, InterfaceAIFOperationListener paramInterfaceAIFOperationListener) {
    this((Window)paramDecisionDialog, paramTCComponentTask, paramString1, paramString2, paramTCCRDecision.toString(), paramInterfaceAIFOperationListener, "SIGNOFF_DECISION_OPERATION");
    this.supportObject = paramTCComponent;
    this.decision = paramTCCRDecision;
    this.dialog = paramDecisionDialog;
  }
  
  public void executeOperation() {
    try {
      TCTaskState tCTaskState = this.task.getState();
      this.m_operation = getTaskOperation();
      if (tCTaskState == TCTaskState.STARTED) {
        byte b1 = 4;
        if (this.task.getTypeComponent().toString().equals("EPMPerformSignoffTask"))
          b1 = 100; 
        TCComponentActionHandler tCComponentActionHandler1 = null;
        TCComponentActionHandler tCComponentActionHandler2 = null;
        TCComponentActionHandler[] arrayOfTCComponentActionHandler = this.task.getActionHandlers(b1);
        for (byte b2 = 0; b2 < arrayOfTCComponentActionHandler.length; b2++) {
          if (arrayOfTCComponentActionHandler[b2].getName().equals("EPM-apply-digital-signature")) {
            tCComponentActionHandler1 = arrayOfTCComponentActionHandler[b2];
          } else if (arrayOfTCComponentActionHandler[b2].getName().equals("EPM-request-PKI-authentication")) {
            tCComponentActionHandler2 = arrayOfTCComponentActionHandler[b2];
          } 
        } 
        if (tCComponentActionHandler1 != null) {
          if (this.m_operation instanceof CompleteOperation) {
            ((CompleteOperation)this.m_operation).setDigitalSignatureContext(null);
          } else if (this.m_operation instanceof SignoffDecisionOperation) {
            ((SignoffDecisionOperation)this.m_operation).setDigitalSignatureContext(null);
          } 
          this.session.queueOperation((Job)this.m_operation);
        } else if (tCComponentActionHandler2 != null) {
          String str = performSmartCardAuthentication();
          if (str != null) {
            if (this.m_operation instanceof CompleteOperation) {
              ((CompleteOperation)this.m_operation).setDigitalSignatureContext(str);
            } else if (this.m_operation instanceof FailureOperation) {
              ((FailureOperation)this.m_operation).setDigitalSignatureContext(str);
            } else if (this.m_operation instanceof SignoffDecisionOperation) {
              ((SignoffDecisionOperation)this.m_operation).setDigitalSignatureContext(str);
            } 
            this.session.queueOperation((Job)this.m_operation);
          } 
        } else {
          this.session.queueOperation((Job)this.m_operation);
        } 
      } else if (tCTaskState == TCTaskState.COMPLETED) {
        this.session.queueOperation((Job)this.m_operation);
      } 
    } catch (TCException tCException) {
      MessageBox.post((Throwable)tCException);
    } 
  }
  
  private AbstractAIFOperation getTaskOperation() {
    AbstractAIFOperation abstractAIFOperation = null;
    if (this.operationType == null || this.operationType.equals("COMPLETE_OPERATION")) {
      abstractAIFOperation = getCompleteOperation();
    } else if (this.operationType.equals("SIGNOFF_DECISION_OPERATION")) {
      abstractAIFOperation = getSignoffDecisionOperation();
    } else if (this.operationType.equals("FAILURE_OPERATION")) {
      abstractAIFOperation = getFailureOperation();
    } 
    if (this.m_lsnr != null)
      abstractAIFOperation.addOperationListener(this.m_lsnr); 
    return abstractAIFOperation;
  }
  
  public AbstractAIFOperation getOperation() {
    return this.m_operation;
  }
  
  private AbstractAIFOperation getSignoffDecisionOperation() {
    return (AbstractAIFOperation)new SignoffDecisionOperation(this.session, this.dialog, this.task, (TCComponentSignoff)this.supportObject, this.decision, this.commentsStr, this.passwordStr);
  }
  
  private AbstractAIFOperation getCompleteOperation() {
    return (AbstractAIFOperation)new CompleteOperation(this.m_window, new TCComponentTask[] { this.task }, this.commentsStr, this.passwordStr, this.resultStr);
  }
  
  private AbstractAIFOperation getFailureOperation() {
    return (AbstractAIFOperation)new FailureOperation(this.m_window, new TCComponentTask[] { this.task }, this.commentsStr, this.passwordStr, this.resultStr);
  }
  
  private String performSmartCardAuthentication() {
    String str = null;
//    try {
//      str = PKCS7.sign(this.session.getUserName());
//    } catch (TSPException tSPException) {
//      MessageBox.post((Throwable)tSPException);
//    } catch (IOException iOException) {
//      MessageBox.post(iOException);
//    } 
    return str;
  }
}


/* Location:              D:\plugins tc13\plugins\com.teamcenter.rac.tcapps_13000.1.0.jar!\com\teamcenter\rac\workflow\commands\digitalsign\PerformTaskUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */