| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
} |