Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/grad2 31025 #718

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e72562e
GRAD2-2645: task is complete.
infstar Sep 3, 2024
42879d6
GRAD2-2761: initial commit to utilize the school clob data from insti…
infstar Oct 7, 2024
147e588
Clean up the comments.
infstar Oct 28, 2024
592de63
Merge branch 'grad-release' into feature/GRAD2-2761
infstar Nov 1, 2024
0302eff
Merge pull request #677 from bcgov/feature/GRAD2-2645
infstar Nov 4, 2024
d76a1e1
Merge pull request #694 from bcgov/feature/GRAD2-2761
infstar Nov 4, 2024
b3301c0
GRA2-2951: task is complete. (#698)
infstar Nov 6, 2024
30eb4e1
start of gdc messaging
alexmcdermid Nov 13, 2024
bd02fa6
gdc messaging
alexmcdermid Nov 13, 2024
1671dea
use grad student service
alexmcdermid Nov 19, 2024
541dbb8
clean
alexmcdermid Nov 19, 2024
a406871
extend base integration test
alexmcdermid Nov 19, 2024
61bec8a
required fields for grad student record payload
alexmcdermid Nov 19, 2024
1cbaddc
clean
alexmcdermid Nov 19, 2024
6e49a5f
test
alexmcdermid Nov 19, 2024
9a2fc6e
GRAD2-2761: replaced minCode with schoolId for School v2 endpoint & s…
infstar Nov 20, 2024
7481e55
GRAD2-2761: schoolCategoryCode from TRAX is changed to schoolCategory…
infstar Nov 20, 2024
698092f
Feature/grad2 3060 - gdc messaging (#701)
alexmcdermid Nov 20, 2024
4e692a7
Fixed the wrong endpoint.
infstar Nov 20, 2024
38d8cf4
Merge pull request #703 from bcgov/feature/GRAD2-2761
infstar Nov 21, 2024
649c7ba
add studentStatusCode to grad student record messaging
alexmcdermid Nov 25, 2024
21b9e4b
merge grad-release
alexmcdermid Nov 25, 2024
fd2b9bf
Merge pull request #705 from bcgov/feature/GRAD2-3060
arcshiftsolutions Nov 25, 2024
38f1f56
add student id and graduated status to grad stud messaging (#706)
alexmcdermid Nov 28, 2024
480c89b
GRAD2-31025
mightycox Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum FieldName {
SCHOOL_OF_RECORD,
SCHOOL_OF_RECORD_ID,
GRAD_PROGRAM,
ADULT_START_DATE,
SLP_DATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum FieldType {
STRING,
DATE
DATE,
GUID
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum Topics {
* GradStatus events topic.
*/
GRAD_STATUS_EVENT_TOPIC,
GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC
GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC,
GRAD_STUDENT_API_FETCH_GRAD_STUDENT_TOPIC,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package ca.bc.gov.educ.api.gradstudent.messaging.jetstream;

import ca.bc.gov.educ.api.gradstudent.constant.Topics;
import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException;
import ca.bc.gov.educ.api.gradstudent.model.dc.Event;
import ca.bc.gov.educ.api.gradstudent.model.dc.GradStudentRecordPayload;
import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GradStudentRecord;
import ca.bc.gov.educ.api.gradstudent.service.GradStudentService;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiUtils;
import ca.bc.gov.educ.api.gradstudent.util.JsonUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.nats.client.*;
import lombok.val;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.UUID;

@Component
public class FetchGradStudentRecordSubscriber implements MessageHandler {

private final Connection natsConnection;
private Dispatcher dispatcher;
private final GradStudentService gradStudentService;
public static final String RESPONDING_BACK_TO_NATS_ON_CHANNEL = "responding back to NATS on {} channel ";
public static final String PAYLOAD_LOG = "payload is :: {}";
private static final String TOPIC = Topics.GRAD_STUDENT_API_FETCH_GRAD_STUDENT_TOPIC.toString();
private static final Logger log = LoggerFactory.getLogger(FetchGradStudentRecordSubscriber.class);

@Autowired
public FetchGradStudentRecordSubscriber(final Connection natsConnection, GradStudentService gradStudentService, EducGradStudentApiConstants constants) {
this.natsConnection = natsConnection;
this.gradStudentService = gradStudentService;
}

@PostConstruct
public void subscribe() {
this.dispatcher = this.natsConnection.createDispatcher(this);
this.dispatcher.subscribe(TOPIC);
}

@Override
public void onMessage(Message message) {
val eventString = new String(message.getData());
log.debug("Received message: {}", eventString);
String response;

try {
Event event = JsonUtil.getJsonObjectFromString(Event.class, eventString);
log.info("received GET_STUDENT event :: {}", event.getSagaId());
log.trace(PAYLOAD_LOG, event.getEventPayload());
UUID studentId = JsonUtil.getJsonObjectFromString(UUID.class, event.getEventPayload());
GradStudentRecord studentRecord = gradStudentService.getGraduationStudentRecord(studentId);
response = getResponse(studentRecord);
log.info(RESPONDING_BACK_TO_NATS_ON_CHANNEL, message.getReplyTo() != null ? message.getReplyTo() : event.getReplyTo());
} catch (Exception e) {
response = getErrorResponse(e);
log.error("Error while processing GET_STUDENT event", e);
}
this.natsConnection.publish(message.getReplyTo(), response.getBytes());
}

private String getResponse(GradStudentRecord studentRecord) throws JsonProcessingException {
GradStudentRecordPayload gradStudentRecordPayload = GradStudentRecordPayload.builder()
.studentID(String.valueOf(studentRecord.getStudentID()))
.program(studentRecord.getProgram())
.programCompletionDate(studentRecord.getProgramCompletionDate() != null ? EducGradStudentApiUtils.formatDate(studentRecord.getProgramCompletionDate()) : null)
.schoolOfRecord(studentRecord.getSchoolOfRecord())
.studentStatusCode(studentRecord.getStudentStatusCode())
.graduated(studentRecord.getGraduated().toString())
.build();
return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload);
}

private String getErrorResponse(Exception e) {
String ex = (e instanceof EntityNotFoundException) ? "not found" : "error";
GradStudentRecordPayload gradStudentRecordPayload = GradStudentRecordPayload.builder()
.exception(ex)
.build();
try {
return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload);
} catch (JsonProcessingException exc) {
log.error("Error while serializing error response", exc);
return "{\"studentID\": \"\", \"program\": \"\", \"programCompletionDate\": \"\", \"schoolOfRecord\": \"\", \"studentStatusCode\": \"\", \"graduated\": \"\", \"exception\": \"JSON Parsing exception\"}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ca.bc.gov.educ.api.gradstudent.model.dc;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class GradStudentRecordPayload {

private String studentID;
private String exception;
private String program;
private String programCompletionDate;
private String schoolOfRecord;
private String studentStatusCode;
private String graduated;

}
Loading
Loading