Skip to content

Commit

Permalink
Enhancement to pull back the data on edx callout
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Oct 4, 2023
1 parent 1718cc2 commit 3f6cc51
Show file tree
Hide file tree
Showing 32 changed files with 166 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import ca.bc.gov.educ.api.edx.exception.EntityNotFoundException;
import ca.bc.gov.educ.api.edx.exception.InvalidPayloadException;
import ca.bc.gov.educ.api.edx.exception.errors.ApiError;
import ca.bc.gov.educ.api.edx.mappers.v1.EdxUserMapper;
import ca.bc.gov.educ.api.edx.model.v1.*;
import ca.bc.gov.educ.api.edx.props.ApplicationProperties;
import ca.bc.gov.educ.api.edx.repository.*;
import ca.bc.gov.educ.api.edx.rest.RestUtils;
import ca.bc.gov.educ.api.edx.struct.v1.*;
import ca.bc.gov.educ.api.edx.utils.TransformUtil;
import com.google.common.primitives.Chars;
import jakarta.persistence.EntityExistsException;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -24,11 +24,11 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import jakarta.persistence.EntityExistsException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static org.springframework.http.HttpStatus.*;

Expand Down Expand Up @@ -134,11 +134,20 @@ public List<EdxSchool> findAllDistrictEdxUsers(String districtID) {
if(!edxSchools.containsKey(schoolID)){
EdxSchool school = new EdxSchool();
school.setSchoolID(schoolID);
school.setEdxUsers(new ArrayList<>());
school.setEdxDistrictSchoolUsers(new ArrayList<>());
edxSchools.put(schoolID, school);
}

edxSchools.get(schoolID).getEdxUsers().add(EdxUserMapper.mapper.toStructure(edxUserSchoolEntity.getEdxUserEntity()));
EdxDistrictSchoolUserTombstone tomb = new EdxDistrictSchoolUserTombstone();
var edxUserEntity = edxUserSchoolEntity.getEdxUserEntity();
tomb.setEdxUserID(edxUserEntity.getEdxUserID().toString());
tomb.setDigitalIdentityID(edxUserEntity.getDigitalIdentityID().toString());
tomb.setEmail(edxUserEntity.getEmail());
tomb.setFullName(edxUserEntity.getFirstName() + " " + edxUserEntity.getLastName());
var rolesMap = getEdxRolesMap();
tomb.setSchoolRoles(edxUserSchoolEntity.getEdxUserSchoolRoleEntities().stream().map(edxSchool -> rolesMap.get(edxSchool.getEdxRoleCode()).getLabel()).toList());

edxSchools.get(schoolID).getEdxDistrictSchoolUsers().add(tomb);
});

return edxSchools.values().stream().toList();
Expand Down Expand Up @@ -328,6 +337,10 @@ public List<EdxRoleEntity> findAllEdxRoles() {
return this.getEdxRoleRepository().findAll();
}

public Map<String, EdxRoleEntity> getEdxRolesMap() {
return this.getEdxRoleRepository().findAll().stream().collect(Collectors.toMap(EdxRoleEntity::getEdxRoleCode, item -> item));
}

