semanticwfs  Version 0.1.0.0
TripleStoreConnector Class Referenceabstract

Abstract class to connect to triple stores and executing queries for the SemanticWFS implementation. More...

Collaboration diagram for TripleStoreConnector:

Static Public Member Functions

static Double[] getBoundingBoxFromTripleStoreData (String triplestore, String queryString)
 Retrieves a bounding box for a specific feature type which can be used in the SemanticWFS description. More...
 
static String executeQuery (String query, String endpoint, Boolean geojsonout)
 Executes a SPARQL query to a specific endpoint with the option to retrieve an additional GeoJSON result. More...
 
static String executeLDAPIQuery (String query, String formatter, String crs, String endpoint, JSONObject currentobj, Writer writer)
 
static String getTemporalExtentFromTripleStoreData (String triplestore, String queryString)
 May execute a SPARQL query to indicate a temporal extent of the given dataset. More...
 
static String getMetaData (String queryString, String queryurl, String featuretype, JSONObject workingobject)
 Retrieves metadata about the current object. More...
 
static String getStyleNames (String baseurl, JSONObject workingobject, String format)
 Retrieves a list of style names either in JSON, XML or HTML. More...
 
static StyleObject getStyle (String featuretype, String stylename, String triplestore, String namespace)
 Retrieves a style for a given featuretype given its name and caches it if it has not been cached before. More...
 
static Map< String, String > getClassesFromOntology (JSONObject triplestoreconf)
 Gets classes from a given triplestore. More...
 
static Map< String, String > getPropertiesByClass (String triplestoreurl, String classs)
 Gets properties by class from a given triplestore. More...
 
static Map< String, String > getFeatureTypeInformation (String queryString, String queryurl, String featuretype, JSONObject workingobj)
 Retrieves feature type information about a configured feature type. More...
 
static String getPropertyFromMapping (String typename, String propertyname)
 
static String CQLfilterStringToSPARQLQuery (String filter, String bbox, String curquery, String queryurl, String featuretype, String indvar, String bboxcrs, String targetCRS)
 Converts a CQL filter String to a SPARQL query expression. More...
 
static String executePropertyValueQuery (String queryurl, String output, String propertyValue, String startingElement, String featuretype, String resourceids, JSONObject workingobj, String filter, String count, String resultType, String srsName, BufferedWriter out) throws XMLStreamException, JSONException, IOException
 Executes a Property/Value Query against a triple store. More...
 
static String executeQuery (String queryString, String queryurl, String output, String count, String offset, String startingElement, String featuretype, String resourceids, JSONObject workingobj, String filter, String resultType, String srsName, String bboxcrs, String bbox, String mapstyle, Boolean alternativeFormat, Boolean invertXY, Writer out) throws XMLStreamException, JSONException, IOException
 Executes a SPARQL query which is issued because of a request to the WFS or OGC API features API. More...
 

Static Public Attributes

static String prefixCollection =""
 

Static Protected Attributes

static Map< String, Map< String, String > > featureTypes =new TreeMap<>()
 Map of feature types which have been loaded in the SemanticWFS. More...
 

Static Package Functions

 [static initializer]
 

Static Package Attributes

static Pattern spatialFunctions =Pattern.compile(".*(equals|disjoint|intersects|touches|crosses|within|contains|overlaps|dwithin).*",Pattern.CASE_INSENSITIVE)
 Supported spatial filter functions by the SemanticWFS. More...
 
static Pattern binaryOperators =Pattern.compile(".*(<|>|=|<=|>=|<>).*",Pattern.CASE_INSENSITIVE)
 Supported binary filter operators by the SemanticWFS. More...
 
static Integer resultSetSize =0
 

Detailed Description

Abstract class to connect to triple stores and executing queries for the SemanticWFS implementation.

Member Function Documentation

◆ [static initializer]()

[static initializer]
staticpackage

◆ CQLfilterStringToSPARQLQuery()

static String CQLfilterStringToSPARQLQuery ( String  filter,
String  bbox,
String  curquery,
String  queryurl,
String  featuretype,
String  indvar,
String  bboxcrs,
String  targetCRS 
)
static

Converts a CQL filter String to a SPARQL query expression.

