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

Elinks Dev branch #518

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
29 changes: 26 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
springBootVersion = '2.4.6'
}
dependencies {
classpath("net.serenity-bdd:serenity-gradle-plugin:2.0.11")
classpath("net.serenity-bdd:serenity-gradle-plugin:2.4.34")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
Expand Down Expand Up @@ -32,7 +32,7 @@ apply plugin: "io.spring.dependency-management"
def versions = [
lombok : '1.18.22',
reformLogging : '5.1.9',
serenity : '2.0.23',
serenity : '2.0.76',
sonarPitest : '0.5',
springBoot : '2.6.6',
springHystrix : '2.2.8.RELEASE',
Expand Down Expand Up @@ -223,7 +223,11 @@ sonarqube {
"src/main/java/uk/gov/hmcts/reform/juddata/JudicialApplication.java," +
"src/main/java/uk/gov/hmcts/reform/juddata/client/**," +
"src/main/java/uk/gov/hmcts/reform/juddata/response/**," +
"src/main/java/uk/gov/hmcts/reform/juddata/camel/binder/**,"
"src/main/java/uk/gov/hmcts/reform/juddata/camel/binder/**," +
"src/main/java/uk/gov/hmcts/reform/elinks/configuration/**," +
"src/main/java/uk/gov/hmcts/reform/elinks/response/**," +
"src/main/java/uk/gov/hmcts/reform/elinks/domain/**," +
"src/main/java/uk/gov/hmcts/reform/elinks/util/**,"
}
}

Expand Down Expand Up @@ -301,6 +305,9 @@ dependencies {
implementation 'commons-io:commons-io:2.11.0'
implementation group: 'org.apache.camel', name: 'camel-bom', version: versions.camel, ext: 'pom'
implementation group: 'org.apache.camel.springboot', name: 'camel-spring-boot-dependencies', version: versions.camel
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: versions.springBoot

testImplementation group: 'io.rest-assured', name: 'rest-assured', version: '3.3.0'

testImplementation group: 'com.microsoft.azure', name: 'azure-storage-blob', version: '11.0.0'

Expand Down Expand Up @@ -347,7 +354,23 @@ dependencies {
exclude group: "org.hamcrest", module: "hamcrest-core"
exclude group: "org.hamcrest", module: "hamcrest-library"
}
testImplementation ("com.github.tomakehurst:wiremock-jre8:2.32.0") {
exclude group: 'com.github.jknack'
}

testCompileOnly group: 'org.projectlombok', name: 'lombok', version: versions.lombok
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: versions.lombok
integrationTestCompileOnly group: 'org.projectlombok', name: 'lombok', version: versions.lombok
integrationTestAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: versions.lombok
functionalTestCompileOnly group: 'org.projectlombok', name: 'lombok', version: versions.lombok
functionalTestAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: versions.lombok

testImplementation ('com.github.hmcts:rd-commons-lib:v0.0.13'){
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-web'
}

implementation group: 'org.yaml', name: 'snakeyaml', version: '1.33'
implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '8.20'
testImplementation (group: 'io.rest-assured', name: 'rest-assured', version: '4.1.2') {
exclude group: "com.sun.xml.bind", module: "jaxb-osgi"
}
Expand Down
3 changes: 3 additions & 0 deletions config/owasp/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@
<cve>CVE-2021-37533</cve>
<cve>CVE-2022-45046</cve>
</suppress>
<suppress until="2024-01-01">
<cve>CVE-2022-41881</cve>
</suppress>
</suppressions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
--Require to modify flywayscript to run integration test cases

DROP SCHEMA if EXISTS dbjudicialdata CASCADE;

CREATE SCHEMA IF NOT EXISTS dbjudicialdata;



-- Create table script : base_location_type
CREATE TABLE dbjudicialdata.base_location_type (
base_location_id varchar(64) NOT NULL,
court_name varchar(128) NULL,
court_type varchar(128) NULL,
circuit varchar(128) NULL,
area_of_expertise varchar(128) NULL,
CONSTRAINT base_location_id PRIMARY KEY (base_location_id)
);

-- Create table script : region_type
CREATE TABLE dbjudicialdata.region_type (
region_id varchar(64) NOT NULL,
region_desc_en varchar(256) NOT NULL,
region_desc_cy varchar(256) NULL,
CONSTRAINT region_id PRIMARY KEY (region_id)
);



-- Create table script : judicial_user_profile
CREATE TABLE dbjudicialdata.judicial_user_profile (
personal_code varchar(32) NOT NULL,
known_as varchar(64) NOT NULL,
surname varchar(256) NOT NULL,
full_name varchar(256) NOT NULL,
post_nominals varchar(64) NULL,
ejudiciary_email varchar(256) NULL,
last_working_date date NULL,
active_flag boolean NULL,
created_date timestamp NULL,
last_loaded_date timestamp NULL,
object_id varchar(64) NULL,
sidam_id varchar(64) NULL,
initials varchar(64) NULL,
CONSTRAINT judicial_user_profile_pkey PRIMARY KEY (personal_code)
);

-- Create table script : judicial_role_type
CREATE TABLE dbjudicialdata.judicial_role_type (
role_id SERIAL,
personal_code varchar(32) NOT NULL,
title varchar(256) NULL,
start_date timestamp NULL,
end_date timestamp NULL,
CONSTRAINT role_id PRIMARY KEY (role_id),
CONSTRAINT personal_code_fk FOREIGN KEY (personal_code) REFERENCES dbjudicialdata.judicial_user_profile(personal_code)
);



-- Create table script : judicial_office_authorisation
CREATE TABLE dbjudicialdata.judicial_office_authorisation (
judicial_office_auth_id bigint NOT NULL,
personal_code varchar(32) NOT NULL,
jurisdiction varchar(256) NULL,
start_date timestamp NULL,
end_date timestamp NULL,
created_date timestamp NULL,
last_updated timestamp NULL,
lower_level varchar(256) NULL,
object_id varchar(64) NULL,
ticket_code varchar(16) NULL,
CONSTRAINT jud_auth_pk PRIMARY KEY (judicial_office_auth_id),
CONSTRAINT personal_code_fk FOREIGN KEY (personal_code) REFERENCES dbjudicialdata.judicial_user_profile(personal_code)

);

-- Create table script : judicial_office_appointment
CREATE TABLE dbjudicialdata.judicial_office_appointment (
judicial_office_appointment_id bigint NOT NULL,
personal_code varchar(32) NOT NULL,
base_location_id varchar(64) NULL,
region_id varchar(256) NULL,
is_prinicple_appointment boolean NULL,
start_date date NULL,
end_date date NULL,
created_date timestamp NULL,
last_loaded_date timestamp NULL,
epimms_id varchar(16) NULL,
service_code varchar(64) NULL,
object_id varchar(64) NULL,
appointment varchar(64) NULL,
appointment_type varchar(32) NULL,
work_pattern varchar(64) NULL,
CONSTRAINT judicial_office_appointment_id PRIMARY KEY (judicial_office_appointment_id),
CONSTRAINT base_location_id_fk1 FOREIGN KEY (base_location_id) REFERENCES dbjudicialdata.base_location_type(base_location_id),
CONSTRAINT personal_code_fk FOREIGN KEY (personal_code) REFERENCES dbjudicialdata.judicial_user_profile(personal_code),

CONSTRAINT region_id_fk1 FOREIGN KEY (region_id) REFERENCES dbjudicialdata.region_type(region_id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

CREATE TABLE dbjudicialdata.dataload_schedular_audit (
id serial NOT NULL,
scheduler_name varchar(64) NOT NULL,
scheduler_start_time timestamp NOT NULL,
scheduler_end_time timestamp NULL,
status varchar(32) NULL,
api_name varchar(128) NULL,
CONSTRAINT dataload_schedular_audit_pk PRIMARY KEY (id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--Create sequence for dbjudicialdata.judicial_office_authorisation
CREATE SEQUENCE dbjudicialdata.judicial_office_auth_id_sequence AS integer START 1 OWNED
BY dbjudicialdata.judicial_office_authorisation.judicial_office_auth_id;

ALTER TABLE dbjudicialdata.judicial_office_authorisation
ALTER COLUMN judicial_office_auth_id SET DEFAULT nextval('dbjudicialdata.judicial_office_auth_id_sequence');

--Create sequence for dbjudicialdata.judicial_office_appointment
CREATE SEQUENCE dbjudicialdata.judicial_office_appointment_id_sequence AS integer START 1 OWNED
BY dbjudicialdata.judicial_office_appointment.judicial_office_appointment_id;


ALTER TABLE dbjudicialdata.judicial_office_appointment
ALTER COLUMN judicial_office_appointment_id SET DEFAULT nextval('dbjudicialdata.judicial_office_appointment_id_sequence');


Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.gov.hmcts.reform.elinks.configuration;

import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

import javax.sql.DataSource;

@Configuration
public class DataConfig {

@Autowired
DataSource dataSource;


@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean emfb =
new LocalContainerEntityManagerFactoryBean();
emfb.setDataSource(dataSource);
emfb.setPersistenceProviderClass(HibernatePersistenceProvider.class);
emfb.setPackagesToScan("uk.gov.hmcts.reform.elinks");
return emfb;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
@Getter
@AllArgsConstructor
public class FeignHeaderConfig {

private final List<String> headers;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package uk.gov.hmcts.reform.elinks.domain;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;



@Entity(name = "dataload_schedular_audit")
@Table(name = "dbjudicialdata.dataload_schedular_audit")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ElinkDataSchedularAudit implements Serializable {

@Id
@GeneratedValue()
@Column(name = "id")
private int id;

@Column(name = "scheduler_name")
private String schedulerName;

@Column(name = "scheduler_start_time")
private LocalDateTime schedulerStartTime;

@Column(name = "scheduler_end_time")
private LocalDateTime schedulerEndTime;

@Column(name = "status")
private String status;

@Column(name = "api_name")
private String apiName;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.gov.hmcts.reform.elinks.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import uk.gov.hmcts.reform.elinks.domain.ElinkDataSchedularAudit;


@Repository
public interface ElinkSchedularAuditRepository extends JpaRepository<ElinkDataSchedularAudit, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package uk.gov.hmcts.reform.elinks.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.reform.elinks.domain.ElinkDataSchedularAudit;
import uk.gov.hmcts.reform.elinks.repository.ElinkSchedularAuditRepository;

import java.time.LocalDateTime;

@Component
@Slf4j
public class ElinkDataIngestionSchedularAudit {
@Value("${loggingComponentName}")
private String loggingComponentName;

@Autowired
private ElinkSchedularAuditRepository elinkSchedularAuditRepository;

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void auditSchedulerStatus(String schedulerName, LocalDateTime schedulerStartTime,
LocalDateTime schedulerEndTime, String status, String apiName) {

try {
ElinkDataSchedularAudit audit = new ElinkDataSchedularAudit();
audit.setSchedulerName(schedulerName);
audit.setSchedulerStartTime(schedulerStartTime);
audit.setSchedulerEndTime(schedulerEndTime);
audit.setStatus(status);
audit.setApiName(apiName);

elinkSchedularAuditRepository.save(audit);
} catch (Exception e) {
log.error("{}:: Failure error Message {} in auditSchedulerStatus {} ",
loggingComponentName, e.getMessage(), schedulerName);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import uk.gov.hmcts.reform.data.ingestion.camel.service.AuditServiceImpl;
import uk.gov.hmcts.reform.idam.client.IdamApi;
import uk.gov.hmcts.reform.juddata.camel.util.JrdDataIngestionLibraryRunner;
Expand All @@ -25,7 +25,8 @@
@Slf4j
@EnableFeignClients(basePackages = {
"uk.gov.hmcts.reform.juddata"}, basePackageClasses = {IdamApi.class})
public class JudicialApplication implements ApplicationRunner {
@EnableJpaRepositories(basePackages = "uk.gov.hmcts.reform")
public class JudicialApplication {

@Autowired
JobLauncher jobLauncher;
Expand All @@ -47,13 +48,12 @@ public class JudicialApplication implements ApplicationRunner {
public static void main(final String[] args) throws Exception {
ApplicationContext context = SpringApplication.run(JudicialApplication.class);
//Sleep added to allow app-insights to flush the logs
Thread.sleep(7000);
Thread.sleep(1000 * 60 * 60 * 10);
int exitCode = SpringApplication.exit(context);
log.info("{}:: Judicial Application exiting with exit code {} ", logComponentName, exitCode);
System.exit(exitCode);
}

@Override
public void run(ApplicationArguments args) throws Exception {
JobParameters params = new JobParametersBuilder()
.addString(jobName, String.valueOf(System.currentTimeMillis()))
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ management:
endpoint:
health:
show-details: "always"

loggingComponentName: RD-Judicial-dataload
spring:
application:
name: Judicial reference data blob store sync API
Expand Down
Loading