001/*
002 * Copyright 2007 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.coa.document;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.kuali.ole.coa.businessobject.Account;
022import org.kuali.ole.coa.businessobject.AccountGlobal;
023import org.kuali.ole.coa.businessobject.AccountGlobalDetail;
024import org.kuali.ole.sys.OLEConstants;
025import org.kuali.ole.sys.document.FinancialSystemGlobalMaintainable;
026import org.kuali.rice.krad.bo.PersistableBusinessObject;
027import org.kuali.rice.krad.maintenance.MaintenanceLock;
028
029/**
030 * This class overrides the base {@link KualiGlobalMaintainableImpl} to generate the specific maintenance locks for Global accounts
031 */
032public class AccountGlobalMaintainableImpl extends FinancialSystemGlobalMaintainable {
033
034    /**
035     * This creates the particular locking representation for this global document.
036     * 
037     * @see org.kuali.rice.kns.maintenance.Maintainable#generateMaintenanceLocks()
038     */
039    @Override
040    public List<MaintenanceLock> generateMaintenanceLocks() {
041        AccountGlobal accountGlobal = (AccountGlobal) getBusinessObject();
042        List<MaintenanceLock> maintenanceLocks = new ArrayList();
043
044        for (AccountGlobalDetail detail : accountGlobal.getAccountGlobalDetails()) {
045            MaintenanceLock maintenanceLock = new MaintenanceLock();
046            StringBuffer lockrep = new StringBuffer();
047
048            lockrep.append(Account.class.getName() + OLEConstants.Maintenance.AFTER_CLASS_DELIM);
049            lockrep.append("chartOfAccountsCode" + OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
050            lockrep.append(detail.getChartOfAccountsCode() + OLEConstants.Maintenance.AFTER_VALUE_DELIM);
051            lockrep.append("accountNumber" + OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
052            lockrep.append(detail.getAccountNumber());
053
054            maintenanceLock.setDocumentNumber(accountGlobal.getDocumentNumber());
055            maintenanceLock.setLockingRepresentation(lockrep.toString());
056            maintenanceLocks.add(maintenanceLock);
057        }
058        return maintenanceLocks;
059    }
060
061    @Override
062    public Class<? extends PersistableBusinessObject> getPrimaryEditedBusinessObjectClass() {
063        return Account.class;
064    }
065}