23
23
/**
24
24
* SPARQL 1.1 Graph Store HTTP Protocol
25
25
*
26
- * Olivier Corby
26
+ * @author Olivier Corby
27
+ * @author Pierre Maillot, P16 Wimmics INRIA I3S, 2024
27
28
*/
28
29
@ Path ("rdf-graph-store" )
29
30
public class GraphProtocol {
30
31
static private final Logger logger = LogManager .getLogger (GraphProtocol .class );
31
32
32
- static final String NAMED_GRAPH_QUERY = "construct {?s ?p ?o} where {graph <%s> {?s ?p ?o}}" ;
33
- static final String DEFAULT_GRAPH_QUERY = "construct where {?s ?p ?o}" ;
33
+ static final String NAMED_GRAPH_QUERY = "CONSTRUCT {?s ?p ?o} WHERE { GRAPH <%s> {?s ?p ?o}}" ;
34
+ static final String DEFAULT_GRAPH_QUERY = "CONSTRUCT {?s ?p ?o}" ;
34
35
35
- static final String NAMED_GRAPH_INSERT = "insert data {graph <%s> {%s}}" ;
36
- static final String DEFAULT_GRAPH_INSERT = "insert data {%s}" ;
36
+ static final String NAMED_GRAPH_INSERT = "INSERT DATA { GRAPH <%s> {%s}}" ;
37
+ static final String DEFAULT_GRAPH_INSERT = "INSERT DATA {%s}" ;
37
38
38
39
Response get (HttpServletRequest request , String name , String graph , String pattern , String access , int format ) {
39
40
String query = pattern ;
40
41
if (name != null ) {
41
42
query = String .format (pattern , NSManager .nsm ().toNamespace (graph ));
42
43
}
43
- return new SPARQLRestAPI ().myGetResult (request , name , null , null , null , null , query , access , null , null ,
44
+ return new SPARQLRestAPI ().getResultFormat (request , name , null , null , null , null , query , access , null , null ,
44
45
format );
45
46
}
46
47
@@ -51,7 +52,7 @@ Response post(HttpServletRequest request, String name, String graph, String patt
51
52
} else {
52
53
query = String .format (NAMED_GRAPH_INSERT , NSManager .nsm ().toNamespace (graph ), pattern );
53
54
}
54
- return new SPARQLRestAPI ().myGetResult (request , name , null , null , null , null , query , access , null , null ,
55
+ return new SPARQLRestAPI ().getResultFormat (request , name , null , null , null , null , query , access , null , null ,
55
56
format );
56
57
}
57
58
@@ -80,7 +81,7 @@ public Response getTurtle(@jakarta.ws.rs.core.Context HttpServletRequest request
80
81
@ QueryParam ("mode" ) List <String > mode ) {
81
82
82
83
logger .info ("getTurtle" );
83
- return get (request , name , graph , getQuery (name ), access , ResultFormat .TURTLE_FORMAT );
84
+ return get (request , name , graph , getQuery (graph ), access , ResultFormat .TURTLE_FORMAT );
84
85
}
85
86
86
87
@ GET
@@ -92,7 +93,7 @@ public Response getXML(@jakarta.ws.rs.core.Context HttpServletRequest request,
92
93
@ QueryParam ("mode" ) List <String > mode ) {
93
94
94
95
logger .info ("getXML" );
95
- return get (request , name , graph , getQuery (name ), access , ResultFormat .RDF_XML_FORMAT );
96
+ return get (request , name , graph , getQuery (graph ), access , ResultFormat .RDF_XML_FORMAT );
96
97
}
97
98
98
99
@ GET
@@ -104,58 +105,30 @@ public Response getJSON(@jakarta.ws.rs.core.Context HttpServletRequest request,
104
105
@ QueryParam ("mode" ) List <String > mode ) {
105
106
106
107
logger .info ("getJSON" );
107
- return get (request , name , graph , getQuery (name ), access , ResultFormat .JSONLD_FORMAT );
108
+ return get (request , name , graph , getQuery (graph ), access , ResultFormat .JSONLD_FORMAT );
108
109
}
109
110
110
111
@ PUT
112
+ @ Produces ({ ResultFormat .SPARQL_RESULTS_XML , ResultFormat .XML })
111
113
public Response put (@ jakarta .ws .rs .core .Context HttpServletRequest request ,
112
114
@ PathParam ("name" ) String name ,
113
115
@ QueryParam ("graph" ) String graph ,
114
- // @QueryParam("query")
115
- String query ,
116
116
@ QueryParam ("access" ) String access ,
117
117
@ QueryParam ("mode" ) List <String > mode ) {
118
118
119
119
logger .info ("put" );
120
- return post (request , name , graph , query , access , ResultFormat .XML_FORMAT );
121
- }
122
-
123
- @ PUT
124
- @ Consumes (MediaType .APPLICATION_FORM_URLENCODED )
125
- public Response put2 (@ jakarta .ws .rs .core .Context HttpServletRequest request ,
126
- @ PathParam ("name" ) String name ,
127
- @ FormParam ("graph" ) String graph ,
128
- @ FormParam ("query" ) String query ,
129
- @ FormParam ("access" ) String access ,
130
- @ FormParam ("mode" ) List <String > mode ) {
131
-
132
- logger .info (String .format ("put2: graph %s" , graph ));
133
- return post (request , name , graph , query , access , ResultFormat .XML_FORMAT );
120
+ return post (request , name , graph , getQuery (graph ), access , ResultFormat .XML_FORMAT );
134
121
}
135
122
136
123
@ POST
137
124
public Response post (@ jakarta .ws .rs .core .Context HttpServletRequest request ,
138
125
@ PathParam ("name" ) String name ,
139
126
@ QueryParam ("graph" ) String graph ,
140
- @ QueryParam ("query" ) String query ,
141
127
@ QueryParam ("access" ) String access ,
142
128
@ QueryParam ("mode" ) List <String > mode ) {
143
129
144
130
logger .info ("post" );
145
- return post (request , name , graph , query , access , ResultFormat .XML_FORMAT );
146
- }
147
-
148
- @ POST
149
- @ Consumes (MediaType .APPLICATION_FORM_URLENCODED )
150
- public Response post2 (@ jakarta .ws .rs .core .Context HttpServletRequest request ,
151
- @ PathParam ("name" ) String name ,
152
- @ FormParam ("graph" ) String graph ,
153
- @ FormParam ("query" ) String query ,
154
- @ FormParam ("access" ) String access ,
155
- @ FormParam ("mode" ) List <String > mode ) {
156
-
157
- logger .info (String .format ("post2: graph %s" , graph ));
158
- return post (request , name , graph , query , access , ResultFormat .XML_FORMAT );
131
+ return post (request , name , graph , getQuery (graph ), access , ResultFormat .XML_FORMAT );
159
132
}
160
133
161
134
}
0 commit comments