View Javadoc

1   /*
2    * Copyright 2012 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 1.0 (the
5    * "License"); 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/ecl1.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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.kuali.student.class3.krms.termresolver;
17  
18  import java.util.Date;
19  import java.util.HashSet;
20  import java.util.Map;
21  import java.util.Set;
22  
23  import org.kuali.rice.krms.api.engine.TermResolutionException;
24  import org.kuali.rice.krms.api.engine.TermResolver;
25  import org.kuali.student.r2.common.dto.ContextInfo;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  /**
30   * A base term resolver that allows it to be used with multiple term names.
31   * 
32   * The precise term this resolver works for is set at instantiation.
33   * 
34   * @author Kuali Student Team 
35   *
36   */
37  public abstract class AbstractKSTermResolver<T> implements TermResolver<T> {
38      private static final Logger log = LoggerFactory
39              .getLogger(AbstractKSTermResolver.class);
40  
41      protected static final int LOW_COST = 1;
42  
43      private String termName;
44  
45      private String principalId;
46      
47      protected ContextInfo getServiceContext() {
48          
49          ContextInfo info = new ContextInfo();
50          
51          info.setPrincipalId(principalId);
52          info.setAuthenticatedPrincipalId(principalId);
53      
54          info.setCurrentDate(new Date());
55          
56          return info;
57      }
58      /**
59       * 
60       */
61      public AbstractKSTermResolver(String termName, String principalId) {
62          this.termName = termName;
63          this.principalId = principalId;
64      }
65  
66      @Override
67      public Set<String> getPrerequisites() {
68          return new HashSet<String>();
69      }
70  
71      @Override
72      public String getOutput() {
73          return termName;
74      }
75  
76      @Override
77      public Set<String> getParameterNames() {
78          return new HashSet<String>();
79      }
80  
81      @Override
82      public int getCost() {
83          return LOW_COST;
84      }
85  
86      @Override
87      public abstract T resolve(Map<String, Object> resolvedPrereqs,
88              Map<String, String> parameters) throws TermResolutionException;
89      
90  }