diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfiguration.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfiguration.java index 69fe1f82..f784ffc4 100644 --- a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfiguration.java +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfiguration.java @@ -11,4 +11,6 @@ public interface FormatterConfiguration { /** for testing purposes. */ void setLinkToLegacyGN4(Boolean linkToLegacyGN4); + + void setLinkToCustomUrl(Boolean linkToCustomUrl); } diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfigurationImpl.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfigurationImpl.java index f33cd7dc..8cb6d825 100644 --- a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfigurationImpl.java +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/FormatterConfigurationImpl.java @@ -9,9 +9,27 @@ public class FormatterConfigurationImpl implements FormatterConfiguration { @Value("${gn.linkToLegacyGN4:false}") Boolean linkToLegacyGN4; + /** + * Used to enable customMetadataUrl in rss response. + */ + @Value("${gn.linkToCustomMetadataUrl:false}") + Boolean linkToCustomMetadataUrl; + @Value("${gn.legacy.url}") String legacyUrl; + /** + * Used to override link to metadata in rss response BUT not source home page link. + * It takes precedence over legacyUrl if both enabled. + * By default, it will redirect to host url with a trailing slash + * and followed by the metadata uuid. + * e.g: http://geonetwork.org/uuid + * You can customize it by redirect to another service (always followed by metadata uuid). + * e.g: http://my-other-service.com/uuid + */ + @Value("${gn.customMetadataUrl:}") + String customMetadataUrl; + @Value("${gn.baseurl}") private String baseUrl; @@ -40,6 +58,11 @@ public String getSourceSiteTitle() { @Override public String buildLandingPageLink(String metadataId) { + if (linkToCustomMetadataUrl) { + return String.format("%s/%s", + customMetadataUrl, + metadataId); + } if (linkToLegacyGN4) { return String.format("%s/srv/metadata/%s", legacyUrl, @@ -55,4 +78,9 @@ public String buildLandingPageLink(String metadataId) { public void setLinkToLegacyGN4(Boolean linkToLegacyGN4) { this.linkToLegacyGN4 = linkToLegacyGN4; } + + @Override + public void setLinkToCustomUrl(Boolean linkToCustomMetadataUrl) { + this.linkToCustomMetadataUrl = linkToCustomMetadataUrl; + } } diff --git a/modules/library/common-search/src/test/java/org/fao/geonet/common/search/processor/impl/RssResponseProcessorImplTest.java b/modules/library/common-search/src/test/java/org/fao/geonet/common/search/processor/impl/RssResponseProcessorImplTest.java index fad0f7c9..737820bb 100644 --- a/modules/library/common-search/src/test/java/org/fao/geonet/common/search/processor/impl/RssResponseProcessorImplTest.java +++ b/modules/library/common-search/src/test/java/org/fao/geonet/common/search/processor/impl/RssResponseProcessorImplTest.java @@ -40,6 +40,7 @@ public class RssResponseProcessorImplTest { @Test public void channelLinkPointToGnServer() throws Exception { formatterConfiguration.setLinkToLegacyGN4(false); + formatterConfiguration.setLinkToCustomUrl(false); InputStream is = new ByteArrayInputStream("{}".getBytes(UTF_8)); ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -109,6 +110,27 @@ public void nominalOneItemToGn4() throws Exception { assertFalse(diff.hasDifferences()); } + @Test + public void nominalOneItemToCustom() throws Exception { + formatterConfiguration.setLinkToLegacyGN4(true); + formatterConfiguration.setLinkToCustomUrl(true); + + InputStream is = this.getClass().getResourceAsStream("es_flow.json"); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + + toTest.processResponse(null, is, os, null, null, null); + + InputStream expected = this.getClass().getResourceAsStream("one_item_feed_to_custom.xml"); + String actual = os.toString(UTF_8); + Diff diff = DiffBuilder + .compare(Input.fromStream(expected)) + .withTest(actual) + .withDifferenceEvaluator(EVALUATOR) + .ignoreWhitespace() + .build(); + assertFalse(diff.hasDifferences()); + } + @TestConfiguration static class RssResponseProcessorImplTestConf { @Bean @@ -120,6 +142,8 @@ public static PropertySourcesPlaceholderConfigurer properties() throws Exception properties.setProperty("gn.site.organization", "momorg"); properties.setProperty("gn.baseurl", "http://gn5:8277/geonetwork"); properties.setProperty("gn.linkToLegacyGN4", "true"); + properties.setProperty("gn.linkToCustomMetadataUrl", "false"); + properties.setProperty("gn.customMetadataUrl", "http://gn:8277/custom"); pspc.setProperties(properties); return pspc; } diff --git a/modules/library/common-search/src/test/resources/org/fao/geonet/common/search/processor/impl/one_item_feed_to_custom.xml b/modules/library/common-search/src/test/resources/org/fao/geonet/common/search/processor/impl/one_item_feed_to_custom.xml new file mode 100644 index 00000000..bd98b0b9 --- /dev/null +++ b/modules/library/common-search/src/test/resources/org/fao/geonet/common/search/processor/impl/one_item_feed_to_custom.xml @@ -0,0 +1,13 @@ + + + the geonetwork momorg + http://gn4:8277/geonetwork + Search for datasets, services and maps... + + multilingual + http://gn:8277/custom/6b21e3a6-5a53-433f-aba9-3f93ac2bdd74 + + 6b21e3a6-5a53-433f-aba9-3f93ac2bdd74 + + + \ No newline at end of file