Ejemplo n.º 1
0
 public boolean isAlive() {
   int testPhaseId = 19968;
   AdDcCoopBean adDcCoopBean = null;
   try {
     adDcCoopBean = getAdDcCoopByPhaseId(testPhaseId);
   } catch (ApplicationException e) {
     LOG.log(Level.SEVERE, "isAlive(): " + e);
     return false;
   }
   if (adDcCoopBean == null) {
     LOG.log(Level.SEVERE, "isAlive(): Unexpected null AdDcCoopBean.");
     return false;
   }
   int expectedCoopId = 905;
   int coopId = adDcCoopBean.getCoopId();
   if (coopId != expectedCoopId) {
     LOG.log(
         Level.SEVERE,
         "isAlive(): Unexpected value for coopId property. Expected "
             + expectedCoopId
             + ", "
             + coopId
             + " was returned.");
     return false;
   }
   return true;
 }
Ejemplo n.º 2
0
  public void deleteDcCoopsByCoopIdAndRegionMemberId(AdDcCoopBean dcCoop)
      throws ApplicationException {
    if (LOG.isLoggable(Level.FINER)) {
      LOG.entering(
          AdDcCoopCommandImpl.class.getName(),
          "deleteDcCoopsByCoopIdAndRegionMemberId",
          new Object[] {new Integer(dcCoop.getCoopId()), new Integer(dcCoop.getRegionMemberId())});
    }
    boolean success = false;

    try {
      DBHelper.startTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, false);

      cancelWorkflowForDcCoop(dcCoop);
      AdDcCoopManager.deleteDcCoopByCoopIdAndRegMbrId(
          dcCoop.getCoopId(), dcCoop.getRegionMemberId());

      success = true;
    } finally {
      DBHelper.finalizeActiveTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, success);
    }
    if (LOG.isLoggable(Level.FINER)) {
      LOG.exiting(AdDcCoopCommandImpl.class.getName(), "deleteDcCoopsByCoopIdAndRegionMemberId");
    }
  }
Ejemplo n.º 3
0
 public void cancelWorkflowForDcCoop(AdDcCoopBean dcCoop) throws ApplicationException {
   if (dcCoop != null && dcCoop.getWorkFlowPhaseId() > 0) {
     int tranId =
         ContractsUtils.getTransactionPhaseCommand()
             .getTransactionPhaseById(dcCoop.getWorkFlowPhaseId())
             .getTransactionId();
     if (LOG.isLoggable(Level.FINER))
       LOG.log(
           Level.FINER,
           "Cancelling transaction [" + tranId + "] for Ad Coop [" + dcCoop.getCoopId() + "].");
     ContractsUtils.getTransactionCommand().cancelTransaction(tranId);
   }
 }
