Skip to content

Commit

Permalink
GAP-2132 fixing dtos mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicwest committed Aug 28, 2023
1 parent 39f2823 commit fec758b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,14 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.io.*;
import java.util.List;
import java.util.UUID;

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

@Log4j2
@RestController
@RequestMapping("/submissions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
import com.auth0.jwt.interfaces.DecodedJWT;
import gov.cabinetoffice.gap.adminbackend.dtos.MigrateUserDto;
import gov.cabinetoffice.gap.adminbackend.dtos.UserDTO;
import gov.cabinetoffice.gap.adminbackend.exceptions.ForbiddenException;
import gov.cabinetoffice.gap.adminbackend.exceptions.UnauthorizedException;
import gov.cabinetoffice.gap.adminbackend.mappers.UserMapper;
import gov.cabinetoffice.gap.adminbackend.models.AdminSession;
import gov.cabinetoffice.gap.adminbackend.security.AuthManager;
import gov.cabinetoffice.gap.adminbackend.services.JwtService;
import gov.cabinetoffice.gap.adminbackend.services.UserService;
import gov.cabinetoffice.gap.adminbackend.utils.HelperUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package gov.cabinetoffice.gap.adminbackend.dtos;

public record DepartmentDto(Integer id, String name, String ggisID) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package gov.cabinetoffice.gap.adminbackend.dtos;

public record RoleDto(Integer id, String name, String label, String description) {
}
12 changes: 0 additions & 12 deletions src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/UserDTO.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package gov.cabinetoffice.gap.adminbackend.dtos;

import io.micrometer.core.lang.Nullable;
import lombok.Builder;
import lombok.Data;

import java.time.Instant;

@Data
@Builder
public class UserDTO {

private String firstName;
Expand All @@ -18,11 +13,4 @@ public class UserDTO {

private String emailAddress;

private String gapUserId;

private String sub;

@Nullable
private Instant created;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gov.cabinetoffice.gap.adminbackend.dtos;

import lombok.Builder;

import javax.annotation.Nullable;
import java.time.Instant;
import java.util.List;

@Builder
public record UserV2DTO(String gapUserId, String emailAddress, String sub, List<RoleDto> roles, RoleDto role,
@Nullable DepartmentDto department, @Nullable Instant created) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry;
import com.google.common.collect.Lists;
import gov.cabinetoffice.gap.adminbackend.constants.AWSConstants;
import gov.cabinetoffice.gap.adminbackend.dtos.UserDTO;
import gov.cabinetoffice.gap.adminbackend.dtos.UserV2DTO;
import gov.cabinetoffice.gap.adminbackend.dtos.application.ApplicationFormDTO;
import gov.cabinetoffice.gap.adminbackend.dtos.submission.LambdaSubmissionDefinition;
import gov.cabinetoffice.gap.adminbackend.dtos.submission.SubmissionExportsDTO;
Expand Down Expand Up @@ -334,8 +334,8 @@ private String getEmailFromUserId(final String userId, final String authHeader)
final HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Authorization", authHeader);
HttpEntity<?> httpEntity = new HttpEntity<>(requestHeaders);
final ResponseEntity<UserDTO> user = restTemplate.exchange(url, HttpMethod.GET, httpEntity, UserDTO.class);
return user.getBody().getEmailAddress();
final ResponseEntity<UserV2DTO> user = restTemplate.exchange(url, HttpMethod.GET, httpEntity, UserV2DTO.class);
return user.getBody().emailAddress();
}

public void updateExportStatus(String submissionId, String batchExportId, GrantExportStatus status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.model.AmazonSQSException;
import gov.cabinetoffice.gap.adminbackend.annotations.WithAdminSession;
import gov.cabinetoffice.gap.adminbackend.dtos.UserDTO;
import gov.cabinetoffice.gap.adminbackend.dtos.UserV2DTO;
import gov.cabinetoffice.gap.adminbackend.dtos.application.ApplicationAuditDTO;
import gov.cabinetoffice.gap.adminbackend.dtos.application.ApplicationFormDTO;
import gov.cabinetoffice.gap.adminbackend.dtos.submission.*;
Expand Down Expand Up @@ -458,19 +458,19 @@ void happyPath() {
.build())
.scheme(SchemeEntity.builder().id(1).name("testSchemeName").build()).submittedDate(zonedDateTime)
.build();
final UserDTO userDTO = UserDTO.builder().emailAddress("testEmailAddress").build();
final UserV2DTO userDTO = UserV2DTO.builder().emailAddress("testEmailAddress").build();

when(grantExportRepository.existsById(any(GrantExportId.class))).thenReturn(true);
when(submissionRepository.findByIdWithApplicant(any(UUID.class))).thenReturn(Optional.of(submission));
when(submissionMapper.submissionToLambdaSubmissionDefinition(any(Submission.class))).thenCallRealMethod();
when(restTemplate.exchange(anyString(), any(), any(), eq(UserDTO.class)))
when(restTemplate.exchange(anyString(), any(), any(), eq(UserV2DTO.class)))
.thenReturn(new ResponseEntity<>(userDTO, HttpStatus.OK));

final LambdaSubmissionDefinition actual = submissionsService.getSubmissionInfo(UUID.randomUUID(),
UUID.randomUUID(), authHeader);
final LambdaSubmissionDefinition expected = submissionMapper
.submissionToLambdaSubmissionDefinition(submission);
expected.setEmail(userDTO.getEmailAddress());
expected.setEmail(userDTO.emailAddress());

assertEquals(expected, actual);
}
Expand Down

0 comments on commit fec758b

Please sign in to comment.