Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Hibernate Setup #62

Merged
merged 67 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d691967
Added hibernate, postgres, lombok and flyway. Set java version to 17.
lucas-phillips28 Oct 9, 2023
698d3b4
Updated Open API config
lucas-phillips28 Oct 9, 2023
df3491f
Added local docker compose to generate local db
lucas-phillips28 Oct 9, 2023
79006f1
Updated application.yaml with settings for hibernate and flyway
lucas-phillips28 Oct 9, 2023
005ca93
Added placeholder code for variables needed from key vault
lucas-phillips28 Oct 9, 2023
0e90389
Added SQL script to generate the database via flyway
lucas-phillips28 Oct 9, 2023
90f267b
Updated values.yaml to get correct environment variables from key vault
lucas-phillips28 Oct 9, 2023
4015ba6
Fixed environment vars in docker-compose-local.yml
lucas-phillips28 Oct 9, 2023
3b81386
Merge branch 'master' into feature/initial-setup
lucas-phillips28 Oct 9, 2023
ced1d0c
Updated README with details for running local docker image
lucas-phillips28 Oct 9, 2023
08748ec
Hibernate and rest controller for recording
lucas-phillips28 Oct 18, 2023
882a2d1
checkstyle fix
jasonpaige Nov 23, 2023
aa0f158
Remove old code for old db + created enums for new db types
lucas-phillips28 Nov 23, 2023
a90b9f8
Remove old db schema
lucas-phillips28 Nov 23, 2023
e093ebb
Fix Application.java re-added
lucas-phillips28 Nov 23, 2023
d395b0e
Add updated hibernate entities
lucas-phillips28 Nov 23, 2023
58f3a23
Add updated hibernate repositories
lucas-phillips28 Nov 23, 2023
fb35e16
Move id field out of each entity into base entity class
lucas-phillips28 Nov 23, 2023
64c7d10
Remove unused imports
lucas-phillips28 Nov 23, 2023
4c61aa4
Merge branch 'master' into feature/hibernate-setup
lucas-phillips28 Nov 23, 2023
bfbd7e7
Remove setting fields to false
lucas-phillips28 Nov 24, 2023
d283e69
Fix Class cannot have field of same name
lucas-phillips28 Nov 24, 2023
b1bc8ec
Add PMD suppressing on the enums
lucas-phillips28 Nov 24, 2023
0823eeb
Fix spacing
lucas-phillips28 Nov 24, 2023
b47a7f2
Merge branch 'master' into feature/hibernate-setup
lucas-phillips28 Nov 24, 2023
3537997
Fix editInstruction column with type json
lucas-phillips28 Nov 24, 2023
a40b6ec
Add tests for each of the entities and a helper class to generate ent…
lucas-phillips28 Nov 24, 2023
6dc6474
Fix checkstyle and pmd
lucas-phillips28 Nov 24, 2023
4f1155a
Merge branch 'master' into feature/hibernate-setup
lucas-phillips28 Nov 24, 2023
edf4c4f
Added hibernate, postgres, lombok and flyway. Set java version to 17.
lucas-phillips28 Oct 9, 2023
fcc86b7
Updated Open API config
lucas-phillips28 Oct 9, 2023
9e51f10
Added local docker compose to generate local db
lucas-phillips28 Oct 9, 2023
1022951
Updated application.yaml with settings for hibernate and flyway
lucas-phillips28 Oct 9, 2023
305d1be
Added placeholder code for variables needed from key vault
lucas-phillips28 Oct 9, 2023
a55a9bc
Added SQL script to generate the database via flyway
lucas-phillips28 Oct 9, 2023
1c77902
Fixed environment vars in docker-compose-local.yml
lucas-phillips28 Oct 9, 2023
4761228
Updated README with details for running local docker image
lucas-phillips28 Oct 9, 2023
b035c69
Hibernate and rest controller for recording
lucas-phillips28 Oct 18, 2023
4f8c9ae
checkstyle fix
jasonpaige Nov 23, 2023
f92c878
removed duplicate flyway gradle tasks
jasonpaige Nov 27, 2023
abbc61a
Bumping chart version/ fixing aliases
hmcts-jenkins-cnp[bot] Nov 27, 2023
bac2e9b
Merge branch 'feature/hibernate-setup-updated' into feature/hibernate…
lucas-phillips28 Nov 27, 2023
c14b370
Remove old code for old db
lucas-phillips28 Nov 27, 2023
0804528
Remove old code for old db
lucas-phillips28 Nov 27, 2023
99498cf
Fix Enum types work correctly now
lucas-phillips28 Nov 27, 2023
40dbaf0
Remove BookingParticipant entity and replaced with many to many
lucas-phillips28 Nov 27, 2023
fc121c9
Update entities to match new schema changes
lucas-phillips28 Nov 27, 2023
cdd437a
Update entities to match new schema changes (deleted -> deleted_at)
lucas-phillips28 Nov 28, 2023
e932a3e
Fix Tests for updated entities
lucas-phillips28 Nov 28, 2023
92792fe
Styling
lucas-phillips28 Nov 28, 2023
98b3cd1
Styling
lucas-phillips28 Nov 28, 2023
aa6db13
Update entities to match new schema changes (capture session, recording)
lucas-phillips28 Nov 28, 2023
80d0448
Revert readme changes
lucas-phillips28 Nov 29, 2023
87a018a
Merge branch 'master' into feature/hibernate-setup
lucas-phillips28 Nov 29, 2023
5f10977
Update build.gradle
lucas-phillips28 Nov 29, 2023
2cdad86
Move schema file db.migrations -> db.migration
lucas-phillips28 Nov 29, 2023
7e2f313
Revert springboot version to fix enum errors
lucas-phillips28 Nov 29, 2023
97eb330
Merge branch 'master' into feature/hibernate-setup
lucas-phillips28 Nov 30, 2023
609af1b
Move tests to integration testing
lucas-phillips28 Nov 30, 2023
c093349
Merge branch 'master' into feature/hibernate-setup
lucas-phillips28 Nov 30, 2023
df3a8fc
Remove timezone setting
lucas-phillips28 Nov 30, 2023
9995da5
Add comment for downgraded spring plugin
lucas-phillips28 Nov 30, 2023
9424cbd
Add default test user to entity factory
lucas-phillips28 Nov 30, 2023
5423994
Capitalize enums in db and code
lucas-phillips28 Nov 30, 2023
379ba12
Merge remote-tracking branch 'origin/feature/hibernate-setup' into fe…
lucas-phillips28 Nov 30, 2023
793150b
Update column definition default
lucas-phillips28 Nov 30, 2023
2ae8723
Merge branch 'master' into feature/hibernate-setup
jasonpaige Nov 30, 2023
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
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ plugins {
id 'pmd'
id 'jacoco'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.springframework.boot' version '3.2.0'
id 'org.springframework.boot' version '3.1.5' // issues with 3.2.0 https://github.com/spring-projects/spring-framework/issues/31705
id 'org.owasp.dependencycheck' version '9.0.1'
id 'com.github.ben-manes.versions' version '0.50.0'
id 'org.sonarqube' version '4.4.1.3373'
id "io.freefair.lombok" version "8.3"
id 'org.flywaydb.flyway' version '9.22.3' // issues with 10.0.x https://github.com/spring-projects/spring-boot/issues/38164
}

