View Javadoc

1   /**
2    * Copyright 2005-2014 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.maintenance;
17  
18  import org.kuali.rice.kim.api.KimConstants;
19  import org.kuali.rice.kim.api.identity.Person;
20  import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
21  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22  import org.kuali.rice.krad.util.KRADConstants;
23  import org.kuali.rice.krad.util.KRADUtils;
24  
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  /**
29   * Implementation of {@link org.kuali.rice.krad.uif.view.ViewAuthorizer} for
30   * {@link org.kuali.rice.krad.uif.view.MaintenanceDocumentView} instances
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class MaintenanceViewAuthorizerBase extends DocumentViewAuthorizerBase {
35      private static final long serialVersionUID = 8688732738163609576L;
36  
37      public final boolean canCreate(Class<?> boClass, Person user) {
38          Map<String, String> permissionDetails = new HashMap<String, String>();
39  
40          permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
41                  KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(boClass));
42          permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_NEW_ACTION);
43  
44          return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE,
45                  KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails)
46                  || getPermissionService().isAuthorizedByTemplate(user.getPrincipalId(), KRADConstants.KNS_NAMESPACE,
47                  KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails,
48                  new HashMap<String, String>());
49      }
50  
51      public final boolean canMaintain(Object dataObject, Person user) {
52          Map<String, String> permissionDetails = new HashMap<String, String>(2);
53  
54          permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
55                  KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(
56                          dataObject.getClass()));
57          permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_EDIT_ACTION);
58  
59          return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE,
60                  KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails)
61                  || isAuthorizedByTemplate(dataObject, KRADConstants.KNS_NAMESPACE,
62                  KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId(), permissionDetails,
63                  null);
64      }
65  
66      public final boolean canCreateOrMaintain(MaintenanceDocument maintenanceDocument, Person user) {
67          return !permissionExistsByTemplate(maintenanceDocument, KRADConstants.KNS_NAMESPACE,
68                  KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) || isAuthorizedByTemplate(
69                  maintenanceDocument, KRADConstants.KNS_NAMESPACE,
70                  KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId());
71      }
72  
73      @SuppressWarnings("unchecked")
74      @Override
75      protected void addRoleQualification(Object dataObject, Map<String, String> attributes) {
76          super.addRoleQualification(dataObject, attributes);
77          if (dataObject instanceof MaintenanceDocument) {
78              MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
79              if (maintDoc.getNewMaintainableObject() != null) {
80                  attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName(
81                          maintDoc.getNewMaintainableObject().getDataObjectClass()));
82              }
83          }
84      }
85  
86      @SuppressWarnings("unchecked")
87      @Override
88      protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) {
89          super.addPermissionDetails(dataObject, attributes);
90          if (dataObject instanceof MaintenanceDocument) {
91              MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
92              if (maintDoc.getNewMaintainableObject() != null) {
93                  attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName(
94                          maintDoc.getNewMaintainableObject().getDataObjectClass()));
95                  attributes.put(KRADConstants.MAINTENANCE_ACTN,
96                          maintDoc.getNewMaintainableObject().getMaintenanceAction());
97              }
98          }
99      }
100 }