0

How can I get the title of an item from a modified version of the feedback page just like in the "Recommend this item" in jspui? I'm hoping also to generate the resulting url of the page to be like http://example.com/feedback?handle=123456789/123. I've asked this from a comment in my previous post but I don't know how to use the HandleManager. I've tried many times using part of the code from itemRequestForm but I always get null pointer error.

    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
    if (!(dso instanceof Item)) {
        return;
    }
    Request request = ObjectModelHelper.getRequest(objectModel);
    boolean firstVisit=Boolean.valueOf(request.getParameter("firstVisit"));

    Item item = (Item) dso;

I also tried to looked in /ViewArtifacts/sitemap.xmap but right now it is beyond me to figure out what I am missing.

Community
  • 1
  • 1
euler
  • 1,401
  • 2
  • 18
  • 39
  • Which line of the code is giving you a NullPointerException? At a glance, the code looks reasonable enough, but it's been taken out of context, so it is difficult to determine which line (or lines) is not working properly. – Tim Donohue Sep 29 '14 at 14:10
  • Also, what class are you modifying? The code you've borrowed above looks to be an "Action" class (one that extends "AbstractAction"), e.g. [SendItemRequestAction](https://github.com/DSpace/DSpace/blob/master/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/SendItemRequestAction.java#L97). If you are attempting to modify the [FeedbackForm](https://github.com/DSpace/DSpace/blob/master/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/artifactbrowser/FeedbackForm.java), this code will not work as the "objectModel" Map does not exist. – Tim Donohue Sep 29 '14 at 14:17
  • Ignore my previous comment..I now notice that FeedbackForm extends [AbstractDSpaceTransformer](https://github.com/DSpace/DSpace/blob/master/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/AbstractDSpaceTransformer.java) which defines the "objectModel" Map. So, you *should* be able to use this code in FeedbackForm. Likely we just need more info on where the NullPointerException occurs. – Tim Donohue Sep 29 '14 at 14:28
  • Hello @tim-donohue, I actually borrowed that code above from the item request feature and tried to integrate it with the feedback form. My goal is very similar to [DS-2099](https://jira.duraspace.org/browse/DS-2099). Please see my comment below to Adan's answer. – euler Sep 30 '14 at 01:36

2 Answers2

1

You can get the complete patch of DS-2099 at:

https://github.com/arvoConsultores/DSpace/commit/3e971d70daaa4762a443c89fb7fa6f9e5b8e630d.patch

(TIP: you can add ".patch" to a commit at github to view the patch)

I Think its too long to post here.

Check SolicitarCorreccionForm to show the title and what you want using my other response to get the data from the handle and instead:

feedback.addPara(T_para1.parameterize(parameters.getParameter("handle","unknown")));

you should do:

String handle=parameters.getParameter("handle","unknown");

  // context=new Context(); // Context exist in a form:

  DSpaceOBject dso = HandleManager.resolveToObject(context,handle);

  if (dso instanceof Item){
       Item item=((Item)dso);
       DCValue[] titles= item.getMetadata("dc", "contributor", "author",null); 

       feedback.addPara(titles[0].value); // check for nulls or multiple values;
  }

to send the title to the mail class you should do:

feedback.addHidden("title").setValue(titles[0].value);

And at aspects/ViewArtifacts/sitemap.xmap you should set the parameter:

<map:transform type="SolicitarCorreccionForm">
<map:parameter name="title" value="{title}" />
...

Get at SendSolicitarCorreccionAction and send to email, to add the parameters to the mail like:

String title= request.getParameter("title");
email.addArgument(title);    // Titulo
...

You whould like to change the url from

<map:match pattern="solicitarCorreccion/**">

to what wou want.

P.D.- I forget to mention to add imports of SolicitarCorreccionForm:

import org.dspace.content.DCValue;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.handle.HandleManager;

I hope this help.

Adán
  • 381
  • 3
  • 14
  • I successfully applied DS-2099. When I add the line `dso=HandleManager.resolveToObject(context,handle);`, I got cannot resolve symbol 'dso'. Making it `DSpaceOBject dso`, I got Inconvertible types error in the line `(dso instanceof Item)` and cannot find symbol error in `DCValue[] titles= dso.getMetadata("dc", "contributor", "author",null);` Please advise. Thanks. – euler Oct 01 '14 at 14:44
  • My fault, I forget to declare variable "dso" and cast it. The code is corrected now. – Adán Oct 01 '14 at 14:54
  • I may be missing some import statements because I got cannot resolve method error in `feedback.addPara(titles[0]);` and `feedback.addHidden("title").setValue(titles[0]);`? – euler Oct 01 '14 at 15:55
0

try

  String handle="1234/1234";

  context=new Context(); // Or reuse the Context:

  dso = HandleManager.resolveToObject(context,handle);

  if (dso instanceof Item){

       DCValue[] titles= dso.getMetadata("dc", "contributor", "author",null); 

       // use titles
  }
Adán
  • 381
  • 3
  • 14
  • Could you post an explanation to go along with your answer? – damian Sep 29 '14 at 15:22
  • 1
    This code is slightly dangerous as it creates a *new* Context (which in turn creates a new DB connection) and never closes it. While the concept is OK, it should either reuse a currently open Context, or it should include a final call to `context.abort();` in order to close out the Context object. – Tim Donohue Sep 29 '14 at 21:48
  • Hello Adan, I think want I want to achieve is very similar to your work here: [DS-2099](https://jira.duraspace.org/browse/DS-2099), but instead of just showing the item handle, I would like to display the title (and other metadata) to the user and pass the title (and other metadata) to the recipient of that form. – euler Sep 30 '14 at 01:23
  • I agree @TimDonohue, it only pretended to be a functional example of HandleManager. – Adán Sep 30 '14 at 11:16