Ejemplo n.º 4
0
  public void updateDivisionCoopMonies(int coopId) throws ApplicationException {

    if (LOG.isLoggable(Level.FINE)) {
      LOG.entering(this.getClass().getName(), "updateDivisionCoopMonies", String.valueOf(coopId));
    }

    boolean success = false;

    try {
      //			DBHelper.startTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, false);

      AdCoopBean coop = AdCoopManager.getCoopById(coopId);
      if (coop == null) throw new ApplicationException("No coop exists having id: " + coopId);

      ArrayList<AdDcCoopBean> divisionCoops = AdDcCoopManager.getDivisionCoops(coopId);

      if (coop.getType() == ContractsUtils.getCoopIdRegional()) {
        AdDcCoopBean divisionBean = null, lastAccepted = null;
        double acceptedDollars = 0.0;
        double runningTotal = 0.0;
        // Find the total sum for all accepted dollars
        for (int i = 0; i < divisionCoops.size(); i++) {
          divisionBean = divisionCoops.get(i);
          if (divisionBean.getDivisionTaken() == 1 && divisionBean.getAccountRejectReason() <= 0) {
            acceptedDollars += divisionBean.getInitialAmount();
          }
        }

        if (LOG.isLoggable(Level.FINER)) {
          LOG.finer("total amount of accepted coop dollars is: " + acceptedDollars);
        }

        for (int i = 0; i < divisionCoops.size(); i++) {
          divisionBean = (AdDcCoopBean) divisionCoops.get(i);
          if (divisionBean.getDivisionTaken() == 1
              && divisionBean.getAccountRejectReason() <= 0
              && acceptedDollars > 0.0) {
            lastAccepted = divisionBean;
            // Multiply the accepted amount by a scaling factor in order to reallocate the dollars
            // that were
            //   not accepted.  For example, if only $500 (acceptedDollars) out of $1000
            // (coop.getTotal)
            //   dollars were accepted, the amounts that WERE accepted would be multiplied by 2 =
            // 1000/500
            double newAmount =
                (divisionBean.getInitialAmount() * coop.getTotal()) / acceptedDollars;
            newAmount = Math.round(newAmount * 100.0D) / 100.0D; // get rid of extra digits
            runningTotal += newAmount;
            divisionBean.setBilledAmount(newAmount);
          } else {
            divisionBean.setBilledAmount(0.0);
          }
        }

        if (lastAccepted != null && runningTotal != coop.getTotal()) {
          if (LOG.isLoggable(Level.FINER)) {
            LOG.finer(
                "offsetting funds from rounding errors of "
                    + (coop.getTotal() - runningTotal)
                    + " to division "
                    + lastAccepted.getRegionMemberId());
          }
          double newAmount = lastAccepted.getBilledAmount() + coop.getTotal() - runningTotal;
          lastAccepted.setBilledAmount(Math.round(newAmount * 100.0D) / 100.0D);
        }
      } else {
        boolean isCaseRate = coop.getType() == ContractsUtils.getCoopIdCaseRate();

        for (int i = 0; i < divisionCoops.size(); i++) {
          AdDcCoopBean divisionBean = (AdDcCoopBean) divisionCoops.get(i);
          if (divisionBean.getDivisionTaken() == 1 && divisionBean.getAccountRejectReason() <= 0) {
            if (isCaseRate) {
              int actualCases =
                  divisionBean.getActualCases() <= 0 ? 0 : divisionBean.getActualCases();
              divisionBean.setBilledAmount(
                  Math.round(actualCases * divisionBean.getInitialAmount() * 100.0D) / 100.0D);
            } else {
              divisionBean.setBilledAmount(divisionBean.getInitialAmount());
            }
          } else {
            divisionBean.setBilledAmount(0.0);
          }
          LOG.finer("billed amount for division : " + divisionBean.getBilledAmount());
        }
      }

      this.storeAdDcCoops(
          (AdDcCoopBean[]) ArrayUtils.toTypedArray(divisionCoops, AdDcCoopBean.class));

      success = true;
    } finally {
      //			DBHelper.finalizeActiveTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, success);
    }

    if (LOG.isLoggable(Level.FINE)) {
      LOG.exiting(this.getClass().getName(), "updateDivisionCoopMonies", String.valueOf(coopId));
    }
  }
