Skip to content

Commit

Permalink
#96 - minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 7, 2023
1 parent a045880 commit 6e9e5b6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void checkAge(String dateOfBirth) {
if (dateOfBirth == null) {
isNotValid = true;
}
if (Period.between(DateTimeUtil.dob(dateOfBirth), LocalDate.now()).getYears() < 14) {
if (Period.between(DateTimeUtil.toLocalDate(dateOfBirth, DateTimeUtil.DD_MM_YYYY), LocalDate.now()).getYears() < 14) {
isNotValid = true;
}
if (isNotValid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public LahiIntegrationDataService(IntegratingEntityStatusRepository integratingE
}

public void studentProcessed(LahiStudent student) {
Date date = DateTimeUtil.lastUpdatedDate(student.getLastUpdatedAt());
Date date = DateTimeUtil.toDate(student.getLastUpdatedAt(), DateTimeUtil.DATE_TIME);
IntegratingEntityStatus integratingEntityStatus = integratingEntityStatusRepository.findByEntityType(ENTITYTYPE);
integratingEntityStatus.setReadUptoDateTime(date);
integratingEntityStatusRepository.save(integratingEntityStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ public StudentErrorService(ErrorRecordRepository errorRecordRepository, Integrat
}

public void errorOccurred(String entityUuid, StudentErrorType studentErrorType, AvniEntityType avniEntityType, String errorMsg) {
saveAvniError(entityUuid, studentErrorType, avniEntityType, errorMsg);
}

private void saveAvniError(String entityUuid, StudentErrorType studentErrorType, AvniEntityType avniEntityType, String errorMsg) {
ErrorType errorType = getErrorType(studentErrorType);
ErrorRecord errorRecord = new ErrorRecord();
errorRecord.setIntegratingEntityType("Student");
errorRecord.setIntegrationSystem(integrationSystemRepository.findBySystemType(IntegrationSystem.IntegrationSystemType.lahi));
errorRecord.setEntityId(entityUuid);
errorRecord.setProcessingDisabled(true);
errorRecord.setAvniEntityType(avniEntityType);
errorRecord.addErrorType(errorType,errorMsg);
errorRecord.addErrorType(errorType, errorMsg);
errorRecordRepository.save(errorRecord);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ private void setAlternatePhoneNumber(LahiStudent student, Map<String, Object> su
subjectObservations.put(AvniStudentRepository.ALTERNATE_PHONE_NUMBER, alternatePhoneNumber);
}

private Subject subjectWithoutObservations(LahiStudent student) {
private Subject subjectWithoutObservations(LahiStudent lahiStudent) {
Subject subject = new Subject();

String firstName = StringUtils.capitalize(student.getFirstName());
String lastName = StringUtils.capitalize(student.getLastName());
Date registrationDate = DateTimeUtil.registrationDate(student.getDateOfRegistration());
Date dob = DateTimeUtil.dateOfBirth(student.getDateOfBirth());
String gender = student.getGender();
String externalId = student.getFlowResultId();
String firstName = StringUtils.capitalize(lahiStudent.getFirstName());
String lastName = StringUtils.capitalize(lahiStudent.getLastName());
Date registrationDate = DateTimeUtil.toDate(lahiStudent.getDateOfRegistration(), DateTimeUtil.DATE_TIME);
Date dob = DateTimeUtil.toDate(lahiStudent.getDateOfBirth(), DateTimeUtil.DD_MM_YYYY);
String gender = lahiStudent.getGender();
String externalId = lahiStudent.getFlowResultId();

subject.setExternalId(externalId);
subject.setAddress(STUDENT_ADDRESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class DateTimeUtil {
// TODO: 20/09/23 If needed we have to change date type
// public static final String REGISTRATION_DATE = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS";
public static final String DATE_TIME = "yyyy-MM-dd'T'HH:mm:ss";
public static final String DATE_OF_BIRTH = "dd-MM-yyyy";
public static final String DD_MM_YYYY = "dd-MM-yyyy";

public static Date toDate(String dateString,String format){
public static Date toDate(String dateString, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
Date date = sdf.parse(dateString);
Expand All @@ -23,30 +23,14 @@ public static Date toDate(String dateString,String format){
return null;
}

public static LocalDate toLocalDate(String dateString,String format){
public static LocalDate toLocalDate(String dateString, String format) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(format);
try {
LocalDate date = LocalDate.parse(dateString,dtf);
LocalDate date = LocalDate.parse(dateString, dtf);
return date;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public static Date registrationDate(String dateString){
return toDate(dateString, DATE_TIME);
}

public static Date lastUpdatedDate(String dateString){
return toDate(dateString, DATE_TIME);
}

public static Date dateOfBirth(String dateString){
return toDate(dateString,DATE_OF_BIRTH);
}

public static LocalDate dob(String dateString){
return toLocalDate(dateString,DATE_OF_BIRTH);
}
}

0 comments on commit 6e9e5b6

Please sign in to comment.