Skip to content

Commit

Permalink
Merge pull request #1572 from bcgov/fix/ellCloseCollection
Browse files Browse the repository at this point in the history
Revert Ell changes
  • Loading branch information
arcshiftsolutions authored Jan 28, 2025
2 parents 37ee653 + 9d16aa0 commit 5fe5cbe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ protected UpdateStudentDownstreamOrchestrator(SagaService sagaService, MessagePu
public void populateStepsToExecuteMap() {
this.stepBuilder()
.begin(UPDATE_STUDENT, this::updateStudent)
.step(UPDATE_STUDENT, STUDENT_UPDATED, UPDATE_SDC_STUDENT_STATUS, this::updateSdcStudentEllAndStatus)
.step(UPDATE_STUDENT, NO_STUDENT_UPDATE_NEEDED, UPDATE_SDC_STUDENT_STATUS, this::updateSdcStudentEllAndStatus)
.step(UPDATE_STUDENT, STUDENT_UPDATED, UPDATE_SDC_STUDENT_STATUS, this::updateSdcStudentStatus)
.step(UPDATE_STUDENT, NO_STUDENT_UPDATE_NEEDED, UPDATE_SDC_STUDENT_STATUS, this::updateSdcStudentStatus)
.end(UPDATE_SDC_STUDENT_STATUS, SDC_STUDENT_STATUS_UPDATED);
}

Expand Down Expand Up @@ -175,14 +175,14 @@ public Integer extractRelevantMincode(SchoolTombstone school){
}
}

