Skip to content

Commit

Permalink
Grad release 1.2.0
Browse files Browse the repository at this point in the history
Grad release 1.2.0
  • Loading branch information
kamal-mohammed authored Jul 6, 2023
2 parents 6c55961 + 67b15de commit 4537b01
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 52 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-batch-graduation-api</artifactId>
<version>1.8.41</version>
<version>1.8.42</version>
<name>educ-grad-batch-graduation-api</name>
<description>Ministry of Education GRAD BATCH GRADUATION API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -94,11 +94,15 @@ private void processGlobalList(List<PsiCredentialDistribution> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public Map<String, ExecutionContext> partition(int gridSize) {
if (responseObj != null) {
accessToken = responseObj.getAccess_token();
}

List<PsiCredentialDistribution> credentialList = getRecordsForPSIUserReqDisRun(req,transmissionType,accessToken);
if(!credentialList.isEmpty()) {
// update count size
Expand All @@ -73,6 +72,7 @@ public Map<String, ExecutionContext> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Student> getStudentsByPen(String pen, String accessToken) {
final ParameterizedTypeReference<List<Student>> responseType = new ParameterizedTypeReference<>() {
Expand Down Expand Up @@ -380,25 +374,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<Student> 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<Student> 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;
}
Expand Down Expand Up @@ -478,7 +465,7 @@ public void createAndStoreSchoolReports(String accessToken, List<String> 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<String, DistributionPrintRequest> mapDist,String localDownload, String transmissionType) {
UUID correlationID = UUID.randomUUID();
DistributionResponse result = webClient.post()
Expand Down Expand Up @@ -562,8 +549,15 @@ public List<StudentCredentialDistribution> 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.
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);
}
}

public List<GraduationStudentRecord> updateStudentFlagReadyForBatch(List<UUID> studentIds, String batchJobType, String accessToken) {
Expand All @@ -586,5 +580,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();

}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,25 +14,23 @@
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;

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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -632,26 +622,25 @@ public void testProcessBlankDistribution_OC_null() {

@Test
public void testProcessPsiDistribution() {
final UUID studentID = UUID.randomUUID();
final String pen = "1232131231";
final Long batchId = 9879L;
List<PsiCredentialDistribution> 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();
summary.setBatchId(batchId);
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);
Expand Down Expand Up @@ -1242,6 +1231,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();
Expand Down

0 comments on commit 4537b01

Please sign in to comment.