From c9928fa72a427f5c8cdd60dbf55e3c91bdfa6847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20K=C3=B6rner?= Date: Thu, 28 Mar 2024 18:05:58 +0100 Subject: [PATCH] Fix cached resources deserialization - for startup with resources from previous deployment --- CHANGELOG.md | 5 +++ .../sru/fcs/aggregator/app/Aggregator.java | 31 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cbca3..f0ed579 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +# WIP - 2024-03-28 + +- Bug Fixes: + - Fix cached resources (`fcsAggregatorResources.json`) deserialization (invisible non-default constructor of external FCS libraries) + # [3.9.1](https://github.com/clarin-eric/fcs-sru-aggregator/releases/tag/3.9.1) - 2024-02-05 - Bug Fixes: diff --git a/src/main/java/eu/clarin/sru/fcs/aggregator/app/Aggregator.java b/src/main/java/eu/clarin/sru/fcs/aggregator/app/Aggregator.java index 9d0509f..a20ae1e 100644 --- a/src/main/java/eu/clarin/sru/fcs/aggregator/app/Aggregator.java +++ b/src/main/java/eu/clarin/sru/fcs/aggregator/app/Aggregator.java @@ -1,5 +1,6 @@ package eu.clarin.sru.fcs.aggregator.app; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.optimaize.langdetect.LanguageDetector; import com.optimaize.langdetect.LanguageDetectorBuilder; @@ -15,6 +16,7 @@ import eu.clarin.sru.fcs.aggregator.scan.Resources; import eu.clarin.sru.client.SRUVersion; import eu.clarin.sru.client.fcs.ClarinFCSClientBuilder; +import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescription; import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescriptionParser; import eu.clarin.sru.fcs.aggregator.client.MaxConcurrentRequestsCallback; import eu.clarin.sru.fcs.aggregator.client.ThrottledClient; @@ -295,15 +297,20 @@ public int getMaxConcurrentRequest(URI baseURI) { // init resources from file { + ObjectMapper mapper = new ObjectMapper() + .addMixIn(ClarinFCSEndpointDescription.DataView.class, + ClarinFCSEndpointDescriptionDataViewMixin.class) + .addMixIn(ClarinFCSEndpointDescription.Layer.class, ClarinFCSEndpointDescriptionLayerMixin.class); + Resources resources = null; try { - resources = new ObjectMapper().readValue(resourcesCacheFile, Resources.class); + resources = mapper.readValue(resourcesCacheFile, Resources.class); } catch (Exception xc) { log.error("Failed to load cached resources from primary file:", xc); } if (resources == null) { try { - resources = new ObjectMapper().readValue(resourcesOldCacheFile, Resources.class); + resources = mapper.readValue(resourcesOldCacheFile, Resources.class); } catch (Exception e) { log.error("Failed to load cached resources from backup file:", e); } @@ -333,6 +340,26 @@ public int getMaxConcurrentRequest(URI baseURI) { log.info("Aggregator initialization finished."); } + // Definitions for Jackson Deserializer due to non-public non-default + // constructors + private static abstract class ClarinFCSEndpointDescriptionDataViewMixin { + @SuppressWarnings("unused") + ClarinFCSEndpointDescriptionDataViewMixin(@JsonProperty("identifier") String identifier, + @JsonProperty("mimeType") String mimeType, + @JsonProperty("deliveryPolicy") ClarinFCSEndpointDescription.DataView.DeliveryPolicy deliveryPolicy) { + } + } + + private static abstract class ClarinFCSEndpointDescriptionLayerMixin { + @SuppressWarnings("unused") + ClarinFCSEndpointDescriptionLayerMixin(@JsonProperty("identifier") String identifier, + @JsonProperty("resultId") URI resultId, @JsonProperty("layerType") String layerType, + @JsonProperty("encoding") ClarinFCSEndpointDescription.Layer.ContentEncoding encoding, + @JsonProperty("qualifier") String qualifier, @JsonProperty("altValueInfo") String altValueInfo, + @JsonProperty("altValueInfoURI") URI altValueInfoURI) { + } + } + public void shutdown(AggregatorConfiguration config) { log.info("Aggregator is shutting down."); for (Search search : activeSearches.values()) {