Skip to content
Draft
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
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
<sonar.password/>
<sonar.projectKey>uk.gov.companieshouse:dissolution-api</sonar.projectKey>
<sonar.java.binaries>${project.basedir}/target,${project.basedir}/target/*</sonar.java.binaries>
<!-- Source: https://mvnrepository.com/artifact/org.mapstruct/mapstruct -->
<mapstruct.version>1.6.3</mapstruct.version>

</properties>

Expand Down Expand Up @@ -569,6 +571,12 @@
<artifactId>testcontainers-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -597,6 +605,17 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import uk.gov.companieshouse.exception.DissolutionNotFoundException;
import uk.gov.companieshouse.exception.NotFoundException;
import uk.gov.companieshouse.logging.Logger;
import uk.gov.companieshouse.model.domain.DissolutionUserData;
import uk.gov.companieshouse.model.dto.companyofficers.CompanyOfficer;
import uk.gov.companieshouse.model.dto.companyprofile.CompanyProfile;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionCreateRequest;
Expand All @@ -37,6 +38,7 @@

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;

import java.util.Map;

import static uk.gov.companieshouse.util.EricHelper.getEmail;
Expand Down Expand Up @@ -98,7 +100,7 @@ public DissolutionCreateResponse submitDissolutionRequest(
throw new BadRequestException(error);
});

return dissolutionService.create(body, company, directors, userId, request.getRemoteAddr(), getEmail(authorisedUser));
return dissolutionService.create(body, company, directors, new DissolutionUserData(userId, getEmail(authorisedUser), request.getRemoteAddr()));
}

@Operation(summary = "Get Dissolution Application", tags = "Dissolution")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import uk.gov.companieshouse.api.model.transaction.TransactionStatus;
import uk.gov.companieshouse.exception.BadRequestException;
import uk.gov.companieshouse.exception.ConflictException;
import uk.gov.companieshouse.model.domain.DissolutionUserData;
import uk.gov.companieshouse.model.dto.companyprofile.CompanyProfile;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionCreateDraftResponse;
import uk.gov.companieshouse.sdk.manager.ApiSdkManager;
Expand Down Expand Up @@ -78,6 +79,6 @@ public DissolutionCreateDraftResponse submitDraftDissolution(
throw new BadRequestException("Company must be of a closable type, have an active status and must not be an overseas company");
}

return dissolutionService.createDraft(transaction, company, userId, request.getRemoteAddr(), getEmail(authorisedUser));
return dissolutionService.createDraft(transaction, company, new DissolutionUserData(userId, getEmail(authorisedUser), request.getRemoteAddr()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uk.gov.companieshouse.mapper;

import org.mapstruct.Mapper;
import uk.gov.companieshouse.api.model.company.CompanyProfileApi;
import uk.gov.companieshouse.model.dto.companyprofile.CompanyProfile;

@Mapper(componentModel = "spring")
public interface CompanyProfileMapper {
CompanyProfile mapToCompanyProfile(CompanyProfileApi companyProfileApi);
}
14 changes: 14 additions & 0 deletions src/main/java/uk/gov/companieshouse/mapper/CreatedByMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package uk.gov.companieshouse.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import uk.gov.companieshouse.model.db.dissolution.CreatedBy;
import uk.gov.companieshouse.model.domain.DissolutionUserData;
import uk.gov.companieshouse.util.DateTimeGenerator;

@Mapper(componentModel = "spring", imports = DateTimeGenerator.class)
public interface CreatedByMapper {

@Mapping(target = "dateTime", expression = "java(DateTimeGenerator.generateCurrentDateTime())")
CreatedBy mapToCreatedBy(DissolutionUserData userData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import org.springframework.stereotype.Service;
import uk.gov.companieshouse.model.db.dissolution.Dissolution;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionDirectorPatchResponse;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionLinks;

@Service
public class DissolutionDirectorResponseMapper extends ResponseMapper {
public class DissolutionDirectorResponseMapper {

public DissolutionDirectorPatchResponse mapToDissolutionDirectorPatchResponse(Dissolution dissolution) {
final DissolutionDirectorPatchResponse response = new DissolutionDirectorPatchResponse();

response.setLinks(generateLinks(
response.setLinks(DissolutionLinks.of(
dissolution.getCompany().getNumber(),
dissolution.getData().getApplication().getReference()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@
@Service
public class DissolutionRequestMapper {

private final CreatedByMapper createdByMapper;

public DissolutionRequestMapper(CreatedByMapper createdByMapper) {
this.createdByMapper = createdByMapper;
}

public Dissolution mapToDissolution(DissolutionCreateRequest body, CompanyProfile company, Map<String, CompanyOfficer> directors, DissolutionUserData userData, String reference, String barcode) {
final Dissolution dissolution = new Dissolution();

dissolution.setModifiedDateTime(generateCurrentDateTime());
dissolution.setData(mapToDissolutionData(body, company.getType(), directors, reference, barcode));
dissolution.setCompany(mapToCompany(company.getCompanyNumber(), company.getCompanyName()));
dissolution.setCreatedBy(mapToCreatedBy(userData.getUserId(), userData.getEmail(), userData.getIpAddress()));
dissolution.setData(mapToDissolutionData(body, company.type(), directors, reference, barcode));
dissolution.setCompany(mapToCompany(company.companyNumber(), company.companyName()));
dissolution.setCreatedBy(createdByMapper.mapToCreatedBy(userData));
dissolution.setActive(true);

return dissolution;
}

public Dissolution mapToDraftDissolution(Transaction transaction, CompanyProfile company, DissolutionUserData userData) {
final DissolutionApplication application = new DissolutionApplication();
application.setType(company.getType().equals(CompanyType.LLP.getValue()) ? ApplicationType.LLDS01 : ApplicationType.DS01);
application.setType(company.type().equals(CompanyType.LLP.getValue()) ? ApplicationType.LLDS01 : ApplicationType.DS01);

final DissolutionData data = new DissolutionData();
data.setETag(GenerateEtagUtil.generateEtag());
Expand All @@ -51,8 +57,8 @@ public Dissolution mapToDraftDissolution(Transaction transaction, CompanyProfile
final Dissolution dissolution = new Dissolution();
dissolution.setModifiedDateTime(generateCurrentDateTime());
dissolution.setData(data);
dissolution.setCompany(mapToCompany(company.getCompanyNumber(), company.getCompanyName()));
dissolution.setCreatedBy(mapToCreatedBy(userData.getUserId(), userData.getEmail(), userData.getIpAddress()));
dissolution.setCompany(mapToCompany(company.companyNumber(), company.companyName()));
dissolution.setCreatedBy(createdByMapper.mapToCreatedBy(userData));
// The active flag must be false so that transaction model dissolution applications
// do not get picked up by the pre-migration dissolution process.
dissolution.setActive(false);
Expand Down Expand Up @@ -111,15 +117,4 @@ private Company mapToCompany(String companyNumber, String companyName) {

return company;
}

private CreatedBy mapToCreatedBy(String userId, String email, String ip) {
final CreatedBy createdBy = new CreatedBy();

createdBy.setUserId(userId);
createdBy.setEmail(email);
createdBy.setIpAddress(ip);
createdBy.setDateTime(generateCurrentDateTime());

return createdBy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uk.gov.companieshouse.model.dto.dissolution.DissolutionCreateResponse;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionGetDirector;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionGetResponse;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionLinks;
import uk.gov.companieshouse.model.dto.dissolution.DissolutionPatchResponse;

import java.sql.Timestamp;
Expand All @@ -19,15 +20,15 @@
import static uk.gov.companieshouse.model.Constants.DISSOLUTION_KIND;

@Service
public class DissolutionResponseMapper extends ResponseMapper {
public class DissolutionResponseMapper {

public DissolutionCreateResponse mapToDissolutionCreateResponse(Dissolution dissolution) {
final DissolutionCreateResponse response = new DissolutionCreateResponse();

final String reference = dissolution.getData().getApplication().getReference();

response.setApplicationReferenceNumber(reference);
response.setLinks(generateLinks(dissolution.getCompany().getNumber(), reference));
response.setLinks(DissolutionLinks.of(dissolution.getCompany().getNumber(), reference));

return response;
}
Expand All @@ -36,7 +37,7 @@ public DissolutionCreateDraftResponse mapToDissolutionCreateDraftResponse(Transa
final DissolutionCreateDraftResponse response = new DissolutionCreateDraftResponse();

response.setDissolutionId(dissolution.getId());
response.setLinks(generateDissolutionLinks(dissolution.getCompany().getNumber(), transaction.getId()));
response.setLinks(DissolutionLinks.forTransaction(dissolution.getCompany().getNumber(), transaction.getId()));

return response;
}
Expand All @@ -48,7 +49,7 @@ public DissolutionGetResponse mapToDissolutionGetResponse(Dissolution dissolutio

response.setETag(dissolution.getData().getETag());
response.setKind(DISSOLUTION_KIND);
response.setLinks(generateLinks(dissolution.getCompany().getNumber(), reference));
response.setLinks(DissolutionLinks.of(dissolution.getCompany().getNumber(), reference));
response.setApplicationStatus(dissolution.getData().getApplication().getStatus());
response.setApplicationReference(reference);
response.setApplicationType(dissolution.getData().getApplication().getType());
Expand Down Expand Up @@ -81,7 +82,7 @@ public DissolutionGetResponse mapToDissolutionGetResponse(Dissolution dissolutio
public DissolutionPatchResponse mapToDissolutionPatchResponse(Dissolution dissolution) {
final DissolutionPatchResponse response = new DissolutionPatchResponse();

response.setLinks(generateLinks(
response.setLinks(DissolutionLinks.of(
dissolution.getCompany().getNumber(),
dissolution.getData().getApplication().getReference()
));
Expand Down

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/uk/gov/companieshouse/mapper/ResponseMapper.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
package uk.gov.companieshouse.model.domain;

public class DissolutionUserData {
private String userId;
private String email;
private String ipAddress;

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getIpAddress() {
return ipAddress;
}

public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
}
public record DissolutionUserData(String userId, String email, String ipAddress) {}
Loading