freme-project / e-Link

Apache License 2.0
0 stars 0 forks source link

Template with unknown variable name #35

Closed ghsnd closed 9 years ago

ghsnd commented 9 years ago

It is possible to POST a template with a variable named @@@hello_world@@@; this returns a 200 OK response, the template is added and gets an ID. E.g.,:

{ "query":" PREFIX geo-pos: http://www.w3.org/2003/01/geo/wgs84_pos# CONSTRUCT { @@@hello_world@@@ geo-pos:lat ?lat . @@@hello_world@@@ geo-pos:long ?long . } WHERE { @@@hello_world@@@ geo-pos:lat ?lat . @@@hello_world@@@ geo-pos:long ?long . }", "endpoint":"http://factforge.net/sparql", "label":"Template with wrong variables", "description":"This template contains wrong variable names." }

If you then link a document using this template, the response is

{
    "exception": "eu.freme.broker.exception.InternalServerErrorException",
    "path": "/e-link/documents",
    "message": "Unknown problem. Please contact us.",
    "error": "Internal Server Error",
    "status": 500,
    "timestamp": 1440503837265
}

Maybe it shouldn't be possible to post a template with a wrong variable name. Or if allowed, the error message when trying to use it could improve.

m1ci commented 9 years ago

whats wrong with this template?

ghsnd commented 9 years ago

I thought only certain variable names are allowed, not "hello_world" as in this example. If this is allowed though, then only the error response could have a better message.

m1ci commented 9 years ago

the name of the variables are assigned by the template creator. So, name of a variable can be anything.

m1ci commented 9 years ago

anyway, the InternalServerError exception is informative, will provide better explantation.

m1ci commented 9 years ago

can you please provide the exact request which causes the following exception?

{
  "exception": "eu.freme.broker.exception.InternalServerErrorException",
  "path": "/e-link/documents",
  "message": "Unknown problem. Please contact us.",
  "error": "Internal Server Error",
  "status": 500,
  "timestamp": 1440503837265
}
ghsnd commented 9 years ago

OK, so here are the steps I took:

1. Post template with some variable

curl -v -d @template.json -X POST -H "Content-Type: application/json" "http://localhost:8080/e-link/templates/"

where template.json is

{
    "query":" PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> CONSTRUCT { <@@@hello_world@@@> geo-pos:lat ?lat . <@@@hello_world@@@> geo-pos:long ?long . } WHERE { <@@@hello_world@@@> geo-pos:lat ?lat . <@@@hello_world@@@> geo-pos:long ?long . }",
    "endpoint":"http://factforge.net/sparql",
    "label":"Good name for template",
    "description":"This template finds the geo coordinates of a place."
}

Response:

<http://www.freme-project.eu/data/templates/302>
    a       <http://www.freme-project.eu/ns#Template> ;
    <http://www.w3.org/2000/01/rdf-schema#label>
            "Good name for template" ;
    <http://purl.org/dc/terms/description>
            "This template finds the geo coordinates of a place." ;
    <http://www.freme-project.eu/ns#endpoint>
            "http://factforge.net/sparql" ;
    <http://www.freme-project.eu/ns#query>
            " PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> CONSTRUCT { <@@@hello_world@@@> geo-pos:lat ?lat . <@@@hello_world@@@> geo-pos:long ?long . } WHERE { <@@@hello_world@@@> geo-pos:lat ?lat . <@@@hello_world@@@> geo-pos:long ?long . }" ;
    <http://www.freme-project.eu/ns#templateId>
            "302" .

2. Post document using the template

curl -v -d @example.ttl -X POST -H "Content-Type: text/turtle" "http://localhost:8080/e-link/documents?templateid=302"

where example.ttl is the "This is Berlin" example from the documentation.

The response is the exception as described above.

This is the stack trace:

ERROR   2015-08-27 10:57:08,026 [http-nio-8080-exec-3] eu.freme.broker.eservices.BaseRestController  - Internal service problem. Please contact the service provider.
HttpException: 400
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.rewrap(HttpQuery.java:414)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:358)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:295)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execModel(QueryEngineHTTP.java:413)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execConstruct(QueryEngineHTTP.java:387)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execConstruct(QueryEngineHTTP.java:382)
at eu.freme.eservices.elink.api.DataEnricher.enrichNIF(DataEnricher.java:54)
at eu.freme.broker.eservices.ELink.enrich(ELink.java:133)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
m1ci commented 9 years ago

a more human-readable error description is returned now, example:

{
  "timestamp": 1440671513471,
  "message": "It seems your SPARQL template is not correctly defined.",
  "error": "Bad Request",
  "status": 400,
  "exception": "eu.freme.eservices.elink.exceptions.BadRequestException",
  "path": "/e-link/documents"
}

Actually, your template is incorrect - sorry, the documentation probably doesn't provide enough info on how the SPARQL CONSTRUCT query should be defined. @ArneBinder: can you improve it please? see my comment bellow.

In fact, each template should have field @@@enttiy_uri@@@ which identifies an entity. When performing enrichment, the template is executed for each entity (identified with taIdentRef) in the document. It means, each @@@enttiy_uri@@@ is replaced with the taIdentRef link from the submitted document for enrichment. So @@@entity_uri@@@ us a reserved field name.

However you can always introduce your fields e.g. ... } LIMIT @@@my_limit@@@ and then use this fields by submitting my_limit parameter in the request. Example (see my_limit param):

curl -v -d @example.ttl -X POST -H "Content-Type: text/turtle" "http://localhost:8080/e-link/documents?templateid=116&my_limit=5"

So, if you redefine your template as:

PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>

CONSTRUCT {
    <@@@entity_uri@@@> geo-pos:lat ?lat .
    <@@@entity_uri@@@> geo-pos:long ?long .
} WHERE {
    <@@@entity_uri@@@> geo-pos:lat ?lat .
    <@@@entity_uri@@@> geo-pos:long ?long .
}

... it should work.

Can you re-check please?

ghsnd commented 9 years ago

OK, got it now. It works, thanks!