labelingsystem-server  Version 0.1.0.0
InfoResource Class Reference

Public Member Functions

Response getAPIpage () throws URISyntaxException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, IOException, SparqlQueryException, SparqlParseException
 

Member Function Documentation

◆ getAPIpage()

Response getAPIpage ( ) throws URISyntaxException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, IOException, SparqlQueryException, SparqlParseException
32  {
33  JSONObject outObject = new JSONObject();
34  try {
35  // get last modified data
36  File file = new File(InfoResource.class.getClassLoader().getResource("config.properties").getFile());
37  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
38  outObject.put("last build", sdf.format(file.lastModified()));
39  // get label data
40  RDF rdf = new RDF();
41  String query = "";
42  List<BindingSet> result = null;
43  // metadata
44  outObject.put("name", ConfigProperties.getPropertyParam("name"));
45  outObject.put("owner", ConfigProperties.getPropertyParam("owner"));
46  outObject.put("license", ConfigProperties.getPropertyParam("license"));
47  // vocabs
48  query = rdf.getPREFIXSPARQL();
49  query += "SELECT (COUNT(DISTINCT ?v) AS ?vcount) WHERE { ?v a ls:Vocabulary. }";
50  result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
51  HashSet<String> count_v = RDF4J_20.getValuesFromBindingSet_UNIQUESET(result, "vcount");
52  query = rdf.getPREFIXSPARQL();
53  query += "SELECT (COUNT(DISTINCT ?v) AS ?vcount) WHERE { ?v a ls:Vocabulary. ?v ls:hasReleaseType ls:Public. }";
54  result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
55  HashSet<String> count_vp = RDF4J_20.getValuesFromBindingSet_UNIQUESET(result, "vcount");
56  JSONObject oVocabs = new JSONObject();
57  oVocabs.put("count", Integer.parseInt(count_v.iterator().next()));
58  oVocabs.put("public", Integer.parseInt(count_vp.iterator().next()));
59  outObject.put("vocabs", oVocabs);
60  // labels
61  query = rdf.getPREFIXSPARQL();
62  query += "SELECT (COUNT(DISTINCT ?l) AS ?lcount) WHERE { ?l a ls:Label. }";
63  result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
64  HashSet<String> count_l = RDF4J_20.getValuesFromBindingSet_UNIQUESET(result, "lcount");
65  query = rdf.getPREFIXSPARQL();
66  query += "SELECT (COUNT(DISTINCT ?l) AS ?lcount) WHERE { ?l a ls:Label. ?l skos:inScheme ?v. ?v ls:hasReleaseType ls:Public. }";
67  result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
68  HashSet<String> count_lp = RDF4J_20.getValuesFromBindingSet_UNIQUESET(result, "lcount");
69  JSONObject oLabels = new JSONObject();
70  oLabels.put("count", Integer.parseInt(count_l.iterator().next()));
71  oLabels.put("public", Integer.parseInt(count_lp.iterator().next()));
72  outObject.put("labels", oLabels);
73  // triples
74  query = rdf.getPREFIXSPARQL();
75  query += "SELECT (COUNT(?s) AS ?scount) WHERE { ?s ?p ?o. }";
76  result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
77  HashSet<String> count_s = RDF4J_20.getValuesFromBindingSet_UNIQUESET(result, "scount");
78  outObject.put("triples", Integer.parseInt(count_s.iterator().next()));
79  // agents
80  query = rdf.getPREFIXSPARQL();
81  query += "SELECT (COUNT(DISTINCT ?a) AS ?acount) WHERE { ?a a ls:Agent. }";
82  result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
83  HashSet<String> count_a = RDF4J_20.getValuesFromBindingSet_UNIQUESET(result, "acount");
84  outObject.put("agents", Integer.parseInt(count_a.iterator().next()));
85  // revisions
86  query = rdf.getPREFIXSPARQL();
87  query += "SELECT (COUNT(DISTINCT ?r) AS ?rcount) WHERE { ?r a ls:Revision. }";
88  result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
89  HashSet<String> count_r = RDF4J_20.getValuesFromBindingSet_UNIQUESET(result, "rcount");
90  outObject.put("revisions", Integer.parseInt(count_r.iterator().next()));
91  return Response.ok(outObject).header("Content-Type", "application/json;charset=UTF-8").build();
92  } catch (Exception e) {
93  return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Logging.getMessageJSON(e, "v1.rest.InfoResource"))
94  .header("Content-Type", "application/json;charset=UTF-8").build();
95  }
96  }

References Logging.getMessageJSON(), and ConfigProperties.getPropertyParam().

rdf
Definition: RDF.java:1
Exception