@Profiled() @SuppressWarnings("unchecked") Object onJSON(String query, String callback) { // List<PersonProfile> persons = null; // List<Author> authors = new ArrayList<Authors.Author>(); Author[] authors = null; List<Authors.Author> authorList = null; // if query match ":top hindex", return top h-index authors. if (query.equals(":top hindex")) { Set<Long> idList = featureService.topAuthors(AuthorFeatureType.HINDEX, 0, 1000); List<Integer> ids = Lists.newArrayList(); if (null != idList) { for (Long id : idList) { ids.add(id.intValue()); } } authors = authorService.getAuthors(idList, AuthorFieldSelector.create().feature().contact(), null); // persons = personService.getProfile((short) (PersonService.CONTACT | // PersonService.PERSON_FEATURE), ids); } else if (query.startsWith(":jconf")) { String[] split = query.split(" "); Long jconfid = Long.parseLong(split[1]); Integer year = Integer.parseInt(split[2]); List<Long> autherIDList = jconfAuthorService.getAutherIDListByJconfIDByYear(jconfid, year); authors = authorService.getAuthors( autherIDList, AuthorFieldSelector.create().contact().feature(), null); // persons = personService.getProfile(autherIDList, (short) (PersonService.CONTACT | // PersonService.PERSON_FEATURE)); } else { SearchCriteria criteria = new SearchCriteria(); criteria.setQuery(query); criteria.setItemsPerPage(1000); SearchResultMeta result = search.searchExperts2(criteria); authorList = (List<Authors.Author>) result.getData(); // persons = (List<PersonProfile>) result.getData(); } if (authorList == null && authors != null) { authorList = new ArrayList<Authors.Author>(); for (Author a : authors) { authorList.add(a); } } // TODO: batch get service; JSONObject json = new JSONObject(); json.put("query", query); for (Author author : authorList) { if (null == author) continue; JSONObject object = new JSONObject(); object.put("id", author.getId()); object.put("name", author.getNames(0)); object.put("degree", author.getFeature().getHindex()); // ContactInformation info = person.getContactInformation(); Contact contact = author.getContact(); object.put("img", contact.getAvatar()); object.put("affiliation", contact.getAffiliation()); object.put("url", URLWriter.getPersonURL((int) author.getId(), author.getNames(0))); Map<String, Object> params = new HashMap<String, Object>(); params.put("aid", (int) author.getId()); PersonGeo geo = crudService.findUniqueWithNamedQuery(PersonGeo.BY_AID, params); if (geo != null) { object.put("lat", geo.getLat()); object.put("lng", geo.getLng()); json.append("results", object); } } // for (PersonProfile person : persons) { // JSONObject object = new JSONObject(); // object.put("id", person.getId()); // object.put("name", person.getRealPerson().getName()); // // object.put("degree", person.getPersonFeatureData().getHindex()); // // ContactInformation info = person.getContactInformation(); // object.put("img", info.getDisplayImage(ContactInformation.IMG_SIZE_SMALL)); // object.put("affiliation", info.get_sAffiliation()); // object.put("url", URLWriter.getPersonURL(person.getRealPerson())); // // Map<String, Object> params = new HashMap<String, Object>(); // params.put("aid", person.getId()); // PersonGeo geo = crudService.findUniqueWithNamedQuery(PersonGeo.BY_AID, params); // // if (geo != null) { // object.put("lat", geo.getLat()); // object.put("lng", geo.getLng()); // json.append("results", object); // } // } if (null == callback) { return new TextStreamResponse("application/json", json.toCompactString()); } else { String jsonp = json.toCompactString(); jsonp = jsonp.replaceAll("\n", " "); jsonp = String.format("%s(%s);", callback, jsonp); return new TextStreamResponse("application/json", jsonp); } }