Skip to content

Commit

Permalink
Updated to Java 17
Browse files Browse the repository at this point in the history
* JDK 15 has been unsupported for a while
* Gson had to be replaced with Jackson
  • Loading branch information
tilovillwock committed May 31, 2024
1 parent 3c5ac86 commit 41efdde
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<properties>
<elasticsearch.version>7.15.2</elasticsearch.version>
<jacoco-maven-plugin.version>0.8.6</jacoco-maven-plugin.version>
<java.version>15</java.version>
<java.version>17</java.version>
<log4j2.version>2.17.1</log4j2.version>
<maven-sortpom-plugin.version>2.12.0</maven-sortpom-plugin.version>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -127,7 +127,7 @@ public class ElasticsearchUpdateQueueService {

private final ElasticsearchDao elasticsearchDao;

private final Gson gson;
private final ObjectMapper objectMapper;

private final DoiBuilder doiBuilder;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 41efdde

Please sign in to comment.