From 47b79bb2cb84688a869826c1e41410726c1bfac0 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Mon, 13 May 2024 15:15:53 -0500 Subject: [PATCH 1/2] Remove references to UI type from OpenSearch / RSS feeds --- .../dspace/app/util/OpenSearchServiceImpl.java | 2 +- .../org/dspace/app/util/SyndicationFeed.java | 17 ++--------------- .../dspace/app/rest/OpenSearchController.java | 1 - 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/app/util/OpenSearchServiceImpl.java b/dspace-api/src/main/java/org/dspace/app/util/OpenSearchServiceImpl.java index 514143c93ea..bff741b5ca4 100644 --- a/dspace-api/src/main/java/org/dspace/app/util/OpenSearchServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/app/util/OpenSearchServiceImpl.java @@ -155,7 +155,7 @@ protected SyndicationFeed getResults(Context context, String format, String quer format = "atom_1.0"; } - SyndicationFeed feed = new SyndicationFeed(labels.get(SyndicationFeed.MSG_UITYPE)); + SyndicationFeed feed = new SyndicationFeed(); feed.populate(null, context, scope, results, labels); feed.setType(format); feed.addModule(openSearchMarkup(query, totalResults, start, pageSize)); diff --git a/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java b/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java index 2ab99e54d2e..65403696357 100644 --- a/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java +++ b/dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java @@ -84,11 +84,6 @@ public class SyndicationFeed { public static final String MSG_FEED_TITLE = "feed.title"; public static final String MSG_FEED_DESCRIPTION = "general-feed.description"; public static final String MSG_METADATA = "metadata."; - public static final String MSG_UITYPE = "ui.type"; - - // UI keywords - public static final String UITYPE_XMLUI = "xmlui"; - public static final String UITYPE_JSPUI = "jspui"; // default DC fields for entry protected String defaultTitleField = "dc.title"; @@ -145,10 +140,6 @@ public class SyndicationFeed { // the feed object we are building protected SyndFeed feed = null; - // memory of UI that called us, "xmlui" or "jspui" - // affects Bitstream retrieval URL and I18N keys - protected String uiType = null; - protected HttpServletRequest request = null; protected CollectionService collectionService; @@ -157,12 +148,9 @@ public class SyndicationFeed { /** * Constructor. - * - * @param ui either "xmlui" or "jspui" */ - public SyndicationFeed(String ui) { + public SyndicationFeed() { feed = new SyndFeedImpl(); - uiType = ui; ContentServiceFactory contentServiceFactory = ContentServiceFactory.getInstance(); itemService = contentServiceFactory.getItemService(); collectionService = contentServiceFactory.getCollectionService(); @@ -518,8 +506,7 @@ protected static String getDefaultedConfiguration(String key, String dfl) { protected String urlOfBitstream(HttpServletRequest request, Bitstream logo) { String name = logo.getName(); return resolveURL(request, null) + - (uiType.equalsIgnoreCase(UITYPE_XMLUI) ? "/bitstream/id/" : "/retrieve/") + - logo.getID() + "/" + (name == null ? "" : name); + "/bitstreams/" + logo.getID() + "/download"; } protected String baseURL = null; // cache the result for null diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/OpenSearchController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/OpenSearchController.java index d10b5ed9f7a..baf45c14b6e 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/OpenSearchController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/OpenSearchController.java @@ -285,7 +285,6 @@ private Map getLabels(HttpServletRequest request) { labelMap.put(SyndicationFeed.MSG_UNTITLED, "notitle"); labelMap.put(SyndicationFeed.MSG_LOGO_TITLE, "logo.title"); labelMap.put(SyndicationFeed.MSG_FEED_DESCRIPTION, "general-feed.description"); - labelMap.put(SyndicationFeed.MSG_UITYPE, SyndicationFeed.UITYPE_JSPUI); for (String selector : SyndicationFeed.getDescriptionSelectors()) { labelMap.put("metadata." + selector, selector); } From 8c22915adf9ce39e29a03034c0ebde3321188840 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Mon, 13 May 2024 15:16:14 -0500 Subject: [PATCH 2/2] Add a basic test that refactoring of code results in correct logo URLs. Also enable/fix a test for special characters. --- .../opensearch/OpenSearchControllerIT.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/opensearch/OpenSearchControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/opensearch/OpenSearchControllerIT.java index b533e14568e..645d52df59f 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/opensearch/OpenSearchControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/opensearch/OpenSearchControllerIT.java @@ -96,7 +96,12 @@ public void findResultSimpleTest() throws Exception { Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity) .withName("Sub Community") .build(); - Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build(); + // Add a fake logo to the Collection + Collection col1 = CollectionBuilder.createCollection(context, child1) + .withName("Collection 1") + .withLogo("logo_collection") + .build(); + String colLogoUuid = col1.getLogo().getID().toString(); Item publicItem1 = ItemBuilder.createItem(context, col1) .withTitle("Boars at Yellowstone") @@ -118,10 +123,24 @@ public void findResultSimpleTest() throws Exception { .andExpect(xpath("feed/Query/@searchTerms").string("Yellowstone")) .andExpect(xpath("feed/totalResults").string("2")) ; + + // When we search at the Collection level (scope = Collection UUID) + getClient().perform(get("/opensearch/search") + .param("scope", col1.getID().toString()) + .param("query", "Yellowstone")) + //The status has to be 200 OK + .andExpect(status().isOk()) + // We expect the content type to be "application/atom+xml;charset=UTF-8" + .andExpect(content().contentType("application/atom+xml;charset=UTF-8")) + .andExpect(xpath("feed/Query/@searchTerms").string("Yellowstone")) + .andExpect(xpath("feed/totalResults").string("2")) + // We expect feed will have the Collection logo + .andExpect(xpath("feed/logo") + .string("http://localhost:4000/bitstreams/" + colLogoUuid + "/download")) + ; } // This test does not find the record, so there are obviously issues with special chars - @Ignore @Test public void findResultWithSpecialCharsTest() throws Exception { //Turn off the authorization system, otherwise we can't make the objects @@ -144,12 +163,12 @@ public void findResultWithSpecialCharsTest() throws Exception { .build(); //When we call the root endpoint getClient().perform(get("/opensearch/search") - .param("query", "Bär")) + .param("query", "Bären")) //The status has to be 200 OK .andExpect(status().isOk()) //We expect the content type to be "application/atom+xml;charset=UTF-8" .andExpect(content().contentType("application/atom+xml;charset=UTF-8")) - .andExpect(xpath("feed/Query/@searchTerms").string("B%C3%A4r")) + .andExpect(xpath("feed/Query/@searchTerms").string("B%C3%A4ren")) .andExpect(xpath("feed/totalResults").string("1")) ; }