Lyo Store - OSLC Query with SPARQL, issues with the where clause


#1

Hello,

I am trying to use the Lyo Store library to implement OSLC Query capability in my OSLC adapter. I managed to setup the Store, and getting individual resources or querying for all resources works fine. However, I am unable to get any results when using queries with a where clause. The result always contains zero resources.
I am using Lyo.store 2.4.0.M1 (also tried the 4.0.0-SNAPSHOT), and I am using Apache Jena Fuseki as the SPARQL server (also tried RDF4J Server).

When I do a query for all resources (with no where clause), like this: http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/queryAutomationResult
I get a response with a list of AutomationResult resources. One of which contains a property <dcterms:identifier>0</dcterms:identifier>
But when I do another query with a where clause to find the resource with identifier equal to zero, like this:
http://localhost:8080/AnacondaOSLC/services/Automation/A0/resources/queryAutomationResult?oslc.prefix=dcterms=<http://purl.org/dc/terms/>&oslc.where=dcterms:identifier="0"
The response returns zero resources found.

This is what my implementation of the query capability generated by Lyo looks like:

public static List<AutomationResult> queryAutomationResults(HttpServletRequest httpServletRequest, final String serviceProviderId, String where, int page, int limit)
{
    List<AutomationResult> resources = null;
    
    // Start of user code queryAutomationResults
    try {
    	if (where == null)
    		where = "";

		String oslcPrefixes = httpServletRequest.getParameter("oslc.prefix");
    	Model jenaModel = store.getResources(new URI("http://autoResults"), oslcPrefixes, where, limit, page);
    	resources = getResourcesFromModel(jenaModel, AutomationResult.class);

	} catch (StoreAccessException | ModelUnmarshallingException | URISyntaxException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    // End of user code
    return resources;
}

I would like to kindly ask for help with this issue. Any suggestions on what am I doing wrong or what could cause the problem are greatly appreciated.

Thanks!


#2

Hi,

Thanks for giving Lyo Store a try! Initially, it was not designed to support OSLC Query but experimental support has been added by @jad. Hopefully he can help you. He will likely need more info, so I have added a log statement into the getResources method to help you: https://github.com/eclipse/lyo.store/commit/112e45ef9afcd0a737cfb09bcb1d6b71c92bbff9

Just re-run your code with Store 4.0.0-SNAPSHOT and logger at the TRACE level to see what kind of SPARQL query is generated by Lyo Store to see where the problem lies.

Happy Easter!

Cheers,
Andrew


#3

Thanks for the reply.

I see, so the OSLC Query support is still experimental. It is very useful feature to have in the Store, as it allowed me to add persistence and query capabilities to my OSLC adapter with minimal effort. Hope the implementation eventually gets finished.

I already have logs of the query from the Jena Fuseki server logger and they look like this (after url decoding):

[2019-04-20 20:53:57] Fuseki     INFO  [26] GET http://localhost:8081/fuseki/anaconda_automation/query?query=ASK
WHERE
  { GRAPH <http://automation_resources>
      { ?s  ?p  ?o }
  }

[2019-04-20 20:53:57] Fuseki     INFO  [26] Query = ASK WHERE   { GRAPH <http://automation_resources>       { ?s  ?p  ?o }   } 
[2019-04-20 20:53:57] Fuseki     INFO  [26] 200 OK (2 ms)
[2019-04-20 20:53:57] Fuseki     INFO  [27] GET http://localhost:8081/fuseki/anaconda_automation/query?query=PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  dcterms: <http://purl.org/dc/terms/>

DESCRIBE ?s
WHERE
  { GRAPH <http://automation_resources>
      { ?s  ?p  ?o
        { SELECT DISTINCT  ?s
          WHERE
            { ?s  ?p                  ?o ;
                  dcterms:identifier  0 ;
                  rdf:type            <http://open-services.net/ns/auto#AutomationResult>
            }
          LIMIT   20
        }
      }
  }

[2019-04-20 20:53:57] Fuseki     INFO  [27] Query = PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX  dcterms: <http://purl.org/dc/terms/>  DESCRIBE ?s WHERE   { GRAPH <http://automation_resources>       { ?s  ?p  ?o         { SELECT DISTINCT  ?s           WHERE             { ?s  ?p                  ?o ;                   dcterms:identifier  0 ;                   rdf:type            <http://open-services.net/ns/auto#AutomationResult>             }           LIMIT   20         }       }   } 
[2019-04-20 20:53:57] Fuseki     INFO  [27] 200 OK (6 ms)

Is this log fine, or should I make a new one using the log statement you have added?

I have switched to Store 4.0.0-SNAPSHOT already and started using oslc.searchTerms which works fine. Still cant get oslc.where to work though. My implementation of the Lyo query capability has changed like this (a bit cleaner and straight forward):

if (where == null)
    where = "";
    	
String oslcPrefixes = httpServletRequest.getParameter("oslc.prefix");
String searchTerms = httpServletRequest.getParameter("oslc.searchTerms");
return store.getResources(namedGraph, clazz, oslcPrefixes, where, searchTerms, limit, page);

To be honest, I dont know much about SPARQL and getting the oslc.where to work is not essential for me right now. So I will be happy if @jad could just confirm whether oslc.where is currently working in Lyo Store, and maybe give me a simple example of a query GET request for Lyo Store.

Thanks again, any help is much appreciated!


#4

Hi

The fact that you are getting a SPARQL query is a good sign. we just need to fine-tune it to make it respond to your query.

Could you please do the following for me:

  1. Run the sparql query without the 8th line ( dcterms:identifier 0 ;).
  2. From the response you receive, can you please post to me one or two resources that you believe should have been included in your query.

Although you are expecting dcterms:identifier to be 0, I wonder if the paramter is being sent in the most appropriate way. For example, should you be sending (a) dcterms:identifier=“0” or (b) dcterms:identifier=0 or © dcterms:identifier=“0”^^http://www.w3.org/2001/XMLSchema#integer

The formatting for the query parameters is unfortuantly not so well documented, and I myself normally need to reverse-engineering the SPARQL query to work out how to best set my OSLC-query paramters.


#5

and BTW, the query capability is as experimental/mature as the rest of the Store. And I use it quite often as well. It is experimental in the sense that it does not cover (yet) the full OSLC Query language. I am only expanding it as the needs for it arise.