Re: [dspace-tech] change the query

2016-09-21 Thread Bruno Nocera Zanette
Well remembered, Luiz!
Specially the second point if you're dealing with a Git repository, because
it allows you to pull new versions of code without having to deal with code
conflicts. I've already used this method to do some customisation on xmlui
interface and it worked like a charm.


Em qua, 21 de set de 2016 às 17:29, Luiz dos Santos 
escreveu:

> 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 findItemsByMetadata 
>> {
>> ...
>> id_array = Array.new()
>> for (Item i : items){
>> id_array.add()
>> }
>> 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 items = new ArrayList();
 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
 {
  

Re: [dspace-tech] change the query

2016-09-21 Thread Luiz dos Santos
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 findItemsByMetadata 
> {
> ...
> id_array = Array.new()
> for (Item i : items){
> id_array.add()
> }
> 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 items = new ArrayList();
>>> 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

Re: [dspace-tech] change the query

2016-09-21 Thread Bruno Nocera Zanette
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 findItemsByMetadata 
{
...
id_array = Array.new()
for (Item i : items){
id_array.add()
}
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 items = new ArrayList();
>> 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

Re: [dspace-tech] change the query

2016-09-21 Thread Dante Valencia
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 items = new ArrayList();
> 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.


Re: [dspace-tech] change the query

2016-09-18 Thread Bruno Nocera Zanette
Dante,
You'll have to alter ItemResource's code on REST api:
https://github.com/DSpace/DSpace/blob/master/dspace-rest/src/main/java/org/dspace/rest/ItemsResource.java#L903
Specially the line 967. As i'm not a Java specialist i can't help you
besides that, but the idea is to return a hash like object (id,name) or an
array of ids, intead of an array of items.


Em sex, 16 de set de 2016 às 13:13, Dante Valencia <
dante.valenci...@gmail.com> escreveu:

> Hi friends,
> I was researching and testing, how to change the query of
> http://localhost:8080/rest/items/find-by-metadata-field
> I just want to get the internal id and a specific field of metadata, for
> example just want the key: dc.identifier
>
> I trying this because I have a lot of result and the other metadata
> results it doesn't relevant for me.
>
> Any suggestion?
>
> Thank you
>
> --
> 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.


[dspace-tech] change the query

2016-09-16 Thread Dante Valencia
Hi friends, 
I was researching and testing, how to change the query of
http://localhost:8080/rest/items/find-by-metadata-field
I just want to get the internal id and a specific field of metadata, for 
example just want the key: dc.identifier

I trying this because I have a lot of result and the other metadata results 
it doesn't relevant for me.

Any suggestion?

Thank you

-- 
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.