/**
* Activate school user edx user entity.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ca.bc.gov.educ.api.edx.struct.v1;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class EdxDistrictSchoolUserTombstone implements Serializable {
private static final long serialVersionUID = 583620260139143932L;

String edxUserID;

String digitalIdentityID;

String fullName;

private List<String> schoolRoles;

String email;
}





Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class EdxSchool implements Serializable {

String schoolID;

private List<EdxUser> edxUsers;
private List<EdxDistrictSchoolUserTombstone> edxDistrictSchoolUsers;
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import ca.bc.gov.educ.api.edx.utils.SecureExchangeAPITestUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

Expand All @@ -30,11 +32,17 @@
@SpringBootTest(classes = {EdxApiResourceApplication.class})
@ActiveProfiles("test")
@AutoConfigureMockMvc
public abstract class BaseSecureExchangeAPITest {
public abstract class BaseEdxAPITest {
protected final static ObjectMapper objectMapper = createMapper();
@Autowired
protected SecureExchangeAPITestUtils secureExchangeAPITestUtils;

@MockBean
ClientRegistrationRepository clientRegistrationRepository;

@MockBean
OAuth2AuthorizedClientRepository oAuth2AuthorizedClientRepository;

@BeforeEach
public void before() {
this.secureExchangeAPITestUtils.cleanDB();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ca.bc.gov.educ.api.edx.controller;

import ca.bc.gov.educ.api.edx.BaseSecureExchangeAPITest;
import ca.bc.gov.educ.api.edx.BaseEdxAPITest;
import ca.bc.gov.educ.api.edx.struct.v1.SecureExchange;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Set;

public abstract class BaseSecureExchangeControllerTest extends BaseSecureExchangeAPITest {
public abstract class BaseEdxControllerTest extends BaseEdxAPITest {

protected String dummySecureExchangeJson() {
return "{\"updateUser\":\"TEST\",\"createUser\":\"TEST\",\"secureExchangeStatusCode\":\"OPEN\",\"isReadByExchangeContact\":\"false\",\"isReadByMinistry\":\"false\",\"statusUpdateDate\":\"1952-10-31T00:00:00\",\"updateDate\":\"1952-10-31T00:00:00\",\"createDate\":\"1952-10-31T00:00:00\",\"subject\":\"Hello Student\",\"ministryOwnershipTeamID\":\"b1e0788a-7dab-4b92-af86-c678e411f1e3\",\"contactIdentifier\":\"b1e0788a-7dab-4b92-af86-c678e411f1e4\",\"secureExchangeContactTypeCode\":\"EDXUSER\", \"secureExchangeID\":\"0a004b01-7027-17b1-8170-27cb21100000\"}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.GregorianCalendar;
import java.util.UUID;

public abstract class BaseSagaControllerTest extends BaseSecureExchangeControllerTest {
public abstract class BaseSagaControllerTest extends BaseEdxControllerTest {

protected String secureExchangeCreateJsonWithMinAndComment(final String ministryOwnershipTeamID) {
return "{\"updateUser\":\"TEST\",\"createUser\":\"TEST\",\"isReadByExchangeContact\":\"false\",\"isReadByMinistry\":\"false\",\"secureExchangeStatusCode\":\"OPEN\",\"statusUpdateDate\":\"1952-10-31T00:00:00\",\"subject\":\"Hello Student\",\"ministryOwnershipTeamID\":\"" + ministryOwnershipTeamID + "\",\"contactIdentifier\":\"b1e0788a-7dab-4b92-af86-c678e411f1e4\",\"secureExchangeContactTypeCode\":\"EDXUSER\", \"commentsList\": [{\"staffUserIdentifier\": \"TEST\", \"commentUserName\": \"JACKSON, JAMES\", \"content\": \"This is content\", \"updateUser\":\"TEST\",\"createUser\":\"TEST\"}]}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class SecureExchangeCommentControllerTest extends BaseSecureExchangeControllerTest {
class EdxCommentControllerTest extends BaseEdxControllerTest {
private static final SecureExchangeEntityMapper mapper = SecureExchangeEntityMapper.mapper;
@Autowired
private MockMvc mockMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class SecureExchangeControllerTest extends BaseSecureExchangeControllerTest {
class EdxControllerTest extends BaseEdxControllerTest {

private static final SecureExchangeEntityMapper mapper = SecureExchangeEntityMapper.mapper;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ca.bc.gov.educ.api.edx.controller;

import ca.bc.gov.educ.api.edx.BaseSecureExchangeAPITest;
import ca.bc.gov.educ.api.edx.BaseEdxAPITest;
import ca.bc.gov.educ.api.edx.constants.v1.URL;
import ca.bc.gov.educ.api.edx.controller.v1.SecureExchangeDocumentController;
import ca.bc.gov.educ.api.edx.model.v1.SecureExchangeDocumentEntity;
Expand Down Expand Up @@ -37,7 +37,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


class SecureExchangeDocumentControllerTest extends BaseSecureExchangeAPITest {
class EdxDocumentControllerTest extends BaseEdxAPITest {
@Autowired
private MockMvc mvc;

Expand Down Expand Up @@ -97,7 +97,7 @@ void createDocumentTest() throws Exception {
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_SECURE_EXCHANGE_DOCUMENT")))
.contentType(MediaType.APPLICATION_JSON)
.content(Files.readAllBytes(new ClassPathResource(
"../model/document-req.json", SecureExchangeDocumentControllerTest.class).getFile().toPath()))
"../model/document-req.json", EdxDocumentControllerTest.class).getFile().toPath()))
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andDo(print())
Expand All @@ -113,7 +113,7 @@ void updateDocumentTest() throws Exception {
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_SECURE_EXCHANGE_DOCUMENT")))
.contentType(MediaType.APPLICATION_JSON)
.content(Files.readAllBytes(new ClassPathResource(
"../model/document-req.json", SecureExchangeDocumentControllerTest.class).getFile().toPath()))
"../model/document-req.json", EdxDocumentControllerTest.class).getFile().toPath()))
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andDo(print())
Expand Down Expand Up @@ -233,7 +233,7 @@ void createDocumentWithInvalidFileSizeTest() throws Exception {
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_SECURE_EXCHANGE_DOCUMENT")))
.contentType(MediaType.APPLICATION_JSON)
.content(Files.readAllBytes(new ClassPathResource(
"../model/document-req-invalid-filesize.json", SecureExchangeDocumentControllerTest.class).getFile().toPath()))
"../model/document-req-invalid-filesize.json", EdxDocumentControllerTest.class).getFile().toPath()))
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andDo(print())
Expand All @@ -247,7 +247,7 @@ void createDocumentWithoutDocumentDataTest() throws Exception {
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_SECURE_EXCHANGE_DOCUMENT")))
.contentType(MediaType.APPLICATION_JSON)
.content(Files.readAllBytes(new ClassPathResource(
"../model/document-req-without-doc-data.json", SecureExchangeDocumentControllerTest.class).getFile().toPath()))
"../model/document-req-without-doc-data.json", EdxDocumentControllerTest.class).getFile().toPath()))
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andDo(print());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ca.bc.gov.educ.api.edx.repository.SecureExchangeRequestRepository;
import ca.bc.gov.educ.api.edx.struct.v1.SecureExchangeNote;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.transaction.Transactional;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -17,7 +18,6 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import jakarta.transaction.Transactional;
import java.util.HashSet;
import java.util.UUID;

Expand All @@ -26,7 +26,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class SecureExchangeNoteControllerTest extends BaseSecureExchangeControllerTest {
class EdxNoteControllerTest extends BaseEdxControllerTest {

private static final SecureExchangeNoteMapper noteMapper = SecureExchangeNoteMapper.mapper;
private static final SecureExchangeEntityMapper exchangeMapper = SecureExchangeEntityMapper.mapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
package ca.bc.gov.educ.api.edx.controller;

import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import ca.bc.gov.educ.api.edx.constants.v1.URL;
import ca.bc.gov.educ.api.edx.controller.v1.EdxStatsController;
import ca.bc.gov.educ.api.edx.model.v1.SecureExchangeEntity;
import ca.bc.gov.educ.api.edx.repository.*;
import ca.bc.gov.educ.api.edx.rest.RestUtils;
import ca.bc.gov.educ.api.edx.struct.v1.District;
import ca.bc.gov.educ.api.edx.struct.v1.School;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -28,7 +15,21 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;

class EdxStatsControllerTest extends BaseSecureExchangeControllerTest {
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class EdxStatsControllerTest extends BaseEdxControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class SecureExchangeStudentControllerTest extends BaseSecureExchangeControllerTest {
class EdxStudentControllerTest extends BaseEdxControllerTest {

private static final SecureExchangeEntityMapper mapper = SecureExchangeEntityMapper.mapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
import lombok.val;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;

import java.lang.reflect.Array;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
Expand All @@ -34,7 +33,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

class EdxUsersControllerTest extends BaseSecureExchangeControllerTest {
class EdxUsersControllerTest extends BaseEdxControllerTest {

@Autowired
private MockMvc mockMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.boot.test.json.JsonContent;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

Expand All @@ -22,6 +25,10 @@
@SpringBootTest
@ActiveProfiles("test")
class SecureExchangeDocRequirementEntityJsonTests {
@MockBean
ClientRegistrationRepository clientRegistrationRepository;
@MockBean
OAuth2AuthorizedClientRepository oAuth2AuthorizedClientRepository;
@Autowired
private JacksonTester<SecureExchangeDocRequirement> jsonTester;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

class EdxDistrictSecureExchangeCommentOrchestratorTest extends BaseSagaControllerTest {
class EdxDistrictEdxCommentOrchestratorTest extends BaseSagaControllerTest {

/**
* The Repository.
*/
@Autowired
SagaRepository sagaRepository;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ca.bc.gov.educ.api.edx.orchestrator;

import ca.bc.gov.educ.api.edx.BaseSecureExchangeAPITest;
import ca.bc.gov.educ.api.edx.BaseEdxAPITest;
import ca.bc.gov.educ.api.edx.constants.EventOutcome;
import ca.bc.gov.educ.api.edx.constants.EventType;
import ca.bc.gov.educ.api.edx.constants.SagaEnum;
Expand Down Expand Up @@ -38,7 +38,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

class EdxDistrictUserActivationInviteOrchestratorTest extends BaseSecureExchangeAPITest {
class EdxDistrictUserActivationInviteOrchestratorTest extends BaseEdxAPITest {


/**
Expand Down
Loading

0 comments on commit 3f6cc51

Please sign in to comment.