Coverage Report - org.kuali.rice.krad.uif.authorization.MaintenanceDocumentAuthorizerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentAuthorizerBase
0%
0/25
0%
0/20
2
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krad.uif.authorization;
 17  
 
 18  
 
 19  
 import org.kuali.rice.kim.api.KimConstants;
 20  
 import org.kuali.rice.kim.api.identity.Person;
 21  
 import org.kuali.rice.krad.document.MaintenanceDocument;
 22  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 23  
 import org.kuali.rice.krad.util.KRADConstants;
 24  
 import org.kuali.rice.krad.util.KRADUtils;
 25  
 
 26  
 import java.util.HashMap;
 27  
 import java.util.HashSet;
 28  
 import java.util.Map;
 29  
 import java.util.Set;
 30  
 
 31  
 /**
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  0
 public class MaintenanceDocumentAuthorizerBase extends DocumentAuthorizerBase {
 35  
 
 36  
         public final boolean canCreate(Class<?> boClass, Person user) {
 37  0
                 Map<String, String> permissionDetails = new HashMap<String, String>();
 38  0
         permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
 39  
                 KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(boClass));
 40  0
                 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN,
 41  
                                 KRADConstants.MAINTENANCE_NEW_ACTION);
 42  0
                 return !permissionExistsByTemplate(KRADConstants.KRAD_NAMESPACE,
 43  
                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 44  
                                 permissionDetails)
 45  
                                 || getPermissionService()
 46  
                                                 .isAuthorizedByTemplateName(
 47  
                                                                 user.getPrincipalId(),
 48  
                                                                 KRADConstants.KRAD_NAMESPACE,
 49  
                                                                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS,
 50  
                                                                 permissionDetails, new HashMap<String, String>());
 51  
         }
 52  
 
 53  
     public final boolean canMaintain(Object dataObject, Person user) {
 54  0
         Map<String, String> permissionDetails = new HashMap<String, String>(2);
 55  0
         permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
 56  
                 KRADServiceLocatorWeb.getDocumentDictionaryService()
 57  
                         .getMaintenanceDocumentTypeName(dataObject.getClass()));
 58  0
         permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_EDIT_ACTION);
 59  0
         return !permissionExistsByTemplate(KRADConstants.KRAD_NAMESPACE,
 60  
                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails) ||
 61  
                 isAuthorizedByTemplate(dataObject, KRADConstants.KRAD_NAMESPACE,
 62  
                         KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId(),
 63  
                         permissionDetails, null);
 64  
     }
 65  
 
 66  
     public final boolean canCreateOrMaintain(MaintenanceDocument maintenanceDocument, Person user) {
 67  0
         return !permissionExistsByTemplate(maintenanceDocument, KRADConstants.KRAD_NAMESPACE,
 68  
                 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) ||
 69  
                 isAuthorizedByTemplate(maintenanceDocument, KRADConstants.KRAD_NAMESPACE,
 70  
                         KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId());
 71  
     }
 72  
 
 73  
     public Set<String> getSecurePotentiallyHiddenSectionIds() {
 74  0
         return new HashSet<String>();
 75  
     }
 76  
 
 77  
     public Set<String> getSecurePotentiallyReadOnlySectionIds() {
 78  0
         return new HashSet<String>();
 79  
     }
 80  
 
 81  
     @SuppressWarnings("unchecked")
 82  
     @Override
 83  
     protected void addRoleQualification(Object dataObject, Map<String, String> attributes) {
 84  0
         super.addRoleQualification(dataObject, attributes);
 85  0
         if (dataObject instanceof MaintenanceDocument) {
 86  0
             MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
 87  0
             if (maintDoc.getNewMaintainableObject() != null) {
 88  0
                 attributes.putAll(KRADUtils
 89  
                         .getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass()));
 90  
             }
 91  
         }
 92  0
     }
 93  
 
 94  
     @SuppressWarnings("unchecked")
 95  
     @Override
 96  
     protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) {
 97  0
         super.addPermissionDetails(dataObject, attributes);
 98  0
         if (dataObject instanceof MaintenanceDocument) {
 99  0
             MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
 100  0
             if (maintDoc.getNewMaintainableObject() != null) {
 101  0
                 attributes.putAll(KRADUtils
 102  
                         .getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getDataObjectClass()));
 103  0
                 attributes.put(KRADConstants.MAINTENANCE_ACTN,
 104  
                         maintDoc.getNewMaintainableObject().getMaintenanceAction());
 105  
             }
 106  
         }
 107  0
     }
 108  
 }