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