Expand Down Expand Up @@ -226,8 +227,8 @@ dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-json'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.2.0'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'

implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: '6.0.1'

Expand All @@ -236,12 +237,16 @@ dependencies {

implementation group: 'org.flywaydb', name: 'flyway-core', version: '9.22.3'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.7.0'
implementation group: 'io.hypersistence', name: 'hypersistence-utils-hibernate-62', version: '3.6.1'

implementation group: 'io.rest-assured', name: 'rest-assured'

annotationProcessor('org.hibernate.orm:hibernate-jpamodelgen:6.3.1.Final')

testImplementation 'com.github.hmcts:fortify-client:1.3.0:all'
testImplementation 'org.springframework.security:spring-security-test:6.2.0'
testImplementation libraries.junit5

testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', {
exclude group: 'junit', module: 'junit'
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
Expand Down Expand Up @@ -291,5 +296,5 @@ rootProject.tasks.named("processSmokeTestResources") {
}

wrapper {
distributionType = Wrapper.DistributionType.ALL
distributionType = Wrapper.DistributionType.ALL
}
2 changes: 1 addition & 1 deletion charts/pre-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ appVersion: "1.0"
description: A Helm chart for pre-api App
name: pre-api
home: https://github.com/hmcts/pre-api
version: 0.0.19
version: 0.0.20
maintainers:
- name: HMCTS pre team
dependencies:
Expand Down
1 change: 0 additions & 1 deletion charts/pre-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ java:
image: 'sdshmctspublic.azurecr.io/pre/api:latest'
ingressHost: pre-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal
aadIdentityName: pre
# Uncomment once the vault containing the app insights key has been set up
keyVaults:
pre:
secrets:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package uk.gov.hmcts.reform.preapi.entities;

import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import uk.gov.hmcts.reform.preapi.Application;
import uk.gov.hmcts.reform.preapi.enums.CourtType;

import java.sql.Date;
import java.sql.Timestamp;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest(classes = Application.class)
class AppAccessTest {

@Autowired
private EntityManager entityManager;

@Test
@Transactional
public void testSaveAndRetrieveAppAccess() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate
User user = HelperFactory.createUser(
lucas-phillips28 marked this conversation as resolved.
Show resolved Hide resolved
"Test",
"User",
"[email protected]",
new Timestamp(System.currentTimeMillis()),
null,
null
);
entityManager.persist(user);

Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", "Test123");
entityManager.persist(court);

Role role = HelperFactory.createRole("TestRole");
entityManager.persist(role);

AppAccess appAccess = HelperFactory.createAppAccess(
user,
court,
role,
true,
new Timestamp(System.currentTimeMillis()),
new Date(System.currentTimeMillis())
);

entityManager.persist(appAccess);
entityManager.flush();

AppAccess retrievedAppAccess = entityManager.find(AppAccess.class, appAccess.getId());

assertEquals(appAccess.getId(), retrievedAppAccess.getId(), "Ids should match");
assertEquals(appAccess.getUser(), retrievedAppAccess.getUser(), "Users should match");
assertEquals(appAccess.getCourt(), retrievedAppAccess.getCourt(), "Courts should match");
assertEquals(appAccess.getRole(), retrievedAppAccess.getRole(), "Roles should match");
assertEquals(appAccess.getLastAccess(), retrievedAppAccess.getLastAccess(), "Last access should match");
assertEquals(appAccess.isActive(), retrievedAppAccess.isActive(), "Active status should match");
assertEquals(appAccess.getDeletedAt(), retrievedAppAccess.getDeletedAt(), "Deleted at should match");
assertEquals(appAccess.getCreatedAt(), retrievedAppAccess.getCreatedAt(), "Created at should match");
assertEquals(appAccess.getModifiedAt(), retrievedAppAccess.getModifiedAt(), "Modified at should match");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package uk.gov.hmcts.reform.preapi.entities;

import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import uk.gov.hmcts.reform.preapi.Application;
import uk.gov.hmcts.reform.preapi.enums.AuditLogSource;
import uk.gov.hmcts.reform.preapi.enums.AuditLogType;

import java.sql.Timestamp;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest(classes = Application.class)
class AuditTest {

@Autowired
private EntityManager entityManager;

@Test
@Transactional
public void testSaveAndRetrieveAudit() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate
Audit audit = new Audit();
audit.setTableName("TestTable");
audit.setTableRecordId(UUID.randomUUID());
audit.setSource(AuditLogSource.PORTAL);
audit.setType(AuditLogType.CREATE);
audit.setCategory("TestCategory");
audit.setActivity("TestActivity");
audit.setFunctionalArea("TestFunctionalArea");
audit.setAuditDetails("TestAuditDetails");
audit.setCreatedBy("TestUser");
audit.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
entityManager.persist(audit);
entityManager.flush();

Audit retrievedAudit = entityManager.find(Audit.class, audit.getId());

assertEquals(audit.getId(), retrievedAudit.getId(), "Id should match");
assertEquals(audit.getTableName(), retrievedAudit.getTableName(), "Table names should match");
assertEquals(audit.getTableRecordId(), retrievedAudit.getTableRecordId(), "Record ids should match");
assertEquals(audit.getSource(), retrievedAudit.getSource(), "Source should match");
assertEquals(audit.getType(), retrievedAudit.getType(), "Type should match");
assertEquals(audit.getCategory(), retrievedAudit.getCategory(), "Category should match");
assertEquals(audit.getActivity(), retrievedAudit.getActivity(), "Activity should match");
assertEquals(audit.getFunctionalArea(), retrievedAudit.getFunctionalArea(), "Functional area should match");
assertEquals(audit.getAuditDetails(), retrievedAudit.getAuditDetails(), "Audit details should match");
assertEquals(audit.getCreatedBy(), retrievedAudit.getCreatedBy(), "Created by should match");
assertEquals(audit.getCreatedAt(), retrievedAudit.getCreatedAt(), "Created at should match");
assertEquals(audit.getUpdatedAt(), retrievedAudit.getUpdatedAt(), "Updated at should match");
assertEquals(audit.getDeletedAt(), retrievedAudit.getDeletedAt(), "Deleted at should match");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.hmcts.reform.preapi.entities;


import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import uk.gov.hmcts.reform.preapi.Application;
import uk.gov.hmcts.reform.preapi.enums.CourtType;

import java.sql.Timestamp;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest(classes = Application.class)
class BookingTest {

@Autowired
private EntityManager entityManager;

@Test
@Transactional
public void testSaveAndRetrieveBooking() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate
Timestamp now = new Timestamp(System.currentTimeMillis());
Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", null);
entityManager.persist(court);

Case testCase = HelperFactory.createCase(court, "ref1234", true, now);
entityManager.persist(testCase);

Booking booking = HelperFactory.createBooking(testCase, now, now);
entityManager.persist(booking);
entityManager.flush();

Booking retrievedBooking = entityManager.find(Booking.class, booking.getId());

assertEquals(booking.getId(), retrievedBooking.getId(), "Id should match");
assertEquals(booking.getCaseId(), retrievedBooking.getCaseId(), "Case should match");
assertEquals(booking.getScheduledFor(), retrievedBooking.getScheduledFor(), "Scheduled for should match");
assertEquals(booking.getDeletedAt(), retrievedBooking.getDeletedAt(), "Deleted at should match");
assertEquals(booking.getCreatedAt(), retrievedBooking.getCreatedAt(), "Created at should match");
assertEquals(booking.getModifiedAt(), retrievedBooking.getModifiedAt(), "Modified at should match");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package uk.gov.hmcts.reform.preapi.entities;

import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import uk.gov.hmcts.reform.preapi.Application;
import uk.gov.hmcts.reform.preapi.enums.CourtType;
import uk.gov.hmcts.reform.preapi.enums.RecordingOrigin;
import uk.gov.hmcts.reform.preapi.enums.RecordingStatus;

import java.sql.Timestamp;
import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest(classes = Application.class)
class CaptureSessionTest {

@Autowired
private EntityManager entityManager;

@Test
@Transactional
public void testSaveAndRetrieveCaptureSession() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate
Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", null);
entityManager.persist(court);

Case testCase = HelperFactory.createCase(court, "ref1234", true, new Timestamp(System.currentTimeMillis()));
entityManager.persist(testCase);

Booking booking = HelperFactory.createBooking(
testCase,
Timestamp.valueOf(LocalDateTime.now()),
new Timestamp(System.currentTimeMillis())
);
entityManager.persist(booking);

User user = HelperFactory.createDefaultTestUser();
entityManager.persist(user);

CaptureSession captureSession = HelperFactory.createCaptureSession(
booking,
RecordingOrigin.PRE,
"TestIngrestAddress",
"TestLiveOutputAddress",
new Timestamp(System.currentTimeMillis()),
user,
new Timestamp(System.currentTimeMillis()),
user,
RecordingStatus.FINISHED,
new Timestamp(System.currentTimeMillis())
);
entityManager.persist(captureSession);
entityManager.flush();

CaptureSession retrievedCaptureSession = entityManager.find(CaptureSession.class, captureSession.getId());

assertEquals(captureSession.getId(), retrievedCaptureSession.getId(), "Id should match");
assertEquals(captureSession.getBooking(), retrievedCaptureSession.getBooking(), "Booking should match");
assertEquals(captureSession.getOrigin(), retrievedCaptureSession.getOrigin(), "Origin should match");
assertEquals(
captureSession.getIngestAddress(),
retrievedCaptureSession.getIngestAddress(),
"Ingest address should match"
);
assertEquals(
captureSession.getLiveOutputUrl(),
retrievedCaptureSession.getLiveOutputUrl(),
"Live output url should match"
);
assertEquals(captureSession.getStartedAt(), retrievedCaptureSession.getStartedAt(), "Started at should match");
assertEquals(
captureSession.getStartedByUser(),
retrievedCaptureSession.getStartedByUser(),
"Started by by user should match"
);
assertEquals(
captureSession.getFinishedAt(),
retrievedCaptureSession.getFinishedAt(),
"Finished at should match"
);
assertEquals(
captureSession.getFinishedByUserId(),
retrievedCaptureSession.getFinishedByUserId(),
"Finished by user should match"
);
assertEquals(captureSession.getStatus(), retrievedCaptureSession.getStatus(), "Status should match");
assertEquals(captureSession.getDeletedAt(), retrievedCaptureSession.getDeletedAt(), "Deleted at should match");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package uk.gov.hmcts.reform.preapi.entities;

import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import uk.gov.hmcts.reform.preapi.Application;
import uk.gov.hmcts.reform.preapi.enums.CourtType;

import java.sql.Timestamp;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest(classes = Application.class)
class CaseTest {

@Autowired
private EntityManager entityManager;

@Test
@Transactional
public void testSaveAndRetrieveCase() { //NOPMD - suppressed JUnit5TestShouldBePackagePrivate
Court court = HelperFactory.createCourt(CourtType.CROWN, "Test Court", null);
entityManager.persist(court);

Case testCase = HelperFactory.createCase(court, "ref1234", true, new Timestamp(System.currentTimeMillis()));
entityManager.persist(testCase);
entityManager.flush();

Case retrievedCase = entityManager.find(Case.class, testCase.getId());

assertEquals(testCase.getId(), retrievedCase.getId(), "Id should match");
assertEquals(testCase.getCourt(), retrievedCase.getCourt(), "Court should match");
assertEquals(testCase.getReference(), retrievedCase.getReference(), "Case reference should match");
assertEquals(testCase.isTest(), retrievedCase.isTest(), "Test status should match");
assertEquals(testCase.getDeletedAt(), retrievedCase.getDeletedAt(), "Deleted at should match");
assertEquals(testCase.getCreatedAt(), retrievedCase.getCreatedAt(), "Created at should match");
assertEquals(testCase.getModifiedAt(), retrievedCase.getModifiedAt(), "Modified at should match");
}
}
Loading