Parameters
filterthe filter expression to convert
bboxa boundingbox to consider
curquerythe current SPARQL query to modify
queryurlthe URL of the triple store
featuretypethe featuretype which is queried
indvarthe variable indicating the individual queried
Returns
A String containing the modified SPARQL query
629  {
630  System.out.println("BBOX: "+bbox.toString()+" BBOX-CRS: "+bboxcrs+" - TargetCRS: "+targetCRS);
631  if(filter.isEmpty() && bbox.isEmpty())
632  return curquery;
633  StringBuilder additionaltriples=new StringBuilder();
634  StringBuilder builder=new StringBuilder();
635  System.out.println("Curquery: "+curquery);
636  if(!bbox.isEmpty()) {
637  String[] bboxcoords=bbox.split(",");
638  if(bboxcrs!=null && targetCRS!=null && !bboxcrs.isEmpty() && !targetCRS.isEmpty()) {
639  Coordinate p=ReprojectionUtils.reproject(Double.valueOf(bboxcoords[0]), Double.valueOf(bboxcoords[1]), bboxcrs, targetCRS);
640  Coordinate p2=ReprojectionUtils.reproject(Double.valueOf(bboxcoords[0]), Double.valueOf(bboxcoords[1]), bboxcrs, targetCRS);
641  bboxcoords[0]=p.x+"";
642  bboxcoords[1]=p.y+"";
643  bboxcoords[2]=p2.x+"";
644  bboxcoords[3]=p2.x+"";
645  }
646  System.out.println(Arrays.toString(bboxcoords));
647  if(queryurl.contains("wikidata")) {
648  String newcurquery="";
649  String the_geomline="";
650  for(String line:curquery.split(System.lineSeparator())) {
651  if(line.contains("the_geom") && !line.contains("SELECT")) {
652  the_geomline=line;
653  }else {
654  newcurquery+=line+System.lineSeparator();
655  }
656  }
657  curquery=newcurquery;
658  builder.append("SERVICE wikibase:box { "+the_geomline+System.lineSeparator()+" bd:serviceParam wikibase:cornerSouthWest \"POINT("+bboxcoords[1]+","+bboxcoords[0]+")\"^^geo:wktLiteral . "+System.lineSeparator()+"bd:serviceParam wikibase:cornerNorthEast \"POINT("+bboxcoords[3]+","+bboxcoords[2]+")\"^^geo:wktLiteral . "+System.lineSeparator()+" }"+System.lineSeparator());
659  builder.append("FILTER(");
660  }else {
661  builder.append("FILTER(");
662  builder.append("!geof:sfIntersects(\"POLYGON(("+bboxcoords[1].replace("\"", "")+" "+bboxcoords[0].replace("\"", "")+","+bboxcoords[1].replace("\"", "")+" "+bboxcoords[2].replace("\"", "")+","+bboxcoords[3].replace("\"", "")+" "+bboxcoords[2].replace("\"", "")+","+bboxcoords[3].replace("\"", "")+" "+bboxcoords[0].replace("\"", "")+","+bboxcoords[1].replace("\"", "")+" "+bboxcoords[0].replace("\"", "")+"))\"^^geo:wktLiteral,?the_geom) ");
663  }
664  }else {
665  builder.append("FILTER(");
666  }
667  if(filter.isEmpty()) {
668  builder.append(")");
669  return curquery+builder.toString().replace("FILTER()","")+System.lineSeparator();
670  }
671  if(filter.contains("AND")) {
672  Boolean containedbetween=false;
673  String betweenleftoperand="";
674  String betweenrightoperand="";
675  for(String filterex:filter.split("AND")) {
676  System.out.println(filterex);
677  if(filterex.contains("BETWEEN")) {
678  containedbetween=true;
679  betweenleftoperand=filterex.substring(0,filterex.indexOf("BETWEEN"));
680  betweenrightoperand=filterex.substring(filterex.indexOf("BETWEEN")+8);
681  }else if(!filterex.contains("BETWEEN") && containedbetween) {
682  containedbetween=false;
683  String propname=filterex.substring(0,filterex.indexOf("LIKE")).trim();
684  additionaltriples.append("?"+betweenleftoperand+" <"+getPropertyFromMapping(featuretype, propname)+"> ?"+propname+" ."+System.lineSeparator());
685  builder.append("?"+betweenleftoperand+" > "+betweenrightoperand+" && ?"+betweenleftoperand+" < "+filterex.trim()+" ");
686  } if(filterex.equalsIgnoreCase("LIKE")){
687  String propname=filterex.substring(0,filterex.indexOf("LIKE")).trim();
688  additionaltriples.append("?"+indvar+" <"+getPropertyFromMapping(featuretype, propname)+"> ?"+propname+" ."+System.lineSeparator());
689  builder.append("regex(str(?"+propname+"),\""+filterex.substring(filterex.indexOf("LIKE")+4).trim()+"\",\"i\") ");
690  }else if(spatialFunctions.matcher(filterex).matches()){
691  String prefix=filterex.substring(0,filterex.indexOf(',')+1).trim();
692  builder.append("geo:sf"+prefix+" \""+filterex.substring(filterex.indexOf(',')+1,filterex.length()-1).trim()+"\"^^geo:wktLiteral)");
693  }else if(binaryOperators.matcher(filterex).matches()) {
694  String[] splitted=filterex.split("<|>|=|<=|>=|<>");
695  if(filterex.contains("=")) {
696  String propname=filterex.substring(0,filterex.indexOf('=')).toLowerCase();
697  additionaltriples.append("?"+indvar+" <"+getPropertyFromMapping(featuretype, propname)+"> ?"+propname+" ."+System.lineSeparator());
698  builder.append("?"+filterex.toLowerCase().trim()+" ");
699  }else {
700  //builder.append("?"+featuretype.toLowerCase()+" "+getPropertyFromMapping(featuretype, )
701  }
702 
703  //builder.append("?"+featuretype.toLowerCase()+" ?abc "+WebService+". "+System.lineSeparator());
704  builder.append("?"+filterex);
705  }
706  builder.append(" && ");
707  }
708  builder.delete(builder.length()-4,builder.length());
709  }else if(filter.contains("=")){
710  builder.append("?"+filter.substring(0,filter.lastIndexOf('=')+1));
711  String suffix=filter.substring(filter.lastIndexOf('=')+1);
712  if(suffix.matches("[0-9\\.]+")) {
713  builder.append(suffix+" ");
714  }else {
715  builder.append("\""+suffix+"\"");
716  }
717  }
718  builder.append(")"+System.lineSeparator());
719  return curquery+builder.toString();
720  }
static String getPropertyFromMapping(String typename, String propertyname)
Definition: TripleStoreConnector.java:609
static Pattern binaryOperators
Supported binary filter operators by the SemanticWFS.
Definition: TripleStoreConnector.java:69
static Pattern spatialFunctions
Supported spatial filter functions by the SemanticWFS.
Definition: TripleStoreConnector.java:64

References TripleStoreConnector.binaryOperators, TripleStoreConnector.getPropertyFromMapping(), ReprojectionUtils.reproject(), and TripleStoreConnector.spatialFunctions.

Referenced by TripleStoreConnector.executePropertyValueQuery(), and TripleStoreConnector.executeQuery().

◆ executeLDAPIQuery()

static String executeLDAPIQuery ( String  query,
String  formatter,
String  crs,
String  endpoint,
JSONObject  currentobj,
Writer  writer 
)
static
203  {
204  ResultFormatter resformat=ResultFormatter.getFormatter(formatter);
205  query = prefixCollection + query;
206  System.out.println(query);
207  Query queryjena = QueryFactory.create(query);
208  //"http://localhost:8080/rdf4j-server/repositories/pleiades"
209  QueryExecution qe = QueryExecutionFactory.sparqlService(endpoint, queryjena);
210  ResultSet rs = qe.execSelect();
211  String res;
212  try {
213  res = resformat.formatter(rs, "", "item", "", "", false, false, "","item","",null,null,null,false,false,false,writer);
214  return res;
215  } catch (XMLStreamException | IOException e) {
216  // TODO Auto-generated catch block
217  e.printStackTrace();
218  }
219  return null;
220  }
static String prefixCollection
Definition: TripleStoreConnector.java:45

References ResultFormatter.formatter(), ResultFormatter.getFormatter(), and TripleStoreConnector.prefixCollection.

Referenced by WebService.docCollectionItemJSON(), and WebService.docCollectionJSON().

◆ executePropertyValueQuery()

static String executePropertyValueQuery ( String  queryurl,
String  output,
String  propertyValue,
String  startingElement,
String  featuretype,
String  resourceids,
JSONObject  workingobj,
String  filter,
String  count,
String  resultType,
String  srsName,
BufferedWriter  out 
) throws XMLStreamException, JSONException, IOException
static

Executes a Property/Value Query against a triple store.

