From d51f8e1295a140ee3e295ce41a04896d12a9a4ec Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Fri, 3 Nov 2023 11:17:23 +0530 Subject: [PATCH] #96 - renamed to fix spelling and clarifying the source of data --- .../lahi/config/LahiMappingDbConstants.java | 11 +++--- .../lahi/domain/LahiEntity.java | 2 +- .../lahi/domain/LahiStudent.java | 6 +--- ...nstants.java => LahiStudentConstants.java} | 4 +-- .../lahi/domain/StudentValidator.java | 2 +- .../service/LahiIntegrationDataService.java | 2 +- .../lahi/service/LahiStudentService.java | 2 +- .../lahi/service/StudentMapper.java | 34 +++++++++---------- 8 files changed, 29 insertions(+), 34 deletions(-) rename lahi/src/main/java/org/avni_integration_service/lahi/domain/{StudentConstants.java => LahiStudentConstants.java} (97%) diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/config/LahiMappingDbConstants.java b/lahi/src/main/java/org/avni_integration_service/lahi/config/LahiMappingDbConstants.java index 24273a19..0a0269af 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/config/LahiMappingDbConstants.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/config/LahiMappingDbConstants.java @@ -1,21 +1,20 @@ package org.avni_integration_service.lahi.config; -import java.util.Arrays; +import java.util.Collections; import java.util.Map; import static java.util.Map.entry; public interface LahiMappingDbConstants { - String MAPPINGTYPE_OBS = "Observations"; - String MAPPINGGROUP_STUDENT = "Student"; + String MAPPING_TYPE_OBS = "Observations"; + String MAPPING_GROUP_STUDENT = "Student"; String CONTACT_PHONE_NUMBER = "Student contact number"; String ALTERNATE_PHONE_NUMBER = "Alternate (Whatsapp number)"; - //todo create constants for all string literals below - Map DEFAUL_STUDENT_OBSVALUE_MAP = Map.ofEntries( + Map DEFAULT_STUDENT_OBS_VALUE_MAP = Map.ofEntries( entry("Does student give permission to LAHI to Send Whatsapp/SMS/Call for any career opportunities?","Yes"), - entry("Career options you are interested in", Arrays.asList("Other")), + entry("Career options you are interested in", Collections.singletonList("Other")), entry("User","LAHI Program Team"), entry("Student/Trainee Type","Regular"), entry("Registration Source","Glific"), diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiEntity.java b/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiEntity.java index bd2d9fde..6007f12d 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiEntity.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiEntity.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Map; -import static org.avni_integration_service.lahi.domain.StudentConstants.FLOWRESULT_ID; +import static org.avni_integration_service.lahi.domain.LahiStudentConstants.FLOWRESULT_ID; public abstract class LahiEntity { protected Map response; diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiStudent.java b/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiStudent.java index 363e9418..b2cf7ba3 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiStudent.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiStudent.java @@ -2,18 +2,14 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.apache.log4j.Logger; -import org.avni_integration_service.avni.domain.Subject; -import org.avni_integration_service.lahi.util.DateTimeUtil; -import org.springframework.util.StringUtils; import java.util.Arrays; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @JsonIgnoreProperties(ignoreUnknown = true) -public class LahiStudent extends LahiEntity implements StudentConstants { +public class LahiStudent extends LahiEntity implements LahiStudentConstants { private static final Logger logger = Logger.getLogger(LahiStudent.class); private static final List Core_Fields = Arrays.asList(FIRST_NAME,LAST_NAME,DATE_OF_BIRTH, DATE_OF_REGISTRATION,GENDER); diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/domain/StudentConstants.java b/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiStudentConstants.java similarity index 97% rename from lahi/src/main/java/org/avni_integration_service/lahi/domain/StudentConstants.java rename to lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiStudentConstants.java index 169056c3..12387429 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/domain/StudentConstants.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/domain/LahiStudentConstants.java @@ -3,7 +3,7 @@ import java.util.Arrays; import java.util.List; -public interface StudentConstants { +public interface LahiStudentConstants { String FIRST_NAME = "avni_first_name"; String LAST_NAME = "avni_last_name"; String DATE_OF_BIRTH = "avni_date_of_birth"; @@ -57,7 +57,7 @@ public interface StudentConstants { FLOWRESULT_ID ); - List MandatoryField = + List MandatoryFields = Arrays.asList( FIRST_NAME, LAST_NAME, diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/domain/StudentValidator.java b/lahi/src/main/java/org/avni_integration_service/lahi/domain/StudentValidator.java index a7b186a2..2791efc1 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/domain/StudentValidator.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/domain/StudentValidator.java @@ -14,7 +14,7 @@ public class StudentValidator { private static final Logger logger = Logger.getLogger(BigQueryClient.class); public void validateMandatoryField(Map map) { - long count = StudentConstants.MandatoryField.stream().filter(field -> { + long count = LahiStudentConstants.MandatoryFields.stream().filter(field -> { if (map.getOrDefault(field, null) == null) { logger.error(String.format("%s missing for id:%s", field, map.get("id"))); return false; diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiIntegrationDataService.java b/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiIntegrationDataService.java index 95bbf233..a8904553 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiIntegrationDataService.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiIntegrationDataService.java @@ -9,7 +9,7 @@ import java.util.Date; -import static org.avni_integration_service.lahi.domain.StudentConstants.FLOW_RESULT_UPDATED_AT; +import static org.avni_integration_service.lahi.domain.LahiStudentConstants.FLOW_RESULT_UPDATED_AT; import static org.avni_integration_service.lahi.service.LahiStudentService.ENTITYTYPE; @Service diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiStudentService.java b/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiStudentService.java index 4eef94cd..4b2fd474 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiStudentService.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/service/LahiStudentService.java @@ -10,7 +10,7 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.avni_integration_service.lahi.domain.StudentConstants.ResultFieldList; +import static org.avni_integration_service.lahi.domain.LahiStudentConstants.ResultFieldList; @Service public class LahiStudentService { diff --git a/lahi/src/main/java/org/avni_integration_service/lahi/service/StudentMapper.java b/lahi/src/main/java/org/avni_integration_service/lahi/service/StudentMapper.java index 61722a9c..3cd7bbe1 100644 --- a/lahi/src/main/java/org/avni_integration_service/lahi/service/StudentMapper.java +++ b/lahi/src/main/java/org/avni_integration_service/lahi/service/StudentMapper.java @@ -9,7 +9,7 @@ import org.avni_integration_service.lahi.config.LahiMappingDbConstants; import org.avni_integration_service.lahi.domain.LahiEntity; import org.avni_integration_service.lahi.domain.LahiStudent; -import org.avni_integration_service.lahi.domain.StudentConstants; +import org.avni_integration_service.lahi.domain.LahiStudentConstants; import org.avni_integration_service.lahi.util.DateTimeUtil; import org.avni_integration_service.util.ObsDataType; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ import java.util.Map; @Service -public class StudentMapper implements StudentConstants { +public class StudentMapper implements LahiStudentConstants { private static final Logger logger = Logger.getLogger(StudentMapper.class); private final MappingMetaDataRepository mappingMetaDataRepository; @@ -30,9 +30,9 @@ public StudentMapper(MappingMetaDataRepository mappingMetaDataRepository) { public Subject mapToSubject(LahiStudent lahiStudent) { Subject subject = this.subjectWithoutObservations(lahiStudent.getResponse()); - this.populateObservations(subject, lahiStudent, LahiMappingDbConstants.MAPPINGGROUP_STUDENT); + this.populateObservations(subject, lahiStudent, LahiMappingDbConstants.MAPPING_GROUP_STUDENT); Map observations = subject.getObservations(); - LahiMappingDbConstants.DEFAUL_STUDENT_OBSVALUE_MAP.forEach(observations::put); + LahiMappingDbConstants.DEFAULT_STUDENT_OBS_VALUE_MAP.forEach(observations::put); setOtherAddress(subject, lahiStudent); setPhoneNumber(subject, lahiStudent); return subject; @@ -41,7 +41,7 @@ public Subject mapToSubject(LahiStudent lahiStudent) { private void populateObservations(ObservationHolder observationHolder, LahiEntity lahiEntity, String mappingGroup) { List observationFields = lahiEntity.getObservationFields(); for (String obsField : observationFields) { - MappingMetaData mapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPINGTYPE_OBS, obsField, 5); + MappingMetaData mapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPING_TYPE_OBS, obsField, 5); if(mapping == null) { logger.error("Mapping entry not found for observation field: " + obsField); continue; @@ -50,7 +50,7 @@ private void populateObservations(ObservationHolder observationHolder, LahiEntit if (dataTypeHint == null) observationHolder.addObservation(mapping.getAvniValue(), lahiEntity.getValue(obsField)); else if (dataTypeHint == ObsDataType.Coded && lahiEntity.getValue(obsField) != null) { - MappingMetaData answerMapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPINGTYPE_OBS, lahiEntity.getValue(obsField).toString(), 5); + MappingMetaData answerMapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPING_TYPE_OBS, lahiEntity.getValue(obsField).toString(), 5); if(answerMapping == null) { String errorMessage = "Answer Mapping entry not found for coded concept answer field: " + obsField; logger.error(errorMessage); @@ -65,28 +65,28 @@ private void setOtherAddress(Subject subject, LahiStudent student) { Map subjectObservations = subject.getObservations(); Map studentResponse = student.getResponse(); StringBuilder stringBuilder = new StringBuilder(); - setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.STATE, "")); - setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.OTHER_STATE, "")); - setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.DISTRICT, "")); - setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.CITY_NAME, "")); - setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.SCHOOL, "")); + setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.STATE, "")); + setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.OTHER_STATE, "")); + setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.DISTRICT, "")); + setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.CITY_NAME, "")); + setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.SCHOOL, "")); if (stringBuilder.length() > 0) { subjectObservations.put("Other School name", stringBuilder.toString()); } } private void setAddressString(StringBuilder stringBuilder, String string) { - if (string != null && !string.equals("")) { - stringBuilder.append(string + " "); + if (StringUtils.hasLength(string)) { + stringBuilder.append(string).append(" "); } } private void setPhoneNumber(Subject subject, LahiStudent student) { Map subjectObservations = subject.getObservations(); String contactPhoneNumber = null; - if (student.getValue(StudentConstants.STUDENT_CONTACT_NUMBER) != null - && student.getValue(StudentConstants.STUDENT_CONTACT_NUMBER).toString().length() == 12) { - contactPhoneNumber = ((String) student.getValue(StudentConstants.STUDENT_CONTACT_NUMBER)).substring(2); + Object contactNumber = student.getValue(LahiStudentConstants.STUDENT_CONTACT_NUMBER); + if (contactNumber != null && contactNumber.toString().length() == 12) { + contactPhoneNumber = ((String) contactNumber).substring(2); subjectObservations.put(LahiMappingDbConstants.CONTACT_PHONE_NUMBER, contactPhoneNumber); } setAlternatePhoneNumber(student, subjectObservations, contactPhoneNumber); @@ -94,7 +94,7 @@ private void setPhoneNumber(Subject subject, LahiStudent student) { private void setAlternatePhoneNumber(LahiStudent student, Map subjectObservations, String contactPhoneNumber) { Long alternatePhoneNumber; - String alternateNumber = (String) student.getValue(StudentConstants.ALTERNATE_NUMBER); + String alternateNumber = (String) student.getValue(LahiStudentConstants.ALTERNATE_NUMBER); if (StringUtils.hasText(alternateNumber) && alternateNumber.length() == 12) { alternateNumber = alternateNumber.substring(2); }