/* ----------------------------------------------------------------
  // Function Name    : CheckBODO
  // Date Written     : 29/03/2009
  // Author           : Utsav
  // Input Parameters :
  // Return Values    : boolean
  // Description      : CheckBODO Implemented
  // ---------------------------------------------------------------- */
  private static boolean CheckBODO(CmdRowData tempData) {
    boolean bCheckBODO = true;
    String strErrorMsg = "";
    if (tempData.getSourceBO().trim().equalsIgnoreCase("") || tempData.getSourceBO() == null) {
      bCheckBODO = false;
      strErrorMsg = strErrorMsg + " Source BO not found in command data.";
    }
    if (tempData.getSourceDO().trim().equalsIgnoreCase("") || tempData.getSourceDO() == null) {
      bCheckBODO = false;
      strErrorMsg = strErrorMsg + " Source DO not found in command data.";
    }
    if (tempData.getDestinationBO().trim().equalsIgnoreCase("")
        || tempData.getDestinationBO() == null) {
      bCheckBODO = false;
      strErrorMsg = strErrorMsg + " Destination BO not found in command data.";
    }
    if (tempData.getDestinationDO().trim().equalsIgnoreCase("")
        || tempData.getDestinationDO() == null) {
      bCheckBODO = false;
      strErrorMsg = strErrorMsg + " Destination DO not found in command data.";
    } else {
      if (tempData.getDestinationDO().trim().length() == 1) {
        tempData.setDestinatonDO("00" + tempData.getDestinationDO().trim());
      } else if (tempData.getDestinationDO().trim().length() == 2) {
        tempData.setDestinatonDO("0" + tempData.getDestinationDO().trim());
      }
    }
    if (bCheckBODO == false) {
      ServiceConfiguration.serviceLog.info("Error Occured for !! " + strErrorMsg);
      ServiceConfiguration.serviceErrorLog.info("Error Occured!! " + strErrorMsg);
      strErrorMsg = "Error occured : " + strErrorMsg;

      try {
        UnderProcessFile.getReference()
            .setProperty(tempData.getUID(), SynchConstants.INITIAL_STATE);
        String inputXML =
            ServiceConfiguration.getUpdateSynchDataXML(
                tempData.getUID(), SynchConstants.INITIAL_STATE, strErrorMsg);
        String outputXML = ServiceConfiguration.executeLocalXML(inputXML);
        DMSXmlResponse xmlResponse = null;
        xmlResponse.setXmlString(outputXML);
        String statusValue = xmlResponse.getVal("Status");
        if (statusValue.equalsIgnoreCase(
            "0")) { // if local update is successful then  clear the Propessing File
          UnderProcessFile.getReference().remove(tempData.getUID());
        } else {
          // WE KEEP THE VALUE IN THE PROCESS FILE TO BE SAME STATE
          // SO THAT IT CAN BE UPDATED LATER..
        }
      } catch (IOException ex) {
        ServiceConfiguration.serviceLog.info(
            "Error Occured for !! " + tempData.getUID() + " Printing Stack Trace in Error Log");
        ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", ex);
      } catch (NGException ex) {
        ServiceConfiguration.serviceLog.info(
            "Error Occured for !! " + tempData.getUID() + " Printing Stack Trace in Error Log");
        ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", ex);
      }
    }
    return bCheckBODO;
  }
  //	 ---------------------------------------------------------------------------------------
  // Function Name : forwardAcknowledgeComplete
  // Date Written : 29/03/2009
  // Author : Utsav Turray
  // Input Parameters : none
  // Output Parameters : None
  // Return Values : None
  // Description : To acknowledge the forwarded data
  //
  // ---------------------------------------------------------------------------------------
  public static void forwardAcknowledgeComplete(
      CmdRowData tempData, String strLocalCabinet, String strDestinationCabinet) {
    ServiceConfiguration.serviceLog.info("############################");
    ServiceConfiguration.serviceLog.info(
        "#Forward and Acknowledge Process Started for UID "
            + tempData.getUID()
            + "  Source : "
            + tempData.getSource());
    DMSXmlResponse xmlResponse = new DMSXmlResponse();
    String inputXML = "";
    String outputXML = "";
    String statusValue = "";
    String destination = strDestinationCabinet.toLowerCase();

    try {

      inputXML =
          ServiceConfiguration.getForwardAckXML(
              tempData.getUID(),
              SynchConstants.B_ACK_STATE_SENT,
              SynchConstants.B_ACK_STATE_SENT_MESSAGE,
              destination);
      ServiceConfiguration.serviceXMLLog.info(inputXML);
      outputXML =
          ServiceConfiguration.executeRemoteXML(tempData.getStatusFlag(), destination, inputXML);
      ServiceConfiguration.serviceXMLLog.info("OutputXML " + outputXML);
      xmlResponse.setXmlString(outputXML);
      statusValue = xmlResponse.getVal("Status");
      if (statusValue.equalsIgnoreCase("0")) {
        UnderProcessFile.getReference()
            .setProperty(tempData.getUID(), SynchConstants.PROCESSED_ACK_SENT);
        inputXML =
            ServiceConfiguration.getForwardAckXML(
                tempData.getUID(),
                SynchConstants.PROCESSED_ACK_SENT,
                SynchConstants.B_ACK_STATE_RCVD_MESSAGE,
                strLocalCabinet);
        outputXML = ServiceConfiguration.executeLocalXML(inputXML);
        xmlResponse.setXmlString(outputXML);
        statusValue = xmlResponse.getVal("Status");
        if (statusValue.equalsIgnoreCase("0")) {
          ServiceConfiguration.serviceLog.info(
              "#Process and Acknowlged Completed Sucessfully# for UID "
                  + tempData.getUID()
                  + "  Source : "
                  + tempData.getSource());
        } else {
          ServiceConfiguration.serviceLog.info(
              "#Process and Acknowledge Process failed for UID "
                  + tempData.getUID()
                  + "  Source : "
                  + tempData.getSource());
        }
        if (statusValue.equalsIgnoreCase("0")) { // if local
          // update is
          // successful
          // then clear
          // the
          // Processing
          // File
          UnderProcessFile.getReference().remove(tempData.getUID());
        } else {
          // WE KEEP THE VALUE IN THE PROCESS FILE TO BE SAME
          // STATE SO THAT IT CAN BE UPDATED LATER..
        }
      } else {
        ServiceConfiguration.serviceLog.info(
            "#Unable to Acknowledge the Synchronization Request for :- "
                + tempData.getUID()
                + "  Source : "
                + tempData.getSource());
        String error = xmlResponse.getVal("Error");
        try {
          inputXML =
              ServiceConfiguration.getUpdateSynchDataXML(
                  tempData.getUID(),
                  SynchConstants.PROCESSED_STATE,
                  "Unable to Acknowledge the Synchronization Request");
          outputXML = ServiceConfiguration.executeLocalXML(inputXML);
          xmlResponse.setXmlString(outputXML);
          statusValue = xmlResponse.getVal("Status");
        } catch (IOException e) {
          ServiceConfiguration.serviceLog.info(
              "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
          ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
          // Error Handling
        } catch (NGException e) {
          ServiceConfiguration.serviceLog.info(
              "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
          ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
        }
      }

    } catch (NGException e) {
      ServiceConfiguration.serviceLog.info(
          "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
      ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);

    } catch (IOException e) {
      ServiceConfiguration.serviceLog.info(
          "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
      ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
    }
  }
  /* ----------------------------------------------------------------
  // Function Name    : UpdateStatusLocally
  // Date Written     : 29/03/2009
  // Author           : Utsav
  // Input Parameters :
  // Return Values    : void
  // Description      : UpdateStatusLocally Implemented
  // ---------------------------------------------------------------- */
  public static void UpdateStatusLocally(
      CmdRowData tempData,
      String strIntitialState,
      String strSuccessState,
      String strSucessStateMessage) {
    ServiceConfiguration.serviceLog.info("############################");
    ServiceConfiguration.serviceLog.info("#Local Update Started# For UID :" + tempData.getUID());
    DMSXmlResponse xmlResponse = new DMSXmlResponse();
    String inputXML = "";
    String outputXML = "";
    String statusValue = "";
    // Error Handling if source is not in that format
    try {
      UnderProcessFile.getReference().setProperty(tempData.getUID(), strIntitialState);
      inputXML =
          ServiceConfiguration.getUpdateSynchDataXML(
              tempData.getUID(), strSuccessState, strSucessStateMessage);
      outputXML = ServiceConfiguration.executeLocalXML(inputXML);
      ServiceConfiguration.serviceXMLLog.info(inputXML);
      ServiceConfiguration.serviceXMLLog.info("OutputXML " + outputXML);
      xmlResponse.setXmlString(outputXML);
      statusValue = xmlResponse.getVal("Status");
      if (statusValue.equalsIgnoreCase("0")) {
        ServiceConfiguration.serviceLog.info(
            "#Local Update Completed Sucessfully# For UID :" + tempData.getUID());
        UnderProcessFile.getReference().remove(tempData.getUID());
      } else {
        ServiceConfiguration.serviceLog.info("#Local Update Process Failed#");
        ServiceConfiguration.serviceLog.info(
            "#Local Update Process Failed for :- " + tempData.getUID());
        String error = xmlResponse.getVal("Error");
        try {
          inputXML =
              ServiceConfiguration.getUpdateSynchDataXML(
                  tempData.getUID(), strIntitialState, error);
          outputXML = ServiceConfiguration.executeLocalXML(inputXML);
          xmlResponse.setXmlString(outputXML);
          statusValue = xmlResponse.getVal("Status");
        } catch (IOException e) {
          ServiceConfiguration.serviceLog.info(
              "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
          ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
          // Error Handling
        } catch (NGException e) {
          ServiceConfiguration.serviceLog.info(
              "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
          ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
        }
      }

    } catch (NGException e) {
      ServiceConfiguration.serviceLog.info(
          "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
      ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);

    } catch (IOException e) {
      ServiceConfiguration.serviceLog.info(
          "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
      ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
    }
  }
  // ---------------------------------------------------------------------------------------
  // Function Name : selfAcknowledge
  // Date Written : 31/10/2011
  // Author : Ankur Bedi
  // Input Parameters : none
  // Output Parameters : None
  // Return Values : None
  // Description : To self acknowledge after forwarding to destination or after processing of
  // forwarded request from source
  // EDMS3.0-ERC-00033
  // ---------------------------------------------------------------------------------------
  private static void selfAcknowledgeProcessedCall(CmdRowData tempData, String STATE) {

    ServiceConfiguration.serviceLog.info("############################");
    ServiceConfiguration.serviceLog.info(
        "#Self Acknowledge Process Started for UID " + tempData.getUID());

    DMSXmlResponse xmlResponse = new DMSXmlResponse();
    String inputXML = "";
    String outputXML = "";
    String statusValue = "";
    String ACK_STATE = "";
    String ACK_MESSAGE = "";
    String localCabinet = ServiceConfiguration.getProperty("localcabinetname");
    try {

      if (STATE.equalsIgnoreCase(SynchConstants.FORWARDED_STATE)) {

        ACK_STATE = SynchConstants.PROCESSED_ACK;
        ACK_MESSAGE = SynchConstants.PROCESSED_ACK_MESSAGE;
      } else if (STATE.equalsIgnoreCase(SynchConstants.PROCESSED_STATE)) {
        ACK_STATE = SynchConstants.PROCESSED_SYNCHED_ACK;
        ACK_MESSAGE = SynchConstants.PROCESSED_SYNCHED_ACK_MESSAGE;
      } else {
        return;
      }

      inputXML =
          ServiceConfiguration.getForwardAckXML(
              tempData.getUID(), ACK_STATE, ACK_MESSAGE, localCabinet);
      ServiceConfiguration.serviceXMLLog.info(inputXML);
      outputXML = ServiceConfiguration.executeLocalXML(inputXML);
      ServiceConfiguration.serviceXMLLog.info("OutputXML " + outputXML);
      xmlResponse.setXmlString(outputXML);
      statusValue = xmlResponse.getVal("Status");
      if (statusValue.equalsIgnoreCase("0")) {
        UnderProcessFile.getReference().remove(tempData.getUID());
        ServiceConfiguration.serviceLog.info(
            "#Local Acknowlgment Completed Sucessfully# for UID " + tempData.getUID());
      } else {

        ServiceConfiguration.serviceLog.info(
            "#Unable to Local Acknowledge the Synchronization Request for :- " + tempData.getUID());
        String error = xmlResponse.getVal("Error");
        if (error == null) {
          error = "Status:" + statusValue;
        }
        try {

          inputXML = ServiceConfiguration.getUpdateSynchDataXML(tempData.getUID(), STATE, error);
          outputXML = ServiceConfiguration.executeLocalXML(inputXML);
          xmlResponse.setXmlString(outputXML);
          statusValue = xmlResponse.getVal("Status");
        } catch (IOException e) {
          ServiceConfiguration.serviceLog.info(
              "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
          ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
          // Error Handling
        } catch (NGException e) {
          ServiceConfiguration.serviceLog.info(
              "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
          ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
        }
      }

    } catch (NGException e) {
      ServiceConfiguration.serviceLog.info(
          "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
      ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);

    } catch (IOException e) {
      ServiceConfiguration.serviceLog.info(
          "Error Occured!!" + tempData.getUID() + "Printing Stack Trace in Error Log");
      ServiceConfiguration.serviceErrorLog.info("Error Occured!! ", e);
    }
  }