Exemplo n.º 1
0
 public Budget getFinalBudgetForThisProposal() {
   BudgetDocumentVersion budgetDocumentVersion = this.getFinalBudgetVersion();
   if (budgetDocumentVersion != null) {
     return budgetDocumentVersion.getFinalBudget();
   }
   return null;
 }
Exemplo n.º 2
0
 private void refreshBudgetDocumentVersion(BudgetDocument savedBudgetDoc) {
   Budget budget = savedBudgetDoc.getBudget();
   for (BudgetDocumentVersion documentVersion :
       savedBudgetDoc.getParentDocument().getBudgetDocumentVersions()) {
     documentVersion.refreshReferenceObject("documentHeader");
     BudgetVersionOverview version = documentVersion.getBudgetVersionOverview();
     if (budget.getBudgetVersionNumber().equals(version.getBudgetVersionNumber())) {
       documentVersion.refreshReferenceObject("budgetVersionOverviews");
     }
   }
 }
Exemplo n.º 3
0
  /**
   * This method sets additional document information in the document header of the budget form. If
   * the document contained in the budget form is null then empty values will be placed for the
   * additional information.
   *
   * @param budgetForm the budget form
   */
  private void setAdditionalDocumentHeaderInfo(final BudgetForm budgetForm) {
    assert budgetForm != null : "the budgetForm is null";

    final BudgetDocument budgetDocument = budgetForm.getDocument();
    Budget budget = budgetDocument.getBudget();
    BudgetParentDocument parentDocument = budgetDocument.getParentDocument();
    if (budget != null
        && parentDocument != null
        && parentDocument.getBudgetDocumentVersions() != null) {
      boolean setAdditionalInfo = false;
      for (final BudgetDocumentVersion budgetVersion : parentDocument.getBudgetDocumentVersions()) {
        if (budgetVersion
            .getBudgetVersionOverview()
            .getBudgetVersionNumber()
            .equals(budget.getBudgetVersionNumber())) {
          budgetForm
              .getDocInfo()
              .add(
                  new HeaderField(
                      BudgetForm.BUDGET_NAME_KEY,
                      budgetVersion.getBudgetVersionOverview().getDocumentDescription()));
          setAdditionalInfo = true;
          break;
        } else {
          budgetForm
              .getDocInfo()
              .add(new HeaderField(BudgetForm.BUDGET_NAME_KEY, Constants.EMPTY_STRING));
        }
      }
      if (!setAdditionalInfo) {
        budgetForm
            .getDocInfo()
            .add(new HeaderField(BudgetForm.BUDGET_NAME_KEY, Constants.EMPTY_STRING));
      }

      if (budget.getBudgetVersionNumber() != null) {
        budgetForm
            .getDocInfo()
            .add(
                new HeaderField(
                    BudgetForm.VERSION_NUMBER_KEY, budget.getBudgetVersionNumber().toString()));
      } else {
        budgetForm
            .getDocInfo()
            .add(new HeaderField(BudgetForm.VERSION_NUMBER_KEY, Constants.EMPTY_STRING));
      }
    }
  }
  /**
   * This method checks budget versions business rules.
   *
   * @param budgetParentDocument the document
   * @param runDatactionaryValidation if dd validation should be run
   * @return true if valid false if not
   * @throws NullPointerException if the proposalDevelopmentDocument is null
   */
  protected boolean processBudgetVersionsBusinessRule(
      final BudgetParentDocument budgetParentDocument, final boolean runDatactionaryValidation) {
    if (budgetParentDocument == null) {
      throw new NullPointerException("the parentDocument is null.");
    }

    boolean valid = true;
    final MessageMap errorMap = GlobalVariables.getMessageMap();
    boolean finalVersionFound = false;

    final DictionaryValidationService dictionaryValidationService =
        getKnsDictionaryValidationService();

    int index = 0;
    for (BudgetDocumentVersion budgetDocumentVersion :
        budgetParentDocument.getBudgetDocumentVersions()) {
      BudgetVersionOverview budgetVersion = budgetDocumentVersion.getBudgetVersionOverview();
      if (runDatactionaryValidation) {
        dictionaryValidationService.validateBusinessObject(budgetVersion, true);
      }
      if (budgetVersion.isFinalVersionFlag()) {
        if (finalVersionFound) {
          errorMap.putError("finalVersionFlag", KeyConstants.ERROR_MULTIPLE_FINAL_BUDGETS);
        } else {
          finalVersionFound = true;
        }
      }

      final String budgetStatusCompleteCode =
          getParameterService()
              .getParameterValueAsString(
                  BudgetDocument.class, Constants.BUDGET_STATUS_COMPLETE_CODE);

      if (budgetStatusCompleteCode.equalsIgnoreCase(budgetVersion.getBudgetStatus())) {
        if (!budgetVersion.isFinalVersionFlag()) {
          errorMap.putError(
              "budgetVersionOverview[" + index + "].budgetStatus",
              KeyConstants.ERROR_NO_FINAL_BUDGET);
          valid = false;
        }
      }
      index++;
    }

    return valid;
  }