Parameters
queryurl
output
propertyValue
startingElement
featuretype
resourceids
workingobj
filter
count
resultType
srsName
Returns
Exceptions
XMLStreamException
IOException
JSONException
743  {
744  String queryString="",indvar="item";
745  if(workingobj.has("indvar")) {
746  indvar=workingobj.getString("indvar");
747  }
748  if(resultType.equalsIgnoreCase("hits")) {
749  queryString=" SELECT (COUNT(DISTINCT ?"+indvar+") AS ?count) "+queryString.substring(queryString.indexOf("WHERE"));
750  //queryString=" SELECT (COUNT(DISTINCT ?"+featuretype.toLowerCase()+") AS ?count) WHERE { ?"+featuretype.toLowerCase()+" ?abc ?def .} "+System.lineSeparator();
751  }else {
752  queryString+=" SELECT ?"+featuretype.toLowerCase()+" ?member WHERE{"+System.lineSeparator();
753  }
754  if(!resourceids.isEmpty() && !resourceids.contains(",")) {
755  queryString=queryString.replace("WHERE{","WHERE{"+System.lineSeparator()+" BIND( <"+workingobj.getString("namespace")+resourceids+"> AS ?"+indvar+") "+System.lineSeparator());
756  }else if(!resourceids.isEmpty() && resourceids.contains(",")) {
757  StringBuilder toreplace=new StringBuilder();
758  toreplace.append("WHERE{ "+System.lineSeparator()+"VALUES ?"+indvar+"{ ");
759  for(String uri:resourceids.split(",")) {
760  toreplace.append("<"+workingobj.getString("namespace")+uri+"> ");
761  }
762  toreplace.append("} "+System.lineSeparator());
763  queryString=queryString.replace("WHERE{",System.lineSeparator()+toreplace.toString());
764  }else {
765  queryString=queryString.replace("WHERE{","WHERE{"+System.lineSeparator());
766  }
767  queryString+="?"+workingobj.getString("indvar")+" <"+propertyValue+"> ?member ."+System.lineSeparator();
768  queryString=queryString.substring(0,queryString.lastIndexOf('}'));
769  queryString=CQLfilterStringToSPARQLQuery(filter,"",queryString,queryurl,featuretype,indvar,"","");
770  queryString+="}"+System.lineSeparator();
771  if(!resultType.equalsIgnoreCase("hits") && workingobj.has("useorderby") && workingobj.getBoolean("useorderby"))
772  queryString+=" ORDER BY ?"+indvar+System.lineSeparator();
773  Integer limit=Integer.valueOf(count);
774  if(limit>0 && !resultType.equalsIgnoreCase("hits"))
775  queryString+=" LIMIT "+limit;
776  System.out.println(prefixCollection+queryString);
777  System.out.println(resourceids);
778  Query query = QueryFactory.create(prefixCollection+queryString);
779  QueryExecution qexec = QueryExecutionFactory.sparqlService(queryurl, query);
780  ResultFormatter resformat=ResultFormatter.getFormatter(output);
781  if(resformat==null) {
782  return null;
783  }
784  ResultSet results = qexec.execSelect();
785  if(resultType.equalsIgnoreCase("hits")) {
786  if(results.hasNext()) {
787  return results.next().getLiteral("count").getString();
788  }
789  }
790  String res=resformat.formatter(results,startingElement,featuretype.toLowerCase(),propertyValue,
791  (workingobj.has("typeColumn")?workingobj.get("typeColumn").toString():""),true,false,
792  srsName,(workingobj.has("indvar")?workingobj.getString("indvar"):"item"),
793  (workingobj.has("targetCRS")?workingobj.getString("targetCRS"):""),
794  null,null,null,false,false,workingobj.get("geometrytype").equals("Coverage"),out);
795  qexec.close();
796  if(resformat.lastQueriedElemCount==0) {
797  return "";
798  }
799  return res;
800  }
static String CQLfilterStringToSPARQLQuery(String filter, String bbox, String curquery, String queryurl, String featuretype, String indvar, String bboxcrs, String targetCRS)
Converts a CQL filter String to a SPARQL query expression.
Definition: TripleStoreConnector.java:629

References TripleStoreConnector.CQLfilterStringToSPARQLQuery(), ResultFormatter.formatter(), ResultFormatter.getFormatter(), ResultFormatter.lastQueriedElemCount, and TripleStoreConnector.prefixCollection.

Referenced by WebService.getPropertyValue().

◆ executeQuery() [1/2]

static String executeQuery ( String  query,
String  endpoint,
Boolean  geojsonout 
)
static

Executes a SPARQL query to a specific endpoint with the option to retrieve an additional GeoJSON result.

Parameters
querythe query to execute
endpointthe endpoint to issue the query against
geojsonoutindicates if an additional GeoJSON representation should be created
Returns
The result of the query execution as String according to a GeoJSON formatter
184  {
185  query = prefixCollection + query;
186  System.out.println(query);
187  Query queryjena = QueryFactory.create(query);
188  //"http://localhost:8080/rdf4j-server/repositories/pleiades"
189  QueryExecution qe = QueryExecutionFactory.sparqlService(endpoint, queryjena);
190  ResultSet rs = qe.execSelect();
191  GeoJSONFormatter form=new GeoJSONFormatter();
192  String res="";
193  try {
194  res = form.formatter(rs, "", "item", "", "", false, false, "","item","",null,null,null,false,false,false,null);
195  } catch (IOException e) {
196  // TODO Auto-generated catch block
197  e.printStackTrace();
198  }
199  qe.close();
200  return res;
201  }

References GeoJSONFormatter.formatter(), and TripleStoreConnector.prefixCollection.

Referenced by WebService.collectionItems(), WebService.getFeature(), WebService.getFeatureById(), and WebService.queryService().

◆ executeQuery() [2/2]

static String executeQuery ( String  queryString,
String  queryurl,
String  output,
String  count,
String  offset,
String  startingElement,
String  featuretype,
String  resourceids,
JSONObject  workingobj,
String  filter,
String  resultType,
String  srsName,
String  bboxcrs,
String  bbox,
String  mapstyle,
Boolean  alternativeFormat,
Boolean  invertXY,
Writer  out 
) throws XMLStreamException, JSONException, IOException
static

Executes a SPARQL query which is issued because of a request to the WFS or OGC API features API.

