Получение модифицированной версии ItemRequestForm. java для работы в DSpace версии 6x - PullRequest
5 голосов
/ 04 мая 2020

У меня есть измененная версия ItemRequestForm.java, которая ранее работала в версии 5x. В item-view.xsl я создал ссылку, которая при нажатии перенаправит пользователя на эту измененную форму. Шаблон URL этой ссылки http://example.com/documentdelivery/123456789/1234. Когда я обновляю свою версию DSpace до 6x, мне трудно заставить ее работать. Из-за серьезного рефакторинга кода между версиями 5 и 6 мне сложно перенести мой код на последнюю версию.

Ниже приведен фрагмент кода, который работал в версии 5x ( DocumentDeliveryForm. java)

Код в основном основан на этом ответе: Как получить заголовок ссылающейся страницы (элемента) из модифицированной версии страницы обратной связи в DSpace ?

    String handle=parameters.getParameter("handle","unknown");
    DSpaceObject dso = HandleManager.resolveToObject(context, handle);
    if (!(dso instanceof Item)) {
        return;
    }
    Request request = ObjectModelHelper.getRequest(objectModel);
    boolean firstVisit=Boolean.valueOf(request.getParameter("firstVisit"));

    Item item = (Item) dso;

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle","unknown"),Division.METHOD_POST,"primary");

При обновлении до версии 6 я обнаружил, что DSpaceObject dso = HandleManager.resolveToObject(context, handle) больше не работает, поэтому я заменил его на DSpaceObject dso = handleService.resolveToObject(context, handle).

ниже моя попытка перенести мой 5x код в 6x (Результат: java .lang.NullPointerException)

    String handle=parameters.getParameter("handle","unknown");
    DSpaceObject dso = handleService.resolveToObject(context, handle);
    if (!(dso instanceof Item)) {
        return;
    }
    Request request = ObjectModelHelper.getRequest(objectModel);
    Item item = (Item) dso;

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            request.getRequestURI() + "/documentdelivery/" + item.getHandle(), Division.METHOD_POST,"primary");

Ниже приведена еще одна попытка, которая привела к тому, что Handle имеет значение null

    Request request = ObjectModelHelper.getRequest(objectModel);
    String handle = request.getParameter("handle");
    DSpaceObject dso = handleService.resolveToObject(context, handle);
    if (!(dso instanceof Item)) {
        return;
    }
    boolean firstVisit=Boolean.valueOf(request.getParameter("firstVisit"));

    Item item = (Item) dso;

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle","unknown"),Division.METHOD_POST,"primary");

Глядя на трассировку стека java, он указывает на следующую строку кода: DSpaceObject dso = handleService.resolveToObject(context, handle). Кажется, что значение для handle не загружается.

Какую часть моего кода я должен изменить, чтобы я мог успешно перенаправить пользователей на http://example.com/documentdelivery/123456789/1234 с http://example.com/handle/123456789/1234?

Какая конструкция деления средства просмотра предметов правильная?

    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            request.getRequestURI() + "/documentdelivery/" + item.getHandle(), Division.METHOD_POST,"primary");

ИЛИ

    Division documentdelivery = body.addInteractiveDivision("DocumentDelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle","unknown"),Division.METHOD_POST,"primary");

Заранее спасибо.

1 Ответ

1 голос
/ 11 мая 2020

Наконец-то мне удалось заставить его работать. Я также отобразил другие поля метаданных на основе моего предыдущего поста: Получение других метаданных в ItemRequestForm в DSpace 6x

public void addBody(Body body) throws SAXException, WingException,
        UIException, SQLException, IOException, AuthorizeException
{
    Request request = ObjectModelHelper.getRequest(objectModel);

    // Build the item viewer division.
    Division documentdelivery = body.addInteractiveDivision("documentdelivery-form",
            contextPath+"/documentdelivery/"+parameters.getParameter("handle", "unknown"),Division.METHOD_POST,"primary");

    documentdelivery.setHead(T_head);

    String handle = parameters.getParameter("handle","unknown");
    DSpaceObject dso = handleService.resolveToObject(context, handle);
    Item item = (Item) dso;

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

Я также добавил необходимые импортные данные:

import org.dspace.content.service.ItemService;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;

А также я добавил это:

    private final transient ItemService itemService = ContentServiceFactory.getInstance().getItemService();
    private final transient HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
...