Пример #1
0
  @SuppressWarnings("deprecation")
  public void testApplyGlobalChanges1() throws WorkflowException {

    MaintenanceDocument document;
    document =
        (MaintenanceDocument)
            SpringContext.getBean(DocumentService.class).getNewDocument(GLOBAL_DELEGATE_TYPENAME);
    document.getDocumentHeader().setDocumentDescription("blah");

    // get local references to the Maintainable and the BO
    Maintainable newMaintainable = document.getNewMaintainableObject();
    AccountDelegateGlobal bo = (AccountDelegateGlobal) newMaintainable.getBusinessObject();
    String finDocNumber = document.getDocumentHeader().getDocumentNumber();

    // create the lists
    List<AccountDelegateGlobalDetail> changeDocuments = new ArrayList();
    List<AccountGlobalDetail> accountDetails = new ArrayList();

    // add a delegate change document
    AccountDelegateGlobalDetail change = new AccountDelegateGlobalDetail();
    change.setDocumentNumber(finDocNumber);
    change.setAccountDelegatePrimaryRoutingIndicator(true);
    change.setAccountDelegateStartDate(START_DATE_1);
    change.setAccountDelegateUniversalId(DELEGATE_ID_1);
    change.setApprovalFromThisAmount(FROM_AMOUNT_1);
    change.setApprovalToThisAmount(TO_AMOUNT_1);
    change.setFinancialDocumentTypeCode(DOC_TYPE_ALL);
    changeDocuments.add(change);

    bo.setDelegateGlobals(changeDocuments);

    // add account change detail records
    AccountGlobalDetail account;
    account = new AccountGlobalDetail();
    account.setDocumentNumber(finDocNumber);
    account.setChartOfAccountsCode(COA1);
    account.setAccountNumber(ACCOUNT1);
    accountDetails.add(account);

    account = new AccountGlobalDetail();
    account.setDocumentNumber(finDocNumber);
    account.setChartOfAccountsCode(COA1);
    account.setAccountNumber(ACCOUNT2);
    accountDetails.add(account);

    account = new AccountGlobalDetail();
    account.setDocumentNumber(finDocNumber);
    account.setChartOfAccountsCode(COA1);
    account.setAccountNumber(ACCOUNT3);
    accountDetails.add(account);

    bo.setAccountGlobalDetails(accountDetails);

    GlobalBusinessObject gbo = (GlobalBusinessObject) bo;
    List<PersistableBusinessObject> persistables = gbo.generateGlobalChangesToPersist();

    assertFalse("The list should not be empty.", persistables.isEmpty());
    assertEquals("There should be three output records.", 3, persistables.size());
  }
  /** @see org.kuali.rice.kns.maintenance.Maintainable#saveBusinessObject() */
  @Override
  public void saveBusinessObject() {
    BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class);

    GlobalBusinessObject gbo = (GlobalBusinessObject) businessObject;

    // delete any indicated BOs
    List<PersistableBusinessObject> bosToDeactivate = gbo.generateDeactivationsToPersist();
    if (bosToDeactivate != null) {
      if (!bosToDeactivate.isEmpty()) {
        boService.save(bosToDeactivate);
      }
    }

    // OJB caches the any ObjectCodes that are retrieved from the database.  If multiple queries
    // return the same row (identified by the PK
    // values), OJB will return the same instance of the ObjectCode.  However, in
    // generateGlobalChangesToPersist(), the ObjectCode returned by
    // OJB is altered, meaning that any subsequent OJB calls will return the altered object.  The
    // following cache will store the active statuses
    // of object codes affected by this global document before generateGlobalChangesToPersist()
    // alters them.
    Map<String, Boolean> objectCodeActiveStatusCache =
        buildObjectCodeActiveStatusCache((ObjectCodeGlobal) gbo);

    SubObjectTrickleDownInactivationService subObjectTrickleDownInactivationService =
        SpringContext.getBean(SubObjectTrickleDownInactivationService.class);
    // persist any indicated BOs
    List<PersistableBusinessObject> bosToPersist = gbo.generateGlobalChangesToPersist();
    if (bosToPersist != null) {
      if (!bosToPersist.isEmpty()) {
        for (PersistableBusinessObject bo : bosToPersist) {
          ObjectCode objectCode = (ObjectCode) bo;

          boService.save(objectCode);

          if (isInactivatingObjectCode(objectCode, objectCodeActiveStatusCache)) {
            subObjectTrickleDownInactivationService.trickleDownInactivateSubObjects(
                objectCode, getDocumentNumber());
          }
        }
      }
    }
  }
Пример #3
0
  public void testApplyGlobalChanges_Empty() throws WorkflowException {

    MaintenanceDocument document;
    document =
        (MaintenanceDocument)
            SpringContext.getBean(DocumentService.class).getNewDocument(GLOBAL_DELEGATE_TYPENAME);
    document.getDocumentHeader().setDocumentDescription("blah");

    // get local references to the Maintainable and the BO
    Maintainable newMaintainable = document.getNewMaintainableObject();
    AccountDelegateGlobal bo = (AccountDelegateGlobal) newMaintainable.getBusinessObject();

    List<AccountDelegateGlobalDetail> changeDocuments = new ArrayList();
    bo.setDelegateGlobals(changeDocuments);

    List<AccountGlobalDetail> accountDetails = new ArrayList();
    bo.setAccountGlobalDetails(accountDetails);

    GlobalBusinessObject gbo = (GlobalBusinessObject) bo;
    List<PersistableBusinessObject> persistables = gbo.generateGlobalChangesToPersist();

    assertTrue("Global Changes returned should be an empty list.", persistables.isEmpty());
  }