Ejemplo n.º 5
0
  public AdDcCoopDetailBean[] getAdDcCoopDetailsByWeekAndDivision(
      Calendar adWeek, int regionMemberId) throws Exception {

    LOG.log(
        Level.FINE,
        "beginning of getAdDcCoopDetailsByWeekAndDivision() on the WAS side of NFCCore");

    ArrayList<AdDcCoopBean> coops =
        AdDcCoopManager.getDivisionCoopsByDateAndRegMbrId(adWeek, regionMemberId);

    LOG.log(Level.FINE, "coops_________________" + coops);

    AdDcCoopDetailBean[] results = new AdDcCoopDetailBean[coops.size()];

    LOG.log(Level.FINE, "results_________________" + results);

    LOG.log(
        Level.FINE, "inside of getAdDcCoopDetailsByWeekAndDivision() on the WAS side of NFCCore");
    Workflow coopWorkflow = ContractsUtils.getWorkflowCommand().getWorkflowByName(COOP_WORKFLOW);

    LOG.log(Level.FINE, "coopWorkflow_____________________________" + coopWorkflow);

    if (coopWorkflow == null) {
      LOG.log(Level.FINE, "coopWorkflow_____________________________is null");
      throw new ApplicationException("Unable to locate coop workflow configuration.");
    }

    LOG.log(Level.FINE, "before divisionStateGroup_____________________________");

    State divisionStateGroup =
        ContractsUtils.getStateCommand()
            .getStateByNameAndWorkflowId(DIVISION_STATE, coopWorkflow.getId());

    LOG.log(
        Level.FINE, "before divisionStateGroup_____________________________" + divisionStateGroup);

    State accountingStateGroup =
        ContractsUtils.getStateCommand()
            .getStateByNameAndWorkflowId(ACCOUNTING_STATE, coopWorkflow.getId());

    if (divisionStateGroup == null) {
      throw new ApplicationException("Unable to locate division state in workflow configuration.");
    }

    if (accountingStateGroup == null) {
      throw new ApplicationException(
          "Unable to locate accounting state in workflow configuration.");
    }

    for (int i = 0; i < coops.size(); i++) {
      AdDcCoopBean bean = coops.get(i);
      AdDcCoopDetailBean current = new AdDcCoopDetailBean(bean);
      AdCoopBean adCoop =
          ServiceLocator.getInstance()
              .getService(AdCoopCommand.class)
              .getAdCoopById(current.getCoopId());
      AdEntryBean adEntry =
          ServiceLocator.getInstance()
              .getService(AdEntryCommand.class)
              .getAdEntryByCoopId(current.getCoopId());
      current.setAdEntry(adEntry);
      current.setAdCoop(adCoop);

      current.setInDivisionPhase(
          ContractsUtils.getTransactionPhaseCommand()
              .isPhaseInState(bean.getWorkFlowPhaseId(), divisionStateGroup.getId()));

      current.setInAccountingPhase(
          ContractsUtils.getTransactionPhaseCommand()
              .isPhaseInState(bean.getWorkFlowPhaseId(), accountingStateGroup.getId()));

      results[i] = current;
    }

    LOG.log(Level.FINE, "end of getAdDcCoopDetailsByWeekAndDivision() on the WAS side of NFCCore");

    return results;
  }
Ejemplo n.º 6
0
  public void validateCoop(AdDcCoopBean coop) throws ApplicationException {
    if (coop.getDivisionTaken() == 1) {
      if (coop.getDivisionRejectReason() > 0) {
        throw new ApplicationException(
            "A division reject message was specified when accepting the division record.  Please reject the record or remove the reject message.  Coop ID: "
                + coop.getCoopId());
      }
    } else if (coop.getDivisionTaken() == -1) {
      if (coop.getDivisionRejectReason() <= 0) {
        throw new ApplicationException(
            "A reject message must be specified when rejecting the division record.  Coop ID: "
                + coop.getCoopId());
      }
      if (coop.getEstimatedCases() > 0) {
        throw new ApplicationException(
            "A positive estimated case count can not be specified when rejecting the division record.  Coop ID: "
                + coop.getCoopId());
      }
    }

    if (coop.getAccountRejectReason() > 0) {
      if (Utils.hasContent(coop.getBillSign())) {
        throw new ApplicationException(
            "The entry cannot have a billing signature when it is rejected.  Coop ID: "
                + coop.getCoopId());
      } else if (coop.getBillDate() != null) {
        throw new ApplicationException(
            "The entry cannot have a billing date when it is rejected.  Coop ID: "
                + coop.getCoopId());
      }
    }
  }
