diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e81128a3..94c7716a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,10 +32,10 @@ jobs: with: fetch-depth: '0' token: ${{ secrets.BOT_TOKEN }} - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - uses: actions/cache@v1 with: diff --git a/.java-version b/.java-version new file mode 100644 index 000000000..aabe6ec39 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +21 diff --git a/_infra/docker/Dockerfile b/_infra/docker/Dockerfile index 660580fcc..8674d5ed0 100644 --- a/_infra/docker/Dockerfile +++ b/_infra/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jre-alpine +FROM eclipse-temurin:21-jre-alpine ARG JAR_FILE=case.jar diff --git a/_infra/helm/case/Chart.yaml b/_infra/helm/case/Chart.yaml index c8f8c67dd..4ffcdd87f 100644 --- a/_infra/helm/case/Chart.yaml +++ b/_infra/helm/case/Chart.yaml @@ -14,8 +14,8 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. -version: 12.0.24 +version: 12.0.25 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. -appVersion: 12.0.24 +appVersion: 12.0.25 diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml new file mode 100644 index 000000000..930a4a6d4 --- /dev/null +++ b/checkstyle-suppressions.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/checkstyle.xml b/checkstyle.xml index b4967e311..7b079eb83 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -1,6 +1,6 @@ + "https://checkstyle.org/dtds/configuration_1_3.dtd"> UTF-8 UTF-8 + true @@ -40,14 +41,14 @@ com.google.cloud libraries-bom - 26.29.0 + 26.47.0 pom import com.google.cloud spring-cloud-gcp-dependencies - 3.7.8 + 5.6.0 pom import @@ -133,6 +134,12 @@ spring-cloud-gcp-starter-pubsub + + javax.servlet + javax.servlet-api + 3.1.0 + + @@ -157,15 +164,36 @@ 1.18.30 + + + com.github.tomakehurst wiremock 2.27.2 test - - com.vladmihalcea - hibernate-types-5 - 2.21.1 + + + + + + + + + + + + + + + + + + + + org.hibernate + hibernate-core + 6.5.2.Final org.liquibase @@ -184,7 +212,7 @@ net.logstash.logback logstash-logback-encoder - 6.6 + 8.0 @@ -207,13 +235,13 @@ com.fasterxml.jackson.module jackson-module-jaxb-annotations - 2.7.0 + ${jackson.version} com.godaddy logging - ${godaddylogging.version} + 1.2.5 @@ -230,12 +258,12 @@ com.sun.xml.bind jaxb-core - 4.0.4 + 4.0.5 com.sun.xml.bind jaxb-impl - 4.0.4 + 4.0.5 @@ -287,14 +315,14 @@ org.mockito mockito-core - 5.5.0 + 5.14.1 test net.bytebuddy byte-buddy - 1.14.8 + 1.15.3 @@ -373,16 +401,17 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.8.1 ${java.version} ${java.version} + true org.apache.maven.plugins maven-surefire-plugin - ${surefire.version} + 3.2.5 org.apache.maven.surefire @@ -395,6 +424,14 @@ org.apache.maven.plugins maven-checkstyle-plugin 3.3.1 + + + + true + + checkstyle-suppressions.xml + checkstyle.suppressions.file + org.springframework.boot @@ -420,6 +457,16 @@ source. This seemed to be the only solution --> --add-opens java.base/java.util=ALL-UNNAMED + ${failsafe.skipITs} + + + **/CaseActionEventIT.java + **/CaseReceiptReceiverIT.java + **/CaseActionEventIT.java + **/CaseEndpointIT.java + + **/CachingTestIT.java + diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/CaseSvcApplication.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/CaseSvcApplication.java index 5ac7c7ed9..eaf877343 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/CaseSvcApplication.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/CaseSvcApplication.java @@ -95,7 +95,7 @@ public CustomSpringLiquibase liquibase() { liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema()); liquibase.setDropFirst(liquibaseProperties.isDropFirst()); liquibase.setShouldRun(true); - liquibase.setLabels(liquibaseProperties.getLabels()); + // liquibase.setLabels(liquibaseProperties.getLabels()); liquibase.setChangeLogParameters(liquibaseProperties.getParameters()); liquibase.setLiquibaseSchema(liquibaseProperties.getLiquibaseSchema()); return new CustomSpringLiquibase(liquibase); diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Case.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Case.java index 40f275b71..699a6d255 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Case.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Case.java @@ -1,23 +1,23 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.PostLoad; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; +import jakarta.persistence.Version; import java.io.Serializable; import java.sql.Timestamp; import java.util.List; import java.util.UUID; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.PostLoad; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.persistence.Version; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionAuditEvent.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionAuditEvent.java index 89fa8d68b..2ba4d1919 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionAuditEvent.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionAuditEvent.java @@ -1,11 +1,11 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import java.io.Serializable; import java.math.BigInteger; import java.sql.Timestamp; import java.util.UUID; -import javax.persistence.*; -import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionEventRequest.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionEventRequest.java index c64785121..305d04a6d 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionEventRequest.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionEventRequest.java @@ -1,11 +1,11 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import java.io.Serializable; import java.math.BigInteger; import java.sql.Timestamp; import java.util.UUID; -import javax.persistence.*; -import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionTemplate.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionTemplate.java index 0982c3a6f..fcb467512 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionTemplate.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseActionTemplate.java @@ -1,8 +1,8 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import java.io.Serializable; -import javax.persistence.*; -import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseEvent.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseEvent.java index e01f4be9d..26a3ba32c 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseEvent.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseEvent.java @@ -1,26 +1,19 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; -import com.vladmihalcea.hibernate.type.json.JsonBinaryType; +// import com.vladmihalcea.hibernate.type.json.JsonBinaryType; + +import jakarta.persistence.*; import java.io.Serializable; import java.sql.Timestamp; import java.util.Map; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.annotations.Parameter; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; -import org.hibernate.annotations.TypeDefs; +import org.hibernate.type.SqlTypes; import uk.gov.ons.ctp.response.casesvc.representation.CategoryDTO; /** Domain model object. */ @@ -29,7 +22,8 @@ @Builder @AllArgsConstructor @NoArgsConstructor -@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)}) +// @TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)}) +// @Convert(attributeName = "entityAttrName", converter = JsonBinaryType.class) @Table(name = "caseevent", schema = "casesvc") public class CaseEvent implements Serializable { @@ -66,6 +60,7 @@ public class CaseEvent implements Serializable { private String subCategory; @Column(name = "metadata") - @Type(type = "jsonb") + // @Type(type = "jsonb") + @JdbcTypeCode(SqlTypes.JSON) private Map metadata; } diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java index b5c840ee7..e36791ebd 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java @@ -1,16 +1,16 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; import java.sql.Timestamp; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroupStatusAudit.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroupStatusAudit.java index a8c5ac09b..3d5baa570 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroupStatusAudit.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroupStatusAudit.java @@ -1,13 +1,13 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.sql.Timestamp; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseIacAudit.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseIacAudit.java index 56d114ccd..a06b5a60b 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseIacAudit.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseIacAudit.java @@ -1,12 +1,12 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.sql.Timestamp; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Category.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Category.java index b4a6cb7db..0ba3b2d9c 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Category.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/Category.java @@ -1,12 +1,12 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.Id; -import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventEndpoint.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventEndpoint.java index d42917a8f..878152929 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventEndpoint.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventEndpoint.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.godaddy.logging.Logger; import com.godaddy.logging.LoggerFactory; +import jakarta.validation.Valid; import java.util.concurrent.ExecutionException; -import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionTemplateEndpoint.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionTemplateEndpoint.java index 8f27588ed..8f7b50b6e 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionTemplateEndpoint.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionTemplateEndpoint.java @@ -2,8 +2,8 @@ import com.godaddy.logging.Logger; import com.godaddy.logging.LoggerFactory; +import jakarta.validation.Valid; import java.net.URI; -import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpoint.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpoint.java index bbf1c457e..3989761c3 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpoint.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpoint.java @@ -1,14 +1,14 @@ package uk.gov.ons.ctp.response.casesvc.endpoint; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +// import com.godaddy.logging.Logger; +// import com.godaddy.logging.LoggerFactory; +import jakarta.validation.Valid; import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; -import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.util.CollectionUtils; @@ -38,7 +38,7 @@ @RestController @RequestMapping(value = "/cases", produces = "application/json") public final class CaseEndpoint implements CTPEndpoint { - private static final Logger log = LoggerFactory.getLogger(CaseEndpoint.class); + // private static final Logger log = LoggerFactory.getLogger(CaseEndpoint.class); public static final String CATEGORY_ACCESS_CODE_AUTHENTICATION_ATTEMPT_NOT_FOUND = "Category ACCESS_CODE_AUTHENTICATION_ATTEMPT does not exist"; @@ -78,7 +78,7 @@ public ResponseEntity findCaseById( @RequestParam(value = "caseevents", required = false) boolean caseevents, @RequestParam(value = "iac", required = false) boolean iac) throws CTPException { - log.with("case_id", caseId).debug("Entering findCaseById"); + // log.with("case_id", caseId).debug("Entering findCaseById"); Case caseObj = caseService.findCaseById(caseId); if (caseObj == null) { throw new CTPException( @@ -94,7 +94,7 @@ public ResponseEntity> findCasesBySampleUnitIds( @RequestParam(value = "sampleUnitId") final List sampleUnitIds, @RequestParam(value = "caseevents", required = false) final boolean caseevents, @RequestParam(value = "iac", required = false) final boolean iac) { - + System.out.println("**** HERE 3 ****"); List cases = sampleUnitIds .stream() @@ -106,7 +106,8 @@ public ResponseEntity> findCasesBySampleUnitIds( return cdd; }) .collect(Collectors.toList()); - + System.out.println("**** caseId: " + cases.get(0).getId()); + System.out.println("**** HERE 4 ****"); return ResponseEntity.ok(cases); } @@ -129,9 +130,9 @@ public ResponseEntity> findCasesByPartyId( List casesList; if (maxCasesPerSurvey != null) { - log.with("party_id", partyId) - .with("max_cases_per_survey", maxCasesPerSurvey) - .info("Retrieving cases by party"); + // log.with("party_id", partyId) + // .with("max_cases_per_survey", maxCasesPerSurvey) + // .info("Retrieving cases by party"); casesList = caseService.findCasesByPartyIdLimitedPerSurvey(partyId, iac, maxCasesPerSurvey); } else { @@ -158,7 +159,7 @@ public ResponseEntity> findCasesByPartyId( @RequestMapping(value = "/surveyid/{surveyId}", method = RequestMethod.GET) public ResponseEntity> findCasesBySurveyId( @PathVariable("surveyId") final UUID surveyId) { - log.with("survey_id", surveyId).debug("Retrieving cases by survey"); + // log.with("survey_id", surveyId).debug("Retrieving cases by survey"); List caseGroupsList = caseGroupService.findCaseGroupBySurveyId(surveyId); List cases = new ArrayList<>(); @@ -189,7 +190,7 @@ public ResponseEntity findCaseByIac( @RequestParam(value = "caseevents", required = false) final boolean caseevents, @RequestParam(value = "iac", required = false) final boolean iacFlag) throws CTPException { - log.debug("Retrieving case by iac"); + // log.debug("Retrieving case by iac"); Case targetCase = caseService.findCaseByIac(iac); if (targetCase == null) { throw new CTPException( @@ -238,7 +239,7 @@ public ResponseEntity> findCasesInCaseGroup( @PathVariable("casegroupId") final UUID casegroupId, @RequestParam(value = "iac", required = false) final boolean iacFlag) throws CTPException { - log.with("case_group_id", casegroupId).debug("Entering findCasesInCaseGroup"); + // log.with("case_group_id", casegroupId).debug("Entering findCasesInCaseGroup"); CaseGroup caseGroup = caseGroupService.findCaseGroupById(casegroupId); if (caseGroup == null) { @@ -273,7 +274,7 @@ public ResponseEntity> findCaseEventsByCaseId( @PathVariable("caseId") final UUID caseId, @RequestParam(value = "category", required = false) final List categories) throws CTPException { - log.with("case_id", caseId).debug("Entering findCaseEventsByCaseId"); + // log.with("case_id", caseId).debug("Entering findCaseEventsByCaseId"); Case caze = caseService.findCaseById(caseId); if (caze == null) { throw new CTPException( @@ -314,9 +315,9 @@ public ResponseEntity createCaseEvent( @RequestBody @Valid final CaseEventCreationRequestDTO caseEventCreationRequestDTO, BindingResult bindingResult) throws CTPException, InvalidRequestException { - log.with("case_id", caseId) - .with("category", caseEventCreationRequestDTO.getCategory()) - .debug("Creating case event"); + // log.with("case_id", caseId) + // .with("category", caseEventCreationRequestDTO.getCategory()) + // .debug("Creating case event"); if (bindingResult.hasErrors()) { throw new InvalidRequestException("Binding errors for case event creation: ", bindingResult); } diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpoint.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpoint.java index d3f96c5ae..667ed9375 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpoint.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpoint.java @@ -1,7 +1,7 @@ package uk.gov.ons.ctp.response.casesvc.endpoint; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +// import com.godaddy.logging.Logger; +// import com.godaddy.logging.LoggerFactory; import java.net.URI; import java.util.List; import java.util.UUID; @@ -24,7 +24,7 @@ @RequestMapping(value = "/cases/{caseId}/iac", produces = "application/json") public final class CaseIACEndpoint implements CTPEndpoint { - private static final Logger log = LoggerFactory.getLogger(CaseIACEndpoint.class); + // private static final Logger log = LoggerFactory.getLogger(CaseIACEndpoint.class); private CaseService caseService; private CaseIACService caseIACService; @@ -37,7 +37,7 @@ public CaseIACEndpoint(CaseService caseService, CaseIACService caseIACService) { @RequestMapping(method = RequestMethod.POST) public ResponseEntity generateIACCode(@PathVariable("caseId") final UUID caseId) { - log.debug("Generating iac code for caseId {}", caseId); + // log.debug("Generating iac code for caseId {}", caseId); Case actualCase = caseService.findCaseById(caseId); @@ -55,7 +55,7 @@ public ResponseEntity generateIACCode(@PathVariable("caseId") final @RequestMapping(method = RequestMethod.GET) public ResponseEntity> getIACCodes(@PathVariable("caseId") final UUID caseId) { - log.debug("Get all iac codes for caseId {}", caseId); + // log.debug("Get all iac codes for caseId {}", caseId); Case actualCase = caseService.findCaseById(caseId); diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/message/sampleunitnotification/SampleUnit.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/message/sampleunitnotification/SampleUnit.java index f70d26272..e76605a79 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/message/sampleunitnotification/SampleUnit.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/message/sampleunitnotification/SampleUnit.java @@ -1,6 +1,6 @@ package uk.gov.ons.ctp.response.casesvc.message.sampleunitnotification; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventCreationRequestDTO.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventCreationRequestDTO.java index 51bb9e69b..ff498cb49 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventCreationRequestDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventCreationRequestDTO.java @@ -1,8 +1,8 @@ package uk.gov.ons.ctp.response.casesvc.representation; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.Map; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventDTO.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventDTO.java index a87bf5562..ebee27392 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CaseEventDTO.java @@ -1,9 +1,9 @@ package uk.gov.ons.ctp.response.casesvc.representation; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.Date; import java.util.Map; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CreatedCaseEventDTO.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CreatedCaseEventDTO.java index 831d5a166..465c93253 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CreatedCaseEventDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/CreatedCaseEventDTO.java @@ -1,10 +1,10 @@ package uk.gov.ons.ctp.response.casesvc.representation; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.Date; import java.util.Map; import java.util.UUID; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/action/CaseActionEvent.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/action/CaseActionEvent.java index bee6e6a91..6d1e3adfc 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/action/CaseActionEvent.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/representation/action/CaseActionEvent.java @@ -1,8 +1,8 @@ package uk.gov.ons.ctp.response.casesvc.representation.action; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.validation.constraints.NotNull; import java.util.UUID; -import javax.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseService.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseService.java index daa7aad41..664cde81c 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseService.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseService.java @@ -1,7 +1,7 @@ package uk.gov.ons.ctp.response.casesvc.service; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +// import com.godaddy.logging.Logger; +// import com.godaddy.logging.LoggerFactory; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; @@ -46,7 +46,7 @@ */ @Service public class CaseService { - private static final Logger log = LoggerFactory.getLogger(CaseService.class); + // private static final Logger log = LoggerFactory.getLogger(CaseService.class); public static final String WRONG_OLD_SAMPLE_UNIT_TYPE_MSG = "Old Case has sampleUnitType %s. It is expected to have sampleUnitType %s."; @@ -107,7 +107,7 @@ public Case findCaseById(final UUID id) { String iac = caseIacAuditService.findCaseIacByCasePK(caze.getCasePK()); caze.setIac(iac); } else { - log.with("case_id", id.toString()).warn("Could not find case"); + // log.with("case_id", id.toString()).warn("Could not find case"); } return caze; @@ -270,10 +270,10 @@ public CaseEvent createCaseEvent(final CaseEvent caseEvent, final Case targetCas */ public CaseEvent createCaseEvent(final CaseEvent caseEvent, final Timestamp timestamp) throws CTPException { - log.with("case_event", caseEvent).info("Creating case event"); + // log.with("case_event", caseEvent).info("Creating case event"); Case targetCase = caseRepo.findById(caseEvent.getCaseFK()).orElse(null); - log.with("target_case", targetCase).debug("Found target case"); + // log.with("target_case", targetCase).debug("Found target case"); if (targetCase == null) { return null; } @@ -297,7 +297,7 @@ public CaseEvent createCaseEvent(final CaseEvent caseEvent, final Timestamp time public CaseEvent createCaseEvent( final CaseEvent caseEvent, final Timestamp timestamp, final Case targetCase) throws CTPException { - log.with("case_event", caseEvent).debug("Creating case event"); + // log.with("case_event", caseEvent).debug("Creating case event"); Category category = categoryRepo.findById(caseEvent.getCategory()).orElse(null); validateCaseEventRequest(category, targetCase); @@ -305,7 +305,7 @@ public CaseEvent createCaseEvent( // save the case event to db caseEvent.setCreatedDateTime(DateTimeUtil.nowUTC()); CaseEvent createdCaseEvent = caseEventRepo.save(caseEvent); - log.debug("createdCaseEvent is {}", createdCaseEvent); + // log.debug("createdCaseEvent is {}", createdCaseEvent); transitionCaseGroupStatus(targetCase, caseEvent); @@ -325,7 +325,7 @@ public CaseEvent createCaseEvent( } effectTargetCaseStateTransition(category, targetCase); - log.with("case_event", caseEvent).debug("Successfully created case event"); + // log.with("case_event", caseEvent).debug("Successfully created case event"); return createdCaseEvent; } @@ -339,7 +339,7 @@ public CaseEvent createCaseEvent( readOnly = false, timeout = TRANSACTION_TIMEOUT) private void saveCaseIacAudit(final Case updatedCase) { - log.with("case_id", updatedCase.getId()).debug("Saving case iac audit"); + // log.with("case_id", updatedCase.getId()).debug("Saving case iac audit"); CaseIacAudit caseIacAudit = new CaseIacAudit(); caseIacAudit.setCaseFK(updatedCase.getCasePK()); caseIacAudit.setIac(updatedCase.getIac()); @@ -356,13 +356,13 @@ private void saveCaseIacAudit(final Case updatedCase) { private void generateAndStoreNewIAC(final Case targetCase) { String iac = targetCase.getIac(); if (iac == null || !internetAccessCodeSvcClient.isIacActive(iac)) { - log.with("case_id", targetCase.getId()).debug("Replacing existing case IAC"); + // log.with("case_id", targetCase.getId()).debug("Replacing existing case IAC"); String newIac = internetAccessCodeSvcClient.generateIACs(1).get(0); targetCase.setIac(newIac); caseRepo.saveAndFlush(targetCase); saveCaseIacAudit(targetCase); } else { - log.with("case_id", targetCase.getId()).debug("Existing IAC is still active"); + // log.with("case_id", targetCase.getId()).debug("Existing IAC is still active"); } } @@ -375,7 +375,7 @@ private void transitionCaseGroupStatus(final Case targetCase, final CaseEvent ca // The transition manager throws an exception if the event doesn't cause a transition, however // there are lots of // events which do not cause CaseGroupStatus transitions, (this is valid behaviour). - log.debug(e.getMessage()); + // log.debug(e.getMessage()); } } @@ -409,10 +409,10 @@ private void processActiveEnrolmentChange(final Case targetCase, final boolean e public void createInitialCase(SampleUnitParent sampleUnitParent) throws CTPException { try { CaseGroup newCaseGroup = createNewCaseGroup(sampleUnitParent); - log.with("caseGroupId", newCaseGroup.getId()) - .with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) - .with("sampleUnitRef", sampleUnitParent.getSampleUnitRef()) - .debug("Created new casegroup"); + // log.with("caseGroupId", newCaseGroup.getId()) + // .with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) + // .with("sampleUnitRef", sampleUnitParent.getSampleUnitRef()) + // .debug("Created new casegroup"); Category category = new Category(); category.setShortDescription("Initial creation of case"); @@ -426,35 +426,35 @@ public void createInitialCase(SampleUnitParent sampleUnitParent) throws CTPExcep Case childCase = createNewCase(sampleUnitChild, newCaseGroup); caseRepo.saveAndFlush(childCase); createCaseCreatedEvent(childCase, category); - log.with("caseId", childCase.getId().toString()) - .with("sampleUnitType", childCase.getSampleUnitType().toString()) - .with("sampleUnitRef", sampleUnitChild.getSampleUnitRef()) - .with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) - .debug("New child case created"); + // log.with("caseId", childCase.getId().toString()) + // .with("sampleUnitType", childCase.getSampleUnitType().toString()) + // .with("sampleUnitRef", sampleUnitChild.getSampleUnitRef()) + // .with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) + // .debug("New child case created"); updateCaseWithIACs(childCase, sampleUnitParent.getSampleUnitRef()); processCase(childCase); } } caseRepo.saveAndFlush(parentCase); createCaseCreatedEvent(parentCase, category); - log.with("caseId", parentCase.getId().toString()) - .with("sampleUnitTupe", parentCase.getSampleUnitType().toString()) - .with("sampleUnitRef", sampleUnitParent.getSampleUnitRef()) - .with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) - .info("New Case created"); + // log.with("caseId", parentCase.getId().toString()) + // .with("sampleUnitTupe", parentCase.getSampleUnitType().toString()) + // .with("sampleUnitRef", sampleUnitParent.getSampleUnitRef()) + // .with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) + // .info("New Case created"); updateCaseWithIACs(parentCase, sampleUnitParent.getSampleUnitRef()); processCase(parentCase); } catch (DataIntegrityViolationException exception) { - log.with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) - .with("sampleUnitRef", sampleUnitParent.getSampleUnitRef()) - .with("error", exception) - .warn("Case already exists. Ignoring case creation"); + // log.with("collectionExericseId", sampleUnitParent.getCollectionExerciseId()) + // .with("sampleUnitRef", sampleUnitParent.getSampleUnitRef()) + // .with("error", exception) + // .warn("Case already exists. Ignoring case creation"); } } @Async private void processCase(final Case caze) throws CTPException { - log.with("case_id", caze.getId()).debug("Processing case"); + // log.with("case_id", caze.getId()).debug("Processing case"); CaseDTO.CaseEvent event = null; CaseState initialState = caze.getState(); @@ -466,7 +466,7 @@ private void processCase(final Case caze) throws CTPException { event = CaseDTO.CaseEvent.REPLACED; break; default: - log.with("initial_state", initialState).error("Unexpected state found"); + // log.with("initial_state", initialState).error("Unexpected state found"); } Case updatedCase = transitionCase(caze, event); @@ -486,29 +486,29 @@ private Case transitionCase(final Case caze, final CaseDTO.CaseEvent event) thro */ private void updateCaseWithIACs(Case createdCase, String sampleUnitRef) { try { - log.with("caseId", createdCase.getId().toString()) - .with("sampleUnitRef", sampleUnitRef) - .info("About to call IAC service to generate an IAC code."); + // log.with("caseId", createdCase.getId().toString()) + // .with("sampleUnitRef", sampleUnitRef) + // .info("About to call IAC service to generate an IAC code."); updateCaseWithIACs(createdCase); - log.with("caseId", createdCase.getId().toString()) - .with("sampleUnitRef", sampleUnitRef) - .info("IAC received and saved"); + // log.with("caseId", createdCase.getId().toString()) + // .with("sampleUnitRef", sampleUnitRef) + // .info("IAC received and saved"); } catch (Exception e) { - log.with("caseId", createdCase.getId().toString()) - .with("sampleUnitRef", sampleUnitRef) - .error("Failed to obtain IAC codes", e); + // log.with("caseId", createdCase.getId().toString()) + // .with("sampleUnitRef", sampleUnitRef) + // .error("Failed to obtain IAC codes", e); } } public void updateCaseWithIACs(Case createdCase) { - log.with("caseId", createdCase.getId().toString()) - .info("Calling IAC service to generate an IAC code."); + // log.with("caseId", createdCase.getId().toString()) + // .info("Calling IAC service to generate an IAC code."); String iac = internetAccessCodeSvcClient.generateIACs(1).get(0); createdCase.setIac(iac); Case updatedCase = caseRepo.saveAndFlush(createdCase); updatedCase.setIac(iac); saveCaseIacAudit(updatedCase); - log.with("caseId", createdCase.getId().toString()).info("Case updated with IAC code."); + // log.with("caseId", createdCase.getId().toString()).info("Case updated with IAC code."); } /** @@ -529,7 +529,7 @@ private void validateCaseEventRequest(Category category, Case oldCase) { WRONG_OLD_SAMPLE_UNIT_TYPE_MSG, oldCaseSampleUnitType, expectedOldCaseSampleUnitTypes); - log.error(errorMsg); + // log.error(errorMsg); } } @@ -624,7 +624,7 @@ private void effectTargetCaseStateTransition(Category category, Case targetCase) * @param caseEventCategory the category of the event that led to the creation of the case */ private void createCaseCreatedEvent(Case caze, Category caseEventCategory) { - log.with("caseId", caze.getId().toString()).info("Creating case event."); + // log.with("caseId", caze.getId().toString()).info("Creating case event."); CaseEvent newCaseCaseEvent = new CaseEvent(); newCaseCaseEvent.setCaseFK(caze.getCasePK()); newCaseCaseEvent.setCategory(CategoryDTO.CategoryName.CASE_CREATED); @@ -634,7 +634,7 @@ private void createCaseCreatedEvent(Case caze, Category caseEventCategory) { String.format(CASE_CREATED_EVENT_DESCRIPTION, caseEventCategory.getShortDescription())); caseEventRepo.saveAndFlush(newCaseCaseEvent); - log.with("caseId", caze.getId().toString()).info("Case event saved."); + // log.with("caseId", caze.getId().toString()).info("Case event saved."); } /** @@ -663,7 +663,7 @@ private CaseGroup createNewCaseGroup(SampleUnitParent caseGroupData) newCaseGroup.setSurveyId(UUID.fromString(collectionExercise.getSurveyId())); caseGroupRepo.saveAndFlush(newCaseGroup); - log.with("case_group_id", newCaseGroup.getId().toString()).debug("New CaseGroup created"); + // log.with("case_group_id", newCaseGroup.getId().toString()).debug("New CaseGroup created"); return newCaseGroup; } diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/ProcessCaseActionEventService.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/ProcessCaseActionEventService.java index 430b1da2f..2184ea5a4 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/ProcessCaseActionEventService.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/ProcessCaseActionEventService.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +//import com.godaddy.logging.Logger; +//import com.godaddy.logging.LoggerFactory; import java.sql.Timestamp; import java.time.Instant; import java.util.List; @@ -25,7 +25,7 @@ @Service public class ProcessCaseActionEventService { - private static final Logger log = LoggerFactory.getLogger(ProcessCaseActionEventService.class); + //private static final Logger log = LoggerFactory.getLogger(ProcessCaseActionEventService.class); @Autowired private CollectionExerciseSvcClient collectionExerciseSvcClient; @Autowired private ProcessEmailActionService processEmailService; @@ -51,9 +51,9 @@ public void processEvents(CaseActionEvent event) throws ExecutionException, InterruptedException, JsonProcessingException { UUID collectionExerciseId = event.getCollectionExerciseID(); String eventTag = event.getTag().toString(); - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .info("Started processing"); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .info("Started processing"); Instant instant = Instant.now(); CollectionExerciseDTO collectionExercise = getCollectionExercise(collectionExerciseId); // Check if ProcessActionEventRequest table for existing status else add it. @@ -61,9 +61,9 @@ public void processEvents(CaseActionEvent event) actionEventRequestRepository.findByCollectionExerciseIdAndEventTag( collectionExerciseId, eventTag); if (!existingRequests.isEmpty()) { - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .warn("Aborting processing event as an existing request is in progress."); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .warn("Aborting processing event as an existing request is in progress."); return; } CaseActionEventRequest newRequest = @@ -74,38 +74,38 @@ public void processEvents(CaseActionEvent event) .status(ActionEventRequestStatus.INPROGRESS) .build(); actionEventRequestRepository.save(newRequest); - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .info("Requested event is now in progress."); - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .debug("Requested event will now trigger email processing asynchronously."); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .info("Requested event is now in progress."); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .debug("Requested event will now trigger email processing asynchronously."); Future asyncEmailCall = processEmailService.processEmailService(collectionExercise, eventTag, instant); - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .debug("Requested event will now trigger letter processing asynchronously."); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .debug("Requested event will now trigger letter processing asynchronously."); Future asyncLetterCall = processLetterService.processLetterService(collectionExercise, eventTag, instant); boolean emailStatus = asyncEmailCall.get(); boolean letterStatus = asyncLetterCall.get(); if (emailStatus && letterStatus) { newRequest.setStatus(ActionEventRequestStatus.COMPLETED); - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .info("Requested event is now successfully completed."); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .info("Requested event is now successfully completed."); } else { newRequest.setStatus(ActionEventRequestStatus.RETRY); - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .with("emailAsyncStatus", emailStatus) - .with("letterAsyncStatus", letterStatus) - .info("Requested event was not successful, hence a retry will be initiated soon."); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .with("emailAsyncStatus", emailStatus) +// .with("letterAsyncStatus", letterStatus) +// .info("Requested event was not successful, hence a retry will be initiated soon."); } actionEventRequestRepository.save(newRequest); - log.with("collectionExerciseId", collectionExerciseId) - .with("eventTag", eventTag) - .info("Processing finished."); +// log.with("collectionExerciseId", collectionExerciseId) +// .with("eventTag", eventTag) +// .info("Processing finished."); updateCollectionExerciseEventStatus(newRequest, event); } @@ -128,7 +128,7 @@ private void updateCollectionExerciseEventStatus( caseActionEvent.setCollectionExerciseID(request.getCollectionExerciseId()); caseActionEvent.setTag(CaseActionEvent.EventTag.valueOf(request.getEventTag())); } - log.with("event", event).info("updating collection exercise event status"); + //log.with("event", event).info("updating collection exercise event status"); collectionExerciseEventStatusUpdate.sendToPubSub( objectMapper.writeValueAsString(caseActionEvent)); } @@ -136,35 +136,35 @@ private void updateCollectionExerciseEventStatus( @Async public void retryEvents() throws ExecutionException, InterruptedException, JsonProcessingException { - log.info("Starting retry Event processing"); + //log.info("Starting retry Event processing"); Instant instant = Instant.now(); List existingRequests = actionEventRequestRepository.findByStatus(ActionEventRequestStatus.RETRY); if (existingRequests.isEmpty()) { - log.info("No events are pending retry. Will try again next time."); + //log.info("No events are pending retry. Will try again next time."); return; } for (CaseActionEventRequest existingRequest : existingRequests) { CollectionExerciseDTO collectionExercise = getCollectionExercise(existingRequest.getCollectionExerciseId()); existingRequest.setStatus(ActionEventRequestStatus.INPROGRESS); - log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) - .with("eventTag", existingRequest.getEventTag()) - .debug("Retry event is now in progress."); + //log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) +// .with("eventTag", existingRequest.getEventTag()) +// .debug("Retry event is now in progress."); actionEventRequestRepository.save(existingRequest); CaseActionEvent actionEvent = new CaseActionEvent(); actionEvent.setTag(CaseActionEvent.EventTag.valueOf(existingRequest.getEventTag())); actionEvent.setCollectionExerciseID(existingRequest.getCollectionExerciseId()); - log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) - .with("eventTag", existingRequest.getEventTag()) - .debug("Retry event will now trigger email processing asynchronously."); +// log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) +// .with("eventTag", existingRequest.getEventTag()) +// .debug("Retry event will now trigger email processing asynchronously."); Future asyncEmailCall = processEmailService.processEmailService( collectionExercise, existingRequest.getEventTag(), instant); - log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) - .with("eventTag", existingRequest.getEventTag()) - .debug("Retry event will now trigger letter processing asynchronously."); +// log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) +// .with("eventTag", existingRequest.getEventTag()) +// .debug("Retry event will now trigger letter processing asynchronously."); Future asyncLetterCall = processLetterService.processLetterService( collectionExercise, existingRequest.getEventTag(), instant); @@ -173,19 +173,19 @@ public void retryEvents() boolean letterStatus = asyncLetterCall.get(); if (emailStatus && letterStatus) { existingRequest.setStatus(ActionEventRequestStatus.COMPLETED); - log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) - .with("eventTag", existingRequest.getEventTag()) - .debug("Retry event is now successfully completed"); +// log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) +// .with("eventTag", existingRequest.getEventTag()) +// .debug("Retry event is now successfully completed"); } else { existingRequest.setStatus(ActionEventRequestStatus.FAILED); - log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) - .with("eventTag", existingRequest.getEventTag()) - .debug("Retry event has failed."); +// log.with("collectionExerciseId", existingRequest.getCollectionExerciseId()) +// .with("eventTag", existingRequest.getEventTag()) +// .debug("Retry event has failed."); } actionEventRequestRepository.save(existingRequest); updateCollectionExerciseEventStatus(existingRequest, null); } - log.info("retry Event finished"); + //log.info("retry Event finished"); } /** @@ -195,7 +195,7 @@ public void retryEvents() * @return */ private CollectionExerciseDTO getCollectionExercise(UUID collectionExerciseId) { - log.with("collectionExerciseId", collectionExerciseId).debug("Getting collectionExercise"); + //log.with("collectionExerciseId", collectionExerciseId).debug("Getting collectionExercise"); return collectionExerciseSvcClient.getCollectionExercise(collectionExerciseId); } } diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/email/ProcessEmailActionService.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/email/ProcessEmailActionService.java index 7c45915a3..d61cb48e0 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/email/ProcessEmailActionService.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/action/email/ProcessEmailActionService.java @@ -1,7 +1,13 @@ package uk.gov.ons.ctp.response.casesvc.service.action.email; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +// TODO: if we don't include com.github.tomakehurst:wiremock:2.27.2 in the POM +// (even trying to update to org.wiremock:wiremock-standalone:3.9.1 sees the same error) +// we see Class versions V1_5 or less must use F_NEW frames +// when godaddy logging is called +// we're commenting out the logging calls in this class to prove the error doesn't get thrown when +// logging isn't called +// import com.godaddy.logging.Logger; +// import com.godaddy.logging.LoggerFactory; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.Instant; @@ -35,7 +41,7 @@ @Service public class ProcessEmailActionService { - private static final Logger log = LoggerFactory.getLogger(ProcessEmailActionService.class); + // private static final Logger log = LoggerFactory.getLogger(ProcessEmailActionService.class); public static final String DATE_FORMAT_IN_REMINDER_EMAIL = "dd/MM/yyyy"; @Autowired private AppConfig appConfig; @Autowired private ActionTemplateService actionTemplateService; @@ -58,22 +64,22 @@ public Future processEmailService( actionTemplateService.mapEventTagToTemplate(eventTag, Boolean.TRUE); UUID collectionExerciseId = collectionExerciseDTO.getId(); if (null == actionTemplate) { - log.with("activeEnrolment", true) - .with("event", eventTag) - .with("collectionExerciseId", collectionExerciseId.toString()) - .info("No Email Action Template defined for this event."); + // log.with("activeEnrolment", true) + // .with("event", eventTag) + // .with("collectionExerciseId", collectionExerciseId.toString()) + // .info("No Email Action Template defined for this event."); return new AsyncResult<>(true); } // Initial status of this async call will be considered as success unless the subsequent process // changes AtomicBoolean asyncEmailCallStatus = new AtomicBoolean(true); - log.debug("Getting Email cases against collectionExerciseId and event active enrolment"); + // log.debug("Getting Email cases against collectionExerciseId and event active enrolment"); List emailCases = caseGroupRepository.findByCollectionExerciseIdAndActiveEnrolment( collectionExerciseId, true); - log.with("email cases", emailCases.size()) - .with(collectionExerciseId.toString()) - .info("Processing email cases"); + // log.with("email cases", emailCases.size()) + // .with(collectionExerciseId.toString()) + // .info("Processing email cases"); SurveyDTO survey = actionService.getSurvey(collectionExerciseDTO.getSurveyId()); emailCases .parallelStream() @@ -111,16 +117,16 @@ private void processEmailCase( UUID actionCaseId = caseAction.getCaseId(); String templateType = caseActionTemplate.getType(); Handler templateHandler = caseActionTemplate.getHandler(); - log.with("caseId", actionCaseId) - .with("actionTemplate", templateType) - .with("actionHandler", templateHandler) - .info("Processing Email Event."); + // log.with("caseId", actionCaseId) + // .with("actionTemplate", templateType) + // .with("actionHandler", templateHandler) + // .info("Processing Email Event."); boolean isSuccess = true; try { - log.with("caseId", actionCaseId).info("Getting ActionCaseParty"); + // log.with("caseId", actionCaseId).info("Getting ActionCaseParty"); CaseActionParty actionCaseParty = actionService.setParties(caseAction, survey); if (isBusinessNotification(caseAction)) { - log.with("caseId", caseAction).info("Processing Email for isBusinessNotification true"); + // log.with("caseId", caseAction).info("Processing Email for isBusinessNotification true"); actionCaseParty .getChildParties() .parallelStream() @@ -134,7 +140,8 @@ private void processEmailCase( caseAction, collectionExercise)); } else { - log.with("caseId", caseAction).info("Processing Email for isBusinessNotification false"); + // log.with("caseId", caseAction).info("Processing Email for isBusinessNotification + // false"); processEmail( actionCaseParty.getParentParty(), actionCaseParty.getChildParties().get(0), @@ -144,11 +151,11 @@ private void processEmailCase( collectionExercise); } } catch (Exception e) { - log.with("caseId", actionCaseId) - .with("actionTemplate", templateType) - .with("actionHandler", templateHandler) - .with("exception", e) - .warn("Processing Email Event FAILED."); + // log.with("caseId", actionCaseId) + // .with("actionTemplate", templateType) + // .with("actionHandler", templateHandler) + // .with("exception", e) + // .warn("Processing Email Event FAILED."); isSuccess = false; asyncEmailCallStatus.set(false); } @@ -181,10 +188,10 @@ private void processEmail( CaseActionTemplate caseActionTemplate, CaseAction caseAction, CollectionExerciseDTO collectionExercise) { - log.with("template", caseActionTemplate.getType()) - .with("case", caseAction.getCaseId()) - .with("handler", caseActionTemplate.getHandler()) - .info("Collecting email data."); + // log.with("template", caseActionTemplate.getType()) + // .with("case", caseAction.getCaseId()) + // .with("handler", caseActionTemplate.getHandler()) + // .info("Collecting email data."); String sampleUnitRef = caseAction.getSampleUnitRef(); Classifiers classifiers = getClassifiers(businessParty, survey, caseActionTemplate); Personalisation personalisation = @@ -198,10 +205,10 @@ private void processEmail( .emailAddress(respondentParty.getAttributes().getEmailAddress()) .reference(survey.getSurveyRef() + "-" + sampleUnitRef) .build()); - log.with("template", caseActionTemplate.getType()) - .with("case", caseAction.getCaseId()) - .with("handler", caseActionTemplate.getHandler()) - .info("sending email data to pubsub."); + // log.with("template", caseActionTemplate.getType()) + // .with("case", caseAction.getCaseId()) + // .with("handler", caseActionTemplate.getHandler()) + // .info("sending email data to pubsub."); emailService.processEmail(payload); } @@ -221,7 +228,7 @@ private Personalisation getPersonalisation( SurveyDTO survey, String sampleUnitRef, CollectionExerciseDTO collectionExercise) { - log.info("collecting personalisation for email"); + // log.info("collecting personalisation for email"); DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_IN_REMINDER_EMAIL); return Personalisation.builder() .firstname(respondentParty.getAttributes().getFirstName()) @@ -246,7 +253,7 @@ private Personalisation getPersonalisation( */ private Classifiers getClassifiers( PartyDTO businessParty, SurveyDTO survey, CaseActionTemplate caseActionTemplate) { - log.info("collecting classifiers for email"); + // log.info("collecting classifiers for email"); String formType = isMultipleTemplateSurvey(businessParty, survey) ? businessParty.getAttributes().getFormType() @@ -297,7 +304,7 @@ && isSupportedStringPresent(formType, getSupportedList(supportedMultipleFormsTyp } private String generateTradingStyle(final Attributes businessUnitAttributes) { - log.info("Generate trading style"); + // log.info("Generate trading style"); final List tradeStyles = Arrays.asList( businessUnitAttributes.getTradstyle1(), diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/utility/PubSubEmulator.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/utility/PubSubEmulator.java index f1dfa70f5..6aaa823ab 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/utility/PubSubEmulator.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/utility/PubSubEmulator.java @@ -1,7 +1,7 @@ package uk.gov.ons.ctp.response.casesvc.utility; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +// import com.godaddy.logging.Logger; +// import com.godaddy.logging.LoggerFactory; import com.google.api.core.ApiFuture; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.NoCredentialsProvider; @@ -23,7 +23,7 @@ * function */ public class PubSubEmulator { - private static final Logger log = LoggerFactory.getLogger(PubSubEmulator.class); + // private static final Logger log = LoggerFactory.getLogger(PubSubEmulator.class); private static final String HOST_PORT = "localhost:18681"; public static final ManagedChannel CHANNEL = ManagedChannelBuilder.forTarget(HOST_PORT).usePlaintext().build(); @@ -92,12 +92,12 @@ public void publishMessage(String message) { PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build(); TopicName topicName = TopicName.of(PROJECT_ID, TOPIC_ID); Publisher publisher = getEmulatorPublisher(topicName); - log.with("publisher", publisher).info("Publishing message to pubsub emulator"); + // log.with("publisher", publisher).info("Publishing message to pubsub emulator"); ApiFuture messageIdFuture = publisher.publish(pubsubMessage); String messageId = messageIdFuture.get(); - log.with("messageId", messageId).info("Published message to pubsub emulator"); + // log.with("messageId", messageId).info("Published message to pubsub emulator"); } catch (IOException | InterruptedException | ExecutionException e) { - log.error("Failed to publish message", e); + // log.error("Failed to publish message", e); } } @@ -107,12 +107,14 @@ public void publishSampleCaseCreationMessage(String message) { PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build(); TopicName topicName = TopicName.of(PROJECT_ID, CASE_CREATION_TOPIC_ID); Publisher publisher = getEmulatorPublisher(topicName); - log.with("publisher", publisher).info("Publishing case creation message to pubsub emulator"); + // log.with("publisher", publisher).info("Publishing case creation message to pubsub + // emulator"); ApiFuture messageIdFuture = publisher.publish(pubsubMessage); String messageId = messageIdFuture.get(); - log.with("messageId", messageId).info("Published case creation message to pubsub emulator"); + // log.with("messageId", messageId).info("Published case creation message to pubsub + // emulator"); } catch (IOException | InterruptedException | ExecutionException e) { - log.error("Failed to publish message", e); + // log.error("Failed to publish message", e); } } diff --git a/src/main/java/uk/gov/ons/ctp/response/iac/representation/CreateInternetAccessCodeDTO.java b/src/main/java/uk/gov/ons/ctp/response/iac/representation/CreateInternetAccessCodeDTO.java index fa2b91363..f9e005e2c 100644 --- a/src/main/java/uk/gov/ons/ctp/response/iac/representation/CreateInternetAccessCodeDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/iac/representation/CreateInternetAccessCodeDTO.java @@ -1,6 +1,6 @@ package uk.gov.ons.ctp.response.iac.representation; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/iac/representation/InternetAccessCodeCaseContextDTO.java b/src/main/java/uk/gov/ons/ctp/response/iac/representation/InternetAccessCodeCaseContextDTO.java index dc40fd2fd..4f881ca99 100644 --- a/src/main/java/uk/gov/ons/ctp/response/iac/representation/InternetAccessCodeCaseContextDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/iac/representation/InternetAccessCodeCaseContextDTO.java @@ -1,8 +1,8 @@ package uk.gov.ons.ctp.response.iac.representation; +import jakarta.validation.constraints.NotNull; import java.sql.Timestamp; import java.util.UUID; -import javax.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/iac/representation/UpdateInternetAccessCodeDTO.java b/src/main/java/uk/gov/ons/ctp/response/iac/representation/UpdateInternetAccessCodeDTO.java index bffff3f24..b940398ed 100644 --- a/src/main/java/uk/gov/ons/ctp/response/iac/representation/UpdateInternetAccessCodeDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/iac/representation/UpdateInternetAccessCodeDTO.java @@ -1,6 +1,6 @@ package uk.gov.ons.ctp.response.iac.representation; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionDTO.java b/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionDTO.java index 69806d7fb..011bf6906 100644 --- a/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionDTO.java @@ -1,8 +1,8 @@ package uk.gov.ons.ctp.response.lib.action; +import jakarta.validation.constraints.NotNull; import java.util.Date; import java.util.UUID; -import javax.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionPlanDTO.java b/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionPlanDTO.java index 344119f07..43d72c048 100644 --- a/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionPlanDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/lib/action/ActionPlanDTO.java @@ -1,9 +1,9 @@ package uk.gov.ons.ctp.response.lib.action; +import jakarta.validation.constraints.NotNull; import java.util.Date; import java.util.HashMap; import java.util.UUID; -import javax.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/lib/collection/exercise/CollectionExerciseDTO.java b/src/main/java/uk/gov/ons/ctp/response/lib/collection/exercise/CollectionExerciseDTO.java index 6059cfcb8..1bd83784d 100644 --- a/src/main/java/uk/gov/ons/ctp/response/lib/collection/exercise/CollectionExerciseDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/lib/collection/exercise/CollectionExerciseDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; import java.util.Date; import java.util.UUID; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/lib/common/error/RestExceptionHandler.java b/src/main/java/uk/gov/ons/ctp/response/lib/common/error/RestExceptionHandler.java index 5e729fdeb..09ecc7da0 100644 --- a/src/main/java/uk/gov/ons/ctp/response/lib/common/error/RestExceptionHandler.java +++ b/src/main/java/uk/gov/ons/ctp/response/lib/common/error/RestExceptionHandler.java @@ -1,7 +1,7 @@ package uk.gov.ons.ctp.response.lib.common.error; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +// import com.godaddy.logging.Logger; +// import com.godaddy.logging.LoggerFactory; import java.util.stream.Collectors; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -15,8 +15,9 @@ @ControllerAdvice public class RestExceptionHandler { - private static final Logger log = - LoggerFactory.getLogger(uk.gov.ons.ctp.response.lib.common.error.RestExceptionHandler.class); + // private static final Logger log = + // + // LoggerFactory.getLogger(uk.gov.ons.ctp.response.lib.common.error.RestExceptionHandler.class); public static final String INVALID_JSON = "Provided json fails validation."; public static final String PROVIDED_JSON_INCORRECT = "Provided json is incorrect."; @@ -32,9 +33,9 @@ public class RestExceptionHandler { */ @ExceptionHandler(CTPException.class) public ResponseEntity handleCTPException(CTPException exception) { - log.with("fault", exception.getFault()) - .with("exception_message", exception.getMessage()) - .error("Uncaught CTPException", exception); + // log.with("fault", exception.getFault()) + // .with("exception_message", exception.getMessage()) + // .error("Uncaught CTPException", exception); HttpStatus status; switch (exception.getFault()) { @@ -70,7 +71,7 @@ public ResponseEntity handleCTPException(CTPException exception) { */ @ExceptionHandler(Throwable.class) public ResponseEntity handleGeneralException(Throwable t) { - log.error("Uncaught Throwable", t); + // log.error("Uncaught Throwable", t); return new ResponseEntity<>( new CTPException(CTPException.Fault.SYSTEM_ERROR, t, t.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR); @@ -92,9 +93,9 @@ public ResponseEntity handleInvalidRequestException(InvalidRequestException e .map(e -> String.format("field=%s message=%s", e.getField(), e.getDefaultMessage())) .collect(Collectors.joining(",")); - log.with("validation_errors", errors) - .with("source_message", ex.getSourceMessage()) - .error("Unhandled InvalidRequestException", ex); + // log.with("validation_errors", errors) + // .with("source_message", ex.getSourceMessage()) + // .error("Unhandled InvalidRequestException", ex); CTPException ourException = new CTPException(CTPException.Fault.VALIDATION_FAILED, INVALID_JSON); return new ResponseEntity<>(ourException, HttpStatus.BAD_REQUEST); @@ -110,7 +111,7 @@ public ResponseEntity handleInvalidRequestException(InvalidRequestException e @ExceptionHandler(HttpMessageNotReadableException.class) public ResponseEntity handleHttpMessageNotReadableException( HttpMessageNotReadableException ex) { - log.error("Uncaught HttpMessageNotReadableException", ex); + // log.error("Uncaught HttpMessageNotReadableException", ex); String message = ex.getMessage().startsWith(XML_ERROR_MESSAGE) ? PROVIDED_XML_INCORRECT @@ -131,8 +132,8 @@ public ResponseEntity handleHttpMessageNotReadableException( @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity handleMethodArgumentNotValidException( MethodArgumentNotValidException ex) { - log.with("parameter", ex.getParameter().getParameterName()) - .error("Uncaught MethodArgumentNotValidException", ex); + // log.with("parameter", ex.getParameter().getParameterName()) + // .error("Uncaught MethodArgumentNotValidException", ex); CTPException ourException = new CTPException(CTPException.Fault.VALIDATION_FAILED, INVALID_JSON); return new ResponseEntity<>(ourException, HttpStatus.BAD_REQUEST); diff --git a/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventCreationRequestDTO.java b/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventCreationRequestDTO.java index 3558c2097..5f1e79cd3 100644 --- a/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventCreationRequestDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventCreationRequestDTO.java @@ -1,8 +1,8 @@ package uk.gov.ons.ctp.response.lib.dto; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.Map; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventDTO.java b/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventDTO.java index 996786c76..e62cb56d4 100644 --- a/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/lib/dto/CaseEventDTO.java @@ -1,9 +1,9 @@ package uk.gov.ons.ctp.response.lib.dto; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.Date; import java.util.Map; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/uk/gov/ons/ctp/response/lib/dto/CreatedCaseEventDTO.java b/src/main/java/uk/gov/ons/ctp/response/lib/dto/CreatedCaseEventDTO.java index 488042830..a9507e2a7 100644 --- a/src/main/java/uk/gov/ons/ctp/response/lib/dto/CreatedCaseEventDTO.java +++ b/src/main/java/uk/gov/ons/ctp/response/lib/dto/CreatedCaseEventDTO.java @@ -1,10 +1,10 @@ package uk.gov.ons.ctp.response.lib.dto; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.Date; import java.util.Map; import java.util.UUID; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index df43e6958..5affa72fb 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -44,7 +44,7 @@ spring: password: postgres driverClassName: org.postgresql.Driver jpa: - database-platform: org.hibernate.dialect.PostgreSQL94Dialect + database-platform: org.hibernate.dialect.PostgreSQLDialect open-in-view: true show-sql: false defer-datasource-initialization: true diff --git a/src/test/java/uk/gov/ons/ctp/response/casesvc/client/CachingTestIT.java b/src/test/java/uk/gov/ons/ctp/response/casesvc/client/CachingTestIT.java index d527d571e..99e2f06e2 100644 --- a/src/test/java/uk/gov/ons/ctp/response/casesvc/client/CachingTestIT.java +++ b/src/test/java/uk/gov/ons/ctp/response/casesvc/client/CachingTestIT.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.github.tomakehurst.wiremock.stubbing.StubMapping; import java.util.UUID; @@ -27,13 +26,12 @@ @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @TestPropertySource(locations = "classpath:/application-test.yml") +// TODO: Java 21 Sprint Boot 3: Fix github.tomakehurst.wiremock public class CachingTestIT { @Autowired private CollectionExerciseSvcClient collectionExerciseSvcClient; - @ClassRule - public static WireMockRule wireMockRule = - new WireMockRule(options().extensions(new ResponseTemplateTransformer(false)).port(18002)); + @ClassRule public static WireMockRule wireMockRule = new WireMockRule(options().port(18002)); private UUID collectionExerciseId = UUID.fromString("cb8accda-6118-4d3b-85a3-149e28960c55"); diff --git a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventIT.java b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventIT.java index a94aae153..f032d7661 100644 --- a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventIT.java +++ b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseActionEventIT.java @@ -5,7 +5,6 @@ import static org.mockito.ArgumentMatchers.anyString; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; @@ -19,7 +18,7 @@ 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.web.server.LocalServerPort; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -50,6 +49,7 @@ locations = "classpath:/application-test.yml", properties = "action-svc.deprecated=true") @FixMethodOrder(MethodSorters.NAME_ASCENDING) +// TODO: Java 21 Sprint Boot 3: Fix github.tomakehurst.wiremock public class CaseActionEventIT { private UUID collectionExerciseId; private Map metadata; @@ -58,9 +58,7 @@ public class CaseActionEventIT { @MockBean private ProcessLetterActionService processLetterActionService; @MockBean private ProcessEmailActionService processEmailActionService; - @ClassRule - public static WireMockRule wireMockRule = - new WireMockRule(options().extensions(new ResponseTemplateTransformer(false)).port(18002)); + @ClassRule public static WireMockRule wireMockRule = new WireMockRule(options().port(18002)); @LocalServerPort private int port; diff --git a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointIT.java b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointIT.java index 1856734e8..943a04960 100644 --- a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointIT.java +++ b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointIT.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; @@ -18,7 +17,7 @@ import org.junit.runners.MethodSorters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -42,14 +41,13 @@ @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @TestPropertySource(locations = "classpath:/application-test.yml") @FixMethodOrder(MethodSorters.NAME_ASCENDING) +// TODO: Java 21 Sprint Boot 3: Fix github.tomakehurst.wiremock public class CaseEndpointIT { private UUID collectionExerciseId; private Map metadata; private PubSubEmulator pubSubEmulator = new PubSubEmulator(); - @ClassRule - public static WireMockRule wireMockRule = - new WireMockRule(options().extensions(new ResponseTemplateTransformer(false)).port(18002)); + @ClassRule public static WireMockRule wireMockRule = new WireMockRule(options().port(18002)); @LocalServerPort private int port; diff --git a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointUnitTest.java b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointUnitTest.java index e2871bd98..321f11984 100644 --- a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointUnitTest.java +++ b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseEndpointUnitTest.java @@ -351,7 +351,15 @@ public void findCasesByPartyIdFoundWithoutCaseEventsAndIac() throws Exception { ResultActions actions = mockMvc.perform(getJson(String.format("/cases/partyid/%s", EXISTING_PARTY_UUID))); - + // TODO: if we don't include com.github.tomakehurst:wiremock:2.27.2 in the POM + // (even trying to update to org.wiremock:wiremock-standalone:3.9.1 sees the same error) + // we see this buried exception within the actions object resulting a in in the + // test + // com.fasterxml.jackson.databind.JsonMappingException: Class versions V1_5 or less must use + // F_NEW frames. + // (through reference chain: + // java.util.ArrayList[0]->uk.gov.ons.ctp.response.casesvc.representation.CaseDetailsDTO["createdDateTime"]) + // this is the same error we see when godadddy logging is invoked when the tests run actions.andExpect(status().is2xxSuccessful()); actions.andExpect(handler().handlerType(CaseEndpoint.class)); actions.andExpect(handler().methodName("findCasesByPartyId")); diff --git a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpointIT.java b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpointIT.java index efe4847a6..383b716ee 100644 --- a/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpointIT.java +++ b/src/test/java/uk/gov/ons/ctp/response/casesvc/endpoint/CaseIACEndpointIT.java @@ -9,30 +9,32 @@ import static org.junit.Assert.assertThat; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; import com.github.tomakehurst.wiremock.junit.WireMockRule; -import com.godaddy.logging.Logger; -import com.godaddy.logging.LoggerFactory; +//import com.godaddy.logging.Logger; +//import com.godaddy.logging.LoggerFactory; import com.mashape.unirest.http.HttpResponse; +import com.mashape.unirest.http.JsonNode; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.UUID; +import java.util.*; + import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.web.client.RestClient; import uk.gov.ons.ctp.response.casesvc.CaseCreator; import uk.gov.ons.ctp.response.casesvc.client.CollectionExerciseSvcClient; import uk.gov.ons.ctp.response.casesvc.domain.repository.CaseEventRepository; @@ -42,7 +44,6 @@ import uk.gov.ons.ctp.response.casesvc.representation.CaseIACDTO; import uk.gov.ons.ctp.response.casesvc.utility.PubSubEmulator; import uk.gov.ons.ctp.response.lib.collection.exercise.CollectionExerciseDTO; -import uk.gov.ons.ctp.response.lib.common.UnirestInitialiser; @ContextConfiguration @ActiveProfiles("test") @@ -51,16 +52,15 @@ @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @TestPropertySource(locations = "classpath:/application-test.yml") @FixMethodOrder(MethodSorters.NAME_ASCENDING) +// TODO: Java 21 Sprint Boot 3: Fix github.tomakehurst.wiremock public class CaseIACEndpointIT { private UUID collectionExerciseId; private Map metadata; - private static final Logger log = LoggerFactory.getLogger(CaseIACEndpointIT.class); + //private static final Logger log = LoggerFactory.getLogger(CaseIACEndpointIT.class); private PubSubEmulator pubSubEmulator = new PubSubEmulator(); - @ClassRule - public static WireMockRule wireMockRule = - new WireMockRule(options().extensions(new ResponseTemplateTransformer(false)).port(18002)); + @ClassRule public static WireMockRule wireMockRule = new WireMockRule(options().port(18002)); @LocalServerPort private int port; @@ -69,13 +69,14 @@ public class CaseIACEndpointIT { @Autowired private CaseRepository caseRepository; @Autowired private CaseEventRepository caseEventRepository; @Autowired private CaseGroupRepository caseGroupRepository; + @Autowired private TestRestTemplate testRestTemplate; public CaseIACEndpointIT() throws IOException {} @BeforeClass public static void setUp() throws InterruptedException { ObjectMapper value = new ObjectMapper(); - UnirestInitialiser.initialise(value); + // UnirestInitialiser.initialise(value); Thread.sleep(20000); } @@ -117,8 +118,7 @@ public void shouldCreateNewIACCode() throws Exception { UUID sampleUnitId = UUID.randomUUID(); caseCreator.postSampleUnit("LMS0001", "H", sampleUnitId, collectionExerciseId); Thread.sleep(3000); - HttpResponse casesResponse = getCreatedCase(sampleUnitId); - String caseID = casesResponse.getBody()[0].getId().toString(); + String caseID = String.valueOf(getCreatedCaseId(sampleUnitId)); String notExpected = getCurrentIACCode(caseID); // When @@ -136,8 +136,8 @@ public void shouldGetIacCodes() throws Exception { UUID sampleUnitId = UUID.randomUUID(); caseCreator.postSampleUnit("LMS0001", "H", sampleUnitId, collectionExerciseId); Thread.sleep(3000); - HttpResponse casesResponse = getCreatedCase(sampleUnitId); - String caseID = casesResponse.getBody()[0].getId().toString(); + //HttpResponse casesResponse = getCreatedCase(sampleUnitId); + String caseID = String.valueOf(getCreatedCaseId(sampleUnitId)); // When HttpResponse iacs = Unirest.get("http://localhost:{port}/cases/{caseId}/iac") @@ -173,13 +173,61 @@ private HttpResponse generateNewIACCode(String caseId) throws UnirestExc .asString(); } - private HttpResponse getCreatedCase(UUID sampleUnitId) throws Exception { - HttpResponse casesResponse = - Unirest.get(String.format("http://localhost:%d/cases/sampleunitids", port)) - .basicAuth("admin", "secret") - .queryString("sampleUnitId", sampleUnitId) - .header("Content-Type", "application/json") - .asObject(CaseDetailsDTO[].class); - return casesResponse; + private UUID getCreatedCaseId(UUID sampleUnitId) throws Exception { + // TODO: Could not write JSON: Class versions V1_5 or less must use F_NEW frames + // We are trying a different REST client (Spring's TestRestTemplate) to see if we see the same issue + // as with the old Unirest client (which we do) so it doesn't seem to be an issue with the test request. + // the problem appears to be within the Spring webenvironment server: + // @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) + // which internally throws an exception when returning the response (sadly that exception is our friend we see in the GoDaddy/ASM logging) + // {"error":{"code":"SYSTEM_ERROR","timestamp":"20241101092339701","message":"Could not write JSON: Class versions V1_5 or less must use F_NEW frames."}} + // so something fundamental is going on with Spring and Java bytecode reflection. + // Worth saying our own code is working ok, and the endpoint gets invoked and does indeed yield the correct case details + // however, the Spring testing framework server is not happy and can't render the HTTP response + testRestTemplate.withBasicAuth("admin","secret"); + System.out.println("**** HERE 1 ****"); + // The service returns a JSON array of CaseDetailsDTO objects, but we only need the first one + ResponseEntity jsonString = testRestTemplate.getForEntity( + String.format("http://localhost:%d/cases/sampleunitids?sampleUnitId=%s", port, sampleUnitId), + String.class); + System.out.println("**** HERE 2 ****"); +// ResponseEntity jsonNode = testRestTemplate.getForEntity( +// String.format("http://localhost:%d/cases/sampleunitids?sampleUnitId=%s", port, sampleUnitId), +// JsonNode.class); + + System.out.println(jsonString.getBody()); + + ObjectMapper objectMapper = new ObjectMapper(); + List caseDetailsDTOs = objectMapper.readValue(jsonString.getBody(), + objectMapper.getTypeFactory().constructCollectionType(List.class, CaseDetailsDTO.class)); + + System.out.println("*************** response:::::" + caseDetailsDTOs.get(0)); +// RestClient restClient = RestClient.builder() +// .baseUrl(String.format("http://localhost:%d/cases/sampleunitids", port)) +// .defaultHeaders( +// httpHeaders -> { +// httpHeaders.setBasicAuth("admin", "secret"); +// httpHeaders.set("Content-Type", "application/json"); +// } +// ).build(); +// +// String data = restClient.get() +// .uri("?sampleUnitId=%s",sampleUnitId) +// .accept(MediaType.APPLICATION_JSON) +// .retrieve() +// .body(String.class); +// System.out.println(data); + + // This is the original REST client call that was replaced by the above code +// HttpResponse casesResponse = +// Unirest.get(String.format("http://localhost:%d/cases/sampleunitids", port)) +// .basicAuth("admin", "secret") +// .queryString("sampleUnitId", sampleUnitId) +// .header("Content-Type", "application/json") +// .asObject(CaseDetailsDTO[].class); + +// return casesResponse + + return caseDetailsDTOs.get(0).getId(); } } diff --git a/src/test/java/uk/gov/ons/ctp/response/casesvc/message/CaseReceiptReceiverIT.java b/src/test/java/uk/gov/ons/ctp/response/casesvc/message/CaseReceiptReceiverIT.java index eb54dfaa4..a51a8b8e6 100644 --- a/src/test/java/uk/gov/ons/ctp/response/casesvc/message/CaseReceiptReceiverIT.java +++ b/src/test/java/uk/gov/ons/ctp/response/casesvc/message/CaseReceiptReceiverIT.java @@ -3,7 +3,6 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.io.IOException; import java.nio.file.Files; @@ -28,6 +27,7 @@ @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @TestPropertySource(locations = "classpath:/application-test.yml") +// TODO: Java 21 Sprint Boot 3: Fix github.tomakehurst.wiremock public class CaseReceiptReceiverIT { private static PubSubEmulator PUBSUBEMULATOR; @@ -39,9 +39,7 @@ public class CaseReceiptReceiverIT { public static final EnvironmentVariables environmentVariables = new EnvironmentVariables().set("PUBSUB_EMULATOR_HOST", "127.0.0.1:18681"); - @ClassRule - public static WireMockRule wireMockRule = - new WireMockRule(options().extensions(new ResponseTemplateTransformer(false)).port(18002)); + @ClassRule public static WireMockRule wireMockRule = new WireMockRule(options().port(18002)); @MockBean private CaseReceiptReceiver caseReceiptReceiver; diff --git a/src/test/java/uk/gov/ons/ctp/response/lib/common/UnirestInitialiser.java b/src/test/java/uk/gov/ons/ctp/response/lib/common/UnirestInitialiser.java index c4034d4e9..fca9e2bc2 100644 --- a/src/test/java/uk/gov/ons/ctp/response/lib/common/UnirestInitialiser.java +++ b/src/test/java/uk/gov/ons/ctp/response/lib/common/UnirestInitialiser.java @@ -7,6 +7,7 @@ public class UnirestInitialiser { public static void initialise(final ObjectMapper mapper) { + // mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); Unirest.setObjectMapper( new com.mashape.unirest.http.ObjectMapper() { public T readValue(final String value, final Class valueType) {