001 /** 002 * Copyright 2005-2013 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.rice.krad.maintenance; 017 018 import org.kuali.rice.kim.api.KimConstants; 019 import org.kuali.rice.kim.api.identity.Person; 020 import org.kuali.rice.krad.document.DocumentViewAuthorizerBase; 021 import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 022 import org.kuali.rice.krad.util.KRADConstants; 023 import org.kuali.rice.krad.util.KRADUtils; 024 025 import java.util.HashMap; 026 import java.util.Map; 027 028 /** 029 * Implementation of {@link org.kuali.rice.krad.uif.view.ViewAuthorizer} for 030 * {@link org.kuali.rice.krad.uif.view.MaintenanceDocumentView} instances 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034 public class MaintenanceViewAuthorizerBase extends DocumentViewAuthorizerBase { 035 private static final long serialVersionUID = 8688732738163609576L; 036 037 public final boolean canCreate(Class<?> boClass, Person user) { 038 Map<String, String> permissionDetails = new HashMap<String, String>(); 039 040 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, 041 KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(boClass)); 042 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_NEW_ACTION); 043 044 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE, 045 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails) 046 || getPermissionService().isAuthorizedByTemplate(user.getPrincipalId(), KRADConstants.KNS_NAMESPACE, 047 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails, 048 new HashMap<String, String>()); 049 } 050 051 public final boolean canMaintain(Object dataObject, Person user) { 052 Map<String, String> permissionDetails = new HashMap<String, String>(2); 053 054 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, 055 KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName( 056 dataObject.getClass())); 057 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_EDIT_ACTION); 058 059 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE, 060 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails) 061 || isAuthorizedByTemplate(dataObject, KRADConstants.KNS_NAMESPACE, 062 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId(), permissionDetails, 063 null); 064 } 065 066 public final boolean canCreateOrMaintain(MaintenanceDocument maintenanceDocument, Person user) { 067 return !permissionExistsByTemplate(maintenanceDocument, KRADConstants.KNS_NAMESPACE, 068 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) || isAuthorizedByTemplate( 069 maintenanceDocument, KRADConstants.KNS_NAMESPACE, 070 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId()); 071 } 072 073 @SuppressWarnings("unchecked") 074 @Override 075 protected void addRoleQualification(Object dataObject, Map<String, String> attributes) { 076 super.addRoleQualification(dataObject, attributes); 077 if (dataObject instanceof MaintenanceDocument) { 078 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject; 079 if (maintDoc.getNewMaintainableObject() != null) { 080 attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName( 081 maintDoc.getNewMaintainableObject().getDataObjectClass())); 082 } 083 } 084 } 085 086 @SuppressWarnings("unchecked") 087 @Override 088 protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) { 089 super.addPermissionDetails(dataObject, attributes); 090 if (dataObject instanceof MaintenanceDocument) { 091 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject; 092 if (maintDoc.getNewMaintainableObject() != null) { 093 attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName( 094 maintDoc.getNewMaintainableObject().getDataObjectClass())); 095 attributes.put(KRADConstants.MAINTENANCE_ACTN, 096 maintDoc.getNewMaintainableObject().getMaintenanceAction()); 097 } 098 } 099 } 100 }