View Javadoc

1   /**
2    * Copyright 2005-2013 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.krms.impl.repository;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.lookup.LookupableImpl;
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.kuali.rice.krad.uif.UifParameters;
22  import org.kuali.rice.krad.util.KRADConstants;
23  import org.kuali.rice.krad.util.KRADUtils;
24  import org.kuali.rice.krad.util.UrlFactory;
25  import org.kuali.rice.krad.web.form.LookupForm;
26  import org.kuali.rice.krms.api.KrmsConstants;
27  import org.kuali.rice.krms.impl.ui.AgendaEditor;
28  import org.kuali.rice.krms.impl.util.KrmsImplConstants;
29  
30  import java.util.List;
31  import java.util.Map;
32  import java.util.Properties;
33  
34  public class AgendaStudentLookupableHelperServiceImpl extends LookupableImpl {
35  
36      @Override
37      public boolean allowsMaintenanceNewOrCopyAction() {
38          // The context is unknown on create so we need to let the user in
39          // TODO: maybe restrict it so only user that have rights to some contexts are allowed to create agendas.
40          return true;
41      }
42  
43      @Override
44      public boolean allowsMaintenanceEditAction(Object dataObject) {
45          boolean allowsEdit = false;
46  
47          AgendaBo agenda = (AgendaBo) dataObject;
48          allowsEdit = KrmsRepositoryServiceLocator.getAgendaAuthorizationService().isAuthorized(KrmsConstants.MAINTAIN_KRMS_AGENDA, agenda.getContextId());
49  
50          return allowsEdit;
51      }
52  
53      @Override
54      public boolean allowsMaintenanceDeleteAction(Object dataObject) {
55          boolean allowsMaintain = false;
56          boolean allowsDelete = false;
57  
58          AgendaBo agenda = (AgendaBo) dataObject;
59          allowsMaintain = KrmsRepositoryServiceLocator.getAgendaAuthorizationService().isAuthorized(KrmsConstants.MAINTAIN_KRMS_AGENDA, agenda.getContextId());
60  
61          return allowsDelete && allowsMaintain;
62      }
63  
64      @Override
65      protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall, List<String> pkNames) {
66          Properties props = new Properties();
67          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
68  
69          Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
70          for (String primaryKey : primaryKeyValues.keySet()) {
71              String primaryKeyValue = primaryKeyValues.get(primaryKey);
72  
73              props.put(primaryKey, primaryKeyValue);
74              props.put(KRADConstants.OVERRIDE_KEYS, primaryKey);
75          }
76  
77          if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
78              props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
79          }
80  
81          props.put(UifParameters.DATA_OBJECT_CLASS_NAME, AgendaEditor.class.getName());
82          props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
83          props.put(UifParameters.VIEW_NAME, KrmsImplConstants.STUDENT_LOOKUP_VIEW);
84  
85          return UrlFactory.parameterizeUrl(KrmsImplConstants.WebPaths.AGENDA_STUDENT_EDITOR_PATH, props);
86      }
87  }