View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.krms.termresolver;
17  
18  import org.kuali.rice.krms.api.engine.TermResolutionException;
19  import org.kuali.rice.krms.api.engine.TermResolver;
20  import org.kuali.student.krms.util.KSKRMSExecutionUtil;
21  import org.kuali.student.r2.common.dto.ContextInfo;
22  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
23  import org.kuali.student.r2.core.organization.dto.OrgInfo;
24  import org.kuali.student.r2.core.organization.service.OrganizationService;
25  
26  import java.util.Collections;
27  import java.util.HashSet;
28  import java.util.Map;
29  import java.util.Set;
30  
31  /**
32   * @author Kuali Student Team
33   */
34  public class AdminOrgPermissionTermResolver implements TermResolver<Boolean> {
35  
36      private OrganizationService organizationService;
37  
38      @Override
39      public Set<String> getPrerequisites() {
40          Set<String> prereqs = new HashSet<String>(2);
41          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
42          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
43          return Collections.unmodifiableSet(prereqs);
44      }
45  
46      @Override
47      public String getOutput() {
48          return KSKRMSServiceConstants.TERM_RESOLVER_ADMINORGANIZATIONPERMISSIONREQUIRED;
49      }
50  
51      @Override
52      public Set<String> getParameterNames() {
53          return Collections.singleton(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY);
54      }
55  
56      @Override
57      public int getCost() {
58          return 1;
59      }
60  
61      @Override
62      public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
63          ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
64          String orgId = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY);
65          
66          try {
67              OrgInfo org = organizationService.getOrg(orgId, context);
68              //TODO: Determine permision???
69          } catch (Exception e) {
70              KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
71          }
72  
73          return true;
74      }
75  
76      public OrganizationService getOrganizationService() {
77          return organizationService;
78      }
79  
80      public void setOrganizationService(OrganizationService organizationService) {
81          this.organizationService = organizationService;
82      }
83  
84  }