Hi Dante,

     The code of Bruno makes senses to me, just return a HaspMap instead
the array thing, as Bruno said it will not compile at all, I have two
advices for you:
      1- Instead change the findItemsMetadataField, create a new method.
      2- Create a new class to overload ItemResources, as it is explained
in (https://wiki.duraspace.org/display/DSDOC5x/Advanced+Customisation), the
basic idea here is if you put a class in the folder module/dspace-rest/...
it will replace to original one, I never tested it in the rest-api, but it
should work, and it will save you headache in the future.

Best regards
Luiz

On Wed, Sep 21, 2016 at 3:48 PM, Bruno Nocera Zanette <
brunonzane...@gmail.com> wrote:

> Dante,
> Even if the query returns more than you need, i wouldn't change it in the
> first moment.
> What you really have to change now is the returning line, because this is
> the line that will create the response for your request.
> For now it is returning an array of items. You have to change it to return
> an array of {id,title,...} (hash or map). You may implement it by creating
> a custom array and adding only the attributes of interest of each item of
> items variable to it, and then returning this array. You will also have to
> change the returning type of this function and verify what the calling
> function does with it.
>
> Something like this (custom language):
> public Array<id,string> findItemsByMetadata ....
> {
>     ...
>     id_array = Array.new(<id,title>)
>     for (Item i : items){
>         id_array.add(<i.id,i.title>)
>     }
>     return id_array;
> }
>
> I know there are several syntax errors in this code, but my ideia is this.
> You should also take a look at other code snippets, specially on the
> function that implement hierarchy endpoing on Dspace 6, to verify how it's
> being done by others.
>
>
>
> Em qua, 21 de set de 2016 às 10:36, Dante Valencia <
> dante.valenci...@gmail.com> escreveu:
>
>> Thank you Bruno,
>> I was trying changing  the code of dspace 5.2 and its diferent.
>>
>>> @POST
>>> @Path("/find-by-metadata-field")
>>> @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
>>> public Item[] findItemsByMetadataField(MetadataEntry metadataEntry, 
>>> @QueryParam("expand") String expand,
>>>         @QueryParam("userIP") String user_ip, @QueryParam("userAgent") 
>>> String user_agent,
>>>         @QueryParam("xforwardedfor") String xforwardedfor, @Context 
>>> HttpHeaders headers, @Context HttpServletRequest request)
>>>         throws WebApplicationException
>>> {
>>>
>>>     log.info("Looking for item with metadata(key=" + metadataEntry.getKey() 
>>> + ",value=" + metadataEntry.getValue()
>>>             + ", language=" + metadataEntry.getLanguage() + ").");
>>>     org.dspace.core.Context context = null;
>>>
>>>     List<Item> items = new ArrayList<Item>();
>>>     String[] metadata = mySplit(metadataEntry.getKey());
>>>
>>>     try
>>>     {
>>>         context = createContext(getUser(headers));
>>>
>>>         // Must used own style.
>>>         if ((metadata.length < 2) || (metadata.length > 3))
>>>         {
>>>             context.abort();
>>>             log.error("Finding failed, bad metadata key.");
>>>             throw new WebApplicationException(Response.Status.NOT_FOUND);
>>>         }
>>>
>>>         String sql = "SELECT RESOURCE_ID, TEXT_VALUE, TEXT_LANG, SHORT_ID, 
>>> ELEMENT, QUALIFIER " +
>>>                 "FROM METADATAVALUE " +
>>>                 "JOIN METADATAFIELDREGISTRY ON 
>>> METADATAVALUE.METADATA_FIELD_ID = METADATAFIELDREGISTRY.METADATA_FIELD_ID " 
>>> +
>>>                 "JOIN METADATASCHEMAREGISTRY ON 
>>> METADATAFIELDREGISTRY.METADATA_SCHEMA_ID = 
>>> METADATASCHEMAREGISTRY.METADATA_SCHEMA_ID " +
>>>                 "WHERE " +
>>>                 "SHORT_ID='" + metadata[0] + "'  AND " +
>>>                 "ELEMENT='" + metadata[1] + "' AND ";
>>>         if (metadata.length > 3)
>>>         {
>>>             sql += "QUALIFIER='" + metadata[2] + "' AND ";
>>>         }
>>>         if (org.dspace.storage.rdbms.DatabaseManager.isOracle())
>>>         {
>>>             sql += "dbms_lob.compare(TEXT_VALUE, '" + 
>>> metadataEntry.getValue() + "') = 0 AND ";
>>>         }
>>>         else
>>>         {
>>>             sql += "TEXT_VALUE='" + metadataEntry.getValue() + "' AND ";
>>>         }
>>>         if (metadataEntry.getLanguage() != null)
>>>         {
>>>             sql += "TEXT_LANG='" + metadataEntry.getLanguage() + "'";
>>>         }
>>>         else
>>>         {
>>>             sql += "TEXT_LANG is null";
>>>         }
>>>
>>>         TableRowIterator iterator = 
>>> org.dspace.storage.rdbms.DatabaseManager.query(context, sql);
>>>         while (iterator.hasNext())
>>>         {
>>>             TableRow row = iterator.next();
>>>             org.dspace.content.Item dspaceItem = this.findItem(context, 
>>> row.getIntColumn("RESOURCE_ID"),
>>>                     org.dspace.core.Constants.READ);
>>>             Item item = new Item(dspaceItem, "", context);
>>>             writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, 
>>> user_agent, xforwardedfor, headers,
>>>                     request, context);
>>>             items.add(item);
>>>         }
>>>
>>>         context.complete();
>>>
>>>     }
>>>     catch (SQLException e)
>>>     {
>>>         processException("Something went wrong while finding item. 
>>> SQLException, Message: " + e, context);
>>>     }
>>>     catch (ContextException e)
>>>     {
>>>         processException("Context error:" + e.getMessage(), context);
>>>     }
>>>     finally
>>>     {
>>>         processFinally(context);
>>>     }
>>>
>>>     if (items.size() == 0)
>>>     {
>>>         log.info("Items not found.");
>>>     }
>>>     else
>>>     {
>>>         log.info("Items were found.");
>>>     }
>>>
>>>     return items.toArray(new Item[0]);
>>> }
>>>
>>>
>>
>>  The query has what I want, but I dont know how to obtain the results.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "DSpace Technical Support" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to dspace-tech+unsubscr...@googlegroups.com.
>> To post to this group, send email to dspace-tech@googlegroups.com.
>> Visit this group at https://groups.google.com/group/dspace-tech.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> Bruno Nocera Zanette
> +55 41 9992-2508
>
> --
> You received this message because you are subscribed to the Google Groups
> "DSpace Technical Support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dspace-tech+unsubscr...@googlegroups.com.
> To post to this group, send email to dspace-tech@googlegroups.com.
> Visit this group at https://groups.google.com/group/dspace-tech.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"DSpace Technical Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dspace-tech+unsubscr...@googlegroups.com.
To post to this group, send email to dspace-tech@googlegroups.com.
Visit this group at https://groups.google.com/group/dspace-tech.
For more options, visit https://groups.google.com/d/optout.

Reply via email to