From 42fdbf8054688534f280c4f93b81e732e8086651 Mon Sep 17 00:00:00 2001 From: githubmamatha Date: Mon, 24 Apr 2023 15:53:24 -0700 Subject: [PATCH 1/7] GRAD2-1931 deleting school records. --- .../DistributionRunPartitionerPsiUserReq.java | 2 +- .../educ/api/batchgraduation/rest/RestUtils.java | 10 +++++++++- .../api/batchgraduation/util/RestUtilsTest.java | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java index 8c74e9a7..2c9ae613 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java @@ -50,7 +50,7 @@ public Map partition(int gridSize) { if (responseObj != null) { accessToken = responseObj.getAccess_token(); } - + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_PSI", accessToken); List credentialList = getRecordsForPSIUserReqDisRun(req,transmissionType,accessToken); if(!credentialList.isEmpty()) { // update count size diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java index 646a0a40..d0d9a5de 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java @@ -469,7 +469,7 @@ public void createAndStoreSchoolReports(String accessToken, List uniqueS LOGGER.info("Create and Store School Report Success {}",result); } - //Grad2-1931 sending transmissionType with the webclient. + //Grad2-1931 sending transmissionType with the webclient. - mchintha public DistributionResponse mergePsiAndUpload(Long batchId, String accessToken, Map mapDist,String localDownload, String transmissionType) { UUID correlationID = UUID.randomUUID(); DistributionResponse result = webClient.post() @@ -577,5 +577,13 @@ public Boolean checkSccpCertificateExists (UUID studentID, String accessToken) { .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); }) .retrieve().bodyToMono(Boolean.class).block(); } + //Grad2-1931 + public void deleteSchoolReportRecord(String schoolOfRecord, String reportTypeCode, String accessToken) { + UUID correlationID = UUID.randomUUID(); + webClient.delete().uri(String.format(constants.getUpdateSchoolReport(),schoolOfRecord,reportTypeCode)) + .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); }) + .retrieve().bodyToMono(boolean.class).block(); + + } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java index 5632c6b8..1b4046fb 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java @@ -1242,6 +1242,21 @@ public void testUpdateSchoolReportRecord() { assertThat(reportTypeCode).isEqualTo("E"); } + @Test + public void testDeleteSchoolReportRecord() { + final String mincode = "123213123"; + String reportTypeCode = "E"; + + when(this.webClient.delete()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getUpdateSchoolReport(),mincode,reportTypeCode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(boolean.class)).thenReturn(Mono.just(true)); + + this.restUtils.deleteSchoolReportRecord(mincode,reportTypeCode,null); + assertThat(reportTypeCode).isEqualTo("E"); + } + @Test public void testGetStudentByPenFromStudentAPI() { final UUID studentID = UUID.randomUUID(); From 854faccac704ffa76e8b529655a5da278fac69ff Mon Sep 17 00:00:00 2001 From: githubmamatha Date: Tue, 2 May 2023 10:13:55 -0700 Subject: [PATCH 2/7] GRAD2-1931 deleting school records. --- .../reader/DistributionRunPartitionerPsiUserReq.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java index 2c9ae613..d7e7242d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/reader/DistributionRunPartitionerPsiUserReq.java @@ -50,7 +50,6 @@ public Map partition(int gridSize) { if (responseObj != null) { accessToken = responseObj.getAccess_token(); } - restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_PSI", accessToken); List credentialList = getRecordsForPSIUserReqDisRun(req,transmissionType,accessToken); if(!credentialList.isEmpty()) { // update count size @@ -73,6 +72,7 @@ public Map partition(int gridSize) { String key = "partition" + i; map.put(key, executionContext); } + restUtils.deleteSchoolReportRecord("", "ADDRESS_LABEL_PSI", accessToken); LOGGER.info("Found {} in total running on {} partitions",credentialList.size(),map.size()); return map; } From 9aa05ad9af0397d2b3c1773e4625702f6c93e0cd Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Tue, 20 Jun 2023 15:13:44 -0600 Subject: [PATCH 3/7] Update pom.xml --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index 55726a23..0a964cf7 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-batch-graduation-api - 1.8.41 + 1.8.42 educ-grad-batch-graduation-api Ministry of Education GRAD BATCH GRADUATION API From 9bdb7c1d4cebfb4e518e0e38a499f01bc5c59fed Mon Sep 17 00:00:00 2001 From: githubmamatha Date: Wed, 21 Jun 2023 11:24:29 -0700 Subject: [PATCH 4/7] GRAD2-1931 skipping updating the student grad record if student id is null. --- .../ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java index 9277fb3a..a1148d7b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java @@ -562,8 +562,11 @@ public List getStudentsForUserReqDisRun(String cr } public void updateStudentGradRecord(UUID studentID, Long batchId,String activityCode, String accessToken) { - String url = String.format(constants.getUpdateStudentRecord(), studentID, batchId, activityCode); - this.post(url, "{}", GraduationStudentRecord.class, accessToken); + //Grad2-1931 not updating the school record if student id does not exist. + if(studentID != null) { + String url = String.format(constants.getUpdateStudentRecord(), studentID, batchId, activityCode); + this.post(url, "{}", GraduationStudentRecord.class, accessToken); + } } public List updateStudentFlagReadyForBatch(List studentIds, String batchJobType, String accessToken) { From 97d1e610a5600051e8105c58be88229ee7d02f84 Mon Sep 17 00:00:00 2001 From: arybakov Date: Thu, 22 Jun 2023 12:39:18 -0600 Subject: [PATCH 5/7] Ignore 404 error on student processing --- ...ibutionRunCompletionNotificationListener.java | 16 ++++++++++------ .../educ/api/batchgraduation/rest/RestUtils.java | 10 +++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java index 72d11826..f6797db1 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/listener/UserReqPsiDistributionRunCompletionNotificationListener.java @@ -2,6 +2,7 @@ import ca.bc.gov.educ.api.batchgraduation.model.*; import ca.bc.gov.educ.api.batchgraduation.service.TaskSchedulingService; +import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,7 +16,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants; @Component public class UserReqPsiDistributionRunCompletionNotificationListener extends BaseDistributionRunCompletionNotificationListener { @@ -94,11 +94,15 @@ private void processGlobalList(List cList, Long batch }); String localDownload = StringUtils.equalsIgnoreCase(transmissionType, "FTP")?"Y":"N"; //Grad2-1931 added transmissionType - DistributionResponse disres = restUtils.mergePsiAndUpload(batchId, accessToken, mapDist,localDownload,transmissionType); - if(disres != null) { - String activityCode = StringUtils.equalsIgnoreCase(transmissionType, "PAPER")?"USERDISTPSIP":"USERDISTPISF"; - ResponseObj obj = restUtils.getTokenResponseObject(); - updateBackStudentRecords(cList,batchId,activityCode,obj.getAccess_token()); + if(!mapDist.isEmpty()) { + DistributionResponse disres = restUtils.mergePsiAndUpload(batchId, accessToken, mapDist, localDownload, transmissionType); + if (disres != null) { + String activityCode = StringUtils.equalsIgnoreCase(transmissionType, "PAPER") ? "USERDISTPSIP" : "USERDISTPSIF"; + ResponseObj obj = restUtils.getTokenResponseObject(); + updateBackStudentRecords(cList, batchId, activityCode, obj.getAccess_token()); + } + } else { + LOGGER.warn("No records found to process PSI batch {}", batchId); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java index a1148d7b..16f4e3e8 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java @@ -563,9 +563,13 @@ public List getStudentsForUserReqDisRun(String cr public void updateStudentGradRecord(UUID studentID, Long batchId,String activityCode, String accessToken) { //Grad2-1931 not updating the school record if student id does not exist. - if(studentID != null) { - String url = String.format(constants.getUpdateStudentRecord(), studentID, batchId, activityCode); - this.post(url, "{}", GraduationStudentRecord.class, accessToken); + try { + if (studentID != null) { + String url = String.format(constants.getUpdateStudentRecord(), studentID, batchId, activityCode); + this.post(url, "{}", GraduationStudentRecord.class, accessToken); + } + } catch (Exception e) { + LOGGER.error("Unable to update student record {}", studentID); } } From df7d757e710a8b4819ff62554a1324d3825275ae Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 27 Jun 2023 12:52:33 -0600 Subject: [PATCH 6/7] GRAD2-2187 - PSI Paper run not picking up all expected students --- .../api/batchgraduation/rest/RestUtils.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java index 16f4e3e8..0d0b5de7 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java @@ -380,25 +380,18 @@ public StudentCredentialDistribution processDistribution(StudentCredentialDistri public PsiCredentialDistribution processPsiDistribution(PsiCredentialDistribution item, PsiDistributionSummaryDTO summary) { summary.setProcessedCount(summary.getProcessedCount() + 1L); String accessToken = summary.getAccessToken(); - PsiCredentialDistribution pObj = summary.getGlobalList().stream().filter(pr -> pr.getPen().compareTo(item.getPen()) == 0) - .findAny() - .orElse(null); - if(pObj != null) { - item.setStudentID(pObj.getStudentID()); - }else { - List stuDataList; - try { - stuDataList = this.getStudentsByPen(item.getPen(), accessToken); - if(!stuDataList.isEmpty()) { - item.setStudentID(UUID.fromString(stuDataList.get(0).getStudentID())); - } - summary.getGlobalList().add(item); - } catch (Exception e) { - LOGGER.error("Error processing student with id {} due to {}", item.getStudentID(), e.getLocalizedMessage()); - summary.getErrors().add( - new ProcessError(item.getStudentID().toString(), e.getLocalizedMessage(), e.getMessage()) - ); + List stuDataList; + try { + stuDataList = this.getStudentsByPen(item.getPen(), accessToken); + if(!stuDataList.isEmpty()) { + item.setStudentID(UUID.fromString(stuDataList.get(0).getStudentID())); } + summary.getGlobalList().add(item); + } catch (Exception e) { + LOGGER.error("Error processing student with id {} due to {}", item.getStudentID(), e.getLocalizedMessage()); + summary.getErrors().add( + new ProcessError(item.getStudentID().toString(), e.getLocalizedMessage(), e.getMessage()) + ); } return item; } From 941c398a5089511f86c0aa798757e813bba7606b Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 27 Jun 2023 13:56:55 -0600 Subject: [PATCH 7/7] Fix tests errors --- .../api/batchgraduation/rest/RestUtils.java | 6 ----- .../batchgraduation/util/RestUtilsTest.java | 23 +++++-------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java index 0d0b5de7..90bf3165 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java @@ -18,7 +18,6 @@ import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -141,11 +140,6 @@ private ResponseObj getResponseObj() { .bodyToMono(ResponseObj.class).block(); } - public ResponseObj rtGetTokenFallBack(HttpServerErrorException exception){ - LOGGER.error("{} NOT REACHABLE after many attempts.", constants.getTokenUrl(), exception); - return null; - } - @Retry(name = "rt-getStudent") public List getStudentsByPen(String pen, String accessToken) { final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java index c322200e..d7e421c0 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java @@ -1,13 +1,11 @@ package ca.bc.gov.educ.api.batchgraduation.util; -import ca.bc.gov.educ.api.batchgraduation.exception.ServiceException; import ca.bc.gov.educ.api.batchgraduation.model.*; import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils; import lombok.val; import org.apache.commons.lang3.time.DateUtils; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -16,17 +14,14 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpStatus; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; import reactor.util.retry.Retry; import reactor.util.retry.RetryBackoffSpec; -import java.time.Duration; import java.util.*; import java.util.function.Consumer; import java.util.function.Function; @@ -34,7 +29,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.openMocks; @@ -116,12 +112,6 @@ public void testGetTokenResponseObject_givenExpiredToken_shouldReturnNewToken() } - @Test - public void testFallBackMethod_givenExcpetion_shouldReturnNull(){ - val result = this.restUtils.rtGetTokenFallBack(new HttpServerErrorException(HttpStatus.I_AM_A_TEAPOT)); - assertThat(result).isNull(); - } - @Test public void testGetStudentByPen_givenValues_returnsStudent_with_APICallSuccess() { final String studentID = UUID.randomUUID().toString(); @@ -632,16 +622,14 @@ public void testProcessBlankDistribution_OC_null() { @Test public void testProcessPsiDistribution() { - final UUID studentID = UUID.randomUUID(); - final String pen = "1232131231"; final Long batchId = 9879L; List globalList = new ArrayList<>(); PsiCredentialDistribution scd = new PsiCredentialDistribution(); - scd.setPen(pen); + scd.setPen("1234567"); scd.setPsiYear("2021"); scd.setPsiCode("001"); - scd.setStudentID(studentID); + scd.setStudentID(UUID.randomUUID()); globalList.add(scd); PsiDistributionSummaryDTO summary = new PsiDistributionSummaryDTO(); @@ -649,9 +637,10 @@ public void testProcessPsiDistribution() { summary.setGlobalList(globalList); PsiCredentialDistribution bcd = new PsiCredentialDistribution(); - bcd.setPen(pen); + bcd.setPen("2345678"); bcd.setPsiCode("002"); bcd.setPsiYear("2021"); + bcd.setStudentID(UUID.randomUUID()); PsiCredentialDistribution res = this.restUtils.processPsiDistribution(bcd,summary); assertNotNull(res);