@Test public void testApplyOptionalField() { List<EntityBody> entities = new ArrayList<EntityBody>(); entities.add(new EntityBody(createTestStudentEntity(STUDENT_ID))); entities = studentGradeLevelOptionalFieldAppender.applyOptionalField(entities, null); assertEquals("Should be 1", 1, entities.size()); assertEquals("Should match", "Eighth grade", entities.get(0).get("gradeLevel")); assertEquals("Should match", SCHOOL_ID, entities.get(0).get("schoolId")); }
@Override public List<EntityBody> applyOptionalField(List<EntityBody> entities, String parameters) { List<String> studentIds = optionalFieldAppenderHelper.getIdList(entities, "id"); List<EntityBody> studentSchoolAssociationList = optionalFieldAppenderHelper.queryEntities( ResourceNames.STUDENT_SCHOOL_ASSOCIATIONS, ParameterConstants.STUDENT_ID, studentIds); if (studentSchoolAssociationList == null) { return entities; } Date currentDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for (EntityBody student : entities) { String mostRecentGradeLevel = "Not Available"; String mostRecentSchool = ""; Date mostRecentEntry = null; try { for (EntityBody studentSchoolAssociation : studentSchoolAssociationList) { if (!studentSchoolAssociation.get(ParameterConstants.STUDENT_ID).equals(student.get("id"))) { continue; } if (studentSchoolAssociation.containsKey(EXIT_WITHDRAW_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(EXIT_WITHDRAW_DATE)); if (ssaDate.compareTo(currentDate) <= 0) { continue; } } if (studentSchoolAssociation.containsKey(ENTRY_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(ENTRY_DATE)); if (mostRecentEntry == null) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } else { if (ssaDate.compareTo(mostRecentEntry) > 0) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } } } } } catch (Exception e) { String exceptionMessage = "Exception while retrieving current gradeLevel for student with id: " + student.get("id") + " Exception: " + e.getMessage(); LOG.debug(exceptionMessage); mostRecentGradeLevel = "Not Available"; } student.put(GRADE_LEVEL, mostRecentGradeLevel); student.put(SCHOOL_ID, mostRecentSchool); } return entities; }
StudentGradeLevelOptionalFieldAppender implements OptionalFieldAppender { @Override public List<EntityBody> applyOptionalField(List<EntityBody> entities, String parameters) { List<String> studentIds = optionalFieldAppenderHelper.getIdList(entities, "id"); List<EntityBody> studentSchoolAssociationList = optionalFieldAppenderHelper.queryEntities( ResourceNames.STUDENT_SCHOOL_ASSOCIATIONS, ParameterConstants.STUDENT_ID, studentIds); if (studentSchoolAssociationList == null) { return entities; } Date currentDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for (EntityBody student : entities) { String mostRecentGradeLevel = "Not Available"; String mostRecentSchool = ""; Date mostRecentEntry = null; try { for (EntityBody studentSchoolAssociation : studentSchoolAssociationList) { if (!studentSchoolAssociation.get(ParameterConstants.STUDENT_ID).equals(student.get("id"))) { continue; } if (studentSchoolAssociation.containsKey(EXIT_WITHDRAW_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(EXIT_WITHDRAW_DATE)); if (ssaDate.compareTo(currentDate) <= 0) { continue; } } if (studentSchoolAssociation.containsKey(ENTRY_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(ENTRY_DATE)); if (mostRecentEntry == null) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } else { if (ssaDate.compareTo(mostRecentEntry) > 0) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } } } } } catch (Exception e) { String exceptionMessage = "Exception while retrieving current gradeLevel for student with id: " + student.get("id") + " Exception: " + e.getMessage(); LOG.debug(exceptionMessage); mostRecentGradeLevel = "Not Available"; } student.put(GRADE_LEVEL, mostRecentGradeLevel); student.put(SCHOOL_ID, mostRecentSchool); } return entities; } }
StudentGradeLevelOptionalFieldAppender implements OptionalFieldAppender { @Override public List<EntityBody> applyOptionalField(List<EntityBody> entities, String parameters) { List<String> studentIds = optionalFieldAppenderHelper.getIdList(entities, "id"); List<EntityBody> studentSchoolAssociationList = optionalFieldAppenderHelper.queryEntities( ResourceNames.STUDENT_SCHOOL_ASSOCIATIONS, ParameterConstants.STUDENT_ID, studentIds); if (studentSchoolAssociationList == null) { return entities; } Date currentDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for (EntityBody student : entities) { String mostRecentGradeLevel = "Not Available"; String mostRecentSchool = ""; Date mostRecentEntry = null; try { for (EntityBody studentSchoolAssociation : studentSchoolAssociationList) { if (!studentSchoolAssociation.get(ParameterConstants.STUDENT_ID).equals(student.get("id"))) { continue; } if (studentSchoolAssociation.containsKey(EXIT_WITHDRAW_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(EXIT_WITHDRAW_DATE)); if (ssaDate.compareTo(currentDate) <= 0) { continue; } } if (studentSchoolAssociation.containsKey(ENTRY_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(ENTRY_DATE)); if (mostRecentEntry == null) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } else { if (ssaDate.compareTo(mostRecentEntry) > 0) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } } } } } catch (Exception e) { String exceptionMessage = "Exception while retrieving current gradeLevel for student with id: " + student.get("id") + " Exception: " + e.getMessage(); LOG.debug(exceptionMessage); mostRecentGradeLevel = "Not Available"; } student.put(GRADE_LEVEL, mostRecentGradeLevel); student.put(SCHOOL_ID, mostRecentSchool); } return entities; }  }
StudentGradeLevelOptionalFieldAppender implements OptionalFieldAppender { @Override public List<EntityBody> applyOptionalField(List<EntityBody> entities, String parameters) { List<String> studentIds = optionalFieldAppenderHelper.getIdList(entities, "id"); List<EntityBody> studentSchoolAssociationList = optionalFieldAppenderHelper.queryEntities( ResourceNames.STUDENT_SCHOOL_ASSOCIATIONS, ParameterConstants.STUDENT_ID, studentIds); if (studentSchoolAssociationList == null) { return entities; } Date currentDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for (EntityBody student : entities) { String mostRecentGradeLevel = "Not Available"; String mostRecentSchool = ""; Date mostRecentEntry = null; try { for (EntityBody studentSchoolAssociation : studentSchoolAssociationList) { if (!studentSchoolAssociation.get(ParameterConstants.STUDENT_ID).equals(student.get("id"))) { continue; } if (studentSchoolAssociation.containsKey(EXIT_WITHDRAW_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(EXIT_WITHDRAW_DATE)); if (ssaDate.compareTo(currentDate) <= 0) { continue; } } if (studentSchoolAssociation.containsKey(ENTRY_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(ENTRY_DATE)); if (mostRecentEntry == null) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } else { if (ssaDate.compareTo(mostRecentEntry) > 0) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } } } } } catch (Exception e) { String exceptionMessage = "Exception while retrieving current gradeLevel for student with id: " + student.get("id") + " Exception: " + e.getMessage(); LOG.debug(exceptionMessage); mostRecentGradeLevel = "Not Available"; } student.put(GRADE_LEVEL, mostRecentGradeLevel); student.put(SCHOOL_ID, mostRecentSchool); } return entities; }  @Override List<EntityBody> applyOptionalField(List<EntityBody> entities, String parameters); }
StudentGradeLevelOptionalFieldAppender implements OptionalFieldAppender { @Override public List<EntityBody> applyOptionalField(List<EntityBody> entities, String parameters) { List<String> studentIds = optionalFieldAppenderHelper.getIdList(entities, "id"); List<EntityBody> studentSchoolAssociationList = optionalFieldAppenderHelper.queryEntities( ResourceNames.STUDENT_SCHOOL_ASSOCIATIONS, ParameterConstants.STUDENT_ID, studentIds); if (studentSchoolAssociationList == null) { return entities; } Date currentDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for (EntityBody student : entities) { String mostRecentGradeLevel = "Not Available"; String mostRecentSchool = ""; Date mostRecentEntry = null; try { for (EntityBody studentSchoolAssociation : studentSchoolAssociationList) { if (!studentSchoolAssociation.get(ParameterConstants.STUDENT_ID).equals(student.get("id"))) { continue; } if (studentSchoolAssociation.containsKey(EXIT_WITHDRAW_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(EXIT_WITHDRAW_DATE)); if (ssaDate.compareTo(currentDate) <= 0) { continue; } } if (studentSchoolAssociation.containsKey(ENTRY_DATE)) { Date ssaDate = sdf.parse((String) studentSchoolAssociation.get(ENTRY_DATE)); if (mostRecentEntry == null) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } else { if (ssaDate.compareTo(mostRecentEntry) > 0) { mostRecentEntry = ssaDate; mostRecentGradeLevel = (String) studentSchoolAssociation.get(ENTRY_GRADE_LEVEL); mostRecentSchool = (String) studentSchoolAssociation.get(SCHOOL_ID); } } } } } catch (Exception e) { String exceptionMessage = "Exception while retrieving current gradeLevel for student with id: " + student.get("id") + " Exception: " + e.getMessage(); LOG.debug(exceptionMessage); mostRecentGradeLevel = "Not Available"; } student.put(GRADE_LEVEL, mostRecentGradeLevel); student.put(SCHOOL_ID, mostRecentSchool); } return entities; }  @Override List<EntityBody> applyOptionalField(List<EntityBody> entities, String parameters);  }