-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start of gdc messaging (cherry picked from commit 30eb4e1) * gdc messaging (cherry picked from commit bd02fa6) * use grad student service (cherry picked from commit 1671dea) * clean (cherry picked from commit 541dbb8) * extend base integration test (cherry picked from commit a406871) * required fields for grad student record payload (cherry picked from commit 61bec8a) * clean (cherry picked from commit 1cbaddc) * test (cherry picked from commit 6e49a5f) * add studentStatusCode to grad student record messaging (cherry picked from commit 649c7ba) * add student id and graduated status to grad stud messaging (#706) * add student id and graduated status to grad stud messaging * test parseGraduationStatus (cherry picked from commit 38f1f56) --------- Co-authored-by: alexmcdermid <[email protected]>
- Loading branch information
1 parent
7283d63
commit 9fb18d0
Showing
13 changed files
with
304 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
.../ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\"}"; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ca.bc.gov.educ.api.gradstudent.model.dto.messaging; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
public class GradStudentRecord { | ||
|
||
private UUID studentID; | ||
private String program; | ||
private Date programCompletionDate; | ||
private String schoolOfRecord; | ||
private String studentStatusCode; | ||
private String studentProjectedGradData; | ||
private Boolean graduated; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.