Parameters
queryStringThe queryString as configured in wfsconf.json
queryurlthe url of the triple store
outputthe downlift format
countthe maximum amount of results to retrieve
offsetthe offset of the query, i.e. from which element the results should be retrieved
startingElement
featuretypethe featuretype which is queried
resourceidsan array of resource ids to consider for the query
workingobj
filtera filter expression in CQL which is converted to SPARQL
resultTypethe result type
srsName
bboxthe boundingbox to apply for the SPARQL query
mapstylethe mapstyle to apply to the feature type
alternativeFormat
invertXYindicates whether to invert the XY axis on query
Returns
A string containing the query result. This String is empty if no result has been retrieved.
Exceptions
XMLStreamException
IOException
JSONException
829  {
830  if(invertXY==null) {
831  invertXY=false;
832  }
833  System.out.println(resultType);
834  System.out.println(mapstyle);
835  StyleObject style=null;
836  if(!mapstyle.isEmpty()) {
837  style=TripleStoreConnector.getStyle(featuretype, mapstyle, workingobj.getString("triplestore"),workingobj.getString("namespace"));
838  System.out.println(style);
839  }
840  String indvar="item";
841  if(workingobj.has("indvar")) {
842  indvar=workingobj.getString("indvar");
843  }
844  queryString=queryString.replace(" ."," ."+System.lineSeparator());
845  System.out.println(queryString);
846  if(resultType.equalsIgnoreCase("hits")) {
847  queryString=" SELECT (COUNT(DISTINCT ?"+indvar+") AS ?count) "+queryString.substring(queryString.indexOf("WHERE"));
848  //queryString=" SELECT (COUNT(DISTINCT ?"+featuretype.toLowerCase()+") AS ?count) WHERE{ ?"+featuretype.toLowerCase()+" ?abc ?def .}"+System.lineSeparator();
849  }else {
850  //queryString+=" SELECT ?"+indvar+" ?member WHERE{"+System.lineSeparator();
851  }
852  if(!resourceids.isEmpty() && !resourceids.contains(",")) {
853  queryString=queryString.replace("WHERE{","WHERE{"+System.lineSeparator()+" BIND( <"+workingobj.getString("namespace")+resourceids+"> AS ?"+indvar+") ");
854  }else if(!resourceids.isEmpty() && resourceids.contains(",")) {
855  StringBuilder toreplace=new StringBuilder();
856  toreplace.append("WHERE{ "+System.lineSeparator()+" VALUES ?"+indvar+"{ ");
857  for(String uri:resourceids.split(",")) {
858  toreplace.append("<"+workingobj.getString("namespace")+uri+"> ");
859  }
860  toreplace.append("}"+System.lineSeparator());
861  queryString=queryString.replace("WHERE{",System.lineSeparator()+toreplace.toString());
862  }else {
863  queryString=queryString.replace("WHERE{","WHERE{"+System.lineSeparator());
864  }
865  System.out.println("Before Inner Select: "+queryString);
866  Integer limit=Integer.valueOf(count);
867  Integer offsetval=Integer.valueOf(offset);
868  System.out.println("Limit: "+limit+" - Offset: "+offsetval);
869  if(limit>=1 || offsetval>0) {
870  StringBuilder toreplace=new StringBuilder();
871  toreplace.append("WHERE{ { SELECT ?"+indvar+" WHERE { ?"+indvar+" <"+WebService.triplestoreconf.getJSONObject("endpoints").getJSONObject(workingobj.getString("triplestore")).getString("type")+"> <"+workingobj.getString("class")+"> . }"+System.lineSeparator());
872  if(limit>=1 && !resultType.equalsIgnoreCase("hits")) {
873  toreplace.append(" LIMIT "+count+System.lineSeparator());
874  }
875  if(offsetval>0) {
876  toreplace.append(" OFFSET "+offsetval+System.lineSeparator());
877  }
878  toreplace.append(" } "+System.lineSeparator());
879  queryString=queryString.replace("WHERE{", toreplace);
880  }
881  System.out.println("PreCurQuery: "+queryString);
882  queryString=queryString.substring(0,queryString.lastIndexOf('}'));
883  queryString=CQLfilterStringToSPARQLQuery(filter,bbox,queryString,queryurl,featuretype,indvar,bboxcrs,workingobj.getString("targetCRS"))+"}";
884  if(!resultType.equalsIgnoreCase("hits") && workingobj.has("useorderby") && workingobj.getBoolean("useorderby"))
885  queryString+=System.lineSeparator()+"ORDER BY ?"+indvar+System.lineSeparator();
886 
887  /*System.out.println("Count: "+count);
888  if(limit>=1 && !resultType.equalsIgnoreCase("hits")) {
889  queryString+=" LIMIT "+count+System.lineSeparator();
890  }
891  if(offsetval>0) {
892  queryString+=" OFFSET "+offsetval+System.lineSeparator();
893  }*/
894  ResultFormatter resformat=ResultFormatter.getFormatter(output);
895  //TODO Generate CONSTRUCT query from SELECT query for performance improvement
896  /*if(queryString.trim().startsWith("SELECT") && resformat!=null && resformat.constructQuery) {
897  queryString="CONSTRUCT "+queryString.substring(queryString.indexOf("SELECT")+6);
898  }*/
899  System.out.println("Final Query: "+prefixCollection+queryString);
900  System.out.println(resourceids);
901  Query query = QueryFactory.create(prefixCollection+queryString);
902  QueryExecution qexec = QueryExecutionFactory.sparqlService(queryurl, query);
903 
904  if(resformat==null) {
905  return null;
906  }
907  String res="";
908  /*if(resformat!=null && resformat.constructQuery) {
909  Model results = qexec.execConstruct();
910  res=resformat.formatter(results,
911  startingElement,featuretype.toLowerCase(),"",
912  (workingobj.has("typeColumn")?workingobj.get("typeColumn").toString():""),
913  false,false,
914  srsName,indvar,
915  (workingobj.has("targetCRS")?workingobj.getString("targetCRS"):"")
916  ,null
917  ,null,style,alternativeFormat,invertXY,
918  workingobj.get("geometrytype").equals("Coverage"),out);
919  qexec.close();
920  }else {*/
921  ResultSet results = qexec.execSelect();
922  if(resultType.equalsIgnoreCase("hits")) {
923  if(results.hasNext()) {
924  res=results.next().getLiteral("count").getString();
925  qexec.close();
926  return res;
927  }
928  }
929  res=resformat.formatter(results,
930  startingElement,featuretype.toLowerCase(),"",
931  (workingobj.has("typeColumn")?workingobj.get("typeColumn").toString():""),
932  false,false,
933  srsName,indvar,
934  (workingobj.has("targetCRS")?workingobj.getString("targetCRS"):"")
935  ,null
936  ,null,style,alternativeFormat,invertXY,
937  workingobj.get("geometrytype").equals("Coverage"),out);
938  qexec.close();
939  //}
940 
941  if(resformat.lastQueriedElemCount==0) {
942  return "";
943  }
944  return res;
945  }

References TripleStoreConnector.CQLfilterStringToSPARQLQuery(), ResultFormatter.formatter(), ResultFormatter.getFormatter(), TripleStoreConnector.getStyle(), ResultFormatter.lastQueriedElemCount, TripleStoreConnector.prefixCollection, and WebService.triplestoreconf.

◆ getBoundingBoxFromTripleStoreData()

static Double [] getBoundingBoxFromTripleStoreData ( String  triplestore,
String  queryString 
)
static

Retrieves a bounding box for a specific feature type which can be used in the SemanticWFS description.