Exemplo n.º 5
0
  protected boolean processRunAuditBudgetVersionRule(BudgetParentDocument parentDocument) {
    // audit check for budgetversion with final status
    boolean finalAndCompleteBudgetVersionFound = false;
    boolean budgetVersionsExists = false;
    boolean retval = true;

    List<AuditError> auditErrors = new ArrayList<AuditError>();
    String budgetStatusCompleteCode =
        getParameterService()
            .getParameterValueAsString(BudgetDocument.class, Constants.BUDGET_STATUS_COMPLETE_CODE);
    for (BudgetDocumentVersion budgetDocumentVersion : parentDocument.getBudgetDocumentVersions()) {
      BudgetVersionOverview budgetVersion = budgetDocumentVersion.getBudgetVersionOverview();
      budgetVersionsExists = true;
      if (budgetVersion.isFinalVersionFlag()) {
        BudgetParent budgetParent = parentDocument.getBudgetParent();
        if (budgetParent.getBudgetStatus() != null
            && budgetParent.getBudgetStatus().equals(budgetStatusCompleteCode)) {
          finalAndCompleteBudgetVersionFound = true;
        }
      }
    }
    if (budgetVersionsExists && !finalAndCompleteBudgetVersionFound) {
      auditErrors.add(
          new AuditError(
              "document.parentBudget.budgetVersionOverview",
              KeyConstants.AUDIT_ERROR_NO_BUDGETVERSION_COMPLETE_AND_FINAL,
              Constants.PD_BUDGET_VERSIONS_PAGE + "." + Constants.BUDGET_VERSIONS_PANEL_ANCHOR));
      retval = false;
    }
    if (auditErrors.size() > 0) {
      KNSGlobalVariables.getAuditErrorMap()
          .put(
              "budgetVersionErrors",
              new AuditCluster(
                  Constants.BUDGET_VERSION_PANEL_NAME, auditErrors, Constants.AUDIT_ERRORS));
    }

    return retval;
  }
Exemplo n.º 6
0
 /**
  * Load the document again and ensure that the document header version is the same to avoid
  * optimistic lock exceptions given that the proposal might save this doc header.
  *
  * @param budgetDoc
  * @throws WorkflowException
  */
 protected void fixDocHeaderVersion(BudgetDocument budgetDoc) throws WorkflowException {
   DocumentService docService = KraServiceLocator.getService(DocumentService.class);
   BudgetDocument updatedDoc =
       (BudgetDocument) docService.getByDocumentHeaderId(budgetDoc.getDocumentNumber());
   budgetDoc
       .getDocumentHeader()
       .setVersionNumber(updatedDoc.getDocumentHeader().getVersionNumber());
   // update all budget versions doc headers as we will try to save them all and can be saved by
   // proposal under separate lock as well
   for (int i = 0; i < budgetDoc.getParentDocument().getBudgetDocumentVersions().size(); i++) {
     BudgetDocumentVersion bdVersion = budgetDoc.getParentDocument().getBudgetDocumentVersion(i);
     BudgetDocumentVersion updatedVersion =
         updatedDoc.getParentDocument().getBudgetDocumentVersion(i);
     if (bdVersion != null && updatedVersion != null) {
       if (bdVersion.getDocumentHeader().getVersionNumber()
           < updatedVersion.getDocumentHeader().getVersionNumber()) {
         bdVersion
             .getDocumentHeader()
             .setVersionNumber(updatedVersion.getDocumentHeader().getVersionNumber());
       }
     }
   }
 }