001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.sec.util;
017
018 import java.util.List;
019
020 import org.kuali.kfs.sec.SecConstants;
021 import org.kuali.kfs.sec.service.AccessSecurityService;
022 import org.kuali.kfs.sys.KFSConstants;
023 import org.kuali.kfs.sys.businessobject.AccountingLine;
024 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry;
025 import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
026 import org.kuali.kfs.sys.context.SpringContext;
027 import org.kuali.kfs.sys.document.AccountingDocument;
028 import org.kuali.rice.kns.document.Document;
029 import org.kuali.rice.kns.service.KualiConfigurationService;
030 import org.kuali.rice.kns.util.GlobalVariables;
031
032
033 public class SecUtil {
034
035 /**
036 * Compares the size of the given list against the given previous size and if different adds an info message
037 *
038 * @param previousListSize int giving previous size of list to compare to
039 * @param results List to get size for and compare
040 * @param messageKey String key of message that should be added
041 */
042 @SuppressWarnings("rawtypes")
043 public static void compareListSizeAndAddMessageIfChanged(int previousListSize, List results, String messageKey) {
044 int currentListSize = results.size();
045
046 if (previousListSize != currentListSize) {
047 GlobalVariables.getMessageMap().putInfo(KFSConstants.GLOBAL_MESSAGES, messageKey, (String) null);
048 }
049 }
050
051 /**
052 * Calls access security service to check view access on given GLPE for current user. Access to view the GLPE on the document should be related to the view permissions for an
053 * accounting line with the same account attributes. Called from generalLedgerPendingEntries.tag
054 *
055 * @param pendingEntry GeneralLedgerPendingEntry to check access for
056 * @return boolean true if current user has view permission, false otherwise
057 */
058 public static boolean canViewGLPE(Document document, GeneralLedgerPendingEntry pendingEntry) {
059 boolean canView = true;
060
061 // If the module has not been loaded, then just skip any further checks as the services will not be defined
062 if ( SpringContext.getBean(KualiConfigurationService.class).getPropertyAsBoolean(SecConstants.ACCESS_SECURITY_MODULE_ENABLED_PROPERTY_NAME) ) {
063 if (document instanceof AccountingDocument) {
064 AccountingLine line = new SourceAccountingLine();
065
066 line.setPostingYear(pendingEntry.getUniversityFiscalYear());
067 line.setChartOfAccountsCode(pendingEntry.getChartOfAccountsCode());
068 line.setAccountNumber(pendingEntry.getAccountNumber());
069 line.setSubAccountNumber(pendingEntry.getSubAccountNumber());
070 line.setFinancialObjectCode(pendingEntry.getFinancialObjectCode());
071 line.setFinancialSubObjectCode(pendingEntry.getFinancialSubObjectCode());
072 line.setProjectCode(pendingEntry.getProjectCode());
073
074 line.refreshNonUpdateableReferences();
075
076 canView = SpringContext.getBean(AccessSecurityService.class).canViewDocumentAccountingLine((AccountingDocument) document, line, GlobalVariables.getUserSession().getPerson());
077 }
078 }
079
080 return canView;
081 }
082 }