labelingsystem-server  Version 0.1.0.0
Retcat_PersonDB Class Reference

Static Public Member Functions

static Map< String, SuggestionItem > query (String searchword) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, link.labeling.retcat.exceptions.ResourceNotAvailableException
 
static JSONObject info (String url) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, RetcatException
 

Member Function Documentation

◆ info()

static JSONObject info ( String  url) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, RetcatException
static
75  {
76  try {
77  URL obj = new URL(url);
78  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
79  con.setRequestMethod("POST");
80  String urlParameters = "";
81  con.setDoOutput(true);
82  DataOutputStream wr = new DataOutputStream(con.getOutputStream());
83  wr.writeBytes(urlParameters);
84  wr.flush();
85  wr.close();
86  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF8"));
87  String inputLine;
88  StringBuilder response = new StringBuilder();
89  while ((inputLine = in.readLine()) != null) {
90  response.append(inputLine);
91  }
92  in.close();
93  // parse json
94  JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
95  // output
96  JSONObject jsonOut = new JSONObject();
97  jsonOut.put("label", jsonObject.get("firstName") + " " + jsonObject.get("lastName"));
98  jsonOut.put("lang", "");
99  // get retcat info
100  String type = "persondb";
101  String quality = "";
102  String group = "";
103  for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
104  if (item.getType().equals(type)) {
105  quality = item.getQuality();
106  group = item.getGroup();
107  }
108  }
109  jsonOut.put("type", type);
110  jsonOut.put("quality", quality);
111  jsonOut.put("group", group);
112  jsonOut.put("uri", url);
113  jsonOut.put("scheme", "Person Database");
114  JSONArray broader = new JSONArray();
115  JSONArray narrower = new JSONArray();
116  jsonOut.put("broaderTerms", broader);
117  jsonOut.put("narrowerTerms", narrower);
118  jsonOut.put("description", jsonObject.get("affilliation"));
119  if (jsonOut.get("label") != null && !jsonOut.get("label").equals("")) {
120  return jsonOut;
121  } else {
122  throw new RetcatException("no label for this uri available");
123  }
124  } catch (Exception e) {
125  return new JSONObject();
126  }
127  }

References LocalRetcatItems.getLocalCatalogue().

Referenced by RetcatResource.getInfoPersonDB(), and RetcatResource.getQueryResultsPERSONDB().

◆ query()

static Map<String, SuggestionItem> query ( String  searchword) throws IOException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, ParseException, link.labeling.retcat.exceptions.ResourceNotAvailableException
static
28  {
29  searchword = GeneralFunctions.encodeURIComponent(searchword);
30  String PERSONDBHOST = "http://" + ConfigProperties.getPropertyParam("host") + "/persondb";
31  String url_string = PERSONDBHOST + "/search?query=" + searchword;
32  URL url = new URL(url_string);
33  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
34  conn.setRequestProperty("Accept", "application/json");
35  BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
36  String inputLine;
37  StringBuilder response = new StringBuilder();
38  while ((inputLine = br.readLine()) != null) {
39  response.append(inputLine);
40  }
41  br.close();
42  // fill objects
43  JSONArray jsonArray = (JSONArray) new JSONParser().parse(response.toString());
44  Map<String, SuggestionItem> autosuggests = new HashMap<String, SuggestionItem>();
45  for (Object element : jsonArray) {
46  JSONObject tmpElement = (JSONObject) element;
47  String uriValue = (String) tmpElement.get("id");
48  String uri = PERSONDBHOST + "/persons/" + uriValue;
49  autosuggests.put(uri, new SuggestionItem(uri));
50  SuggestionItem tmpAutosuggest = autosuggests.get(uri);
51  String firstName = (String) tmpElement.get("firstName");
52  String lastName = (String) tmpElement.get("lastName");
53  String labelValue = firstName + " " + lastName;
54  tmpAutosuggest.setLabel(labelValue);
55  String affilliation = (String) tmpElement.get("affilliation");
56  tmpAutosuggest.setDescription(affilliation);
57  tmpAutosuggest.setSchemeTitle("Person Database");
58  // get retcat info
59  String type = "persondb";
60  String quality = "";
61  String group = "";
62  for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
63  if (item.getType().equals(type)) {
64  quality = item.getQuality();
65  group = item.getGroup();
66  }
67  }
68  tmpAutosuggest.setType(type);
69  tmpAutosuggest.setQuality(quality);
70  tmpAutosuggest.setGroup(group);
71  }
72  return autosuggests;
73  }

References GeneralFunctions.encodeURIComponent(), LocalRetcatItems.getLocalCatalogue(), and ConfigProperties.getPropertyParam().

Referenced by RetcatResource.getQueryResultsPERSONDB().

Exception