diff --git a/src/main/java/uk/gov/hmcts/opal/authentication/config/SecurityConfig.java b/src/main/java/uk/gov/hmcts/opal/authentication/config/SecurityConfig.java index 637088818..f58e1b74b 100644 --- a/src/main/java/uk/gov/hmcts/opal/authentication/config/SecurityConfig.java +++ b/src/main/java/uk/gov/hmcts/opal/authentication/config/SecurityConfig.java @@ -36,9 +36,10 @@ import java.util.Map; -@Slf4j +@Slf4j(topic = "SecurityConfig") @Configuration @EnableWebSecurity +//@EnableWebSecurity(debug = true) @RequiredArgsConstructor @Profile("!integration") public class SecurityConfig { @@ -131,7 +132,8 @@ protected void doFilterInternal(HttpServletRequest request, filterChain.doFilter(request, response); return; } - + + log.warn(".AuthorisationTokenExistenceFilter:doFilterInternal: No Bearer Token."); throw new OpalApiException(AuthenticationError.FAILED_TO_OBTAIN_ACCESS_TOKEN); } } diff --git a/src/main/java/uk/gov/hmcts/opal/entity/OffenceEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/OffenceEntity.java index 39f2266e2..c698156ff 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/OffenceEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/OffenceEntity.java @@ -57,6 +57,11 @@ public class OffenceEntity { @Column(name = "offence_title_cy", length = 120) private String offenceTitleCy; + @Column(name = "date_used_from") + @Temporal(TemporalType.TIMESTAMP) + @XmlJavaTypeAdapter(LocalDateTimeAdapter.class) + private LocalDateTime dateUsedFrom; + @Column(name = "date_used_to") @Temporal(TemporalType.TIMESTAMP) @XmlJavaTypeAdapter(LocalDateTimeAdapter.class) diff --git a/src/main/java/uk/gov/hmcts/opal/entity/projection/OffenceReferenceData.java b/src/main/java/uk/gov/hmcts/opal/entity/projection/OffenceReferenceData.java index 68cc832da..9a9fd191f 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/projection/OffenceReferenceData.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/projection/OffenceReferenceData.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.opal.entity.projection; +import java.time.LocalDateTime; + public record OffenceReferenceData(Long offenceId, String getCjsCode, Short businessUnitId, - String getOffenceTitle, String getOffenceTitleCy) { + String getOffenceTitle, String getOffenceTitleCy, LocalDateTime dateUsedFrom, LocalDateTime dateUsedTo, + String offenceOas, String offenceOasCy) { } diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/OffenceSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/OffenceSpecs.java index 7b8c4a576..58d40965e 100644 --- a/src/main/java/uk/gov/hmcts/opal/repository/jpa/OffenceSpecs.java +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/OffenceSpecs.java @@ -35,7 +35,6 @@ public Specification referenceDataFilter(Optional filter, return Specification.allOf(specificationList( List.of( filter.filter(s -> !s.isBlank()).map(OffenceSpecs::likeAnyOffence)), - usedToDateGreaterThenEqualToDate(LocalDateTime.now()), globalOrLocalOffence(businessUnitId) )); } @@ -69,6 +68,13 @@ public static Specification likeOffenceTitleCy(String offenceTitl likeWildcardPredicate(root.get(OffenceEntity_.offenceTitleCy), builder, offenceTitleCy); } + public static Specification usedFromDateLessThenEqualToDate(LocalDateTime offenceStillValidDate) { + return (root, query, builder) -> builder.or( + builder.isNull(root.get(OffenceEntity_.dateUsedFrom)), + builder.lessThanOrEqualTo(root.get(OffenceEntity_.dateUsedFrom), offenceStillValidDate) + ); + } + public static Specification usedToDateGreaterThenEqualToDate(LocalDateTime offenceStillValidDate) { return (root, query, builder) -> builder.or( builder.isNull(root.get(OffenceEntity_.dateUsedTo)), diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/OffenceService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/OffenceService.java index 34200437d..013894f25 100644 --- a/src/main/java/uk/gov/hmcts/opal/service/opal/OffenceService.java +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/OffenceService.java @@ -66,7 +66,11 @@ private OffenceReferenceData toRefData(OffenceEntity entity) { entity.getCjsCode(), Optional.ofNullable(entity.getBusinessUnit()).map(BusinessUnitEntity::getBusinessUnitId).orElse(null), entity.getOffenceTitle(), - entity.getOffenceTitleCy() + entity.getOffenceTitleCy(), + entity.getDateUsedFrom(), + entity.getDateUsedTo(), + entity.getOffenceOas(), + entity.getOffenceOasCy() ); } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 83013a0cd..f428d48f6 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -67,8 +67,10 @@ spring: maxLifetime: 7200000 connectionTimeout: 30000 jpa: + show-sql: false properties: hibernate: + format_sql: false dialect: org.hibernate.dialect.PostgreSQLDialect jdbc: lob: @@ -168,3 +170,13 @@ be-developer-config: printservice: maxRetries: 3 pageSize: 100 + +logging: + level: + org: + hibernate: + SQL: DEBUG + type: + descriptor: + sql: + BasicBinder: TRACE diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/OffenceControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/OffenceControllerTest.java index ce8910405..5a97d4969 100644 --- a/src/test/java/uk/gov/hmcts/opal/controllers/OffenceControllerTest.java +++ b/src/test/java/uk/gov/hmcts/opal/controllers/OffenceControllerTest.java @@ -13,6 +13,7 @@ import uk.gov.hmcts.opal.entity.projection.OffenceReferenceData; import uk.gov.hmcts.opal.service.opal.OffenceService; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -89,7 +90,9 @@ void testGetOffencesRefData_Success() { private OffenceReferenceData createOffenceReferenceData() { return new OffenceReferenceData(1L, "TH123456", (short)007, - "Thief of Time", null); + "Thief of Time", null, + LocalDateTime.of(1909, 3, 3, 3, 30), + null, "", ""); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/OffenceServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/OffenceServiceTest.java index 0dc7b2d02..ece484a3e 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/opal/OffenceServiceTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/OffenceServiceTest.java @@ -16,6 +16,7 @@ import uk.gov.hmcts.opal.entity.projection.OffenceReferenceData; import uk.gov.hmcts.opal.repository.OffenceRepository; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import java.util.function.Function; @@ -81,6 +82,9 @@ void testOffencesReferenceData() { .offenceId(1L) .cjsCode("NINE") .offenceTitle("Theft from a Palace") + .dateUsedFrom(LocalDateTime.of(1909,3,3,3,30)) + .offenceOas("A") + .offenceOasCy("B") .build(); Page mockPage = new PageImpl<>(List.of(offenceEntity), Pageable.unpaged(), 999L); when(offenceRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { @@ -91,8 +95,11 @@ void testOffencesReferenceData() { // Act List result = offenceService.getReferenceData(Optional.empty(), Optional.empty()); - OffenceReferenceData refData = new OffenceReferenceData(1L, "NINE", null, - "Theft from a Palace", null); + OffenceReferenceData refData = + new OffenceReferenceData(1L, "NINE", null, "Theft from a Palace", + null, LocalDateTime.of(1909, 3, 3, 3, 30), + null, "A", "B" + ); // Assert assertEquals(List.of(refData), result);