public void updateSdcStudentEllAndStatus(final Event event, final SdcSagaEntity saga, final UpdateStudentSagaData updateStudentSagaData) throws JsonProcessingException {
public void updateSdcStudentStatus(final Event event, final SdcSagaEntity saga, final UpdateStudentSagaData updateStudentSagaData) throws JsonProcessingException {
final SagaEventStatesEntity eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
saga.setSagaState(UPDATE_SDC_STUDENT_STATUS.toString());
saga.setStatus(IN_PROGRESS.toString());
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);

//service call
closeCollectionService.updateELLAndMarkStudentAsCompleted(updateStudentSagaData);
closeCollectionService.markStudentAsCompleted(updateStudentSagaData);

final Event nextEvent = Event.builder()
.sagaId(saga.getSagaId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ protected UpdateStudentStatusOrchestrator(SagaService sagaService, MessagePublis
@Override
public void populateStepsToExecuteMap() {
this.stepBuilder()
.begin(UPDATE_SDC_STUDENT_STATUS, this::updateSdcStudentEllAndStatus)
.begin(UPDATE_SDC_STUDENT_STATUS, this::updateSdcStudentStatus)
.end(UPDATE_SDC_STUDENT_STATUS, SDC_STUDENT_STATUS_UPDATED);
}

public void updateSdcStudentEllAndStatus(final Event event, final SdcSagaEntity saga, final UpdateStudentSagaData updateStudentSagaData) throws JsonProcessingException {
public void updateSdcStudentStatus(final Event event, final SdcSagaEntity saga, final UpdateStudentSagaData updateStudentSagaData) throws JsonProcessingException {
final SagaEventStatesEntity eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
saga.setSagaState(UPDATE_SDC_STUDENT_STATUS.toString());
saga.setStatus(IN_PROGRESS.toString());
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);

//service call
closeCollectionService.updateELLAndMarkStudentAsCompleted(updateStudentSagaData);
closeCollectionService.markStudentAsCompleted(updateStudentSagaData);

final Event nextEvent = Event.builder()
.sagaId(saga.getSagaId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.IndependentSchoolFundingGroup;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.SchoolTombstone;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.IndependentSchoolFundingGroupSnapshot;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.SdcStudentEll;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

@Service
Expand Down Expand Up @@ -188,33 +184,9 @@ private void startSDCCollection(final CollectionSagaData collectionSagaData, Col
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateELLAndMarkStudentAsCompleted(UpdateStudentSagaData updateStudentSagaData) {
public void markStudentAsCompleted(UpdateStudentSagaData updateStudentSagaData) {
Optional<SdcSchoolCollectionStudentEntity> optionalStudentEntity = sdcSchoolCollectionStudentRepository.findById(UUID.fromString(updateStudentSagaData.getSdcSchoolCollectionStudentID()));
SdcSchoolCollectionStudentEntity studentEntity = optionalStudentEntity.orElseThrow(() -> new EntityNotFoundException(CollectionEntity.class, "sdcSchoolCollectionStudentID", updateStudentSagaData.getSdcSchoolCollectionStudentID()));
final List<String> enrolledProgramCodes = validationRulesService.splitEnrolledProgramsString(studentEntity.getEnrolledProgramCodes());

if (EnrolledProgramCodes.getELLCodes().stream().anyMatch(enrolledProgramCodes::contains)) {
final var studentInEllOpt = validationRulesService.getStudentYearsInEll(studentEntity.getAssignedStudentId());
log.debug("Student years in ELL found for SDC student {} :: is {}", studentEntity.getSdcSchoolCollectionStudentID(), studentInEllOpt);
if(studentInEllOpt.isPresent()){
var studentInEll = studentInEllOpt.get();
studentEntity.setYearsInEll(studentInEll.getYearsInEll() + 1);
studentInEll.setYearsInEll(studentInEll.getYearsInEll() + 1);
studentInEll.setUpdateUser(ApplicationProperties.STUDENT_DATA_COLLECTION_API);
studentInEll.setUpdateDate(LocalDateTime.now());
sdcStudentEllRepository.save(studentInEll);
} else{
studentEntity.setYearsInEll(1);
SdcStudentEllEntity studentEll = new SdcStudentEllEntity();
studentEll.setStudentID(studentEntity.getAssignedStudentId());
studentEll.setYearsInEll(1);
studentEll.setUpdateUser(ApplicationProperties.STUDENT_DATA_COLLECTION_API);
studentEll.setCreateUser(ApplicationProperties.STUDENT_DATA_COLLECTION_API);
studentEll.setUpdateDate(LocalDateTime.now());
studentEll.setCreateDate(LocalDateTime.now());
sdcStudentEllRepository.save(studentEll);
}
}
studentEntity.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.COMPLETED.getCode());
studentEntity.setUpdateUser(ApplicationProperties.STUDENT_DATA_COLLECTION_API);
studentEntity.setUpdateDate(LocalDateTime.now());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.educ.studentdatacollection.api.orchestrator;

import ca.bc.gov.educ.studentdatacollection.api.BaseStudentDataCollectionAPITest;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.CollectionTypeCodes;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SdcSchoolStudentStatus;
import ca.bc.gov.educ.studentdatacollection.api.exception.EntityNotFoundException;
Expand All @@ -10,7 +9,6 @@
import ca.bc.gov.educ.studentdatacollection.api.model.v1.CollectionEntity;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentEntity;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcStudentEllEntity;
import ca.bc.gov.educ.studentdatacollection.api.repository.v1.*;
import ca.bc.gov.educ.studentdatacollection.api.rest.RestUtils;
import ca.bc.gov.educ.studentdatacollection.api.struct.Event;
Expand All @@ -37,7 +35,6 @@

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -77,8 +74,6 @@ class UpdateStudentDownstreamOrchestratorTest extends BaseStudentDataCollectionA
SagaRepository sagaRepository;
@Autowired
MessagePublisher messagePublisher;
@Autowired
SdcStudentEllRepository sdcStudentEllRepository;
@Captor
ArgumentCaptor<byte[]> eventCaptor;

Expand Down Expand Up @@ -129,119 +124,18 @@ void testHandleEvent_givenEventTypeUPDATE_STUDENT_shouldPostEventToSTUDENT_API_T

@SneakyThrows
@Test
void testHandleEvent_givenEventTypeUPDATE_SDC_STUDENT_STATUS_WithNoEllAsEnrolledProgram_shouldExecuteUpdateSdcStudentStatus() {
var school = createMockSchool();
school.setDisplayName("School1");
school.setMincode("0000001");
when(this.restUtils.getSchoolBySchoolID(any())).thenReturn(Optional.of(school));

var student = setMockDataForSaga();
UpdateStudentSagaData sagaData = createSagaData(student);
val saga = this.createMockUpdateStudentDownstreamSaga(sagaData);
saga.setSagaId(null);
this.sagaRepository.save(saga);

var existingEll = sdcStudentEllRepository.findByStudentID(student.getAssignedStudentId());
assertThat(existingEll).isNotPresent();

val event = Event.builder()
.sagaId(saga.getSagaId())
.eventType(UPDATE_STUDENT)
.eventOutcome(STUDENT_UPDATED)
.eventPayload(JsonUtil.getJsonStringFromObject(sagaData)).build();
this.updateStudentDownstreamOrchestrator.handleEvent(event);

verify(this.messagePublisher, atMost(2)).dispatchMessage(eq(UPDATE_STUDENT_DOWNSTREAM_SAGA_TOPIC.toString()), this.eventCaptor.capture());
final var newEvent = JsonUtil.getJsonObjectFromString(Event.class, new String(this.eventCaptor.getValue()));
assertThat(newEvent.getEventType()).isEqualTo(UPDATE_SDC_STUDENT_STATUS);

val savedSagaInDB = this.sagaRepository.findById(saga.getSagaId());
assertThat(savedSagaInDB).isPresent();
assertThat(savedSagaInDB.get().getSagaState()).isEqualTo(UPDATE_SDC_STUDENT_STATUS.toString());

val updatedStudent = sdcSchoolCollectionStudentRepository.findById(UUID.fromString(sagaData.getSdcSchoolCollectionStudentID()));
assertThat(updatedStudent).isPresent();
assertThat(updatedStudent.get().getYearsInEll()).isEqualTo(1);
assertThat(updatedStudent.get().getSdcSchoolCollectionStudentStatusCode()).isEqualTo(SdcSchoolStudentStatus.COMPLETED.toString());

var updatedEll = sdcStudentEllRepository.findByStudentID(student.getAssignedStudentId());
assertThat(updatedEll).isPresent();
assertThat(updatedEll.get().getStudentID()).isEqualTo(updatedStudent.get().getAssignedStudentId());
assertThat(updatedEll.get().getYearsInEll()).isEqualTo(1);
}

@SneakyThrows
@Test
void testHandleEvent_givenEventTypeUPDATE_SDC_STUDENT_STATUS_WithEllAsEnrolledProgram_shouldExecuteUpdateSdcStudentStatus() {
var school = createMockSchool();
school.setDisplayName("School1");
school.setMincode("0000001");
when(this.restUtils.getSchoolBySchoolID(any())).thenReturn(Optional.of(school));

var student = setMockDataForSaga();
student.setYearsInEll(0);
student.setEnrolledProgramCodes("05");
sdcSchoolCollectionStudentRepository.save(student);

UpdateStudentSagaData sagaData = createSagaData(student);
val saga = this.createMockUpdateStudentDownstreamSaga(sagaData);
saga.setSagaId(null);
this.sagaRepository.save(saga);

var existingEll = sdcStudentEllRepository.findByStudentID(student.getAssignedStudentId());
assertThat(existingEll).isNotPresent();

val event = Event.builder()
.sagaId(saga.getSagaId())
.eventType(UPDATE_STUDENT)
.eventOutcome(STUDENT_UPDATED)
.eventPayload(JsonUtil.getJsonStringFromObject(sagaData)).build();
this.updateStudentDownstreamOrchestrator.handleEvent(event);

verify(this.messagePublisher, atMost(2)).dispatchMessage(eq(UPDATE_STUDENT_DOWNSTREAM_SAGA_TOPIC.toString()), this.eventCaptor.capture());
final var newEvent = JsonUtil.getJsonObjectFromString(Event.class, new String(this.eventCaptor.getValue()));
assertThat(newEvent.getEventType()).isEqualTo(UPDATE_SDC_STUDENT_STATUS);

val savedSagaInDB = this.sagaRepository.findById(saga.getSagaId());
assertThat(savedSagaInDB).isPresent();
assertThat(savedSagaInDB.get().getSagaState()).isEqualTo(UPDATE_SDC_STUDENT_STATUS.toString());

val updatedStudent = sdcSchoolCollectionStudentRepository.findById(UUID.fromString(sagaData.getSdcSchoolCollectionStudentID()));
assertThat(updatedStudent).isPresent();
assertThat(updatedStudent.get().getYearsInEll()).isEqualTo(0);
assertThat(updatedStudent.get().getSdcSchoolCollectionStudentStatusCode()).isEqualTo(SdcSchoolStudentStatus.COMPLETED.toString());

var updatedEll = sdcStudentEllRepository.findByStudentID(student.getAssignedStudentId());
assertThat(updatedEll).isNotPresent();
}

@SneakyThrows
@Test
void testHandleEvent_givenEventTypeUPDATE_SDC_STUDENT_STATUS_WithTwoYearsInEll_shouldExecuteUpdateSdcStudentStatus() {
void testHandleEvent_givenEventTypeUPDATE_SDC_STUDENT_STATUS_shouldExecuteUpdateSdcStudentStatus() {
var school = createMockSchool();
school.setDisplayName("School1");
school.setMincode("0000001");
when(this.restUtils.getSchoolBySchoolID(any())).thenReturn(Optional.of(school));

var student = setMockDataForSaga();
student.setYearsInEll(2);
sdcSchoolCollectionStudentRepository.save(student);

var studentEll = new SdcStudentEllEntity();
studentEll.setStudentID(student.getAssignedStudentId());
studentEll.setYearsInEll(2);
studentEll.setCreateDate(LocalDateTime.now());
studentEll.setCreateUser("SDC_TEST");
sdcStudentEllRepository.save(studentEll);

UpdateStudentSagaData sagaData = createSagaData(student);
val saga = this.createMockUpdateStudentDownstreamSaga(sagaData);
saga.setSagaId(null);
this.sagaRepository.save(saga);

var existingEll = sdcStudentEllRepository.findByStudentID(student.getAssignedStudentId());
assertThat(existingEll).isPresent();

val event = Event.builder()
.sagaId(saga.getSagaId())
.eventType(UPDATE_STUDENT)
Expand All @@ -259,13 +153,7 @@ void testHandleEvent_givenEventTypeUPDATE_SDC_STUDENT_STATUS_WithTwoYearsInEll_s

val updatedStudent = sdcSchoolCollectionStudentRepository.findById(UUID.fromString(sagaData.getSdcSchoolCollectionStudentID()));
assertThat(updatedStudent).isPresent();
assertThat(updatedStudent.get().getYearsInEll()).isEqualTo(3);
assertThat(updatedStudent.get().getSdcSchoolCollectionStudentStatusCode()).isEqualTo(SdcSchoolStudentStatus.COMPLETED.toString());

var updatedEll = sdcStudentEllRepository.findByStudentID(student.getAssignedStudentId());
assertThat(updatedEll).isPresent();
assertThat(updatedEll.get().getStudentID()).isEqualTo(updatedStudent.get().getAssignedStudentId());
assertThat(updatedEll.get().getYearsInEll()).isEqualTo(3);
}

public UpdateStudentSagaData createSagaData(SdcSchoolCollectionStudentEntity entity) {
Expand Down Expand Up @@ -320,8 +208,6 @@ public SdcSchoolCollectionStudentEntity setMockDataForSaga() throws IOException
var firstStuToUpdate = sdcSchoolCollectionStudentRepository.findById(savedStudent.get(0).getSdcSchoolCollectionStudentID());
firstStuToUpdate.get().setAssignedStudentId(UUID.randomUUID());
firstStuToUpdate.get().setAssignedPen("123456789");
firstStuToUpdate.get().setYearsInEll(0);
firstStuToUpdate.get().setEnrolledProgramCodes("0517");
return sdcSchoolCollectionStudentRepository.save(firstStuToUpdate.get());
}

Expand Down

0 comments on commit 5fe5cbe

Please sign in to comment.