-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from bcgov/feature/EAC-19
Feature/eac 19
- Loading branch information
Showing
11 changed files
with
327 additions
and
25 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
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
2 changes: 1 addition & 1 deletion
2
api/src/main/java/ca/bc/gov/educ/eas/api/constants/SagaEnum.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package ca.bc.gov.educ.eas.api.constants; | ||
|
||
public enum SagaEnum { | ||
|
||
CREATE_STUDENT_REGISTRATION | ||
} |
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
81 changes: 81 additions & 0 deletions
81
api/src/main/java/ca/bc/gov/educ/eas/api/orchestrator/StudentRegistrationOrchestrator.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,81 @@ | ||
package ca.bc.gov.educ.eas.api.orchestrator; | ||
|
||
import ca.bc.gov.educ.eas.api.constants.SagaEnum; | ||
import ca.bc.gov.educ.eas.api.constants.SagaStatusEnum; | ||
import ca.bc.gov.educ.eas.api.constants.TopicsEnum; | ||
import ca.bc.gov.educ.eas.api.messaging.MessagePublisher; | ||
import ca.bc.gov.educ.eas.api.model.v1.EasSagaEntity; | ||
import ca.bc.gov.educ.eas.api.model.v1.SagaEventStatesEntity; | ||
import ca.bc.gov.educ.eas.api.orchestrator.base.BaseOrchestrator; | ||
import ca.bc.gov.educ.eas.api.service.v1.StudentRegistrationOrchestrationService; | ||
import ca.bc.gov.educ.eas.api.service.v1.SagaService; | ||
import ca.bc.gov.educ.eas.api.struct.Event; | ||
import ca.bc.gov.educ.eas.api.struct.v1.AssessmentStudent; | ||
import ca.bc.gov.educ.eas.api.util.JsonUtil; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static ca.bc.gov.educ.eas.api.constants.EventType.CREATE_STUDENT_REGISTRATION; | ||
import static ca.bc.gov.educ.eas.api.constants.EventType.PUBLISH_STUDENT_REGISTRATION; | ||
|
||
import static ca.bc.gov.educ.eas.api.constants.EventOutcome.STUDENT_REGISTRATION_CREATED; | ||
import static ca.bc.gov.educ.eas.api.constants.EventOutcome.STUDENT_REGISTRATION_PUBLISHED; | ||
|
||
|
||
@Component | ||
@Slf4j | ||
public class StudentRegistrationOrchestrator extends BaseOrchestrator<AssessmentStudent> { | ||
|
||
private final StudentRegistrationOrchestrationService studentRegistrationOrchestrationService; | ||
|
||
protected StudentRegistrationOrchestrator(final SagaService sagaService, final MessagePublisher messagePublisher, StudentRegistrationOrchestrationService studentRegistrationOrchestrationService) { | ||
super(sagaService, messagePublisher, AssessmentStudent.class, SagaEnum.CREATE_STUDENT_REGISTRATION.toString(), TopicsEnum.CREATE_STUDENT_REGISTRATION_SAGA_TOPIC.toString()); | ||
this.studentRegistrationOrchestrationService = studentRegistrationOrchestrationService; | ||
} | ||
|
||
@Override | ||
public void populateStepsToExecuteMap() { | ||
this.stepBuilder() | ||
.begin(CREATE_STUDENT_REGISTRATION, this::createStudentRegistration) | ||
.step(CREATE_STUDENT_REGISTRATION, STUDENT_REGISTRATION_CREATED, PUBLISH_STUDENT_REGISTRATION, this::publishStudentRegistration) | ||
.end(PUBLISH_STUDENT_REGISTRATION, STUDENT_REGISTRATION_PUBLISHED); | ||
} | ||
|
||
private void createStudentRegistration(Event event, EasSagaEntity saga, AssessmentStudent sagaData) throws JsonProcessingException { | ||
final SagaEventStatesEntity eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload()); | ||
saga.setSagaState(CREATE_STUDENT_REGISTRATION.toString()); | ||
saga.setStatus(SagaStatusEnum.IN_PROGRESS.toString()); | ||
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates); | ||
//Service call | ||
studentRegistrationOrchestrationService.createNewStudentRegistration(sagaData); | ||
final Event nextEvent = Event.builder().sagaId(saga.getSagaId()) | ||
.eventType(CREATE_STUDENT_REGISTRATION) | ||
.eventOutcome(STUDENT_REGISTRATION_CREATED) | ||
.eventPayload(JsonUtil.getJsonStringFromObject(sagaData)) | ||
.build(); | ||
this.postMessageToTopic(this.getTopicToSubscribe(), nextEvent); | ||
logMessage(nextEvent, saga); | ||
} | ||
|
||
private void publishStudentRegistration(Event event, EasSagaEntity saga, AssessmentStudent sagaData) throws JsonProcessingException { | ||
final SagaEventStatesEntity eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload()); | ||
saga.setSagaState(PUBLISH_STUDENT_REGISTRATION.toString()); | ||
saga.setStatus(SagaStatusEnum.IN_PROGRESS.toString()); | ||
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates); | ||
//Service call | ||
studentRegistrationOrchestrationService.publishStudentRegistration(sagaData, saga); | ||
|
||
final Event nextEvent = Event.builder().sagaId(saga.getSagaId()) | ||
.eventType(PUBLISH_STUDENT_REGISTRATION).eventOutcome(STUDENT_REGISTRATION_PUBLISHED) | ||
.eventPayload(JsonUtil.getJsonStringFromObject(sagaData)) | ||
.build(); | ||
this.postMessageToTopic(this.getTopicToSubscribe(), nextEvent); | ||
logMessage(nextEvent, saga); | ||
} | ||
|
||
private void logMessage(Event event, EasSagaEntity saga) { | ||
log.debug("message sent to {} for {} Event. :: {}", this.getTopicToSubscribe(), event, saga.getSagaId()); | ||
} | ||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
.../main/java/ca/bc/gov/educ/eas/api/service/v1/StudentRegistrationOrchestrationService.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,43 @@ | ||
package ca.bc.gov.educ.eas.api.service.v1; | ||
|
||
import ca.bc.gov.educ.eas.api.mappers.v1.AssessmentStudentMapper; | ||
import ca.bc.gov.educ.eas.api.model.v1.AssessmentStudentEntity; | ||
import ca.bc.gov.educ.eas.api.model.v1.EasSagaEntity; | ||
import ca.bc.gov.educ.eas.api.struct.v1.AssessmentStudent; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@Slf4j | ||
public class StudentRegistrationOrchestrationService { | ||
|
||
private static final AssessmentStudentMapper mapper = AssessmentStudentMapper.mapper; | ||
protected final SagaService sagaService; | ||
|
||
@Getter(AccessLevel.PRIVATE) | ||
private final AssessmentStudentService assessmentStudentService; | ||
|
||
public StudentRegistrationOrchestrationService(AssessmentStudentService assessmentStudentService, SagaService sagaService) { | ||
this.assessmentStudentService = assessmentStudentService; | ||
this.sagaService = sagaService; | ||
} | ||
|
||
public void createNewStudentRegistration(AssessmentStudent assessmentStudent) { | ||
Optional<AssessmentStudentEntity> studentEntity = assessmentStudentService.getStudentByAssessmentIDAndStudentID(UUID.fromString(assessmentStudent.getAssessmentID()), UUID.fromString(assessmentStudent.getStudentID())); | ||
if (studentEntity.isEmpty()) { | ||
assessmentStudentService.createStudent(mapper.toModel(assessmentStudent)); | ||
} else { | ||
log.info("Student already exists in assessment {} ", assessmentStudent); | ||
} | ||
} | ||
|
||
public void publishStudentRegistration(AssessmentStudent assessmentStudent, EasSagaEntity sagaEntity) { | ||
//Placeholder | ||
} | ||
|
||
} |
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.