Parameters
triplestorethe triplestore to query
queryStringthe initial query string
Returns
An array of Double indicating the bounding box corner coordinates
82  {
83  Double minx=Double.MAX_VALUE,maxx=Double.MIN_VALUE,miny=Double.MAX_VALUE,maxy=Double.MIN_VALUE;
84  if(queryString.contains("the_geom")) {
85  queryString=" SELECT ?the_geom "+queryString.substring(queryString.indexOf("WHERE"));
86  }else if(queryString.contains("lat") && queryString.contains("lon")) {
87  queryString=" SELECT (MIN(?lat) AS ?minlat) (MAX(?lat) AS ?maxlat) (MIN(?lon) AS ?minlon) (MAX(?lon) AS ?maxlon) "+queryString.substring(queryString.indexOf("WHERE"));
88  }
89  try {
90  Query query = QueryFactory.create(prefixCollection+queryString);
91  QueryExecution qexec = QueryExecutionFactory.sparqlService(triplestore, query+" LIMIT 5000");
92  ResultSet results = qexec.execSelect();
93  Integer outercounter=0;
94  while(results.hasNext()) {
95  QuerySolution solu=results.next();
96  if(solu.get("the_geom")==null && solu.get("minlat")==null && solu.get("minlon")==null) {
97  continue;
98  }
99  if(solu.get("minlon")!=null) {
100  if(solu.get("minlon")!=null) {
101  minx=Double.valueOf(solu.get("minlon").toString().substring(0,solu.get("minlon").toString().indexOf("^^")));
102  }
103  if(solu.get("minlat")!=null) {
104  miny=Double.valueOf(solu.get("minlat").toString().substring(0,solu.get("minlat").toString().indexOf("^^")));
105  }
106  if(solu.get("maxlon")!=null) {
107  maxx=Double.valueOf(solu.get("maxlon").toString().substring(0,solu.get("maxlon").toString().indexOf("^^")));
108  }
109  if(solu.get("maxlat")!=null) {
110  maxy=Double.valueOf(solu.get("maxlat").toString().substring(0,solu.get("maxlat").toString().indexOf("^^")));
111  }
112  return new Double[] {minx,miny,maxx,maxy};
113  }
114  if(solu.get("the_geom")!=null) {
115  String wktLiteral=solu.get("the_geom").toString();
116  System.out.println(solu.get("the_geom"));
117  if(!wktLiteral.contains("(")) {
118  continue;
119  }
120  wktLiteral=wktLiteral.substring(0,wktLiteral.indexOf("^^"));
121  wktLiteral=wktLiteral.substring(wktLiteral.indexOf('(')).replace("(","").replace(")","").replace(","," ").trim();
122  Integer counter=0;
123  for(String coord:wktLiteral.split(" ")) {
124  if(coord.isEmpty())
125  continue;
126  Double curcoord=Double.valueOf(coord);
127  if(counter%2==0) {
128  if(curcoord<minx) {
129  minx=curcoord;
130  }
131  if(curcoord>maxx) {
132  maxx=curcoord;
133  }
134  }else {
135  if(curcoord<miny) {
136  miny=curcoord;
137  }
138  if(curcoord>maxy) {
139  maxy=curcoord;
140  }
141  }
142  counter++;
143  }
144  }else if(solu.get("lat")!=null && solu.get("lon")!=null) {
145  Double lon=Double.valueOf(solu.get("lon").toString().substring(0,solu.get("lon").toString().indexOf("^^")));
146  Double lat=Double.valueOf(solu.get("lat").toString().substring(0,solu.get("lat").toString().indexOf("^^")));
147  if(lon<minx) {
148  minx=lon;
149  }
150  if(lon>maxx) {
151  maxx=lon;
152  }
153  if(lat<miny) {
154  miny=lat;
155  }
156  if(lat>maxy) {
157  maxy=lat;
158  }
159  }
160  outercounter++;
161  }
162  System.out.println(outercounter/2);
163  qexec.close();
164  }catch(Exception e) {
165  e.printStackTrace();
166  }
167  return new Double[] {minx,miny,maxx,maxy};
168  }

References TripleStoreConnector.prefixCollection.

Referenced by WebService.describeFeatureType(), and WebService.describeFeatureTypeWFS10().

◆ getClassesFromOntology()

static Map<String,String> getClassesFromOntology ( JSONObject  triplestoreconf)
static

Gets classes from a given triplestore.

Parameters
triplestoreconfThe triplestoreconfiguration for the given triplestore
Returns
A map of class URIs and their labels
362  {
363  Map<String,String> result=new TreeMap<String,String>();
364  System.out.println(prefixCollection+" SELECT DISTINCT ?class ?label WHERE { ?abc <"+triplestoreconf.getString("type")+"> ?class . OPTIONAL{ ?class rdfs:label ?label } ?abc <"+triplestoreconf.getJSONArray("geo").getString(0)+"> ?geom . } ");
365  Query query = QueryFactory.create(prefixCollection+" SELECT DISTINCT ?class ?label WHERE { ?abc <"+triplestoreconf.getString("type")+"> ?class . ?abc <"+triplestoreconf.getJSONArray("geo").getString(0)+"> ?geom . } LIMIT 500");
366  QueryExecution qexec = QueryExecutionFactory.sparqlService(triplestoreconf.getString("endpoint"), query);
367  ResultSet resformat=qexec.execSelect();
368  while(resformat.hasNext()) {
369  QuerySolution cur = resformat.next();
370  if(cur!=null) {
371  if(cur.get("label")!=null) {
372  result.put(cur.get("class").toString(),cur.get("label").toString());
373  }else {
374  result.put(cur.get("class").toString(),cur.get("class").toString().substring(cur.get("class").toString().lastIndexOf('/')+1));
375  }
376  }
377  }
378  qexec.close();
379  return result;
380  }

References TripleStoreConnector.prefixCollection.

Referenced by WebService.getGeoClassesFromOntology().

◆ getFeatureTypeInformation()

static Map<String,String> getFeatureTypeInformation ( String  queryString,
String  queryurl,
String  featuretype,
JSONObject  workingobj 
)
static

Retrieves feature type information about a configured feature type.

This information is needed to indicate the amount of features and common properties associated with those features.

