/** This method sets the object code on each detail object in the collection */
  @Override
  protected void prepareGlobalsForSave() {
    // copy the object code down from the header into the details
    ObjectCodeGlobal objectCodeGlobal = (ObjectCodeGlobal) getBusinessObject();

    for (ObjectCodeGlobalDetail detail : objectCodeGlobal.getObjectCodeGlobalDetails()) {
      detail.setFinancialObjectCode(objectCodeGlobal.getFinancialObjectCode());
    }
    super.prepareGlobalsForSave();
  }
 protected Map<String, Boolean> buildObjectCodeActiveStatusCache(
     ObjectCodeGlobal objectCodeGlobal) {
   ObjectCodeService objectCodeService = SpringContext.getBean(ObjectCodeService.class);
   Map<String, Boolean> cache = new HashMap<String, Boolean>();
   for (ObjectCodeGlobalDetail detail : objectCodeGlobal.getObjectCodeGlobalDetails()) {
     ObjectCode objectCodeFromDB =
         objectCodeService.getByPrimaryId(
             detail.getUniversityFiscalYear(),
             detail.getChartOfAccountsCode(),
             objectCodeGlobal.getFinancialObjectCode());
     if (ObjectUtils.isNotNull(objectCodeFromDB)) {
       cache.put(
           buildObjectCodeCachingKey(objectCodeFromDB),
           Boolean.valueOf(objectCodeFromDB.isActive()));
     }
   }
   return cache;
 }
  /**
   * This generates the appropriate maintenance locks for the {@link ObjectCode}
   *
   * @see org.kuali.rice.kns.maintenance.Maintainable#generateMaintenanceLocks()
   */
  @Override
  public List<MaintenanceLock> generateMaintenanceLocks() {
    ObjectCodeGlobal objectCodeGlobal = (ObjectCodeGlobal) getBusinessObject();
    List<MaintenanceLock> maintenanceLocks = new ArrayList();
    SubObjectTrickleDownInactivationService subObjectTrickleDownInactivationService =
        SpringContext.getBean(SubObjectTrickleDownInactivationService.class);

    for (ObjectCodeGlobalDetail detail : objectCodeGlobal.getObjectCodeGlobalDetails()) {
      MaintenanceLock maintenanceLock = new MaintenanceLock();
      StringBuffer lockrep = new StringBuffer();

      lockrep.append(ObjectCode.class.getName() + KFSConstants.Maintenance.AFTER_CLASS_DELIM);
      lockrep.append("universityFiscalYear" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
      lockrep.append(detail.getUniversityFiscalYear() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
      lockrep.append("chartOfAccountsCode" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
      lockrep.append(detail.getChartOfAccountsCode() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
      lockrep.append("financialObjectCode" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
      lockrep.append(detail.getFinancialObjectCode());

      maintenanceLock.setDocumentNumber(objectCodeGlobal.getDocumentNumber());
      maintenanceLock.setLockingRepresentation(lockrep.toString());
      maintenanceLocks.add(maintenanceLock);

      ObjectCode objectCode = new ObjectCode();
      objectCode.setUniversityFiscalYear(detail.getUniversityFiscalYear());
      objectCode.setChartOfAccountsCode(detail.getChartOfAccountsCode());
      objectCode.setFinancialObjectCode(detail.getFinancialObjectCode());
      objectCode.setActive(objectCodeGlobal.isFinancialObjectActiveIndicator());

      if (isInactivatingObjectCode(objectCode)) {
        // if it turns out that the object code does not have associated sub-objects (either because
        // the object code doesn't exist or doesn't have sub-objects)
        // then the generateTrickleDownMaintenanceLocks method returns an empty list
        maintenanceLocks.addAll(
            subObjectTrickleDownInactivationService.generateTrickleDownMaintenanceLocks(
                objectCode, getDocumentNumber()));
      }
    }
    return maintenanceLocks;
  }