Skip to content

Commit

Permalink
Merge pull request #3 from f-necas/PR91-4.2.2
Browse files Browse the repository at this point in the history
Cherry-pick custom url option for RSS
  • Loading branch information
jahow authored Sep 21, 2023
2 parents ebc3b02 + b0f8fc2 commit 25d9058
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface FormatterConfiguration {

/** for testing purposes. */
void setLinkToLegacyGN4(Boolean linkToLegacyGN4);

void setLinkToCustomUrl(Boolean linkToCustomUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<rss version="2.0">
<channel>
<title>the geonetwork momorg</title>
<link>http://gn4:8277/geonetwork</link>
<description>Search for datasets, services and maps...</description>
<item>
<title>multilingual</title>
<link>http://gn:8277/custom/6b21e3a6-5a53-433f-aba9-3f93ac2bdd74</link>
<author></author>
<guid isPermaLink="false">6b21e3a6-5a53-433f-aba9-3f93ac2bdd74</guid>
</item>
</channel>
</rss>

0 comments on commit 25d9058

Please sign in to comment.