/** UI event. View doc button click */
 public void viewDocument(BCMDocument document) {
   try {
     super.viewDocument(document, dto.getProcessBundleLogId());
     openDocumentView(dto.getProcessBundleLogId(), document, quote.getScanner());
   } catch (ServiceException e) {
     errorMessage(e.getError());
   }
 }
  /**
   * UI Generate document event Generate the selected document<br>
   * - Prepare any data (including loanReferences) before invoking the service.<br>
   * - Bundle logic for appended documents moved to the service layer<br>
   * Update the passed document object with a View ability on success. <br>
   */
  public void generateDocument(BCMDocument document) {
    // always solve the selected offers/settlements first
    // LoanReferences generated if required
    solveSelected();
    super.generateDocument(document);

    // need this otherwise ConfirmOfferBranch malfunctions
    if (!this.getClass().getSimpleName().equals(TASK)) return;

    // Reset to false if conditional on Confirm offer. This is to ensure that Pre Agreement
    // validation fires. (Refactor with BCM)
    if (document.getCode().equalsIgnoreCase(SystemConstants.DOCCODE_LOAN_CONDITIONALAPPROVAL)
        || document.getCode().equalsIgnoreCase(SystemConstants.DOCCODE_CREDITLIFE_DOCUMENTS)) {
      quote.getCurrentOffer().setGenerated(false);
      quote.getCurrentOffer().setSent(false);
    }
  }
  @Override
  @PostConstruct
  protected void onTaskReceive() throws ServiceException {
    try {
      super.onTaskReceive();
      if (task.getPid() == -1L) return;

      // must bypass descendants, let them initialize inside their own post constructs
      if (!this.getClass().getSimpleName().equals(TASK)) return;

      // only works with a valid PID
      dto = dao.read(task.getPid());
      super.setDto(dto);
      super.setQuote(dto);

      LookupItem jobTitle = lookupItemDAO.find(LookupItem.onCode, dto.getJobTitleCode());
      dto.setJobTitle(jobTitle);

      if (task.isSupport()) {
        // task inspector default
        xdsOnlyRequired = false;
        // look for a special support target
        if (task.getTaskTarget().equals("task.confirm.offer.xds")) {
          xdsOnlyRequired = true;
          // set it back to the real target otherwise documents won't load
          task.setTaskTarget("task.confirm.offer.call");
        }
      } else {
        xdsOnlyRequired = isSalesFlowV2_1(task) && !isCallCenterChannel(task.getPid());
      }

      // set some state
      dto.setCurrentTask(task);
      dto.setUserLink(bayfin.getUser());
      resolveLogTag(dto);
      filterSelectedSettlements(dto);
      buildOfferResponse(dto); // used for recalc
      loadBCMBundle();

      // also read in the cart data
      if (boot.findFeature("INSURANCE_CART").equals("On")) {
        cart = cartDAO.read(task.getPid());
        cart.setCurrentTask(task);
        cart.setUserLink(bayfin.getUser());
        resolveLogTag(cart);
        loadCart();
        showBanking =
            taskRules.insuredBankAccountRequired(cart.getInsuredBankAccount())
                || taskRules.insuredBankAccountRequired(cart.getOffers());
      }
      if (task.getOrigin().equals("task.confirm.offer.call.insurance")) {
        dto.setInsStandalone(true);
      }

      // now also fetch the XdsAuthenticationHIstoryLog
      fetchXdsLog(dto);
      checkXDSExistingStatus();

      // Initialize with the task associated branch details
      signingBranchCode = new Long(task.getBranchCode());

      // Search for branch name
      BranchBasedSearchRequest request = new BranchBasedSearchRequest();
      BranchSearch search = new BranchSearch();
      request.setData(search);
      GeneralSearchResponse response;
      // set
      request.setType(ESearchResultType.LIST);
      search.setSearchType(ESearchParameter.CODE);
      search.setIncludeAgentData(false);
      search.setIncludeUserData(false);
      search.setBranchCode(signingBranchCode);

      // execute
      response = bayserv.branchSearch(request);
      List<ViewBranch> branches = response.getBranchItems();
      if (branches != null && branches.size() > 0) {
        signingBranch = branches.get(0).getBranchName();
      } // end if

      dto.initialiseConfirmOfferCall();
      bindPresenceCall();

      if (pilotFlag.equals("BNW_V0")) {
        disVoiceContract = true;
        disBranchContract = false;
        dto.setContractingMethod(EContractingMethod.BRANCH);
        branchpre = true;
      } else if (info.isAppFeatureActive("CONTBRN", dto.getBranchCode().intValue())
          && dto.getRequestedProduct() != EProductType.MEDICAL
          && dto.getSubgroupType() != EEmployerType.PAYROLL
          && !isWebChannel(task.getPid())
          && !isCallCenterChannel(task.getPid())) {
        disVoiceContract = true;
        disBranchContract = false;
        dto.setContractingMethod(EContractingMethod.BRANCH);
        branchpre = true;
      } else if ((info.isAppFeatureActive("CONTVOICE", dto.getBranchCode().intValue())
              && dto.getRequestedProduct() != EProductType.MEDICAL
              && dto.getSubgroupType() != EEmployerType.PAYROLL)
          || isWebChannel(task.getPid())
          || isCallCenterChannel(task.getPid())) {
        disVoiceContract = false;
        disBranchContract = true;
        dto.setContractingMethod(EContractingMethod.VOICE);
        branchpre = false;
      } else if (info.isAppFeatureActive("CONTBOTH", dto.getBranchCode().intValue())
          && dto.getRequestedProduct() != EProductType.MEDICAL
          && dto.getSubgroupType() != EEmployerType.PAYROLL) {
        disVoiceContract = false;
        disBranchContract = false;
      } else if ((dto.getRequestedProduct() != EProductType.MEDICAL)
          && (dto.getSubgroupType() != EEmployerType.PAYROLL)) {
        if (quote.getStartRole().equals("Branch") || quote.getStartRole().equals("Agent")) {
          disVoiceContract = true;
          disBranchContract = false;
          dto.setContractingMethod(EContractingMethod.BRANCH);
          branchpre = true;
        } else {
          disVoiceContract = false;
          disBranchContract = false;
        }
      } else if ((dto.getRequestedProduct() == EProductType.MEDICAL)
          && (dto.getSubgroupType() != EEmployerType.PAYROLL)) {
        disVoiceContract = false;
        disBranchContract = true;
        dto.setContractingMethod(EContractingMethod.VOICE);
        branchpre = false;
      } else if (dto.getSubgroupType() == EEmployerType.PAYROLL) {
        disVoiceContract = true;
        disBranchContract = false;
        dto.setContractingMethod(EContractingMethod.BRANCH);
        branchpre = true;
      }

      if ((disVoiceContract == true) && (disBranchContract == true)) {
        throw new ServiceException("BAD#Error, both voice and branch contracting disabled");
      }

      if (dto.getRequestedProduct() == EProductType.MEDICAL) {
        if (dto.getSubgroupType() == EEmployerType.PAYROLL) {
          throw new Exception("Invalid product subgroup received");
        }
        dto.setContractingMethod(EContractingMethod.VOICE);
        disVoiceContract = false;
      }
      if (dto.getSubgroupType() == EEmployerType.PAYROLL) {
        disBranchContract = false;
      }
      employerName = dto.getEmployerName();

      // do not display settlements on web apps
      if (isWebChannel(task.getPid())) {
        dto.setWebChannel(true);
      }

    } catch (ServiceException e) {
      e.printStackTrace();
      popupErrorMessage(e.getError());
    } catch (Exception e) {
      e.printStackTrace();
      popupErrorMessage("Unhandled exception", e.getMessage());
    }
  }
 /** Uses base method */
 public void submitAnswers() {
   super.submitAnswers(dto);
 }
 /** Uses base method */
 public void onSelectAnswer(XDSQuestion question) {
   super.onSelectAnswer(question, dto);
 }
 /** Uses base method */
 public void retrieveQuestions() {
   super.retrieveQuestions(dto);
 }
  @Override
  public void finish(ActionEvent event) {
    dto.setSigningBranchCode(new BigDecimal(signingBranchCode));

    super.finish(event);
    // let descendants implement their own save and finish methods
    if (!this.getClass().getSimpleName().equals(TASK)) return;

    try {

      // don't do fraud checks for insurance stand-alone
      if (!dto.isInsStandalone()) runSystemFraud(dto, contructFraudSearch(dto));

      // Set Presence UCID and TimeStamp

      if (!isXdsOnlyRequired()) {

        dto.setConfirmOfferCallUCID(dto.getPb().getUcId());
        dto.setConfirmOfferCallTimeStamp(Calendar.getInstance().getTime());

        // check docs are generated and sent (contracting only)
        try {
          if (!dto.isCreditLifeSubstitution()) {

            // don't check loan offer changes if doing confirm offer insurance standalone
            if (!task.getTaskTarget().equals("task.confirm.offer.call.insurance")) {
              if (dto.getContractingMethod() == EContractingMethod.BRANCH)
                taskRules.checkOfferChangeIsGenerated(quote.getCurrentOffer());
              // TODO : Fix this, should not be disabled
              else if (!dto.getRequestedProduct().equals(EProductType.MEDICAL))
                taskRules.checkOfferChangeIsGeneratedAndSent(quote.getCurrentOffer());

              // must send it if !branchpre
              if (!dto.getContractingMethod().equals(EContractingMethod.BRANCH))
                if (!docSent) throw new ServiceException(ErrorCodes.CVA071);
            }
          }

          // generates and send all required insurance stand-alone documents (if there is no AVS)
          if (dto.isInsStandalone()) {
            String skipinsavs = getVariable(ConvertUtils.asInt(dto.getPid()), "skipinsavs");
            boolean sendDocsNow = true;
            if (skipinsavs != null) sendDocsNow = ConvertUtils.asBoolean(skipinsavs);

            if (sendDocsNow) {
              loadInsuranceDocumentsToSend();
              sendSpecificDocuments(cart, task, SystemConstants.DOC_INS_CODES);
            }
          }

          // check av (settlements only)
          avBuilder.submitAV(task, dto);
          getAvCaches().clear();
          findSettlementAvData(dto);
          // forced to do the logic here since AvCache is a BayServ entity so we cannot use
          // TaskRules
          boolean avsDone = true;
          String errorMsg = "Account verification status for AV required settlement account : ";
          for (ProtoAvCache item : avCaches) {
            if (!ValidationUtils.isIn(item.getAppStatus(), SystemConstants.AV_COMPLETED)) {
              String accountRef = "";
              for (ProtoSettlement settlement : quote.getSettlements()) {
                String compare = StringUtils.right(settlement.getAccount().getAccountNumber(), 10);
                if (compare.equals(item.getNumber().toString())) {
                  accountRef = settlement.getFormattedAccountNumber();
                  avsDone = false;
                  break;
                }
              }
              errorMessage(
                  "AVS ", errorMsg + " " + accountRef + " : " + item.getAppStatus(), ERR_GLOBAL);
            }
          }
          if (!avsDone) return;

        } catch (ServiceException e) {
          popupErrorMessage(e.getError());
          return;
        }
      }

      completeConfirmOfferFlux();

      if (!isXdsOnlyRequired()) {
        if (dto.getContractingMethod() == EContractingMethod.BRANCH
            && getFluxTask(
                        quote.getPid().intValue(),
                        "task.account.verification",
                        new EFluxTaskStatus[] {
                          EFluxTaskStatus.CREATED,
                          EFluxTaskStatus.IN_PROGRESS,
                          EFluxTaskStatus.READY,
                          EFluxTaskStatus.SUSPENDED
                        })
                    .size()
                <= 0
            && getFluxTask(
                        quote.getPid().intValue(),
                        "task.employment.confirm",
                        new EFluxTaskStatus[] {
                          EFluxTaskStatus.CREATED,
                          EFluxTaskStatus.IN_PROGRESS,
                          EFluxTaskStatus.READY,
                          EFluxTaskStatus.SUSPENDED
                        })
                    .size()
                <= 0) {
          // Now send Sign at branch sms
          if (!dto.isInsStandalone()) {
            bayserv.sendMessage(MessageBuilder.buildBranchSignSms(dto));
          }
        }
      }

      saveAndExit();

    } catch (ServiceException e) {
      logger.error(e);
      e.getError().setReference(transmitErrorData(quote, TASK));
      info.displayBugDialog(e.getError());
    } catch (Exception e) {
      logger.error(e);
      BaseError error = quote.addError(ErrorCodes.UHE000, e);
      error.setReference(transmitErrorData(quote, TASK));
      info.displayBugDialog(error);
    }
  }