28 searchword = GeneralFunctions.encodeURIComponent(searchword);
29 String url_string =
"http://finto.fi/rest/v1/search?query=*" + searchword +
"*&lang=en&type=skos:Concept&fields=narrower%20broader%20scopeNote&vocab=allars%20koko%20ponduskategorier%20ysa%20yso%20juho%20jupo%20keko%20okm-tieteenala%20liito%20mero%20puho%20tsr%20afo%20kassu%20mesh%20tero%20maotao%20musa%20muso%20valo%20kauno%20kito%20kto&limit=" + RetcatResource.getLimit();
30 URL url =
new URL(url_string);
31 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
32 BufferedReader br =
new BufferedReader(
new InputStreamReader(conn.getInputStream(),
"UTF-8"));
34 StringBuilder response =
new StringBuilder();
35 while ((inputLine = br.readLine()) !=
null) {
36 response.append(inputLine);
40 JSONObject jsonObject = (JSONObject)
new JSONParser().parse(response.toString());
41 JSONArray resultsArray = (JSONArray) jsonObject.get(
"results");
42 Map<String, SuggestionItem> autosuggests =
new HashMap<String, SuggestionItem>();
43 for (Object element : resultsArray) {
44 JSONObject tmpElement = (JSONObject) element;
45 String uriValue = (String) tmpElement.get(
"uri");
46 autosuggests.put(uriValue,
new SuggestionItem(uriValue));
47 SuggestionItem tmpAutosuggest = autosuggests.get(uriValue);
48 String labelValue = (String) tmpElement.get(
"prefLabel");
49 tmpAutosuggest.setLabel(labelValue);
50 JSONArray desArray = (JSONArray) tmpElement.get(
"skos:scopeNote");
51 if (desArray !=
null) {
52 for (Object e : desArray) {
53 String descStr = e.toString();
54 tmpAutosuggest.setDescription(descStr);
57 String vocabValue = (String) tmpElement.get(
"vocab");
58 tmpAutosuggest.setSchemeTitle(vocabValue);
59 JSONArray boraderArray = (JSONArray) tmpElement.get(
"broader");
60 JSONArray narrowerArray = (JSONArray) tmpElement.get(
"narrower");
61 tmpAutosuggest.setLanguage(
"en");
63 if (boraderArray !=
null) {
64 for (Object item : boraderArray) {
65 JSONObject tmpObject = (JSONObject) item;
66 HashMap<String, String> hstmp =
new HashMap();
67 String uriValueTmp = (String) tmpObject.get(
"uri");
68 String labelValueTmp = (String) tmpObject.get(
"prefLabel");
69 hstmp.put(uriValueTmp, labelValueTmp);
70 tmpAutosuggest.setBroaderTerm(hstmp);
74 if (narrowerArray !=
null) {
75 for (Object item : boraderArray) {
76 JSONObject tmpObject = (JSONObject) item;
77 HashMap<String, String> hstmp =
new HashMap();
78 String uriValueTmp = (String) tmpObject.get(
"uri");
79 String labelValueTmp = (String) tmpObject.get(
"prefLabel");
80 hstmp.put(uriValueTmp, labelValueTmp);
81 tmpAutosuggest.setNarrowerTerm(hstmp);
85 String type =
"finto";
88 for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
89 if (item.getType().equals(type)) {
90 quality = item.getQuality();
91 group = item.getGroup();
94 tmpAutosuggest.setType(type);
95 tmpAutosuggest.setQuality(quality);
96 tmpAutosuggest.setGroup(group);