Search code examples
dspace

Getting other metadata in ItemRequestForm in DSpace 6x


Clicking a restricted bitstream in DSpace will display a request form. The form displays the title of the item by default. In version 5x, I managed to get to display other metadata instead of title (eg citation).

The code I used to display:

    Metadatum[] titleDC = item.getMetadata("dc", "title", null, Item.ANY);
    Metadatum[] citationDC = item.getMetadata("dc", "identifier", "citation", Item.ANY);
    String document = "";
    if (citationDC != null && citationDC.length > 0) {
        document = citationDC[0].value;
    } else {
        if (titleDC != null && titleDC.length > 0)
            document = titleDC[0].value;
    }
    itemRequest.addPara(document);

I cannot use this code in version 6x because of major changes in the source code. Below is the default code in DSpace 6x to display the item's title:

String titleDC = item.getName();
if (titleDC != null && titleDC.length() > 0)
    itemRequest.addPara(titleDC);

It seems there is no item.getMetadata in version 6. My question is how to translate the version 5x code

Metadatum[] citationDC = item.getMetadata("dc", "identifier", "citation", Item.ANY);

into version 6?


Solution

  • Looking around in the DSpace 6x code, I managed to get other metadata to display (eg dc.identifier.citation) instead of item title in ItemRequestForm.java. Add to import import org.dspace.content.service.ItemService;

    private final transient ItemService itemService
        = ContentServiceFactory.getInstance().getItemService();
    

    To display dc.identifier.citation

    String citationDC = itemService.getMetadataFirstValue(item, "dc", "identifier", "citation", Item.ANY);
    String titleDC = item.getName();
    String document = "";
        if (citationDC != null && citationDC.length() > 0) {
            document = citationDC;
        } else {
            if (titleDC != null && titleDC.length() > 0)
            document = titleDC;
        }
    
    itemRequest.addPara(document);
    

    I added a test as a fallback in case dc.identifier.citation does not exist.