avniproject / integration-service

Service for integration Avni with other systems
GNU Affero General Public License v3.0
0 stars 2 forks source link

LAHI Student sync filter not working as designed #118

Open himeshr opened 9 months ago

himeshr commented 9 months ago

LAHI Student sync filter to avoid update of previously synced Students to Avni is not working as designed.

As part of LAHI Student sync from Glific to Avni, we are required to filter out update of Students that have been previously synced to Avni based on FirstName, LastName, Gender, DOB, Father'sName and PhoneNumber criteria.

We achieve this through AvniStudentRepository.findMatchingStudents(), which seems to always return 0 (zero) matches. Resulting in system going ahead and attempting save of the student. We need to fix this filter.

    public List<Subject> findMatchingStudents(Subject subject) {
        LinkedHashMap<String, Object> subjectSearchCriteria = new LinkedHashMap<>();
        subjectSearchCriteria.put(CONTACT_PHONE_NUMBER, subject.getObservation(CONTACT_PHONE_NUMBER));
        Subject[] subjects = avniSubjectRepository.getSubjects(STUDENT_SUBJECT_TYPE, subjectSearchCriteria);
        return Arrays.stream(subjects).filter(x -> ObjectUtil.nullSafeEqualsIgnoreCase(x.getFirstName(), subject.getFirstName())
                && ObjectUtil.nullSafeEqualsIgnoreCase(x.getLastName(), subject.getLastName())
                && ObjectUtil.nullSafeEqualsIgnoreCase(x.getGender(), subject.getGender())
                && ObjectUtil.nullSafeEqualsIgnoreCase(x.getDateOfBirth(), subject.getDateOfBirth())
                && ObjectUtil.nullSafeEqualsIgnoreCase(x.getObservation(FATHERS_NAME_CONCEPT), subject.getObservation(FATHERS_NAME_CONCEPT))

        ).collect(Collectors.toList());
    }

Integration-service logs:

2024-01-24 05:50:00,000 INFO  SpringTaskScheduler-17 [lahi.job.AvniLahiMainJob] Lahi Main Job Started
2024-01-24 05:50:00,461 INFO  SpringTaskScheduler-17 [lahi.service.LahiStudentService] Getting students since 2024-01-20 13:05:19.0
2024-01-24 05:50:02,965 DEBUG SpringTaskScheduler-17 [avni.client.AvniHttpClient] GET https://app.avniproject.org/api/subjects?lastModifiedDateTime=1900-01-01T00:00:00.000Z&concepts=%7B%22Student%20contact%20number%22:%229766801808%22%7D&subjectType=Student
2024-01-24 05:50:02,973 DEBUG SpringTaskScheduler-17 [avni.client.AvniHttpClient] Getting cognito details
2024-01-24 05:50:14,689 INFO  SpringTaskScheduler-17 [avni.client.AvniHttpClient] POST: /api/subject
2024-01-24 05:50:14,689 DEBUG SpringTaskScheduler-17 [avni.client.AvniHttpClient] POST https://app.avniproject.org/api/subject
2024-01-24 05:50:16,508 INFO  SpringTaskScheduler-17 [lahi.service.LahiIntegrationDataService] Updating integrating_entity_status with Sat Jan 20 13:05:19 UTC 2024 date
2024-01-24 05:50:16,508 INFO  SpringTaskScheduler-17 [avni_integration_service.util.HealthCheckService] Health check ping for slug:lahi status: SUCCESS
2024-01-24 05:50:16,641 INFO  SpringTaskScheduler-17 [lahi.job.AvniLahiMainJob] Lahi Main Job Ended