Skip to content

Commit

Permalink
Merge pull request #8776 from CVamsi27/ds-8728
Browse files Browse the repository at this point in the history
Implement default description for Community/Collection for OpenSearch
  • Loading branch information
tdonohue committed May 1, 2023
2 parents 80cb844 + fdf4a4d commit 9bbfb8d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
18 changes: 13 additions & 5 deletions dspace-api/src/main/java/org/dspace/app/util/SyndicationFeed.java
Expand Up @@ -51,6 +51,7 @@
import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.core.I18nUtil;
import org.dspace.discovery.IndexableObject;
import org.dspace.discovery.indexobject.IndexableCollection;
import org.dspace.discovery.indexobject.IndexableCommunity;
Expand Down Expand Up @@ -91,6 +92,7 @@ public class SyndicationFeed {

// default DC fields for entry
protected String defaultTitleField = "dc.title";
protected String defaultDescriptionField = "dc.description";
protected String defaultAuthorField = "dc.contributor.author";
protected String defaultDateField = "dc.date.issued";
private static final String[] defaultDescriptionFields =
Expand Down Expand Up @@ -196,15 +198,15 @@ public void populate(HttpServletRequest request, Context context, IndexableObjec
// dso is null for the whole site, or a search without scope
if (dso == null) {
defaultTitle = configurationService.getProperty("dspace.name");
feed.setDescription(localize(labels, MSG_FEED_DESCRIPTION));
defaultDescriptionField = localize(labels, MSG_FEED_DESCRIPTION);
objectURL = resolveURL(request, null);
} else {
Bitstream logo = null;
if (dso instanceof IndexableCollection) {
Collection col = ((IndexableCollection) dso).getIndexedObject();
defaultTitle = col.getName();
feed.setDescription(collectionService.getMetadataFirstValue(col,
CollectionService.MD_SHORT_DESCRIPTION, Item.ANY));
defaultDescriptionField = collectionService.getMetadataFirstValue(col,
CollectionService.MD_SHORT_DESCRIPTION, Item.ANY);
logo = col.getLogo();
String cols = configurationService.getProperty("webui.feed.podcast.collections");
if (cols != null && cols.length() > 1 && cols.contains(col.getHandle())) {
Expand All @@ -214,8 +216,8 @@ public void populate(HttpServletRequest request, Context context, IndexableObjec
} else if (dso instanceof IndexableCommunity) {
Community comm = ((IndexableCommunity) dso).getIndexedObject();
defaultTitle = comm.getName();
feed.setDescription(communityService.getMetadataFirstValue(comm,
CommunityService.MD_SHORT_DESCRIPTION, Item.ANY));
defaultDescriptionField = communityService.getMetadataFirstValue(comm,
CommunityService.MD_SHORT_DESCRIPTION, Item.ANY);
logo = comm.getLogo();
String comms = configurationService.getProperty("webui.feed.podcast.communities");
if (comms != null && comms.length() > 1 && comms.contains(comm.getHandle())) {
Expand All @@ -230,6 +232,12 @@ public void populate(HttpServletRequest request, Context context, IndexableObjec
}
feed.setTitle(labels.containsKey(MSG_FEED_TITLE) ?
localize(labels, MSG_FEED_TITLE) : defaultTitle);

if (defaultDescriptionField == null || defaultDescriptionField == "") {
defaultDescriptionField = I18nUtil.getMessage("org.dspace.app.util.SyndicationFeed.no-description");
}

feed.setDescription(defaultDescriptionField);
feed.setLink(objectURL);
feed.setPublishedDate(new Date());
feed.setUri(objectURL);
Expand Down
1 change: 1 addition & 0 deletions dspace-api/src/main/resources/Messages.properties
Expand Up @@ -51,6 +51,7 @@ metadata.bitstream.iiif-virtual.bytes = File size
metadata.bitstream.iiif-virtual.checksum = Checksum

org.dspace.app.itemexport.no-result = The DSpaceObject that you specified has no items.
org.dspace.app.util.SyndicationFeed.no-description = No Description
org.dspace.checker.ResultsLogger.bitstream-format = Bitstream format
org.dspace.checker.ResultsLogger.bitstream-found = Bitstream found
org.dspace.checker.ResultsLogger.bitstream-id = Bitstream ID
Expand Down
Expand Up @@ -249,4 +249,24 @@ public void serviceDocumentTest() throws Exception {
</OpenSearchDescription>
*/
}

@Test
public void emptyDescriptionTest() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection collection1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1")
.build();

getClient().perform(get("/opensearch/search")
.param("format", "rss")
.param("scope", collection1.getID().toString())
.param("query", "*"))
.andExpect(status().isOk())
.andExpect(xpath("rss/channel/description").string("No Description"));
}
}

0 comments on commit 9bbfb8d

Please sign in to comment.