Getting other metadata in ItemRequestForm in DSpace 6x

爷,独闯天下 提交于 2020-05-17 07:01:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/61556258/getting-other-metadata-in-itemrequestform-in-dspace-6x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!