public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { log.info("API request received path=" + request.getPathInfo()); String[] params = request.getPathInfo().split("/"); Long networkId = new Long(params[1]); log.info("networkId=" + networkId); // EntityManager em = HibernateUtil.getEntityManager(); // HANetwork network = em.find(HANetwork.class, networkId); HANetwork network = HANetwork.getInstance(networkId); String methodClass = "ie.wombat.ha.api.method." + params[2]; Method method; try { method = (Method) Class.forName(methodClass).newInstance(); } catch (InstantiationException e) { returnError(response, METHOD_ERROR); return; } catch (IllegalAccessException e) { returnError(response, METHOD_ERROR); return; } catch (ClassNotFoundException e) { returnError(response, METHOD_NOT_FOUND); return; } log.info("method=" + method); response.setContentType("application/json"); MethodResponse mresp = method.invokeMethod(network, params); response .getOutputStream() .print("{\"status\":0,\"result\":" + JSONUtils.quote(mresp.getResponse()) + "}"); }
private String addVClassDataToResultsList( WebappDaoFactory wadf, VClass vcw, int position, String ontologyUri, int counter) { String tempString = ""; if (ontologyUri == null || ((vcw.getNamespace() != null) && (vcw.getNamespace().equals(ontologyUri)))) { // first if statement ensures that the first class begins with correct format if (counter < 1 && position < 1) { tempString += "{ \"name\": "; } else if (position == previous_posn) { tempString += "}, { \"name\": "; } else if (position > previous_posn) { tempString += " { \"name\": "; } else if (position < previous_posn) { tempString += "}, { \"name\": "; } try { tempString += JSONUtils.quote( "<a href='vclassEdit?uri=" + URLEncoder.encode(vcw.getURI(), "UTF-8") + "'>" + vcw.getPickListName() + "</a>") + ", "; } catch (Exception e) { tempString += JSONUtils.quote(((vcw.getPickListName() == null) ? "" : vcw.getPickListName())) + ", "; } String shortDef = ((vcw.getShortDef() == null) ? "" : vcw.getShortDef()); tempString += "\"data\": { \"shortDef\": " + JSONUtils.quote(shortDef) + ", "; // Get group name if it exists VClassGroupDao groupDao = wadf.getVClassGroupDao(); String groupURI = vcw.getGroupURI(); String groupName = null; VClassGroup classGroup = null; if (groupURI != null) { classGroup = groupDao.getGroupByURI(groupURI); if (classGroup != null) { groupName = classGroup.getPublicName(); } } tempString += "\"classGroup\": " + JSONUtils.quote((groupName == null) ? "" : groupName) + ", "; // Get ontology name OntologyDao ontDao = wadf.getOntologyDao(); String ontName = vcw.getNamespace(); Ontology ont = ontDao.getOntologyByURI(ontName); if (ont != null && ont.getName() != null) { ontName = ont.getName(); } tempString += "\"ontology\": " + JSONUtils.quote((ontName == null) ? "" : ontName) + "}, \"children\": ["; previous_posn = position; } return tempString; }