001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.chart.document;
017:
018: import org.kuali.core.bo.user.KualiGroup;
019: import org.kuali.core.bo.user.UniversalUser;
020: import org.kuali.core.document.Document;
021: import org.kuali.core.document.MaintenanceDocument;
022: import org.kuali.core.document.authorization.DocumentActionFlags;
023: import org.kuali.core.document.authorization.MaintenanceDocumentAuthorizations;
024: import org.kuali.core.document.authorization.MaintenanceDocumentAuthorizerBase;
025: import org.kuali.core.exceptions.GroupNotFoundException;
026: import org.kuali.core.service.KualiGroupService;
027: import org.kuali.core.workflow.service.KualiWorkflowDocument;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.kfs.service.ParameterService;
031: import org.kuali.module.chart.bo.SubAccount;
032:
033: /**
034: * This class...
035: */
036: public class SubAccountDocumentAuthorizer extends
037: MaintenanceDocumentAuthorizerBase {
038:
039: /**
040: * Constructs a SubAccountDocumentAuthorizer.java.
041: */
042: public SubAccountDocumentAuthorizer() {
043: }
044:
045: /**
046: * This method returns the set of authorization restrictions (if any) that apply to this SubAccount in this context.
047: *
048: * @param document
049: * @param user
050: * @return a new set of {@link MaintenanceDocumentAuthorizations} with certain fields marked read-only if necessary
051: */
052: @Override
053: public MaintenanceDocumentAuthorizations getFieldAuthorizations(
054: MaintenanceDocument document, UniversalUser user) {
055:
056: // if the user is the system supervisor, then do nothing, dont apply
057: // any restrictions
058: if (user.isSupervisorUser()) {
059: return new MaintenanceDocumentAuthorizations();
060: }
061:
062: String groupName = SpringContext
063: .getBean(ParameterService.class)
064: .getParameterValue(
065: SubAccount.class,
066: KFSConstants.ChartApcParms.SUBACCOUNT_CG_WORKGROUP_PARM_NAME);
067:
068: // create a new KualiGroup instance with that name
069: KualiGroupService groupService = SpringContext
070: .getBean(KualiGroupService.class);
071: KualiGroup group = null;
072: try {
073: group = groupService.getByGroupName(groupName);
074: } catch (GroupNotFoundException e) {
075: e.printStackTrace();
076: throw new RuntimeException(
077: "The group by name '"
078: + groupName
079: + "' was not "
080: + "found in the KualiGroupService. This is a configuration error, and "
081: + "authorization/business-rules cannot be processed without this.",
082: e);
083: }
084:
085: // if the user is NOT a member of the special group, then mark all the
086: // ICR & CS fields read-only.
087: MaintenanceDocumentAuthorizations auths = new MaintenanceDocumentAuthorizations();
088: if (!user.isMember(group)) {
089: auths
090: .addReadonlyAuthField("a21SubAccount.subAccountTypeCode");
091: auths
092: .addReadonlyAuthField("a21SubAccount.costShareChartOfAccountCode");
093: auths
094: .addReadonlyAuthField("a21SubAccount.costShareSourceAccountNumber");
095: auths
096: .addReadonlyAuthField("a21SubAccount.costShareSourceSubAccountNumber");
097: auths
098: .addReadonlyAuthField("a21SubAccount.financialIcrSeriesIdentifier");
099: auths
100: .addReadonlyAuthField("a21SubAccount.indirectCostRecoveryChartOfAccountsCode");
101: auths
102: .addReadonlyAuthField("a21SubAccount.indirectCostRecoveryAccountNumber");
103: auths
104: .addReadonlyAuthField("a21SubAccount.indirectCostRecoveryTypeCode");
105: auths.addReadonlyAuthField("a21SubAccount.offCampusCode");
106: }
107:
108: return auths;
109: }
110:
111: /**
112: * Adds in a can blanket approve flag for Sub Accounts if the workflow document state is not canceled
113: *
114: * @see org.kuali.core.document.authorization.MaintenanceDocumentAuthorizerBase#getDocumentActionFlags(org.kuali.core.document.Document,
115: * org.kuali.core.bo.user.UniversalUser)
116: */
117: @Override
118: public DocumentActionFlags getDocumentActionFlags(
119: Document document, UniversalUser user) {
120: DocumentActionFlags documentActionFlags = super
121: .getDocumentActionFlags(document, user);
122: // KULRNE-44: even if some fields are readonly to the user, we allow him to blanket approve
123: KualiWorkflowDocument workflowDocument = document
124: .getDocumentHeader().getWorkflowDocument();
125: if (!workflowDocument.stateIsCanceled()) {
126: documentActionFlags.setCanBlanketApprove(workflowDocument
127: .isBlanketApproveCapable());
128: }
129: return documentActionFlags;
130: }
131: }
|