Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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 Jenkinsfile_CNP
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def app = "definition-store-api"
def branchesToSync = ['demo', 'ithc', 'perftest', 'develop']

// Variables to switch pipeline logic and wiring per type of build
def definitionStoreDevelopPr = "PR-575" // This doesn't change frequently, but when it does, only change this value.
def definitionStoreDevelopPr = "PR-1574" // This doesn't change frequently, but when it does, only change this value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be reverted prior to merge


def secrets = [
'ccd-${env}': [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/d3b02d95faf6419ca6fbb15b2e712b8b)](https://www.codacy.com/app/adr1ancho/ccd-definition-store-api?utm_source=github.com&utm_medium=referral&utm_content=hmcts/ccd-definition-store-api&utm_campaign=Badge_Coverage)
[![Known Vulnerabilities](https://snyk.io/test/github/hmcts/ccd-definition-store-api/badge.svg)](https://snyk.io/test/github/hmcts/ccd-definition-store-api)
[![HitCount](http://hits.dwyl.io/hmcts/ccd-definition-store-api.svg)](#ccd-definition-store-api)

Validation and persistence of definitions for field types, jurisdictions, case types and associated display elements.

## Overview
Expand Down
1 change: 1 addition & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {

testImplementation project(":app-insights").sourceSets.main.output
testImplementation project(":commons").sourceSets.main.output
testImplementation("org.json:json:20250517")
}

rootProject.tasks.named("distTar") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package uk.gov.hmcts.net.ccd.definition.store.excel;

import com.github.tomakehurst.wiremock.client.WireMock;
import org.apache.http.HttpStatus;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.ccd.definition.store.excel.client.translation.DictionaryRequest;
import uk.gov.hmcts.ccd.definition.store.excel.client.translation.Translation;
import uk.gov.hmcts.ccd.definition.store.repository.SecurityClassification;
Expand All @@ -17,22 +31,6 @@
import java.util.Map;
import java.util.regex.Pattern;

import com.github.tomakehurst.wiremock.client.WireMock;
import org.apache.http.HttpStatus;
import org.hamcrest.Matcher;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.transaction.annotation.Transactional;

import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
Expand Down Expand Up @@ -131,7 +129,7 @@ public void importValidDefinitionFile_TranslationService_return4XX() throws Exce
stubForPutDictionaryReturns4XX(getDictionaryRequest());

MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.multipart(IMPORT_URL)

.file(file)
.header(AUTHORIZATION, "Bearer testUser"))
.andReturn();
Expand Down Expand Up @@ -348,12 +346,12 @@ public static Matcher<Map<String, Object>> hasColumn(String key, Object value) {
return hasColumn(is(key), is(value));
}

private void assertBody(String contentAsString) throws IOException, URISyntaxException, JSONException {
private void assertBody(String contentAsString) throws IOException, URISyntaxException {
assertBody(contentAsString, RESPONSE_JSON_V55);
}

private void assertBody(String contentAsString, String fileName)
throws IOException, URISyntaxException, JSONException {
throws IOException, URISyntaxException {

String expected = readFileToString(new File(getClass().getClassLoader()
.getResource(fileName)
Expand Down
37 changes: 30 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ tasks.register("printSuppressionFile") {
}

ext {
set('elasticsearch.version', '8.16.2')
set('spring-framework.version', '6.2.1')
set('spring-security.version', '6.4.2')
set('springCloudVersion', '2024.0.0')
set('jackson.version', '2.16.0')
set('snakeyaml.version', '2.3')
set('log4j2.version', '2.24.3')

elasticsearchVersion = '9.1.2'
junitJupiterVersion = '5.11.4'
junitVintageVersion = '5.11.4'
springDocVersion = '2.8.11'
Expand Down Expand Up @@ -91,13 +91,34 @@ allprojects {
mockitoAgent
codacy
}
configurations.configureEach {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}

configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.elasticsearch') {
details.useVersion elasticsearchVersion
}

if (details.requested.group == 'co.elastic.clients') {
details.useVersion elasticsearchVersion
}

if (details.requested.group == 'org.elasticsearch.client') {
details.useVersion elasticsearchVersion
}
}
}
}

apply plugin: 'java'

// Global constraints
dependencies {

// start::CVE Vulnerability dependency overrides
// start::CVE Vulnerability dependency overrides

implementation group: 'commons-fileupload', name: 'commons-fileupload', version: '1.6.0' // spring-cloud-starter-openfeign
implementation group: 'commons-io', name: 'commons-io', version: '2.20.0' // spring-cloud-starter-openfeign
Expand Down Expand Up @@ -130,7 +151,7 @@ allprojects {
testImplementation group: 'org.apache.groovy', name: 'groovy-xml', version: groovyVersion
testImplementation group: 'org.apache.groovy', name: 'groovy-json', version: groovyVersion
testImplementation group: 'com.github.hmcts', name: 'fortify-client', version: '1.4.10', classifier: 'all'

testImplementation("org.json:json:20250517")
}

}
Expand Down Expand Up @@ -195,7 +216,7 @@ subprojects { subproject ->

dependencies {

// start::CVE Vulnerability dependency overrides
// start::CVE Vulnerability dependency overrides

implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '10.4.2' // spring-boot-starter-oauth2-client
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0' // azure-storage
Expand Down Expand Up @@ -243,8 +264,9 @@ subprojects { subproject ->
implementation group: 'org.apache.poi', name: 'poi', version: apachePoiVersion
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: apachePoiVersion
implementation group: 'org.apache.poi', name: 'poi-scratchpad', version: apachePoiVersion
implementation group: 'org.elasticsearch', name: 'elasticsearch', version: elasticSearchVersion
implementation group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: elasticSearchVersion
implementation group: 'org.elasticsearch', name: 'elasticsearch', version: elasticsearchVersion
implementation group: 'co.elastic.clients', name: 'elasticsearch-java', version: elasticsearchVersion
implementation group: 'org.elasticsearch.client', name: 'elasticsearch-rest-client', version: elasticsearchVersion
implementation group: 'org.flywaydb', name: 'flyway-core', version: flywayVersion
implementation group: 'org.flywaydb', name: 'flyway-database-postgresql', version: flywayVersion
implementation group: 'org.jooq', name: 'jool-java-8', version: '0.9.15'
Expand Down Expand Up @@ -283,6 +305,7 @@ subprojects { subproject ->
testImplementation group: 'com.github.hmcts', name: 'ccd-test-definitions', version: ccdTestDefinitionVersion
testImplementation group: 'com.github.hmcts', name: 'befta-fw', version: beftaFwVersion
testImplementation group: 'info.solidsoft.gradle.pitest', name: 'gradle-pitest-plugin', version: '1.4.0'
testImplementation 'org.skyscreamer:jsonassert:1.5.1'
}

// from https://github.com/junit-team/junit5/issues/1024'
Expand Down Expand Up @@ -525,4 +548,4 @@ void loadEnvSecrets(String env) {
project.file("./.${env}-remote-env").write(new String(os.toString().replace('\n', '').decodeBase64(), java.nio.charset.StandardCharsets.UTF_8))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ java:
# enable whenever required and provide host url to match with corresponding data-store-api
ELASTIC_SEARCH_ENABLED: true

ELASTIC_SEARCH_HOST: ccd-data-store-api-pr-1260-es-master
ELASTIC_SEARCH_HOST: ccd-data-store-api-pr-2620-es-master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be reverted before merging


USER_PROFILE_HOST: http://ccd-user-profile-api-pr-399-java

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package uk.gov.hmcts.ccd.definition.store.elastic;

import co.elastic.clients.elasticsearch.core.ReindexResponse;
import co.elastic.clients.elasticsearch.indices.GetAliasResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.GetAliasesResponse;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.ccd.definition.store.elastic.client.HighLevelCCDElasticClient;
Expand Down Expand Up @@ -60,7 +60,8 @@ public void initialiseElasticSearch(DefinitionImportedEvent event) {
String caseMapping = null;
CaseTypeEntity currentCaseType = null;

try (HighLevelCCDElasticClient elasticClient = clientFactory.getObject()) {
HighLevelCCDElasticClient elasticClient = clientFactory.getObject();
try {
for (CaseTypeEntity caseType : caseTypes) {
currentCaseType = caseType;
String baseIndexName = baseIndexName(caseType);
Expand All @@ -71,8 +72,8 @@ public void initialiseElasticSearch(DefinitionImportedEvent event) {
}
if (reindex) {
//get current alias index
GetAliasesResponse aliasResponse = elasticClient.getAlias(baseIndexName);
String caseTypeName = aliasResponse.getAliases().keySet().iterator().next();
GetAliasResponse aliasResponse = elasticClient.getAlias(baseIndexName);
String caseTypeName = aliasResponse.aliases().keySet().iterator().next();

//create new index with generated mapping and incremented case type name (no alias update yet)
caseMapping = mappingGenerator.generateMapping(caseType);
Expand Down Expand Up @@ -109,7 +110,7 @@ private void handleReindexing(String baseIndexName,
HighLevelCCDElasticClient elasticClient = clientFactory.getObject();
elasticClient.reindexData(oldIndex, newIndex, new ActionListener<>() {
@Override
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
public void onResponse(ReindexResponse reindexResponse) {
try (elasticClient; HighLevelCCDElasticClient asyncElasticClient = clientFactory.getObject()) {
//if success set writable and update alias to new index
log.info("updating alias from {} to {}", oldIndex, newIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public void initialiseElasticSearchForGlobalSearch() {

} catch (IOException | ElasticsearchStatusException e) {
throw new ElasticSearchInitialisationException(e);
} finally {
if (elasticClient != null) {
elasticClient.close();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package uk.gov.hmcts.ccd.definition.store.elastic.client;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.elasticsearch.client.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Map;
import java.util.function.Supplier;

public class ElasticsearchClientFactory {

private static final Logger log = LoggerFactory.getLogger(ElasticsearchClientFactory.class);
private final Supplier<RestClient> restClientSupplier;
private final JacksonJsonpMapper mapper;

public ElasticsearchClientFactory(Supplier<RestClient> restClientSupplier, JacksonJsonpMapper mapper) {
this.restClientSupplier = restClientSupplier;
this.mapper = mapper;
}

public ElasticsearchClient createClient() {
RestClient restClient = restClientSupplier.get();
RestClientTransport transport = new RestClientTransport(restClient, mapper);
ElasticsearchClient client = new ElasticsearchClient(transport);
try {
client.cluster().putSettings(s ->
s.persistent(Map.of("action.destructive_requires_name", JsonData.of(false)))
);
} catch (IOException e) {
log.error(e.getMessage(), e);
}

return client;
}
}
Loading