View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.fp.document.validation.impl;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.kfs.fp.document.CapitalAccountingLinesDocumentBase;
23  import org.kuali.kfs.fp.document.authorization.CapitalAccountingLinesAuthorizer;
24  import org.kuali.kfs.integration.cab.CapitalAssetBuilderModuleService;
25  import org.kuali.kfs.sys.KFSPropertyConstants;
26  import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader;
27  import org.kuali.kfs.sys.document.Correctable;
28  import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
29  import org.kuali.kfs.sys.document.validation.impl.AccountingLineAccessibleValidation;
30  
31  /**
32   * FP documents that collect CAMs data need special Accessible logic
33   */
34  public class CapitalAccountingLinesAccessibleValidation extends AccountingLineAccessibleValidation {
35  
36      protected CapitalAssetBuilderModuleService capitalAssetBuilderModuleService;
37  
38      /**
39       * Due to code in CapitalAccountingLinesAuthorizerBase we need alter the accessible logic a bit. Otherwise the user gets stopped for reasons they shouldn't be
40       * @see org.kuali.kfs.fp.document.authorization.CapitalAccountingLinesAuthorizerBase#determineEditPermissionOnField
41       * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#determineEditPermissionOnField
42       * @see org.kuali.kfs.sys.document.validation.impl.AccountingLineAccessibleValidation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
43       */
44      @Override
45      public boolean validate(AttributedDocumentEvent event) {
46          if (accountingDocumentForValidation instanceof CapitalAccountingLinesDocumentBase) {
47              CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) accountingDocumentForValidation;
48  
49              if(caldb.getCapitalAccountingLines().size() > 0 && capitalAssetBuilderModuleService.hasCapitalAssetObjectSubType(accountingLineForValidation)) {
50                  // In this scenario the line is readOnly because of the logic in CapitalAccountingLinesAuthorizerBase. We only stop the user from updating
51                  // if the document shouldn't be editable. That means call AccountingLineAuthorizerBase#determineEditPermissionOnField and skip
52                  // CapitalAccountingLinesAuthorizerBase#determineEditPermissionOnField. Furthermore error correction documents should not be stopped
53                  if (accountingDocumentForValidation instanceof Correctable) {
54                      final String errorDocumentNumber = ((FinancialSystemDocumentHeader)accountingDocumentForValidation.getDocumentHeader()).getFinancialDocumentInErrorNumber();
55                      if (StringUtils.isNotBlank(errorDocumentNumber)) {
56                          return true;
57                      }
58                  }
59  
60                  // we can safely cast the lookup result to CapitalAccountingLinesAuthorizer, because even if the security module is turned on so that
61                  // the returned result is CapitalAccountingLinesAuthorizer, it's still fine since the latter implements CapitalAccountingLinesAuthorizer
62                  final CapitalAccountingLinesAuthorizer capitalAccountingLineAuthorizer = (CapitalAccountingLinesAuthorizer) lookupAccountingLineAuthorizer();
63                  return capitalAccountingLineAuthorizer.determineEditPermissionOnFieldBypassCapitalCheck(accountingDocumentForValidation, accountingLineForValidation, getAccountingLineCollectionProperty(), KFSPropertyConstants.ACCOUNT_NUMBER, true);
64              }
65          }
66  
67          return super.validate(event);
68      }
69  
70      /**
71       * Set the capitalAssetBuilderModuleService
72       *
73       * @param capitalAssetBuilderModuleService
74       */
75      public void setCapitalAssetBuilderModuleService(CapitalAssetBuilderModuleService capitalAssetBuilderModuleService) {
76          this.capitalAssetBuilderModuleService = capitalAssetBuilderModuleService;
77      }
78  }