Ejemplo n.º 7
0
  /**
   * Validate and update the provided list of AdDcCoopBeans in the database in transactional
   * fashion. If validation on any coop, an ApplicationException is thrown and no data is changed on
   * any entry in the database. If all entries are validated, their data is updated in the database
   * and workflow is performed. If <code>divisionUpdate</code> is <code>true</code>, then workflow
   * is sent a <code>open</code>, <code>reject</code>, or <code>accept</code> depending if the
   * <code>divisionTaken</code> attribute is -1, 1, or 0, respectively. If <code>divisionUpdate
   * </code> is <code>false</code> (i.e. an accounting update), then workflow is send <code>billed
   * </code> (bill date or signature is provided), <code>reject</code> (an accounting reject reason
   * is provided), or <code>open</code> (otherwise). Also, for all accounting updates,
   * #updateDivisionCoopMonies(int) is invoked.
   *
   * @param dcCoops the list of division coops to process
   * @param divisionUpdate indicates if this is an update from the division phase
   * @param username the user submitting the workflow request
   * @throws ApplicationException if a database, validation, or workflow error occurs
   */
  public void updateCoopsWithWorkflow(
      AdDcCoopBean[] dcCoops, boolean divisionUpdate, String username) throws ApplicationException {

    if (dcCoops == null || dcCoops.length == 0) {
      return;
    }

    boolean success = false;
    try {
      //	        DBHelper.startTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, false);
      for (int i = 0; i < dcCoops.length; i++) {

        AdDcCoopBean dcCoop = dcCoops[i];
        if (dcCoop != null) {
          validateCoop(dcCoop);

          String outcome = null;
          if (divisionUpdate) {
            AdCoopBean coop = AdCoopManager.getCoopById(dcCoop.getCoopId());
            if (coop == null) {
              throw new ApplicationException(
                  "Unable to locate coop having id: " + dcCoop.getCoopId());
            }

            if (coop.getType() == ContractsUtils.getCoopIdCaseRate()) {
              int divisionTaken = 0;
              if (dcCoop.getEstimatedCases() > 0) {
                divisionTaken = 1;
              } else if (dcCoop.getEstimatedCases() == 0) {
                divisionTaken = -1;
              }
              dcCoop.setDivisionTaken(divisionTaken);
            }
            outcome =
                dcCoop.getDivisionTaken() == 1
                    ? "accept"
                    : dcCoop.getDivisionTaken() == -1 ? "reject" : "open";
          } else {
            if (username.equals(AdCoopExportCommand.WF_USERID)) outcome = "export";
            else
              outcome =
                  Utils.hasContent(dcCoop.getBillSign()) || dcCoop.getBillDate() != null
                      ? "billed"
                      : dcCoop.getAccountRejectReason() > 0 ? "reject" : "open";
          }
          WorkflowTransactionPhase newPhase =
              ContractsUtils.getWorkflowCommand()
                  .processTransition(
                      dcCoop.getWorkFlowPhaseId(), outcome, username, dcCoop.toString());
          dcCoop.setWorkFlowPhaseId(newPhase.getId());

          this.storeAdDcCoop(dcCoop);
          if (!divisionUpdate) {
            this.updateDivisionCoopMonies(
                dcCoop.getCoopId()); // this is an accounting update, so we will affect the billed
            // amounts.
          }
        }
      }

      success = true;
    } finally {
      //	        DBHelper.finalizeActiveTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, success);
    }
  }
Ejemplo n.º 8
0
  public void storeAdDcCoop(AdDcCoopBean adcb) throws ApplicationException {
    boolean success = false;
    try {
      //			DBHelper.startTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, false);

      // Get the AdDcCoop entry from the database
      AdDcCoopBean temp = getAdDcCoopByIdAndDivision(adcb.getCoopId(), adcb.getRegionMemberId());

      // If the AdDcCoop was not already in the database ...
      if (temp == null) {
        // Create the AdDcCoop entry in the database
        AdDcCoopManager.createDivisionCoop(
            adcb.getCoopId(),
            adcb.getRegionMemberId(),
            adcb.getInitialAmount(),
            adcb.getBilledAmount(),
            adcb.getEstimatedCases(),
            adcb.getActualCases(),
            adcb.getWorkFlowPhaseId(),
            adcb.getDivisionTaken(),
            adcb.getDivisionRejectReason(),
            adcb.getBillDate(),
            adcb.getBillSign(),
            adcb.getAccountRejectReason(),
            adcb.getAccountingExportWeek(),
            adcb.getAccountingExportPeriod(),
            adcb.getAccountingExportYear());
      } else {
        // Update the AdDcCoop entry
        AdDcCoopManager.updateDivisionCoop(
            adcb.getRegionMemberId(),
            adcb.getInitialAmount(),
            adcb.getBilledAmount(),
            adcb.getEstimatedCases(),
            adcb.getActualCases(),
            adcb.getWorkFlowPhaseId(),
            adcb.getDivisionTaken(),
            adcb.getDivisionRejectReason(),
            adcb.getBillDate(),
            adcb.getBillSign(),
            adcb.getAccountRejectReason(),
            adcb.getCoopId(),
            adcb.getAccountingExportWeek(),
            adcb.getAccountingExportPeriod(),
            adcb.getAccountingExportYear());
      }

      success = true;
    } finally {
      //			DBHelper.finalizeActiveTransaction(NFCCoreVariables.DATASOURCE_WAG_JNDI, success);
    }
  }