Skip to content

Commit fbb0801

Browse files
TRAX course replication
1 parent cbf5843 commit fbb0801

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

api/src/main/java/ca/bc/gov/educ/api/pen/replication/repository/TraxStudentCourseRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import org.springframework.data.jpa.repository.JpaRepository;
55
import org.springframework.stereotype.Repository;
66

7+
import java.util.List;
8+
79
@Repository
810
public interface TraxStudentCourseRepository extends JpaRepository<TraxStudentCourseEntity, String> {
911
void deleteAllByStudXcrseId_StudNo(String studNo);
12+
List<TraxStudentCourseEntity> findAllByStudXcrseId_StudNo(String studNo);
1013
}

api/src/main/java/ca/bc/gov/educ/api/pen/replication/service/StudentCourseUpdateService.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
import static ca.bc.gov.educ.api.pen.replication.constants.EventType.UPDATE_STUDENT_COURSES;
2121

22-
/**
23-
* The type Student update service.
24-
*/
2522
@Service
2623
@Slf4j
2724
public class StudentCourseUpdateService extends BaseService<StudentCourseUpdate> {
@@ -50,7 +47,8 @@ public void processEvent(final StudentCourseUpdate studentCourseUpdate, final Ev
5047
var studentPEN = restUtils.getStudentPen(studentCourseUpdate.getStudentID());
5148
val existingTraxStudentRecord = this.traxStudentService.findTraxStudentByPen(StringUtils.rightPad(studentPEN, 10));
5249
if (existingTraxStudentRecord.isPresent()) {
53-
this.traxStudentCourseService.deletePriorAndSaveTraxStudentCourses(studentPEN, getStudentCourseEntityList(studentPEN, studentCourseUpdate.getStudentCourses()));
50+
var existingCourses = this.traxStudentCourseService.findTraxStudentCoursesByPen(studentPEN);
51+
this.traxStudentCourseService.deletePriorAndSaveTraxStudentCourses(studentPEN, getStudentCourseEntityList(studentPEN, studentCourseUpdate.getStudentCourses(), existingCourses));
5452
log.info("Processing choreography update event with ID {} :: payload is: {}", event.getEventId(), studentCourseUpdate);
5553
}else{
5654
log.info("Student course event not processed {} :: payload is: {} :: student does not yet exist in TRAX STUDENT_MASTER", event.getEventId(), studentCourseUpdate);
@@ -59,7 +57,7 @@ public void processEvent(final StudentCourseUpdate studentCourseUpdate, final Ev
5957
this.updateEvent(event);
6058
}
6159

62-
private List<TraxStudentCourseEntity> getStudentCourseEntityList(String studentPEN, List<StudentCourse> studentCourse) {
60+
private List<TraxStudentCourseEntity> getStudentCourseEntityList(String studentPEN, List<StudentCourse> studentCourse, List<TraxStudentCourseEntity> existingTraxStudentCourses) {
6361
var entityList = new ArrayList<TraxStudentCourseEntity>();
6462
studentCourse.forEach(student -> {
6563
TraxStudentCourseEntity traxStudentCourseEntity = new TraxStudentCourseEntity();
@@ -69,13 +67,24 @@ private List<TraxStudentCourseEntity> getStudentCourseEntityList(String studentP
6967
traxStudentCourseEntity.setFinalLetterGrade(student.getFinalLetterGrade());
7068
traxStudentCourseEntity.setFinalPercentage(student.getFinalPercent() != null ? student.getFinalPercent().toString() : null);
7169
traxStudentCourseEntity.setNumberOfCredits(student.getCredits() != null ? student.getCredits().toString() : null);
72-
// traxStudentCourseEntity.setStudyType();
73-
// traxStudentCourseEntity.setUsedForGrad();
70+
setStudyTypeAndUsedForGradFields(traxStudentCourseEntity, existingTraxStudentCourses);
7471
entityList.add(traxStudentCourseEntity);
7572
});
7673
return entityList;
7774
}
7875

76+
private void setStudyTypeAndUsedForGradFields(TraxStudentCourseEntity traxStudentCourseEntity, List<TraxStudentCourseEntity> existingTraxStudentCourses){
77+
for(TraxStudentCourseEntity course: existingTraxStudentCourses){
78+
if(course.getStudXcrseId().getCourseCode().equals(traxStudentCourseEntity.getStudXcrseId().getCourseCode()) &&
79+
course.getStudXcrseId().getCourseLevel().equals(traxStudentCourseEntity.getStudXcrseId().getCourseLevel()) &&
80+
course.getStudXcrseId().getCourseSession().equals(traxStudentCourseEntity.getStudXcrseId().getCourseSession())){
81+
traxStudentCourseEntity.setStudyType(course.getStudyType());
82+
traxStudentCourseEntity.setUsedForGrad(course.getUsedForGrad());
83+
break;
84+
}
85+
}
86+
}
87+
7988
private void setCourseCodeAndLevel(TraxStudentCourseEntity traxStudentCourseEntity, String courseID){
8089
var optionalCourse = restUtils.getCoreg39CourseByID(courseID);
8190
if (optionalCourse.isPresent()) {

api/src/main/java/ca/bc/gov/educ/api/pen/replication/service/TraxStudentCourseService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package ca.bc.gov.educ.api.pen.replication.service;
22

33
import ca.bc.gov.educ.api.pen.replication.model.TraxStudentCourseEntity;
4+
import ca.bc.gov.educ.api.pen.replication.model.TraxStudentEntity;
45
import ca.bc.gov.educ.api.pen.replication.repository.TraxStudentCourseRepository;
56
import lombok.extern.slf4j.Slf4j;
67
import org.springframework.stereotype.Service;
78
import org.springframework.transaction.annotation.Propagation;
89
import org.springframework.transaction.annotation.Transactional;
910

1011
import java.util.List;
12+
import java.util.Optional;
1113

1214
@Service
1315
@Slf4j
@@ -18,6 +20,11 @@ public TraxStudentCourseService(TraxStudentCourseRepository traxStudentCourseRep
1820
this.traxStudentCourseRepository = traxStudentCourseRepository;
1921
}
2022

23+
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
24+
public List<TraxStudentCourseEntity> findTraxStudentCoursesByPen(final String pen) {
25+
return this.traxStudentCourseRepository.findAllByStudXcrseId_StudNo(pen);
26+
}
27+
2128
// it is saved in a new transaction to make sure commit happens in DB.
2229
@Transactional(propagation = Propagation.REQUIRES_NEW, timeout = 60)
2330
public void deletePriorAndSaveTraxStudentCourses(final String pen, final List<TraxStudentCourseEntity> studentCourseEntityList) {

0 commit comments

Comments
 (0)