Parameters
queryStringThe query string as configured in wfsconf.json
queryurlThe URL of the triple store
featuretypeThe feature type which is queried
workingobj
Returns
A map of feature type information
416  {
417  System.out.println("Getting FeatureType Information for "+featuretype+"...");
418  if(featureTypes.containsKey(featuretype.toLowerCase())) {
419  return featureTypes.get(featuretype.toLowerCase());
420  }
421  String indvar="item";
422  if(workingobj.has("indvar")) {
423  indvar=workingobj.getString("indvar");
424  }
425  Map<String,String> result=new TreeMap<>();
426  Map<String,String> nscache=new TreeMap<>();
427  System.out.println(prefixCollection+queryString+" LIMIT 1");
428  //if(workingobj.has("useorderby") && workingobj.getBoolean("useorderby"))
429  //queryString+=" ORDER BY ?"+indvar+System.lineSeparator();
430  Query query;
431  if(queryString.contains("?rel") && queryString.contains("?val")) {
432  query = QueryFactory.create(prefixCollection+queryString+" LIMIT 100");
433  }else {
434  query = QueryFactory.create(prefixCollection+queryString+" LIMIT 1");
435  }
436  System.out.println("Starting query execution... "+queryurl);
437  QueryExecution qexec = QueryExecutionFactory.sparqlService(queryurl, query);
438  qexec.setTimeout(1, TimeUnit.MINUTES);
439  ResultSet results = qexec.execSelect();
440  System.out.println("Hello");
441  if(!results.hasNext()) {
442  System.out.println("No results!?!");
443  qexec.close();
444  return null;
445  }
446  System.out.println("Executed query... getting results");
447  QuerySolution solu=results.next();
448  Iterator<String> varnames=solu.varNames();
449  System.out.println(solu.get(indvar));
450  if(solu.get(indvar)!=null) {
451  result=new TreeMap<>();
452  queryString=queryString.replace("WHERE{","WHERE{ BIND( <"+solu.get(indvar)+"> AS ?"+indvar+") ");
453  System.out.println(prefixCollection+queryString);
454  qexec.close();
455  query = QueryFactory.create(prefixCollection+queryString);
456  qexec = QueryExecutionFactory.sparqlService(queryurl, query);
457  results = qexec.execSelect();
458  }
459  Map<String,String> rel = new TreeMap<String,String>();
460  Map<String,String> val=new TreeMap<String,String>();
461  String lat="",lon="",lastInd="";
462  List<String> latlist=new LinkedList<String>();
463  List<String> lonlist=new LinkedList<String>();
464  Integer attcount=0,nscounter=0;
465  result.put("namespaces","");
466  while(results.hasNext()) {
467  solu=results.next();
468  varnames=solu.varNames();
469  if(lastInd.isEmpty()) {
470  if(!latlist.isEmpty() && !lonlist.isEmpty()) {
471  if(latlist.size()==1 && lonlist.size()==1) {
472  result.put("http://www.opengis.net/ont/geosparql#asWKT","Point("+lonlist.get(0)+" "+latlist.get(0)+")");
473  }else if(latlist.get(latlist.size()-1).equals(latlist.get(0)) && lonlist.get(lonlist.size()-1).equals(lonlist.get(0))) {
474  StringBuilder builder=new StringBuilder();
475  for(int i=0;i<latlist.size();i++) {
476  builder.append(lonlist.get(i)+" "+latlist.get(i)+",");
477  }
478  builder.delete(builder.length()-1,builder.length());
479  result.put("http://www.opengis.net/ont/geosparql#asWKT","Polygon(("+builder.toString()+"))");
480  }else if(!latlist.get(latlist.size()-1).equals(latlist.get(0)) || !lonlist.get(lonlist.size()-1).equals(lonlist.get(0))) {
481  StringBuilder builder=new StringBuilder();
482  for(int i=0;i<latlist.size();i++) {
483  builder.append(lonlist.get(i)+" "+latlist.get(i)+",");
484  }
485  builder.delete(builder.length()-1,builder.length());
486  result.put("http://www.opengis.net/ont/geosparql#asWKT","LineString(("+builder.toString()+"))");
487  }
488  latlist.clear();
489  lonlist.clear();
490  }
491  }else if(!lastInd.equals(solu.get(indvar).toString())) {
492  break;
493  }
494  while(varnames.hasNext()) {
495  String varname=varnames.next();
496  if(varname.endsWith("_rel") || varname.equals("rel") || varname.matches("rel[0-9]+$")) {
497  rel.put(varname,solu.get(varname).toString());
498  }else if(varname.endsWith("_val") || varname.equals("val") || varname.matches("val[0-9]+$")){
499  val.put(varname,solu.get(varname).toString());
500  }else if(varname.equals("lat")) {
501  lat=solu.get(varname).toString();
502  }else if(varname.equals("lon")){
503  lon=solu.get(varname).toString();
504  }else if(varname.contains("_geom")){
505  if(!nscache.containsKey("http://www.opengis.net/ont/geosparql#"))
506  nscache.put("http://www.opengis.net/ont/geosparql#","ns"+nscounter++);
507  result.put("http://www.opengis.net/ont/geosparql#asWKT",solu.getLiteral(varname).toString());
508  //geomLiteral=solu.getLiteral(varname).toString();
509  }else {
510  String ns=null;
511  String varval=solu.get(varname).toString();
512  if(varval.contains("http") && varval.contains("#")) {
513  ns=varval.substring(0,varval.lastIndexOf('#')+1);
514  }else if(varval.contains("http") && varval.contains("/")) {
515  ns=varval.substring(0,varval.lastIndexOf('/')+1);
516  }
517  if(ns!=null && !ns.isEmpty() && !nscache.containsKey(ns)) {
518  nscache.put(ns,"ns"+nscounter++);
519  }
520  try {
521  String lit=solu.get(varname).toString();
522  result.put(varname, lit);
523  }catch(Exception e) {
524  e.printStackTrace();
525  result.put(varname, varval);
526  }
527  }
528 
529  }
530  if(!lat.isEmpty() && !lon.isEmpty()) {
531  String ns=null;
532  if(lat.contains("^^")) {
533  ns=lat.substring(lat.lastIndexOf("^^")+2);
534  }else if(lat.contains("http") && lat.contains("#")) {
535  ns=lat.substring(0,lat.lastIndexOf('#')+1);
536  }else if(lat.contains("http") && lat.contains("/")) {
537  ns=lat.substring(0,lat.lastIndexOf('/')+1);
538  }
539  if(ns!=null && !ns.isEmpty() && !nscache.containsKey(ns)) {
540  nscache.put(ns,"ns"+nscounter++);
541  }
542  if(lat.contains("^^") && lon.contains("^^")) {
543  latlist.add(lat.substring(0,lat.indexOf("^^")));
544  lonlist.add(lon.substring(0,lon.indexOf("^^")));
545  }
546  lat="";
547  lon="";
548  }
549  if(!rel.isEmpty() && !val.isEmpty()) {
550  String ns=null;
551  int i=0;
552  String attname="",vall="",rell="";
553  Iterator<String> valit=val.values().iterator();
554  while(valit.hasNext()) {
555  vall=valit.next();
556  }
557  for(String rl:rel.values()) {
558  if(rl.contains("http") && rl.contains("#")) {
559  ns=rl.substring(0,rl.lastIndexOf('#')+1);
560  attname+=rl.substring(rl.lastIndexOf('#')+1);
561  }else if(rl.contains("http") && rl.contains("/")) {
562  ns=rl.substring(0,rl.lastIndexOf('/')+1);
563  attname+=rl.substring(rl.lastIndexOf('/')+1);
564  }
565  rell=rl;
566  if(ns!=null && !ns.isEmpty() && !nscache.containsKey(ns)) {
567  nscache.put(ns,"ns"+nscounter++);
568  }
569  if(i<(rel.size()-1)) {
570  attname+=".";
571  }
572  i++;
573  }
574  result.put(rell, vall);
575  rel.clear();
576  val.clear();
577  }
578  attcount++;
579  }
580  if(!latlist.isEmpty() && !lonlist.isEmpty()) {
581  if(latlist.size()==1 && lonlist.size()==1) {
582  result.put("http://www.opengis.net/ont/geosparql#asWKT","Point("+lonlist.get(0)+" "+latlist.get(0)+")");
583  }else if(latlist.get(latlist.size()-1).equals(latlist.get(0)) && lonlist.get(lonlist.size()-1).equals(lonlist.get(0))) {
584  StringBuilder builder=new StringBuilder();
585  for(int i=0;i<latlist.size();i++) {
586  builder.append(lonlist.get(i)+" "+latlist.get(i)+",");
587  }
588  builder.delete(builder.length()-1,builder.length());
589  result.put("http://www.opengis.net/ont/geosparql#asWKT","Polygon(("+builder.toString()+"))");
590  }else if(!latlist.get(latlist.size()-1).equals(latlist.get(0)) || !lonlist.get(lonlist.size()-1).equals(lonlist.get(0))) {
591  StringBuilder builder=new StringBuilder();
592  for(int i=0;i<latlist.size();i++) {
593  builder.append(lonlist.get(i)+" "+latlist.get(i)+",");
594  }
595  builder.delete(builder.length()-1,builder.length());
596  result.put("http://www.opengis.net/ont/geosparql#asWKT","LineString(("+builder.toString()+"))");
597  }
598  latlist.clear();
599  lonlist.clear();
600  }
601  WebService.nameSpaceCache.put(featuretype.toLowerCase(),nscache);
602  System.out.println("NamespaceCache: "+WebService.nameSpaceCache);
603  System.out.println(result);
604  workingobj.put("attcount",attcount);
605  qexec.close();
606  return result;
607  }
static Map< String, Map< String, String > > featureTypes
Map of feature types which have been loaded in the SemanticWFS.
Definition: TripleStoreConnector.java:74

