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

Add orchestrator for being able to create a school with an optional admin user. #216

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -23,6 +23,7 @@ public enum EventOutcome {
* Personal Activation code creation outcome
*/
PERSONAL_ACTIVATION_CODE_CREATED,
SCHOOL_PRIMARY_CODE_CREATED,
/**
* User activation email sent outcome
*/
Expand All @@ -47,14 +48,15 @@ public enum EventOutcome {
* Email notification for secure exchange comment sent event outcome.
*/
EMAIL_NOTIFICATION_FOR_SECURE_EXCHANGE_COMMENT_SENT,
PRIMARY_ACTIVATION_CODE_SENT,

/**
* Move School Events Outcome
*/

// Create/move school Events Outcome
SCHOOL_CREATED,
SCHOOL_UPDATED,
SCHOOL_MOVED,
USERS_TO_NEW_SCHOOL_COPIED
USERS_TO_NEW_SCHOOL_COPIED,
CREATE_SCHOOL_SAGA_HAS_ADMIN,
CREATE_SCHOOL_SAGA_HAS_NO_ADMIN,
INITIAL_USER_INVITED

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ public enum EventType {
REMOVE_USER_SCHOOL_ACCESS,

REMOVE_USER_DISTRICT_ACCESS,
/**
*
*/
CREATE_PERSONAL_ACTIVATION_CODE,
CREATE_SCHOOL_PRIMARY_CODE,
/**
* Send edx user activation email event type.
*/
Expand Down Expand Up @@ -61,15 +59,16 @@ public enum EventType {
SECURE_EXCHANGE_COMMENT_COMPLETE,

SEND_EDX_DISTRICT_USER_ACTIVATION_EMAIL,
SEND_PRIMARY_ACTIVATION_CODE,


/**
* Move School Events
*/
// Create/move School Events
CREATE_SCHOOL,
CHECK_CREATE_SCHOOL_SAGA_FOR_ADMIN,
UPDATE_SCHOOL,
COPY_USERS_TO_NEW_SCHOOL,
GET_PAGINATED_SCHOOLS,
MOVE_SCHOOL
MOVE_SCHOOL,
INVITE_INITIAL_USER

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public enum SagaEnum {

EDX_DISTRICT_USER_ACTIVATION_RELINK_SAGA,

MOVE_SCHOOL_SAGA
MOVE_SCHOOL_SAGA,

CREATE_NEW_SCHOOL_SAGA

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ca.bc.gov.educ.api.edx.utils.RequestUtil;
import ca.bc.gov.educ.api.edx.validator.CreateSecureExchangeSagaPayloadValidator;
import ca.bc.gov.educ.api.edx.validator.EdxActivationCodeSagaDataPayloadValidator;
import ca.bc.gov.educ.api.edx.validator.EdxUserPayloadValidator;
import ca.bc.gov.educ.api.edx.validator.SecureExchangeCommentSagaValidator;
import ca.bc.gov.educ.api.edx.validator.SecureExchangePayloadValidator;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -31,6 +32,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

import static ca.bc.gov.educ.api.edx.constants.SagaEnum.*;
Expand All @@ -41,6 +43,9 @@
@Slf4j
public class EdxSagaController implements EdxSagaEndpoint {

@Getter(AccessLevel.PRIVATE)
private final EdxUserPayloadValidator edxUserPayLoadValidator;

@Getter(AccessLevel.PRIVATE)
private final EdxActivationCodeSagaDataPayloadValidator edxActivationCodeSagaDataPayLoadValidator;

Expand All @@ -60,12 +65,13 @@ public class EdxSagaController implements EdxSagaEndpoint {

private static final SagaDataMapper SAGA_DATA_MAPPER = SagaDataMapper.mapper;

public EdxSagaController(EdxActivationCodeSagaDataPayloadValidator edxActivationCodeSagaDataPayLoadValidator, SagaService sagaService, List<Orchestrator> orchestrators, SecureExchangePayloadValidator secureExchangePayloadValidator, SecureExchangeCommentSagaValidator secureExchangeCommentSagaValidator, CreateSecureExchangeSagaPayloadValidator createSecureExchangeSagaPayloadValidator) {
public EdxSagaController(EdxActivationCodeSagaDataPayloadValidator edxActivationCodeSagaDataPayLoadValidator, SagaService sagaService, List<Orchestrator> orchestrators, SecureExchangePayloadValidator secureExchangePayloadValidator, SecureExchangeCommentSagaValidator secureExchangeCommentSagaValidator, CreateSecureExchangeSagaPayloadValidator createSecureExchangeSagaPayloadValidator, EdxUserPayloadValidator edxUserPayLoadValidator) {
this.edxActivationCodeSagaDataPayLoadValidator = edxActivationCodeSagaDataPayLoadValidator;
this.sagaService = sagaService;
this.secureExchangePayloadValidator = secureExchangePayloadValidator;
this.secureExchangeCommentSagaValidator = secureExchangeCommentSagaValidator;
this.createSecureExchangeSagaPayloadValidator = createSecureExchangeSagaPayloadValidator;
this.edxUserPayLoadValidator = edxUserPayLoadValidator;
orchestrators.forEach(orchestrator -> this.orchestratorMap.put(orchestrator.getSagaName(), orchestrator));
log.info("'{}' Saga Orchestrators are loaded.", String.join(",", this.orchestratorMap.keySet()));
}
Expand Down Expand Up @@ -113,11 +119,30 @@ public ResponseEntity<String> edxDistrictUserActivationRelink(EdxUserDistrictAct
return this.processEdxDistrictUserActivationLinkSaga(EDX_DISTRICT_USER_ACTIVATION_RELINK_SAGA, edxUserActivationRelinkSagaData);
}

@Override
public ResponseEntity<String> createSchool(CreateSchoolSagaData edxSchoolCreationSagaData) {
Optional<EdxUser> userOptional = edxSchoolCreationSagaData.getInitialEdxUser();
if (userOptional.isPresent()) {
validatePayload(() -> getEdxUserPayLoadValidator().validateEdxUserPayload(userOptional.get(), true));
}
return this.processNewSchoolSaga(CREATE_NEW_SCHOOL_SAGA, edxSchoolCreationSagaData);
}

@Override
public ResponseEntity<String> moveSchool(MoveSchoolData moveSchoolData) {
return this.processMoveSchoolSaga(MOVE_SCHOOL_SAGA, moveSchoolData);
}

private ResponseEntity<String> processNewSchoolSaga(SagaEnum sagaName, CreateSchoolSagaData newSchoolSagaData) {
try {
RequestUtil.setAuditColumnsForCreate(newSchoolSagaData);
SagaEntity sagaEntity = SAGA_DATA_MAPPER.toModel(String.valueOf(sagaName), newSchoolSagaData);
return processServicesSaga(sagaName, sagaEntity);
} catch (JsonProcessingException e) {
throw new SagaRuntimeException(e);
}
}

private ResponseEntity<String> processMoveSchoolSaga(SagaEnum sagaName, MoveSchoolData moveSchoolData) {
try {
RequestUtil.setAuditColumnsForCreate(moveSchoolData);
Expand Down Expand Up @@ -151,7 +176,6 @@ private ResponseEntity<String> processEdxSchoolUserActivationLinkSaga(final Saga
}
}


private ResponseEntity<String> processEdxDistrictUserActivationLinkSaga(final SagaEnum sagaName, final EdxUserDistrictActivationInviteSagaData edxDistrictUserActivationInviteSagaData) {
final var sagaInProgress = this.getSagaService().findAllActiveUserActivationInviteSagasByDistrictIDAndEmailId(edxDistrictUserActivationInviteSagaData.getDistrictID(), edxDistrictUserActivationInviteSagaData.getEmail(), sagaName.toString(), this.getActiveStatusesFilter());
if (sagaInProgress.isPresent()) {
Expand All @@ -168,7 +192,6 @@ private ResponseEntity<String> processEdxDistrictUserActivationLinkSaga(final Sa
}

private ResponseEntity<String> processNewSecureExchangeMessageSaga(final SagaEnum sagaName, final SecureExchangeCreateSagaData secureExchangeCreateSagaData) {

try {
val sagaEntity = SAGA_DATA_MAPPER.toModel(String.valueOf(sagaName),secureExchangeCreateSagaData);
return processServicesSaga(sagaName,sagaEntity);
Expand All @@ -195,7 +218,6 @@ protected List<String> getActiveStatusesFilter() {

private ResponseEntity<String> processServicesSaga(final SagaEnum sagaName, SagaEntity sagaEntity) {
try {

final var orchestrator = this.getOrchestratorMap().get(sagaName.toString());
final var saga = this.getOrchestratorMap()
.get(sagaName.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public interface EdxSagaEndpoint {
@ResponseStatus(ACCEPTED)
ResponseEntity<String> edxDistrictUserActivationRelink(@Validated @RequestBody EdxUserDistrictActivationRelinkSagaData edxUserActivationRelinkSagaData);

@PostMapping("/create-school-saga")
@PreAuthorize("hasAuthority('SCOPE_CREATE_SCHOOL_SAGA')")
@ApiResponses(value = {@ApiResponse(responseCode = "202", description = "ACCEPTED"), @ApiResponse(responseCode = "400", description = "BAD REQUEST."), @ApiResponse(responseCode = "409", description = "CONFLICT.")})
@ResponseStatus(ACCEPTED)
ResponseEntity<String> createSchool(@Validated @RequestBody CreateSchoolSagaData edxSchoolCreationSagaData);

@PostMapping("/move-school-saga")
@PreAuthorize("hasAuthority('SCOPE_MOVE_SCHOOL_SAGA')")
@ApiResponses(value = {@ApiResponse(responseCode = "202", description = "ACCEPTED"), @ApiResponse(responseCode = "400", description = "BAD REQUEST."), @ApiResponse(responseCode = "409", description = "CONFLICT.")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public interface EdxUsersEndpoint {
@PostMapping("/activation")
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "CREATED"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")})
@ResponseStatus(CREATED)
EdxUser activateUser(@Validated @RequestBody EdxActivateUser edxActivateUser);
EdxUser activateUser(@Validated @RequestBody EdxActivateUser edxActivateUser);

@Transactional
@PreAuthorize("hasAuthority('SCOPE_WRITE_ACTIVATION_CODE')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public interface SagaDataMapper {
@Mapping(target = "districtID", ignore = true)
SagaEntity toModel(String sagaName, SecureExchangeCreateSagaData sagaData) throws JsonProcessingException;

@Mapping(target = "status", ignore = true)
@Mapping(target = "secureExchangeId", ignore = true)
@Mapping(target = "sagaState", ignore = true)
@Mapping(target = "sagaId", ignore = true)
@Mapping(target = "sagaCompensated", ignore = true)
@Mapping(target = "retryCount", ignore = true)
@Mapping(target = "payload", expression = "java(ca.bc.gov.educ.api.edx.utils.JsonUtil.getJsonStringFromObject(sagaData))")
@Mapping(target = "emailId", expression = "java(sagaData.getInitialEdxUser().isPresent() ? sagaData.getInitialEdxUser().get().getEmail() : \"\")")
@Mapping(target = "edxUserId", ignore = true)
@Mapping(target = "schoolID", ignore = true)
@Mapping(target = "districtID", ignore = true)
SagaEntity toModel(String sagaName, CreateSchoolSagaData sagaData) throws JsonProcessingException;

@Mapping(target = "status", ignore = true)
@Mapping(target = "secureExchangeId", ignore = true)
@Mapping(target = "sagaState", ignore = true)
Expand All @@ -42,7 +55,6 @@ public interface SagaDataMapper {
@Mapping(target = "districtID", ignore = true)
SagaEntity toModel(String sagaName, EdxUserSchoolActivationInviteSagaData sagaData) throws JsonProcessingException;


@Mapping(target = "status", ignore = true)
@Mapping(target = "secureExchangeId", ignore = true)
@Mapping(target = "sagaState", ignore = true)
Expand All @@ -54,7 +66,6 @@ public interface SagaDataMapper {
@Mapping(target = "emailId", source = "sagaData.email")
SagaEntity toModel(String sagaName, EdxUserDistrictActivationInviteSagaData sagaData) throws JsonProcessingException;


@Mapping(target = "status", ignore = true)
@Mapping(target = "sagaState", ignore = true)
@Mapping(target = "sagaId", ignore = true)
Expand Down
Loading
Loading