private String _returnPublication(HttpServletRequest req, Publication pub) { // to json RestfulPublication result = new RestfulPublication(pub); Gson jsonBuilder = support.getJsonBuilder(request, RestfulPublication.FIELD_SELECTOR); String json = jsonBuilder.toJson(result, RestfulPublication.class); return support.wrapReturn(request, String.format("[%s]", json)); }
private String _returnPublication(HttpServletRequest req, Publication[] pubs) { if (null == pubs) { return "[]"; } System.out.println(">>" + pubs.length); List<RestfulPublication> rPubs = new ArrayList<RestfulPublication>(pubs.length); for (Publication pub : pubs) { RestfulPublication rPub = new RestfulPublication(pub); rPubs.add(rPub); } Gson jsonBuilder = support.getJsonBuilder(request, RestfulPublication.FIELD_SELECTOR); Type type = new TypeToken<List<RestfulPublication>>() {}.getType(); String json = jsonBuilder.toJson(rPubs, type); return support.wrapReturn(request, json); }
@Published("soa") @GET @Path("/getPubLocation/{pubid: [0-9]+}") @Produces({"text/html", "text/javascript", "application/json"}) public String getPubLocationById(@DefaultValue("-1") @PathParam("pubid") Integer PubId) { // Check permission. // String denyReason = support.checkPermission(request, uriInfo); // if (null != denyReason) { // return denyReason; // } try { Publication pub = publicationService.getPublication(PubId); if (null != pub) { RealPerson[] authors = pub.getAuthors(); if (null == authors) { return "[]"; } Integer[] ids = new Integer[authors.length]; for (int i = 0; i < ids.length; ++i) { ids[i] = authors[i].getId(); } List<PersonProfile> profiles = personService.getProfile((short) (PersonService.ORG_ID | PersonService.CONTACT), ids); List<Integer> orgids = Lists.newArrayList(); for (PersonProfile pp : profiles) { orgids.add(pp.getPersonStatisticsData().getOrgid()); } List<Organization> orgs = new ArrayList<Organization>(); for (int oid : orgids) { orgs.add(oid < 0 ? null : orgService.getOrganization(oid)); } String[][] locations = new String[3][]; locations[0] = new String[orgs.size()]; locations[1] = new String[orgs.size()]; locations[2] = new String[orgs.size()]; Organization tmp = new Organization(); for (int i = 0; i < orgs.size(); ++i) { tmp = orgs.get(i); if (tmp == null) { locations[0][i] = String.valueOf(-1); locations[1][i] = String.valueOf(-1); locations[2][i] = ""; } else { locations[0][i] = String.valueOf(tmp.getLongitude()); locations[1][i] = String.valueOf(tmp.getLatitude()); locations[2][i] = tmp.getName(); } } String json = support.jsonBuilder.toJson(locations); return support.wrapReturn(request, json); } else { return "[]"; } } catch (Throwable t) { t.printStackTrace(); return support.throwJson(t.getMessage(), t); } }