References TripleStoreConnector.featureTypes, WebService.nameSpaceCache, and TripleStoreConnector.prefixCollection.

Referenced by WebService.collectionInformation(), WebService.collectionItems(), WebService.describeFeatureType(), WebService.describeFeatureTypeJSON(), WebService.getCollectionMetadata(), WebService.getFeature(), WebService.getFeatureById(), WebService.getPropertyValue(), and WebService.queryables().

◆ getMetaData()

static String getMetaData ( String  queryString,
String  queryurl,
String  featuretype,
JSONObject  workingobject 
)
static

Retrieves metadata about the current object.

Parameters
queryStringThe queryString
queryurlthe query url
featuretypethe featuretype to get metadata about
workingobjectthe current configuration to work with
Returns
250  {
251  queryString="SELECT ?pointstyle ?linestringstyle ?polygonstyle WHERE { <"+featuretype+"> semgis:hasStyle ?style . ?style semgis:hasPointStyle ?pointstyle . ?style semgis:hasPointStyle ?linestringstyle . ?style semgis:hasPointStyle ?polygonstyle . }";
252  Query query = QueryFactory.create(prefixCollection+queryString+" LIMIT 1");
253  QueryExecution qexec = QueryExecutionFactory.sparqlService(queryurl, query);
254  ResultSet results = qexec.execSelect();
255  qexec.close();
256  return "";
257  }

References TripleStoreConnector.prefixCollection.

◆ getPropertiesByClass()

static Map<String,String> getPropertiesByClass ( String  triplestoreurl,
String  classs 
)
static

Gets properties by class from a given triplestore.

Parameters
triplestoreurlthe URL of the triple store
classsThe class for which properties should be retrieved
Returns
A map of property URIs and their labels
388  {
389  Map<String,String> result=new TreeMap<String,String>();
390  Query query = QueryFactory.create(prefixCollection+" SELECT DISTINCT ?rel ?label WHERE { ?item rdf:type <"+classs+"> . ?item ?rel ?val . OPTIONAL { ?rel rdfs:label ?label . } } ");
391  QueryExecution qexec = QueryExecutionFactory.sparqlService(triplestoreurl, query);
392  ResultSet resformat=qexec.execSelect();
393  while(resformat.hasNext()) {
394  QuerySolution res = resformat.next();
395  if(res.get("label")!=null) {
396  result.put(res.get("rel").toString(),res.get("label").toString());
397  }else {
398  result.put(res.get("rel").toString(),res.get("rel").toString().substring(res.get("rel").toString().lastIndexOf('/')+1));
399  }
400 
401  }
402  qexec.close();
403  return result;
404  }

References TripleStoreConnector.prefixCollection.

Referenced by WebService.getPropertiesByClass().

◆ getPropertyFromMapping()

static String getPropertyFromMapping ( String  typename,
String  propertyname 
)
static
609  {
610  for(String key:WebService.featureTypeCache.get(typename.toLowerCase()).keySet()) {
611  if(key.contains(propertyname)) {
612  propertyname=key;
613  return key;
614  }
615  }
616  return null;
617  }

References WebService.featureTypeCache.

Referenced by TripleStoreConnector.CQLfilterStringToSPARQLQuery().

◆ getStyle()

static StyleObject getStyle ( String  featuretype,
String  stylename,
String  triplestore,
String  namespace 
)
static

Retrieves a style for a given featuretype given its name and caches it if it has not been cached before.

Parameters
featuretypethe featuretype for which styles should be queried
stylenameA stylename which should be queried
triplestoreThe triplestore URL
namespaceThe style namespace
Returns
A styleobject indicating the style contents
315  {
316  if(WebService.styleCache.containsKey(triplestore) && WebService.styleCache.get(triplestore).containsKey(stylename)) {
317  return WebService.styleCache.get(triplestore).get(stylename);
318  }
319  String queryString="SELECT ?style ?styleLabel ?pointStyle ?pointImage ?hatch ?linestringStyle ?linestringImage ?linestringImageStyle ?polygonStyle ?polygonImage WHERE { "
320  +" OPTIONAL {<"+namespace+stylename+"> rdfs:label ?styleLabel .}"+System.lineSeparator()
321  +" OPTIONAL {<"+namespace+stylename+"> semgis:linestringImage ?linestringImage .} "+System.lineSeparator()
322  +" OPTIONAL {<"+namespace+stylename+"> semgis:linestringImageStyle ?linestringImageStyle .} "+System.lineSeparator()
323  +" OPTIONAL {<"+namespace+stylename+"> semgis:hatch ?hatch .}"+System.lineSeparator()
324  +" OPTIONAL {<"+namespace+stylename+"> semgis:image ?pointImage .}"+System.lineSeparator()
325  +" OPTIONAL {<"+namespace+stylename+"> semgis:imageStyle ?pointStyle .}"+System.lineSeparator()
326  +" OPTIONAL {<"+namespace+stylename+"> semgis:linestringStyle ?linestringStyle .}"+System.lineSeparator()
327  +" OPTIONAL {<"+namespace+stylename+"> semgis:polygonStyle ?polygonStyle .}"+System.lineSeparator()
328  +" OPTIONAL {<"+namespace+stylename+"> semgis:polygonImage ?polygonImage .}"+System.lineSeparator()+" }";
329  System.out.println(queryString);
330  Query query = QueryFactory.create(prefixCollection+queryString+" LIMIT 1");
331  QueryExecution qexec = QueryExecutionFactory.sparqlService(triplestore, query);
332  ResultSet results = qexec.execSelect();
333  System.out.println("Style Query finished!");
334  StyleObject result=null;
335  if(results.hasNext()) {
336  result=new StyleObject();
337  QuerySolution solu=results.next();
338  result.styleName=stylename;
339  result.pointStyle=solu.get("pointStyle")!=null?solu.get("pointStyle").toString():null;
340  result.pointImage=solu.get("pointImage")!=null?solu.get("pointImage").toString():null;
341  result.lineStringImage=solu.get("linestringImage")!=null?solu.get("linestringImage").toString():null;
342  result.lineStringImageStyle=solu.get("linestringImageStyle")!=null?solu.get("linestringImageStyle").toString():null;
343  result.lineStringStyle=solu.get("linestringStyle")!=null?solu.get("linestringStyle").toString():null;
344  result.polygonStyle=solu.get("polygonStyle")!=null?solu.get("polygonStyle").toString():null;
345  result.polygonImage=solu.get("polygonImage")!=null?solu.get("polygonImage").toString():null;
346  result.hatch=solu.get("hatch")!=null?solu.get("hatch").toString():null;
347  if(!WebService.styleCache.containsKey(triplestore)) {
348  WebService.styleCache.put(triplestore,new TreeMap<>());
349  }
350  WebService.styleCache.get(triplestore).put(stylename,result);
351  }
352  qexec.close();
353  return result;
354  }

