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

feat: DBC and HeeUser requests from TSS #252

Merged
merged 11 commits into from
Jul 12, 2024
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
3 changes: 2 additions & 1 deletion src/main/java/uk/nhs/tis/sync/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

@SpringBootApplication
@ComponentScan(basePackages = {"com.transformuk.hee.tis.tcs",
"uk.nhs.tis.sync", "com.transformuk.hee.tis.reference.client"})
"uk.nhs.tis.sync", "com.transformuk.hee.tis.reference.client",
"com.transformuk.hee.tis.profile.client"})
@EnableWebMvc
@EnableSpringDataWebSupport
@PropertySource({"classpath:/config/application.properties",
Expand Down
49 changes: 32 additions & 17 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 @@ -41,26 +44,29 @@
@Getter
public enum DmsDtoType {

CONTACT_DETAILS(ContactDetailsDTO.class, "tcs", "ContactDetails", null),
CURRICULUM(CurriculumDTO.class, "tcs", "Curriculum", CurriculumMapper.class),
CURRICULUM_MEMBERSHIP(CurriculumMembershipWrapperDto.class, "tcs", "CurriculumMembership",
CONTACT_DETAILS(ContactDetailsDTO.class, Schemas.TCS, "ContactDetails", null),
CURRICULUM(CurriculumDTO.class, Schemas.TCS, "Curriculum", CurriculumMapper.class),
CURRICULUM_MEMBERSHIP(CurriculumMembershipWrapperDto.class, Schemas.TCS, "CurriculumMembership",
CurriculumMembershipMapper.class),
GDC_DETAILS(GdcDetailsDTO.class, "tcs", "GdcDetails", null),
GMC_DETAILS(GmcDetailsDTO.class, "tcs", "GmcDetails", null),
GRADE(GradeDTO.class, "reference", "Grade", GradeMapper.class),
PERSON(PersonDTO.class, "tcs", "Person", PersonMapper.class),
PERSONAL_DETAILS(PersonalDetailsDTO.class, "tcs", "PersonalDetails", null),
PLACEMENT_DETAILS(PlacementSummaryDTO.class, "tcs", "Placement", PlacementSummaryMapper.class),
PLACEMENT_SPECIALTY(PlacementSpecialtyDTO.class, "tcs", "PlacementSpecialty",
DBC_DETAILS(DBCDTO.class, Schemas.REFERENCE, "DBC", null),
GDC_DETAILS(GdcDetailsDTO.class, Schemas.TCS, "GdcDetails", null),
GMC_DETAILS(GmcDetailsDTO.class, Schemas.TCS, "GmcDetails", null),
GRADE(GradeDTO.class, Schemas.REFERENCE, "Grade", GradeMapper.class),
HEE_USER(HeeUserDTO.class, Schemas.AUTH, "HeeUser", HeeUserMapper.class),
PERSON(PersonDTO.class, Schemas.TCS, "Person", PersonMapper.class),
PERSONAL_DETAILS(PersonalDetailsDTO.class, Schemas.TCS, "PersonalDetails", null),
PLACEMENT_DETAILS(PlacementSummaryDTO.class, Schemas.TCS, "Placement",
PlacementSummaryMapper.class),
PLACEMENT_SPECIALTY(PlacementSpecialtyDTO.class, Schemas.TCS, "PlacementSpecialty",
PlacementSpecialtyMapper.class),
POST(PostDTO.class, "tcs", "Post", PostMapper.class),
PROGRAMME(ProgrammeDTO.class, "tcs", "Programme", ProgrammeMapper.class),
PROGRAMME_MEMBERSHIP(ProgrammeMembershipDTO.class, "tcs", "ProgrammeMembership",
POST(PostDTO.class, Schemas.TCS, "Post", PostMapper.class),
PROGRAMME(ProgrammeDTO.class, Schemas.TCS, "Programme", ProgrammeMapper.class),
PROGRAMME_MEMBERSHIP(ProgrammeMembershipDTO.class, Schemas.TCS, "ProgrammeMembership",
ProgrammeMembershipMapper.class),
QUALIFICATION(QualificationDTO.class, "tcs", "Qualification", QualificationMapper.class),
SITE(SiteDTO.class, "reference", "Site", SiteMapper.class),
SPECIALTY(SpecialtyDTO.class, "tcs", "Specialty", SpecialtyMapper.class),
TRUST(TrustDTO.class, "reference", "Trust", TrustMapper.class);
QUALIFICATION(QualificationDTO.class, Schemas.TCS, "Qualification", QualificationMapper.class),
SITE(SiteDTO.class, Schemas.REFERENCE, "Site", SiteMapper.class),
SPECIALTY(SpecialtyDTO.class, Schemas.TCS, "Specialty", SpecialtyMapper.class),
TRUST(TrustDTO.class, Schemas.REFERENCE, "Trust", TrustMapper.class);

private final Class<?> dtoType;
private final String schema;
Expand All @@ -81,4 +87,13 @@ public static DmsDtoType fromDto(Object dto) {
}
return null;
}

/**
* Define the schema names.
*/
private static class Schemas {
JosephKelly marked this conversation as resolved.
Show resolved Hide resolved
public static final String AUTH = "auth";
public static final String REFERENCE = "reference";
public static final String TCS = "tcs";
}
}
17 changes: 17 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,17 @@
package uk.nhs.tis.sync.dto;

import lombok.Data;

/**
* A DTO for transferring HeeUser data to the DMS.
*/
@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";
}
}
22 changes: 21 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,7 @@
package uk.nhs.tis.sync.service;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.reference.api.dto.DBCDTO;
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 @@ -15,6 +17,7 @@
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import uk.nhs.tis.sync.dto.CurriculumMembershipWrapperDto;

Expand All @@ -24,7 +27,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 +44,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 +83,17 @@ 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");
ResponseEntity<DBCDTO> responseEntity = referenceServiceImpl.getDBCByCode(dbc);
return createNonNullList(responseEntity.getBody());
}

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
63 changes: 63 additions & 0 deletions src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package uk.nhs.tis.sync.mapper;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.transformuk.hee.tis.profile.dto.RoleDTO;
import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO;
import com.transformuk.hee.tis.profile.service.dto.UserProgrammeDTO;
import com.transformuk.hee.tis.profile.service.dto.UserTrustDTO;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import uk.nhs.tis.sync.dto.HeeUserDmsDto;

class HeeUserMapperTest {

private HeeUserMapper mapper;

private HeeUserDTO heeUserDto;

@BeforeEach
public void setUp() {
mapper = new HeeUserMapperImpl();

heeUserDto = new HeeUserDTO();
heeUserDto.setActive(true);
heeUserDto.setAssociatedProgrammes(Collections.singleton(new UserProgrammeDTO()));
heeUserDto.setAssociatedTrusts(Collections.singleton(new UserTrustDTO()));
heeUserDto.setFirstName("first name");
heeUserDto.setName("name");
heeUserDto.setDesignatedBodyCodes(Collections.singleton("dbc1"));
heeUserDto.setEmailAddress("email");
heeUserDto.setGmcId("gmc");
heeUserDto.setLastName("last name");
heeUserDto.setPassword("password");
heeUserDto.setPhoneNumber("phone");
heeUserDto.setRoles(Collections.singleton(new RoleDTO()));
heeUserDto.setTemporaryPassword(true);
}

@Test
void shouldMapAHeeUserDtoToADataDmsDto() {
HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto);

assertEquals("1", heeUserDmsDto.getActive());
assertEquals("name", heeUserDmsDto.getName());
assertEquals("first name", heeUserDmsDto.getFirstName());
assertEquals("gmc", heeUserDmsDto.getGmcId());
assertEquals("last name", heeUserDmsDto.getLastName());
assertEquals("email", heeUserDmsDto.getEmailAddress());
assertEquals("phone", heeUserDmsDto.getPhoneNumber());
//other HeeUserDto properties are ignored
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
void shouldMapBooleansToZeroOrOneString(boolean bool) {
heeUserDto.setActive(bool);
HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto);
assertEquals(bool ? "1" : "0", heeUserDmsDto.getActive());
}
}
Loading
Loading