aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Fiedler2011-10-26 11:25:00 (EDT)
committerSteve Speicher2011-10-26 11:25:00 (EDT)
commitcbe6129f53c06c080f1aa36f6b699a1d70e4a02f (patch)
treeba1104780737b0307908ca3262dbee86cc594abf
parent1090e036e9cd839651127763d08a197029e38806 (diff)
downloadorg.eclipse.lyo.rio-cbe6129f53c06c080f1aa36f6b699a1d70e4a02f.zip
org.eclipse.lyo.rio-cbe6129f53c06c080f1aa36f6b699a1d70e4a02f.tar.gz
org.eclipse.lyo.rio-cbe6129f53c06c080f1aa36f6b699a1d70e4a02f.tar.bz2
Bug362012 - Improve query parm handling.
-rw-r--r--org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/linktype/LinkTypeQueryService.java54
-rw-r--r--org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/resource/ResourceService.java55
-rw-r--r--org.eclipse.lyo.rio.cm/src/main/java/org/eclipse/lyo/rio/cm/changerequest/ChangeRequestService.java57
-rw-r--r--org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementService.java54
-rw-r--r--org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementTcService.java68
-rw-r--r--org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirementcollection/RequirementCollectionService.java55
6 files changed, 280 insertions, 63 deletions
diff --git a/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/linktype/LinkTypeQueryService.java b/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/linktype/LinkTypeQueryService.java
index 3ce3c79..bedfd23 100644
--- a/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/linktype/LinkTypeQueryService.java
+++ b/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/linktype/LinkTypeQueryService.java
@@ -78,7 +78,8 @@ public class LinkTypeQueryService extends RioBaseService {
String sparql = queryBuilder.getQueryString(IAmConstants.OSLC_AM_TYPE_LINKTYPE);
RioStore store = this.getStore();
- String queryUri = req.getRequestURL().toString();
+ //don't add ?null if the the query is for queryBase
+ String queryUri = (req.getQueryString() == null ) ? req.getRequestURL().toString() : req.getRequestURL().toString() + '?' + req.getQueryString();
List<Map<String, RioValue>> results = store.query(IConstants.SPARQL, sparql, 100);
@@ -109,10 +110,36 @@ public class LinkTypeQueryService extends RioBaseService {
for (String namespace : namespaces) {
rdf.setAttribute("xmlns:" + namespacePrefixes.get(namespace), namespace); //$NON-NLS-1$
}
+ //If there is are parameters on the request (e.g. ?oslc.where=...), create 2 subject URIs, one for the
+ //results and one to describe the query. If this query was for the queryBase itself all predicates
+ //go under the same subject.
+ //TODO: Refactor the services for all RIO artifacts to eliminate duplicated code.
- Element queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
- rdf.appendChild(queryDescrElement);
+ Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ rdf.appendChild(resultDescr);
+
+ //check for oslc query parameters
+ String uriSplit [] = reqUri.split("\\?",2);
+ String baseUri = uriSplit[0];
+ boolean isOslcQuery = false;
+ if (uriSplit.length > 1)
+ isOslcQuery = hasOSLCQuery(uriSplit[1]);
+
+ resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
+
+
+ //if there are oslc query parameters, put the predicates under the query subject
+ Element queryDescrElement = null;
+ if (isOslcQuery )
+ {
+ queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
+ rdf.appendChild(queryDescrElement);
+ }
+ else {
+ //no oslc query parameters, everything goes under the queryBase subject
+ queryDescrElement = resultDescr;
+ }
Element title = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
queryDescrElement.appendChild(title);
@@ -126,12 +153,6 @@ public class LinkTypeQueryService extends RioBaseService {
rdfType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, IConstants.OSLC_RESPONSEINFO);
queryDescrElement.appendChild(rdfType);
-
- Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- rdf.appendChild(resultDescr);
- String baseUri = reqUri.split("\\?")[0];
- resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
-
Iterator<Map<String, RioValue>> iterator = results.iterator();
while( iterator.hasNext() ) {
@@ -151,6 +172,19 @@ public class LinkTypeQueryService extends RioBaseService {
}
}
+ private boolean hasOSLCQuery(String parms)
+ {
+ boolean containsOslcParm = false;
+ // not perfect - could have "oslc." in some random part of the parameters, but don't
+ // have access to the request at this point to use getPararmeterNames
+ String [] uriParts = parms.toLowerCase().split("oslc\\.",2);
+ if (uriParts.length > 1)
+ {
+ containsOslcParm = true;
+ }
+
+ return containsOslcParm;
+ }
static private Map<String,String> namespacePrefixes = new HashMap<String,String>();
static {
namespacePrefixes.put(IConstants.RDF_NAMESPACE, IConstants.RDF_PREFIX);
diff --git a/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/resource/ResourceService.java b/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/resource/ResourceService.java
index 4717097..f915b25 100644
--- a/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/resource/ResourceService.java
+++ b/org.eclipse.lyo.rio.am/src/main/java/org/eclipse/lyo/oslc/am/resource/ResourceService.java
@@ -488,7 +488,8 @@ public class ResourceService extends RioBaseService {
String sparql = queryBuilder.getQueryString(IAmConstants.OSLC_AM_TYPE_RESOURCE);
RioStore store = this.getStore();
- String queryUri = req.getRequestURL().toString();
+ //don't add ?null if the the query is for queryBase
+ String queryUri = (req.getQueryString() == null ) ? req.getRequestURL().toString() : req.getRequestURL().toString() + '?' + req.getQueryString();
List<Map<String, RioValue>> results = store.query(IConstants.SPARQL, sparql, 100);
@@ -519,10 +520,36 @@ public class ResourceService extends RioBaseService {
for (String namespace : namespaces) {
rdf.setAttribute("xmlns:" + namespacePrefixes.get(namespace), namespace); //$NON-NLS-1$
}
+ //If there is are parameters on the request (e.g. ?oslc.where=...), create 2 subject URIs, one for the
+ //results and one to describe the query. If this query was for the queryBase itself all predicates
+ //go under the same subject.
+ //TODO: Refactor the services for all RIO artifacts to eliminate duplicated code.
- Element queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
- rdf.appendChild(queryDescrElement);
+ Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ rdf.appendChild(resultDescr);
+
+ //check for oslc query parameters
+ String uriSplit [] = reqUri.split("\\?",2);
+ String baseUri = uriSplit[0];
+ boolean isOslcQuery = false;
+ if (uriSplit.length > 1)
+ isOslcQuery = hasOSLCQuery(uriSplit[1]);
+
+ resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
+
+
+ //if there are oslc query parameters, put the predicates under the query subject
+ Element queryDescrElement = null;
+ if (isOslcQuery )
+ {
+ queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
+ rdf.appendChild(queryDescrElement);
+ }
+ else {
+ //no oslc query parameters, everything goes under the queryBase subject
+ queryDescrElement = resultDescr;
+ }
Element title = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
queryDescrElement.appendChild(title);
@@ -536,12 +563,6 @@ public class ResourceService extends RioBaseService {
rdfType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, IConstants.OSLC_RESPONSEINFO);
queryDescrElement.appendChild(rdfType);
-
- Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- rdf.appendChild(resultDescr);
- String baseUri = reqUri.split("\\?")[0];
- resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
-
Iterator<Map<String, RioValue>> iterator = results.iterator();
while( iterator.hasNext() ) {
@@ -561,6 +582,20 @@ public class ResourceService extends RioBaseService {
}
}
+ private boolean hasOSLCQuery(String parms)
+ {
+ boolean containsOslcParm = false;
+ // not perfect - could have "oslc." in some random part of the parameters, but don't
+ // have access to the request at this point to use getPararmeterNames
+ String [] uriParts = parms.toLowerCase().split("oslc\\.",2);
+ if (uriParts.length > 1)
+ {
+ containsOslcParm = true;
+ }
+
+ return containsOslcParm;
+ }
+
static private Map<String,String> namespacePrefixes = new HashMap<String,String>();
static {
namespacePrefixes.put(IConstants.RDF_NAMESPACE, IConstants.RDF_PREFIX);
diff --git a/org.eclipse.lyo.rio.cm/src/main/java/org/eclipse/lyo/rio/cm/changerequest/ChangeRequestService.java b/org.eclipse.lyo.rio.cm/src/main/java/org/eclipse/lyo/rio/cm/changerequest/ChangeRequestService.java
index 9811a6c..77c34e0 100644
--- a/org.eclipse.lyo.rio.cm/src/main/java/org/eclipse/lyo/rio/cm/changerequest/ChangeRequestService.java
+++ b/org.eclipse.lyo.rio.cm/src/main/java/org/eclipse/lyo/rio/cm/changerequest/ChangeRequestService.java
@@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Date;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -298,7 +299,9 @@ public class ChangeRequestService extends RioBaseService {
String sparql = queryBuilder.getQueryString(ICmConstants.OSLC_CM_TYPE_CHANGEREQUEST);
RioStore store = this.getStore();
- String queryUri = req.getRequestURL().toString() + '?' + req.getQueryString();
+
+ //don't add ?null if the the query is for queryBase
+ String queryUri = (req.getQueryString() == null ) ? req.getRequestURL().toString() : req.getRequestURL().toString() + '?' + req.getQueryString();
List<Map<String, RioValue>> results = store.query(IConstants.SPARQL, sparql, 100);
@@ -328,10 +331,36 @@ public class ChangeRequestService extends RioBaseService {
for (String namespace : namespaces) {
rdf.setAttribute("xmlns:" + namespacePrefixes.get(namespace), namespace); //$NON-NLS-1$
}
+ //If there is are parameters on the request (e.g. ?oslc.where=...), create 2 subject URIs, one for the
+ //results and one to describe the query. If this query was for the queryBase itself all predicates
+ //go under the same subject.
+ //TODO: Refactor the services for all RIO artifacts to eliminate duplicated code.
+
+ Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ rdf.appendChild(resultDescr);
+
+ //check for oslc query parameters
+ String uriSplit [] = reqUri.split("\\?",2);
+ String baseUri = uriSplit[0];
+ boolean isOslcQuery = false;
+ if (uriSplit.length > 1)
+ isOslcQuery = hasOSLCQuery(uriSplit[1]);
- Element queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
- rdf.appendChild(queryDescrElement);
+ resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
+
+
+ //if there are oslc query parameters, put the predicates under the query subject
+ Element queryDescrElement = null;
+ if (isOslcQuery )
+ {
+ queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
+ rdf.appendChild(queryDescrElement);
+ }
+ else {
+ //no oslc query parameters, everything goes under the queryBase subject
+ queryDescrElement = resultDescr;
+ }
Element title = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
queryDescrElement.appendChild(title);
@@ -345,12 +374,6 @@ public class ChangeRequestService extends RioBaseService {
rdfType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, IConstants.OSLC_RESPONSEINFO);
queryDescrElement.appendChild(rdfType);
-
- Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- rdf.appendChild(resultDescr);
- String baseUri = reqUri.split("\\?")[0];
- resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
-
Iterator<Map<String, RioValue>> iterator = results.iterator();
while( iterator.hasNext() ) {
@@ -370,6 +393,20 @@ public class ChangeRequestService extends RioBaseService {
}
}
+ private boolean hasOSLCQuery(String parms)
+ {
+ boolean containsOslcParm = false;
+ // not perfect - could have "oslc." in some random part of the parameters, but don't
+ // have access to the request at this point to use getPararmeterNames
+ String [] uriParts = parms.toLowerCase().split("oslc\\.",2);
+ if (uriParts.length > 1)
+ {
+ containsOslcParm = true;
+ }
+
+ return containsOslcParm;
+ }
+
@SuppressWarnings("nls")
private String compactDocument(OslcResource resource ) throws RioServiceException {
String title = XmlUtils.encode(resource.getTitle());
diff --git a/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementService.java b/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementService.java
index 5a96a85..b64cd77 100644
--- a/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementService.java
+++ b/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementService.java
@@ -301,7 +301,8 @@ public class RequirementService extends RioBaseService {
String sparql = queryBuilder.getQueryString(IRmConstants.OSLC_RM_TYPE_REQUIREMENT);
RioStore store = this.getStore();
- String queryUri = req.getRequestURL().toString();
+ //don't add ?null if the the query is for queryBase
+ String queryUri = (req.getQueryString() == null ) ? req.getRequestURL().toString() : req.getRequestURL().toString() + '?' + req.getQueryString();
List<Map<String, RioValue>> results = store.query(IConstants.SPARQL, sparql, 100);
@@ -332,10 +333,36 @@ public class RequirementService extends RioBaseService {
for (String namespace : namespaces) {
rdf.setAttribute("xmlns:" + namespacePrefixes.get(namespace), namespace); //$NON-NLS-1$
}
+ //If there is are parameters on the request (e.g. ?oslc.where=...), create 2 subject URIs, one for the
+ //results and one to describe the query. If this query was for the queryBase itself all predicates
+ //go under the same subject.
+ //TODO: Refactor the services for all RIO artifacts to eliminate duplicated code.
- Element queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
- rdf.appendChild(queryDescrElement);
+ Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ rdf.appendChild(resultDescr);
+
+ //check for oslc query parameters
+ String uriSplit [] = reqUri.split("\\?",2);
+ String baseUri = uriSplit[0];
+ boolean isOslcQuery = false;
+ if (uriSplit.length > 1)
+ isOslcQuery = hasOSLCQuery(uriSplit[1]);
+
+ resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
+
+
+ //if there are oslc query parameters, put the predicates under the query subject
+ Element queryDescrElement = null;
+ if (isOslcQuery )
+ {
+ queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
+ rdf.appendChild(queryDescrElement);
+ }
+ else {
+ //no oslc query parameters, everything goes under the queryBase subject
+ queryDescrElement = resultDescr;
+ }
Element title = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
queryDescrElement.appendChild(title);
@@ -349,12 +376,6 @@ public class RequirementService extends RioBaseService {
rdfType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, IConstants.OSLC_RESPONSEINFO);
queryDescrElement.appendChild(rdfType);
-
- Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- rdf.appendChild(resultDescr);
- String baseUri = reqUri.split("\\?")[0];
- resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
-
Iterator<Map<String, RioValue>> iterator = results.iterator();
while( iterator.hasNext() ) {
@@ -374,6 +395,19 @@ public class RequirementService extends RioBaseService {
}
}
+ private boolean hasOSLCQuery(String parms)
+ {
+ boolean containsOslcParm = false;
+ // not perfect - could have "oslc." in some random part of the parameters, but don't
+ // have access to the request at this point to use getPararmeterNames
+ String [] uriParts = parms.toLowerCase().split("oslc\\.",2);
+ if (uriParts.length > 1)
+ {
+ containsOslcParm = true;
+ }
+
+ return containsOslcParm;
+ }
static private Map<String,String> namespacePrefixes = new HashMap<String,String>();
static {
namespacePrefixes.put(IConstants.RDF_NAMESPACE, IConstants.RDF_PREFIX);
diff --git a/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementTcService.java b/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementTcService.java
index e73978a..1728cf8 100644
--- a/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementTcService.java
+++ b/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirement/RequirementTcService.java
@@ -389,7 +389,8 @@ public class RequirementTcService extends RioBaseService {
String sparql = queryBuilder.getQueryString(IRmConstants.OSLC_RM_TYPE_REQUIREMENT);
RioStore store = this.getStore();
- String queryUri = request.getRequestURL().toString();
+ //don't add ?null if the the query is for queryBase
+ String queryUri = (request.getQueryString() == null ) ? request.getRequestURL().toString() : request.getRequestURL().toString() + '?' + request.getQueryString();
List<Map<String, RioValue>> results = store.query(IConstants.SPARQL, sparql, 100);
@@ -416,8 +417,7 @@ public class RequirementTcService extends RioBaseService {
* @param reqUri
* @return ret
*/
- private String buildResponseResource(List<Map<String, RioValue>> results, Map<String, PName> propNames, String reqUri) throws RioServiceException {
- // Start of user code for method buildResponseResource
+ private String buildResponseResource(List<Map<String, RioValue>> results, Map<String, PName> propNames, String reqUri) throws RioServiceException{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
@@ -431,24 +431,54 @@ public class RequirementTcService extends RioBaseService {
for (String namespace : namespaces) {
rdf.setAttribute("xmlns:" + namespacePrefixes.get(namespace), namespace); //$NON-NLS-1$
}
+ //If there is are parameters on the request (e.g. ?oslc.where=...), create 2 subject URIs, one for the
+ //results and one to describe the query. If this query was for the queryBase itself all predicates
+ //go under the same subject.
+ //TODO: Refactor the services for all RIO artifacts to eliminate duplicated code.
- Element responseElement = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_RESPONSEINFO);
- responseElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
- rdf.appendChild(responseElement);
+ Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ rdf.appendChild(resultDescr);
+ //check for oslc query parameters
+ String uriSplit [] = reqUri.split("\\?",2);
+ String baseUri = uriSplit[0];
+ boolean isOslcQuery = false;
+ if (uriSplit.length > 1)
+ isOslcQuery = hasOSLCQuery(uriSplit[1]);
+
+ resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
+
+
+ //if there are oslc query parameters, put the predicates under the query subject
+ Element queryDescrElement = null;
+ if (isOslcQuery )
+ {
+ queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
+ rdf.appendChild(queryDescrElement);
+ }
+ else {
+ //no oslc query parameters, everything goes under the queryBase subject
+ queryDescrElement = resultDescr;
+ }
+
Element title = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
- responseElement.appendChild(title);
+ queryDescrElement.appendChild(title);
title.setTextContent(Messages.getString("ResourceQuery.Title"));
- Element rdfDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- rdf.appendChild(rdfDescr);
- rdfDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
+ Element count = doc.createElementNS(IConstants.OSLC_NAMESPACE, IConstants.OSLC_PTERM_TOTALCOUNT);
+ queryDescrElement.appendChild(count);
+ count.setTextContent(Integer.toString(results.size()));
+
+ Element rdfType = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_TYPE);
+ rdfType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, IConstants.OSLC_RESPONSEINFO);
+ queryDescrElement.appendChild(rdfType);
Iterator<Map<String, RioValue>> iterator = results.iterator();
while( iterator.hasNext() ) {
Element rdfMem = doc.createElementNS(IConstants.RDFS_NAMESPACE, IConstants.RDFS_PTERM_MEMBER);
- rdfDescr.appendChild(rdfMem);
+ resultDescr.appendChild(rdfMem);
Map<String, RioValue> map = iterator.next();
RioValue uri = map.get("uri"); //$NON-NLS-1$
rdfMem.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, uri.stringValue());
@@ -461,8 +491,20 @@ public class RequirementTcService extends RioBaseService {
} finally {
}
-
- // End of user code
+ }
+
+ private boolean hasOSLCQuery(String parms)
+ {
+ boolean containsOslcParm = false;
+ // not perfect - could have "oslc." in some random part of the parameters, but don't
+ // have access to the request at this point to use getPararmeterNames
+ String [] uriParts = parms.toLowerCase().split("oslc\\.",2);
+ if (uriParts.length > 1)
+ {
+ containsOslcParm = true;
+ }
+
+ return containsOslcParm;
}
// Start of user code to add methods for RequirementTcService
diff --git a/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirementcollection/RequirementCollectionService.java b/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirementcollection/RequirementCollectionService.java
index a300cfc..cadbb48 100644
--- a/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirementcollection/RequirementCollectionService.java
+++ b/org.eclipse.lyo.rio.rm/src/main/java/org/eclipse/lyo/oslc/rm/services/requirementcollection/RequirementCollectionService.java
@@ -267,7 +267,8 @@ public class RequirementCollectionService extends RioBaseService {
String sparql = queryBuilder.getQueryString(IRmConstants.OSLC_RM_TYPE_REQUIREMENTCOLLECTION);
RioStore store = this.getStore();
- String queryUri = req.getRequestURL().toString();
+ //don't add ?null if the the query is for queryBase
+ String queryUri = (req.getQueryString() == null ) ? req.getRequestURL().toString() : req.getRequestURL().toString() + '?' + req.getQueryString();
List<Map<String, RioValue>> results = store.query(IConstants.SPARQL, sparql, 100);
@@ -298,10 +299,36 @@ public class RequirementCollectionService extends RioBaseService {
for (String namespace : namespaces) {
rdf.setAttribute("xmlns:" + namespacePrefixes.get(namespace), namespace); //$NON-NLS-1$
}
+ //If there is are parameters on the request (e.g. ?oslc.where=...), create 2 subject URIs, one for the
+ //results and one to describe the query. If this query was for the queryBase itself all predicates
+ //go under the same subject.
+ //TODO: Refactor the services for all RIO artifacts to eliminate duplicated code.
- Element queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
- rdf.appendChild(queryDescrElement);
+ Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ rdf.appendChild(resultDescr);
+
+ //check for oslc query parameters
+ String uriSplit [] = reqUri.split("\\?",2);
+ String baseUri = uriSplit[0];
+ boolean isOslcQuery = false;
+ if (uriSplit.length > 1)
+ isOslcQuery = hasOSLCQuery(uriSplit[1]);
+
+ resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
+
+
+ //if there are oslc query parameters, put the predicates under the query subject
+ Element queryDescrElement = null;
+ if (isOslcQuery )
+ {
+ queryDescrElement = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
+ queryDescrElement.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, reqUri);
+ rdf.appendChild(queryDescrElement);
+ }
+ else {
+ //no oslc query parameters, everything goes under the queryBase subject
+ queryDescrElement = resultDescr;
+ }
Element title = doc.createElementNS(IConstants.DCTERMS_NAMESPACE, IConstants.DCTERMS_PTERM_TITLE);
queryDescrElement.appendChild(title);
@@ -315,12 +342,6 @@ public class RequirementCollectionService extends RioBaseService {
rdfType.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_RESOURCE, IConstants.OSLC_RESPONSEINFO);
queryDescrElement.appendChild(rdfType);
-
- Element resultDescr = doc.createElementNS(IConstants.RDF_NAMESPACE, IConstants.RDF_TYPE_PTERM_DESCRIPTION);
- rdf.appendChild(resultDescr);
- String baseUri = reqUri.split("\\?")[0];
- resultDescr.setAttributeNS(IConstants.RDF_NAMESPACE, IConstants.RDF_PTERM_ABOUT, baseUri);
-
Iterator<Map<String, RioValue>> iterator = results.iterator();
while( iterator.hasNext() ) {
@@ -340,6 +361,20 @@ public class RequirementCollectionService extends RioBaseService {
}
}
+ private boolean hasOSLCQuery(String parms)
+ {
+ boolean containsOslcParm = false;
+ // not perfect - could have "oslc." in some random part of the parameters, but don't
+ // have access to the request at this point to use getPararmeterNames
+ String [] uriParts = parms.toLowerCase().split("oslc\\.",2);
+ if (uriParts.length > 1)
+ {
+ containsOslcParm = true;
+ }
+
+ return containsOslcParm;
+ }
+
static private Map<String,String> namespacePrefixes = new HashMap<String,String>();
static {
namespacePrefixes.put(IConstants.RDF_NAMESPACE, IConstants.RDF_PREFIX);