Coverage Report - org.kuali.student.process.poc.krms.termresolver.StudentDeceasedTermResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
StudentDeceasedTermResolver
0%
0/24
0%
0/4
1.833
 
 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.process.poc.krms.termresolver;
 17  
 
 18  
 import org.apache.commons.lang.time.DateUtils;
 19  
 import org.kuali.rice.kim.api.identity.IdentityService;
 20  
 import org.kuali.rice.kim.api.identity.Person;
 21  
 import org.kuali.rice.kim.api.identity.PersonService;
 22  
 import org.kuali.rice.kim.api.identity.entity.Entity;
 23  
 import org.kuali.rice.kim.api.identity.personal.EntityBioDemographicsContract;
 24  
 import org.kuali.rice.krms.api.engine.TermResolutionException;
 25  
 import org.kuali.rice.krms.api.engine.TermResolver;
 26  
 import org.kuali.student.common.util.krms.RulesExecutionConstants;
 27  
 
 28  
 import java.text.ParseException;
 29  
 import java.util.Collections;
 30  
 import java.util.Date;
 31  
 import java.util.HashSet;
 32  
 import java.util.Map;
 33  
 import java.util.Set;
 34  
 
 35  
 /**
 36  
  * @author alubbers
 37  
  */
 38  0
 public class StudentDeceasedTermResolver implements TermResolver<Boolean> {
 39  
 
 40  
     private IdentityService identityService;
 41  
 
 42  
     private final static Set<String> preRequisites;
 43  
 
 44  
     static {
 45  0
         Set<String> temp = new HashSet<String>(2);
 46  0
         temp.add(RulesExecutionConstants.STUDENT_ID_TERM_NAME);
 47  0
         temp.add(RulesExecutionConstants.CURRENT_DATE_TERM_NAME);
 48  
 
 49  0
         preRequisites = Collections.unmodifiableSet(temp);
 50  0
     }
 51  
 
 52  
     public void setIdentityService(IdentityService identityService) {
 53  0
         this.identityService = identityService;
 54  0
     }
 55  
 
 56  
     @Override
 57  
     public Set<String> getPrerequisites() {
 58  0
         return preRequisites;
 59  
     }
 60  
 
 61  
     @Override
 62  
     public String getOutput() {
 63  0
         return RulesExecutionConstants.STUDENT_DECEASED_TERM_NAME;
 64  
     }
 65  
 
 66  
     @Override
 67  
     public Set<String> getParameterNames() {
 68  0
         return Collections.emptySet();
 69  
     }
 70  
 
 71  
     @Override
 72  
     public int getCost() {
 73  
         // TODO analyze
 74  0
         return 0;
 75  
     }
 76  
 
 77  
     @Override
 78  
     public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
 79  
 
 80  0
         String studentId = (String) resolvedPrereqs.get(RulesExecutionConstants.STUDENT_ID_TERM_NAME);
 81  0
         Date currentDate = (Date) resolvedPrereqs.get(RulesExecutionConstants.CURRENT_DATE_TERM_NAME);
 82  
 
 83  0
         Entity entity = identityService.getEntity(studentId);
 84  
 
 85  0
         Date deceasedDate = null;
 86  
 
 87  0
         if(entity.getBioDemographics().getDeceasedDate() != null) {
 88  
             try {
 89  0
                 deceasedDate = DateUtils.parseDate(entity.getBioDemographics().getDeceasedDate(), new String[]{EntityBioDemographicsContract.DECEASED_DATE_FORMAT});
 90  0
             } catch (ParseException e) {
 91  0
                 throw new TermResolutionException(e.getMessage(), this, parameters, e);
 92  0
             }
 93  
         }
 94  
 
 95  0
         if(deceasedDate != null) {
 96  0
             return deceasedDate.before(currentDate);
 97  
         }
 98  
 
 99  0
         return false;
 100  
     }
 101  
 }