Skip to content

Commit

Permalink
feat: DBC and HeeUser requests from TSS
Browse files Browse the repository at this point in the history
TIS21-6272
  • Loading branch information
ReubenRobertsHEE committed Jul 10, 2024
1 parent b2b21e0 commit c3c7990
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>uk.nhs.tis</groupId>
<artifactId>sync</artifactId>
<version>1.22.0</version>
<version>1.23.0</version>
<packaging>jar</packaging>
<name>sync</name>
<description>Separate Microservice for synchronisation</description>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.nhs.tis.sync.dto;

import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO;
import com.transformuk.hee.tis.reference.api.dto.DBCDTO;
import com.transformuk.hee.tis.reference.api.dto.GradeDTO;
import com.transformuk.hee.tis.reference.api.dto.SiteDTO;
import com.transformuk.hee.tis.reference.api.dto.TrustDTO;
Expand All @@ -22,6 +24,7 @@
import uk.nhs.tis.sync.mapper.CurriculumMembershipMapper;
import uk.nhs.tis.sync.mapper.DmsMapper;
import uk.nhs.tis.sync.mapper.GradeMapper;
import uk.nhs.tis.sync.mapper.HeeUserMapper;
import uk.nhs.tis.sync.mapper.PersonMapper;
import uk.nhs.tis.sync.mapper.PlacementSpecialtyMapper;
import uk.nhs.tis.sync.mapper.PlacementSummaryMapper;
Expand All @@ -45,9 +48,11 @@ public enum DmsDtoType {
CURRICULUM(CurriculumDTO.class, "tcs", "Curriculum", CurriculumMapper.class),
CURRICULUM_MEMBERSHIP(CurriculumMembershipWrapperDto.class, "tcs", "CurriculumMembership",
CurriculumMembershipMapper.class),
DBC_DETAILS(DBCDTO.class, "reference", "DBC", null),
GDC_DETAILS(GdcDetailsDTO.class, "tcs", "GdcDetails", null),
GMC_DETAILS(GmcDetailsDTO.class, "tcs", "GmcDetails", null),
GRADE(GradeDTO.class, "reference", "Grade", GradeMapper.class),
HEE_USER(HeeUserDTO.class, "auth", "HeeUser", HeeUserMapper.class),
PERSON(PersonDTO.class, "tcs", "Person", PersonMapper.class),
PERSONAL_DETAILS(PersonalDetailsDTO.class, "tcs", "PersonalDetails", null),
PLACEMENT_DETAILS(PlacementSummaryDTO.class, "tcs", "Placement", PlacementSummaryMapper.class),
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package uk.nhs.tis.sync.dto;

import lombok.Data;

@Data
public class HeeUserDmsDto {
private final String name;
private final String firstName;
private final String lastName;
private final String gmcId;
private final String phoneNumber;
private final String emailAddress;
private final String active;
}
25 changes: 25 additions & 0 deletions src/main/java/uk/nhs/tis/sync/mapper/HeeUserMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package uk.nhs.tis.sync.mapper;

import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import uk.nhs.tis.sync.dto.HeeUserDmsDto;

/**
* A mapper to map between Profile and DMS DTOs for the HeeUser data type.
*/
@Mapper(componentModel = "spring")
public interface HeeUserMapper extends DmsMapper<HeeUserDTO, HeeUserDmsDto> {

//note that password, roles, etc. in the HeeUserDTO are excluded from HeeUserDmsDto: we simply
//map the 'base' record fields
@Mapping(target = "active", source = "active",
qualifiedByName = "getBooleanAsZeroOrOne")
HeeUserDmsDto toDmsDto(HeeUserDTO heeUserDto);

@Named("getBooleanAsZeroOrOne")
default String getBooleanAsZeroOrOne(boolean bool) {
return bool ? "1" : "0";
}
}
18 changes: 17 additions & 1 deletion src/main/java/uk/nhs/tis/sync/service/DataRequestService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.nhs.tis.sync.service;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.reference.client.impl.ReferenceServiceImpl;
import com.transformuk.hee.tis.tcs.api.dto.PersonDTO;
import com.transformuk.hee.tis.tcs.api.dto.PlacementDetailsDTO;
Expand All @@ -24,7 +25,9 @@ public class DataRequestService {

private static final String TABLE_CURRICULUM = "Curriculum";
private static final String TABLE_CURRICULUM_MEMBERSHIP = "CurriculumMembership";
private static final String TABLE_DBC = "DBC";
private static final String TABLE_GRADE = "Grade";
private static final String TABLE_HEE_USER = "HeeUser";
private static final String TABLE_PERSON = "Person";
private static final String TABLE_PLACEMENT = "Placement";
private static final String TABLE_PLACEMENT_SPECIALTY = "PlacementSpecialty";
Expand All @@ -39,9 +42,13 @@ public class DataRequestService {

private final ReferenceServiceImpl referenceServiceImpl;

DataRequestService(TcsServiceImpl tcsServiceImpl, ReferenceServiceImpl referenceServiceImpl) {
private final ProfileServiceImpl profileServiceImpl;

DataRequestService(TcsServiceImpl tcsServiceImpl, ReferenceServiceImpl referenceServiceImpl,
ProfileServiceImpl profileServiceImpl) {
this.tcsServiceImpl = tcsServiceImpl;
this.referenceServiceImpl = referenceServiceImpl;
this.profileServiceImpl = profileServiceImpl;
}

/**
Expand Down Expand Up @@ -74,6 +81,15 @@ public List<Object> retrieveDtos(Map<String, String> message) {
.collect(Collectors.toList());
}

if(table.equals(TABLE_HEE_USER) && message.containsKey("name")) {
String name = message.get("name");
return createNonNullList(profileServiceImpl.getSingleAdminUser(name));
}
if(table.equals(TABLE_DBC) && message.containsKey("dbc")) {
String dbc = message.get("dbc");
return createNonNullList(referenceServiceImpl.getDBCByCode(dbc));
}

if (message.containsKey("id")) {
long id = Long.parseLong(message.get("id"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import org.mapstruct.factory.Mappers;
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/uk/nhs/tis/sync/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import uk.nhs.tis.sync.job.RecordResendingJob;
Expand All @@ -15,6 +17,9 @@
@SpringBootTest
public class ApplicationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
Application testClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,6 +30,8 @@ public class JobRunningListenerTest {
private RevalCurrentPmSyncJob revalCurrentPmSyncJob;
@MockBean
private PostFundingStatusSyncJob postFundingStatusSyncJob;
@MockBean
ProfileServiceImpl profileService;

@Autowired
JobRunningListener testClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.tcs.service.repository.PersonRepository;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;
Expand All @@ -30,6 +31,8 @@ public class PersonOwnerRebuildJobTest {

@MockBean
private PersonRepository repo;
@MockBean
ProfileServiceImpl profileService;

@Test
public void testPersonOwnerRebuildJob() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.nhs.tis.sync.job;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.tcs.service.repository.PersonTrustRepository;
import org.hamcrest.CoreMatchers;
import org.junit.After;
Expand All @@ -9,6 +10,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
Expand All @@ -17,6 +19,9 @@
//@Sql(scripts = {"/scripts/deletePlacements.sql","/scripts/deletePersonRows.sql","/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public class PersonPlacementEmployingBodyTrustJobIntegrationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
PersonPlacementEmployingBodyTrustJob job;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.nhs.tis.sync.job;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.tcs.service.repository.PersonTrustRepository;
import org.hamcrest.CoreMatchers;
import org.junit.After;
Expand All @@ -9,6 +10,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
Expand All @@ -17,6 +19,9 @@
//@Sql(scripts = {"/scripts/deletePlacements.sql","/scripts/deletePersonRows.sql","/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public class PersonPlacementTrainingBodyTrustJobIntegrationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
PersonPlacementTrainingBodyTrustJob job;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import java.util.concurrent.TimeUnit;
import org.awaitility.core.ConditionTimeoutException;
import org.hamcrest.CoreMatchers;
Expand All @@ -13,8 +14,10 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
Expand All @@ -23,6 +26,9 @@
//TODO @Sql(scripts = {"/scripts/deleteProgrammeMemberships.sql","/scripts/deletePersonRows.sql","/scripts/deleteProgrammes.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
class PersonRecordStatusJobIntegrationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
PersonRecordStatusJob job;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.nhs.tis.sync.job;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.tcs.service.repository.PostTrustRepository;
import org.hamcrest.CoreMatchers;
import org.junit.After;
Expand All @@ -9,6 +10,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -19,6 +21,9 @@
@Sql(scripts = {"/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public class PostEmployingBodyTrustJobIntegrationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
PostEmployingBodyTrustJob job;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.nhs.tis.sync.job;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.tcs.service.repository.PostTrustRepository;
import org.hamcrest.CoreMatchers;
import org.junit.After;
Expand All @@ -9,6 +10,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -19,6 +21,9 @@
@Sql(scripts = {"/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public class PostTrainingBodyTrustJobIntegrationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
PostTrainingBodyTrustJob job;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.mockito.Mockito.verify;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.awaitility.core.ConditionTimeoutException;
Expand All @@ -18,6 +19,7 @@
import org.mockito.Captor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
Expand All @@ -28,6 +30,9 @@
@SpringBootTest
class RevalCurrentPlacementSyncJobIntegrationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
RevalCurrentPlacementSyncJob job;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.mockito.Mockito.verify;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.awaitility.core.ConditionTimeoutException;
Expand All @@ -18,6 +19,7 @@
import org.mockito.Captor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
Expand All @@ -32,6 +34,9 @@
"/scripts/deletePersonRows.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
class RevalCurrentPmSyncJobIntegrationTest {

@MockBean
ProfileServiceImpl profileService;

@Autowired
RevalCurrentPmSyncJob job;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.reference.api.dto.GradeDTO;
import com.transformuk.hee.tis.reference.api.dto.SiteDTO;
import com.transformuk.hee.tis.reference.api.dto.TrustDTO;
Expand Down Expand Up @@ -61,11 +62,14 @@ class DataRequestServiceTest {

private ReferenceServiceImpl referenceService;

private ProfileServiceImpl profileService;

@BeforeEach
void setUp() {
tcsService = mock(TcsServiceImpl.class);
referenceService = mock(ReferenceServiceImpl.class);
service = new DataRequestService(tcsService, referenceService);
profileService = mock(ProfileServiceImpl.class);
service = new DataRequestService(tcsService, referenceService, profileService);
}

@Test
Expand Down

0 comments on commit c3c7990

Please sign in to comment.