Skip to content

Commit

Permalink
PO-614: Add dateUsedFrom to Offence Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyHMCTS committed Aug 22, 2024
1 parent 534d44a commit f03e298
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
import java.util.Map;


@Slf4j
@Slf4j(topic = "SecurityConfig")
@Configuration
@EnableWebSecurity
//@EnableWebSecurity(debug = true)
@RequiredArgsConstructor
@Profile("!integration")
public class SecurityConfig {
Expand Down Expand Up @@ -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);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/uk/gov/hmcts/opal/entity/OffenceEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public Specification<OffenceEntity> referenceDataFilter(Optional<String> filter,
return Specification.allOf(specificationList(
List.of(
filter.filter(s -> !s.isBlank()).map(OffenceSpecs::likeAnyOffence)),
usedToDateGreaterThenEqualToDate(LocalDateTime.now()),
globalOrLocalOffence(businessUnitId)
));
}
Expand Down Expand Up @@ -69,6 +68,13 @@ public static Specification<OffenceEntity> likeOffenceTitleCy(String offenceTitl
likeWildcardPredicate(root.get(OffenceEntity_.offenceTitleCy), builder, offenceTitleCy);
}

public static Specification<OffenceEntity> 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<OffenceEntity> usedToDateGreaterThenEqualToDate(LocalDateTime offenceStillValidDate) {
return (root, query, builder) -> builder.or(
builder.isNull(root.get(OffenceEntity_.dateUsedTo)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
12 changes: 12 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -168,3 +170,13 @@ be-developer-config:
printservice:
maxRetries: 3
pageSize: 100

logging:
level:
org:
hibernate:
SQL: DEBUG
type:
descriptor:
sql:
BasicBinder: TRACE
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, "", "");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<OffenceEntity> mockPage = new PageImpl<>(List.of(offenceEntity), Pageable.unpaged(), 999L);
when(offenceRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> {
Expand All @@ -91,8 +95,11 @@ void testOffencesReferenceData() {
// Act
List<OffenceReferenceData> 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);

Expand Down

0 comments on commit f03e298

Please sign in to comment.