References StyleObject.hatch, StyleObject.lineStringImage, StyleObject.lineStringImageStyle, StyleObject.lineStringStyle, StyleObject.pointImage, StyleObject.pointStyle, StyleObject.polygonImage, StyleObject.polygonStyle, TripleStoreConnector.prefixCollection, WebService.styleCache, and StyleObject.styleName.

Referenced by TripleStoreConnector.executeQuery(), and WebService.getCollectionStyle().

◆ getStyleNames()

static String getStyleNames ( String  baseurl,
JSONObject  workingobject,
String  format 
)
static

Retrieves a list of style names either in JSON, XML or HTML.

Parameters
baseurlThe baseurl for retrieving the styles
workingobjectthe current configuration
formatthe format in which to return the style
Returns
The style description in the defined format as a String
266  {
267  String queryString="SELECT ?style ?styleLabel ?pointstyle ?linestringstyle ?polygonstyle WHERE { <"+workingobject.getString("class")+"> owl:equivalentClass ?equivclass ."+System.lineSeparator()+" ?equivclass owl:intersectionOf ?intersect ."+System.lineSeparator()+" ?intersect rdf:rest ?rest."+System.lineSeparator()+" ?rest rdf:first ?first ."+System.lineSeparator()+" ?first owl:allValuesFrom ?styleclass ."+System.lineSeparator()+" ?style rdf:type ?styleclass."+System.lineSeparator()+" OPTIONAL{?style rdfs:label ?styleLabel .} }";
268  Query query = QueryFactory.create(prefixCollection+queryString+" LIMIT 1");
269  System.out.println(queryString);
270  QueryExecution qexec = QueryExecutionFactory.sparqlService(workingobject.getString("triplestore"), query);
271  ResultSet results = qexec.execSelect();
272  String result="";
273  if("json".equals(format)) {
274  JSONObject resultjson=new JSONObject();
275  resultjson.put("styles",new JSONArray());
276  while(results.hasNext()) {
277  JSONObject style=new JSONObject();
278  QuerySolution curresult = results.next();
279  style.put("uri",curresult.get("style"));
280  style.put("name",curresult.get("style").toString().substring(curresult.get("style").toString().indexOf("#")+1));
281  resultjson.getJSONArray("styles").put(style);
282  }
283  result=resultjson.toString(2);
284  }else if("html".equals(format)) {
285  result="";
286  result+="<table border=1><tr><th>Stylename</th><th>Styletest</th></tr>";
287  while(results.hasNext()) {
288  QuerySolution curresult = results.next();
289  result+="<tr><td><a href=\""+curresult.get("style")+"\">"+curresult.get("style").toString()
290  .substring(curresult.get("style").toString().indexOf("#")+1)+"</a></td><td><a href=\""
291  +baseurl+"/collections/"+workingobject.getString("name")+"/items?f=html&style="+curresult.get("style").toString()
292  .substring(curresult.get("style").toString().indexOf("#")+1)+"\">View</a></tr>";
293  }
294  result+="</table>";
295  }else {
296  result="<?xml version=\"1.0\"?><styles>"+System.lineSeparator();
297  while(results.hasNext()) {
298  QuerySolution curresult = results.next();
299  result+="<style uri=\""+curresult.get("style")+"\">"+curresult.get("style").toString().substring(curresult.get("style").toString().indexOf("#")+1)+"</style>"+System.lineSeparator();
300  }
301  result+="</styles>"+System.lineSeparator();
302  }
303  qexec.close();
304  return result;
305  }

References TripleStoreConnector.prefixCollection.

Referenced by WebService.getCollectionStyles(), and WebService.queryables().

◆ getTemporalExtentFromTripleStoreData()

static String getTemporalExtentFromTripleStoreData ( String  triplestore,
String  queryString 
)
static

May execute a SPARQL query to indicate a temporal extent of the given dataset.

This feature is currently not yet implemented and would need to be configured on a feature by feature basis as no standard to represent times is available.

Parameters
triplestorethe triplestore to issue the query against
queryStringthe queryString
Returns
The query result as String
229  {
230  Query query = QueryFactory.create(prefixCollection+queryString);
231  QueryExecution qexec = QueryExecutionFactory.sparqlService(triplestore, query);
232  ResultSet results = qexec.execSelect();
233  while(results.hasNext()) {
234  QuerySolution solu=results.next();
235  String wktLiteral=solu.get("the_geom").toString();
236 
237  }
238  qexec.close();
239  return "";
240  }

References TripleStoreConnector.prefixCollection.

Member Data Documentation

◆ binaryOperators

Pattern binaryOperators =Pattern.compile(".*(<|>|=|<=|>=|<>).*",Pattern.CASE_INSENSITIVE)
staticpackage

Supported binary filter operators by the SemanticWFS.

Referenced by TripleStoreConnector.CQLfilterStringToSPARQLQuery().

◆ featureTypes

Map<String,Map<String,String> > featureTypes =new TreeMap<>()
staticprotected

Map of feature types which have been loaded in the SemanticWFS.

Referenced by TripleStoreConnector.getFeatureTypeInformation().

◆ prefixCollection

◆ resultSetSize

Integer resultSetSize =0
staticpackage

◆ spatialFunctions

Pattern spatialFunctions =Pattern.compile(".*(equals|disjoint|intersects|touches|crosses|within|contains|overlaps|dwithin).*",Pattern.CASE_INSENSITIVE)
staticpackage

Supported spatial filter functions by the SemanticWFS.

Referenced by TripleStoreConnector.CQLfilterStringToSPARQLQuery().