From 41efdde29ad9e6b7665e3f75c358243b9b9c4298 Mon Sep 17 00:00:00 2001 From: Tilo Villwock Date: Fri, 31 May 2024 15:16:57 +0200 Subject: [PATCH] Updated to Java 17 * JDK 15 has been unsupported for a while * Gson had to be replaced with Jackson --- pom.xml | 2 +- .../ElasticsearchUpdateQueueService.java | 87 ++++++++++++++----- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 562ae03110..1ab6c24ff5 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 7.15.2 0.8.6 - 15 + 17 2.17.1 2.12.0 yyyyMMddHHmmss diff --git a/src/main/java/eu/dzhw/fdz/metadatamanagement/searchmanagement/service/ElasticsearchUpdateQueueService.java b/src/main/java/eu/dzhw/fdz/metadatamanagement/searchmanagement/service/ElasticsearchUpdateQueueService.java index e9859ecc3d..34da6f1a05 100644 --- a/src/main/java/eu/dzhw/fdz/metadatamanagement/searchmanagement/service/ElasticsearchUpdateQueueService.java +++ b/src/main/java/eu/dzhw/fdz/metadatamanagement/searchmanagement/service/ElasticsearchUpdateQueueService.java @@ -9,6 +9,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.NotImplementedException; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.delete.DeleteRequest; @@ -19,8 +21,6 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import com.google.gson.Gson; - import eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.domain.AnalysisPackage; import eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.domain.projection.AnalysisPackageSubDocumentProjection; import eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.repository.AnalysisPackageRepository; @@ -127,7 +127,7 @@ public class ElasticsearchUpdateQueueService { private final ElasticsearchDao elasticsearchDao; - private final Gson gson; + private final ObjectMapper objectMapper; private final DoiBuilder doiBuilder; @@ -307,8 +307,12 @@ private boolean addUpsertActionForAnalysisPackage(ElasticsearchUpdateQueueItem l AnalysisPackageSearchDocument searchDocument = new AnalysisPackageSearchDocument( analysisPackage, release, configuration, doi, dataPackages, relatedPublications); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting an Analysis Package Document to JSON", e); + } return true; } return false; @@ -335,8 +339,13 @@ private boolean addUpsertActionForDataAcquisitionProjects(ElasticsearchUpdateQue DataAcquisitionProjectSearchDocument searchDocument = new DataAcquisitionProjectSearchDocument( project); - IndexRequest req = new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON); + IndexRequest req = null; + try { + req = new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a Data Acquisition Project Document to JSON", e); + } request.add(req); return true; } @@ -395,8 +404,12 @@ private boolean addUpsertActionForConcept(ElasticsearchUpdateQueueItem lockedIte new ConceptSearchDocument(concept, dataPackageSubDocuments, nestedDataPackageDocuments, questions, instruments, surveys, dataSets, variables); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a Concept Document to JSON", e); + } return true; } return false; @@ -443,8 +456,12 @@ private boolean addUpsertActionForInstrument(ElasticsearchUpdateQueueItem locked new InstrumentSearchDocument(instrument, dataPackage, surveys, questions, variables, dataSets, concepts, release, doi, configuration); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting an Instrument Document to JSON", e); + } return true; } return false; @@ -496,8 +513,12 @@ private boolean addUpsertActionForRelatedPublication(ElasticsearchUpdateQueueIte relatedPublication, dataPackageSubDocuments, nestedDataPackageDocuments, analysisPackageSubDocuments, nestedAnalysisPackageDocuments); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a Related Publication Document to JSON", e); + } return true; } return false; @@ -549,8 +570,12 @@ private boolean addUpsertActionForDataSet(ElasticsearchUpdateQueueItem lockedIte new DataSetSearchDocument(dataSet, dataPackage, variableProjections, surveys, instruments, questions, concepts, release, doi, configuration); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a DataSet Document to JSON", e); + } return true; } return false; @@ -585,8 +610,12 @@ private boolean addUpsertActionForSurvey(ElasticsearchUpdateQueueItem lockedItem SurveySearchDocument searchDocument = new SurveySearchDocument(survey, dataPackage, dataSets, variables, instruments, questions, concepts, release, doi, configuration); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a Survey Document to JSON", e); + } return true; } return false; @@ -654,8 +683,12 @@ private boolean addUpsertActionForVariable(ElasticsearchUpdateQueueItem lockedIt VariableSearchDocument searchDocument = new VariableSearchDocument(variable, dataSet, dataPackage, surveys, instruments, questions, concepts, release, doi, configuration); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a Variable Document to JSON", e); + } return true; } return false; @@ -701,8 +734,12 @@ private boolean addUpsertActionForQuestion(ElasticsearchUpdateQueueItem lockedIt QuestionSearchDocument searchDocument = new QuestionSearchDocument(question, dataPackage, instrument, surveys, variables, dataSets, concepts, release, doi, configuration); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a Question Document to JSON", e); + } return true; } return false; @@ -751,8 +788,12 @@ private boolean addUpsertActionForDataPackage(ElasticsearchUpdateQueueItem locke dataSets, variables, relatedPublications, surveys, questions, instruments, concepts, analysisPackages, release, doi, configuration); - request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) - .source(gson.toJson(searchDocument), XContentType.JSON)); + try { + request.add(new IndexRequest(lockedItem.getDocumentType().name()).id(searchDocument.getId()) + .source(this.objectMapper.writeValueAsString(searchDocument), XContentType.JSON)); + } catch (JsonProcessingException e) { + throw new RuntimeException("An error occurred while converting a data package Document to JSON", e); + } return true; } return false;