Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ apply {
}

dependencies {
implementation('uk.gov.hmcts.cp:api-cp-crime-hearing-case-event-subscription:1.1.3')
implementation('uk.gov.hmcts.cp:api-cp-crime-hearing-case-event-subscription:1.1.4')

// This is proving to be a real puzzle. This is actually included in the api published pom
// ( though with scope of "runtime" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import org.owasp.encoder.Encode;
import org.slf4j.MDC;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.hmcts.cp.filters.ClientIdResolutionFilter;
import uk.gov.hmcts.cp.openapi.api.SubscriptionApi;
import uk.gov.hmcts.cp.openapi.model.ClientSubscription;
import uk.gov.hmcts.cp.openapi.model.ClientSubscriptionRequest;
import uk.gov.hmcts.cp.openapi.model.EventTypeResponse;
import uk.gov.hmcts.cp.subscription.services.EventTypeService;
import uk.gov.hmcts.cp.subscription.services.SubscriptionService;

import java.util.UUID;
Expand All @@ -24,6 +27,7 @@
public class SubscriptionController implements SubscriptionApi {

private final SubscriptionService subscriptionService;
private final EventTypeService eventTypeService;

@Override
public ResponseEntity<ClientSubscription> createClientSubscription(
Expand Down Expand Up @@ -68,4 +72,12 @@ public ResponseEntity<Void> deleteClientSubscription(
subscriptionService.deleteSubscription(clientSubscriptionId, clientId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Override
public ResponseEntity<EventTypeResponse> getEventTypes() {
final EventTypeResponse eventTypes = eventTypeService.getAllEventTypes();
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(eventTypes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.gov.hmcts.cp.subscription.entities;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "event_type")
@Getter
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class EventTypeEntity {

@Id
private Long id;

@Column(name = "event_name")
private String eventName;

@Column(name = "display_name")
private String displayName;

@Column(name = "category")
private String category;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.hmcts.cp.subscription.mappers;

import org.mapstruct.Mapper;
import uk.gov.hmcts.cp.openapi.model.EventTypeResponse;
import uk.gov.hmcts.cp.openapi.model.EventTypePayload;
import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity;

import java.util.List;

@Mapper(componentModel = "spring")
public interface EventTypeMapper {

List<EventTypePayload> map(List<EventTypeEntity> eventTypeEntities);

default EventTypeResponse mapToEventTypes(final List<EventTypeEntity> eventTypeEntities) {
return EventTypeResponse.builder()
.events(map(eventTypeEntities))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.gov.hmcts.cp.subscription.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity;

@Repository
public interface EventTypeRepository extends JpaRepository<EventTypeEntity, Long> {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package uk.gov.hmcts.cp.subscription.services;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.cp.openapi.model.EventTypeResponse;
import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity;
import uk.gov.hmcts.cp.subscription.mappers.EventTypeMapper;
import uk.gov.hmcts.cp.subscription.repositories.EventTypeRepository;

import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class EventTypeService {

private final EventTypeRepository eventTypeRepository;
private final EventTypeMapper eventTypeMapper;

public EventTypeResponse getAllEventTypes() {
final List<EventTypeEntity> eventTypeEntityList = eventTypeRepository.findAll();
return eventTypeMapper.mapToEventTypes(eventTypeEntityList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
DROP TABLE IF EXISTS event_type;

CREATE TABLE event_type (
id integer PRIMARY KEY NOT NULL,
event_name VARCHAR(128) NOT NULL UNIQUE,
display_name VARCHAR(256) NOT NULL,
category VARCHAR(64) NOT NULL
);

CREATE UNIQUE INDEX idx_event_type_event_name ON event_type(event_name);

INSERT INTO event_type (id, event_name, display_name, category) VALUES (1, 'PRISON_COURT_REGISTER_GENERATED', 'Prison court register', 'REGISTER');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (2, 'WEE_Layout5', 'Warrant Supplement', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (3, 'NEE_DetentionOnRecommendationForDeportation', 'Detention on Recommendation for Deportation', 'NOTICE');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (4, 'OEE_MedicalRemandAdditionalDetails', 'Medical Remand - Additional Details', 'ORDER');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (5, 'WEE_RemandAfterBailAppealByProsecutor', 'Remand Warrant After Bail Appeal by Prosecutor', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (6, 'WEE_CustodialSentence', 'Warrant for Custodial Sentence', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (7, 'WEE_CustodialSentenceWitness', 'Warrant for Custodial Sentence (Witness)', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (8, 'WEE_CommittalToCrownCourtForConsiderationOfTheQuestionOfBailOnAChargeOfMurder', 'Warrant of Committal to Crown Court for Consideration of the Question of Bail on a Charge of Murder', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (9, 'WEE_CommittalToCrownCourtForSentence', 'Warrant of Committal to Crown Court for Sentence', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (10, 'WEE_SendingToCrownCourtForTrial', 'Warrant of Sending to Crown Court for Trial', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (11, 'OEE_BailAppealEndOfCustody', 'Bail Appeal - End of Custody', 'ORDER');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (12, 'WEE_CommitmentPendingTransferToServiceCustody', 'Warrant of Commitment Pending Transfer to Service Custody', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (13, 'WEE_NonPaymentOfMoneyOwedCivilDebt', 'Warrant of Committal for Non-Payment of Money Owed Civil Debt,', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (14, 'WEE_CustodyWarrantOnDischargeOfExtraditionPendingAppeal', 'Custody Warrant on Discharge of Extradition Pending Appeal', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (15, 'WEE_CustodyWarrantOnDischargeOfExtraditionPendingAppealPart2', 'Custody Warrant on Discharge of Extradition Pending Appeal (Part 2)', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (16, 'WEE_CustodyWarrantOnExtradition', 'Custody Warrant on Extradition', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (17, 'WEE_CustodyWarrantOnExtraditionCategory2Territory', 'Custody Warrant on Extradition – Category 2 Territory', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (18, 'WEE_CustodyWarrantOnExtraditionWithConsent', 'Custody Warrant on Extradition (Part 1)', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (19, 'WEE_CustodyWarrantOnExtraditionWithBailDirection', 'Custody Warrant on Extradition (with Bail Direction)', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (20, 'WEE_CustodyWarrantOnExtraditionWithBailDirectionWithConsent', 'Custody Warrant on Extradition with Bail Direction', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (21, 'WEE_CustodyWarrantOnExtraditionWithBailDirectionCategory2Territory', 'Custody Warrant on Extradition (with Bail Direction) – Category 2 Territory', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (22, 'WEE_CustodyWarrantSendingToSecretaryOfStateCategory2Territory', 'Custody Warrant Sending to Secretary of State – Category 2 Territory', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (23, 'WEE_CustodyWarrantSendingToSecretaryOfStateOnConsentCategory2Territory', 'Custody Warrant Sending to Secretary of State on Consent – Category 2 Territory', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (24, 'WEE_CustodyWarrantWithBailDirectionOnDischargeOfExtraditionPendingAppeal', 'Custody Warrant with Bail Direction on Discharge of Extradition Pending Appeal', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (25, 'WEE_CustodyWarrantWithBailDirectionOnDischargeOfExtraditionPendingAppealPart2', 'Custody Warrant with Bail Direction on Discharge of Extradition Pending Appeal (Part 2)', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (26, 'WEE_CustodyWarrantWithBailDirectionSendingToSecretaryOfStateCategory2Territory', 'Custody Warrant with Bail Direction Sending to Secretary of State – Category 2 Territory', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (27, 'WEE_CustodyWarrantWithBailDirectionSendingToSecretaryOfStateOnConsentCategory2Territory', 'Custody Warrant with Bail Direction Sending to Secretary of State on Consent – Category 2 Territory', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (28, 'WEE_ExtraditionRemandAfterBailAppealByProsecutor', 'Remand Warrant After Bail Appeal by Prosecutor - Extradition', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (29, 'WEE_ExtraditionSupplementToCustodyWarrant', 'Supplement to Custody Warrant on Extradition', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (30, 'OBE_TerminationOfFootballBanning', 'Application for Termination of Football Banning Order', 'ORDER');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (31, 'OBE_ChangeOfFootballBanning', 'Change of Football Banning Order', 'ORDER');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (32, 'NEE_FootballBanning', 'Notice of Football Banning Order', 'NOTICE');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (33, 'WEE_Remand', 'Remand Warrant', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (34, 'WXE_RemandWarrantYouthDetentionAccommodation', 'Remand Warrant - Youth Detention Accommodation', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (35, 'OXE_DetentionAndTraining', 'Detention and Training Order', 'ORDER');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (36, 'WEE_InjunctionDetention', 'Injunction Warrant of Detention', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (37, 'OPE_SupervisionOnBreachOfDetentionAndTraining', 'Supervision on Breach of Detention and Training Order', 'ORDER');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (38, 'WEE_CommittalToCrownCourtAuthorityToHoldInYouthDetentionAccommodation', 'Warrant of Committal to Crown Court - Authority to Hold in Youth Detention Accommodation', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (39, 'WEE_Detention', 'Warrant of Detention', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (40, 'WEE_DetentionInYouthDetentionAccommodationBreach', 'Warrant of Detention in Youth Detention Accommodation (Breach)', 'WARRANT');
INSERT INTO event_type (id, event_name, display_name, category) VALUES (41, 'WEE_SendingToCrownCourtAuthorityToHoldInYouthDetentionAccommodation', 'Warrant of Sending to Crown Court - Authority to Hold in Youth Detention Accommodation', 'WARRANT');
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import uk.gov.hmcts.cp.subscription.integration.helpers.JwtHelper;
import uk.gov.hmcts.cp.subscription.model.EntityEventType;
import uk.gov.hmcts.cp.subscription.repositories.DocumentMappingRepository;
import uk.gov.hmcts.cp.subscription.repositories.EventTypeRepository;
import uk.gov.hmcts.cp.subscription.repositories.SubscriptionRepository;
import uk.gov.hmcts.cp.subscription.services.ClockService;

Expand Down Expand Up @@ -51,6 +52,9 @@ public abstract class IntegrationTestBase {
@Autowired
protected DocumentMappingRepository documentMappingRepository;

@Autowired
protected EventTypeRepository eventTypeRepository;

@Autowired
protected ClockService clockService;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package uk.gov.hmcts.cp.subscription.integration.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.test.web.servlet.MvcResult;
import uk.gov.hmcts.cp.openapi.model.EventTypePayload;
import uk.gov.hmcts.cp.openapi.model.EventTypeResponse;
import uk.gov.hmcts.cp.subscription.integration.IntegrationTestBase;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class SubscriptionEventTypeGetControllerIntegrationTest extends IntegrationTestBase {

public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

@Test
void get_subscription_should_return_expected() throws Exception {
EventTypePayload expectedEventType1 = EventTypePayload.builder()
.eventName("PRISON_COURT_REGISTER_GENERATED")
.displayName("Prison court register")
.category("REGISTER")
.build();
EventTypePayload expectedEventType2 = EventTypePayload.builder()
.eventName("WEE_Layout5")
.displayName("Warrant Supplement")
.category("WARRANT")
.build();

MvcResult result = mockMvc.perform(get("/event-types"))
.andDo(print())
.andExpect(status().isOk())
.andReturn();

EventTypeResponse getEventTypes = OBJECT_MAPPER.readValue(result.getResponse().getContentAsString(), EventTypeResponse.class);
assertThat(getEventTypes.getEvents().size()).isEqualTo(41);
assertThat(getEventTypes.getEvents()).contains(expectedEventType1, expectedEventType2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.gov.hmcts.cp.subscription.integration.repositories;

import org.junit.jupiter.api.Test;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity;
import uk.gov.hmcts.cp.subscription.integration.IntegrationTestBase;

import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;

class EventTypeRepositoryTest extends IntegrationTestBase {

@Transactional
@Test
void findAllEventTypes_should_return_document() {
EventTypeEntity entity1 = EventTypeEntity.builder()
.id(1L)
.eventName("PRISON_COURT_REGISTER_GENERATED")
.displayName("Prison court register")
.category("REGISTER")
.build();
EventTypeEntity entity2 = EventTypeEntity.builder()
.id(2L)
.eventName("WEE_Layout5")
.displayName("Warrant Supplement")
.category("WARRANT")
.build();

List<EventTypeEntity> found = eventTypeRepository.findAll();
assertThat(found.size()).isEqualTo(41);
assertThat(found).contains(entity1, entity2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package uk.gov.hmcts.cp.subscription.mappers;

import org.junit.jupiter.api.Test;
import uk.gov.hmcts.cp.openapi.model.EventTypePayload;
import uk.gov.hmcts.cp.openapi.model.EventTypeResponse;
import uk.gov.hmcts.cp.subscription.entities.EventTypeEntity;

import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

class EventTypeMapperTest {

EventTypeMapper eventTypeMapper = new EventTypeMapperImpl();

@Test
void entity_should_map_to_payload() {
EventTypeEntity entity1 = EventTypeEntity.builder()
.id(1L)
.eventName("PRISON_COURT_REGISTER_GENERATED")
.displayName("Prison court register")
.category("REGISTER")
.build();
EventTypeEntity entity2 = EventTypeEntity.builder()
.id(2L)
.eventName("WEE_Layout5")
.displayName("Warrant Supplement")
.category("WARRANT")
.build();

EventTypePayload expectedEventType1 = EventTypePayload.builder()
.eventName("PRISON_COURT_REGISTER_GENERATED")
.displayName("Prison court register")
.category("REGISTER")
.build();
EventTypePayload expectedEventType2 = EventTypePayload.builder()
.eventName("WEE_Layout5")
.displayName("Warrant Supplement")
.category("WARRANT")
.build();

List<EventTypePayload> expectedEventTypes = List.of(expectedEventType1, expectedEventType2);
EventTypeResponse eventTypes = eventTypeMapper.mapToEventTypes(List.of(entity1, entity2));
assertThat(eventTypes.getEvents()).isEqualTo(expectedEventTypes);
}


}
Loading
Loading