@GET @Path("join/{spaceName}") public Response join( @PathParam("spaceName") String spaceName, @Context SecurityContext sc, @Context UriInfo uriInfo) { try { String userId = getUserId(sc, uriInfo); if (userId == null) { return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build(); } SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); if (spaceService.getSpaceById(spaceName).getRegistration().equals("open")) spaceService.addMember(spaceService.getSpaceById(spaceName), userId); return Response.ok("{}", MediaType.APPLICATION_JSON).cacheControl(cacheControl).build(); } catch (Exception e) { log.error("Error in space deny rest service: " + e.getMessage(), e); return Response.ok("error").cacheControl(cacheControl).build(); } }
@POST @Path("action") public String action( @FormParam("element_1") double n1, @FormParam("element_2") double n2, @FormParam("element_3") String s) { try { MemcachedClient client = MccFactory.getConst("localhost").getMemcachedClient(); JsonObject innerObject = new JsonObject(); innerObject.addProperty("key", s); innerObject.addProperty("firstNum", n1); innerObject.addProperty("secondNum", n2); client.add(s, 30000, innerObject.toString()); String keys = (String) client.get("mykeys"); keys = (keys == null) ? "" : keys; keys += s + "/"; client.replace("mykeys", 30000, keys); } catch (Exception e) { e.printStackTrace(); return getStringStackTrace(e); } return "String: " + s + ". First number = " + n1 + ", Second number = " + n2; }
@GET @Path("get") public String get(@QueryParam("key") String key) { try { MemcachedClient client = MccFactory.getConst("localhost").getMemcachedClient(); String res = (String) client.get(key); return (res != null) ? res : "No data found for " + key; } catch (Exception e) { e.printStackTrace(); return getStringStackTrace(e); } }
/** * M�todo - Servicio Web REST que sirve para totalRegistros registros a la base de datos * * @return Tipo de retorno Integer */ @GET @Path(value = "CantidadPersonas") @Produces(value = "application/json") public Integer totalRegistros() { Integer cantidad = 0; try { cantidad = personaEJBLocal.totalRegistros(); } catch (Exception e) { e.printStackTrace(); } finally { } return cantidad; }
/** * M�todo - Servicio Web REST que sirve para encontrarTodos registros a la base de datos * * @return Tipo de retorno List<Persona> */ @GET @Path(value = "Personas") @Produces(value = "application/json") public List<Persona> encontrarTodos() { List<Persona> lista = null; try { lista = personaEJBLocal.encontrarTodos(); } catch (Exception e) { e.printStackTrace(); } finally { } return lista; }
/** * M�todo - Servicio Web REST que sirve para encontrarPorId registros a la base de datos * * @param id, parametro enviado al metodo con tipo de dato: Integer * @return Tipo de retorno Persona */ @GET @Path(value = "Persona/{id}") @Produces(value = "application/json") public Persona encontrarPorId(@PathParam("id") Integer id) { Persona persona = null; try { persona = personaEJBLocal.encontrarPorId(id); } catch (Exception e) { e.printStackTrace(); } finally { } return persona; }
/** * M�todo - Servicio Web REST que sirve para actualizar registros a la base de datos * * @param persona, parametro enviado al metodo con tipo de dato: Persona * @return Tipo de retorno Persona */ @PUT @Path(value = "Persona") @Produces(value = "application/json") @Consumes(value = "application/json") public Persona actualizar(Persona persona) { try { persona = personaEJBLocal.actualizar(persona); } catch (Exception e) { e.printStackTrace(); } finally { } return persona; }
@GET @Path("/getcomponents/{orderid}") @Produces(MediaType.APPLICATION_JSON) public List<OutViewComponent> getComponentsByOrder(@PathParam("orderid") String orderid) { List<OutViewComponent> returnValue = new ArrayList<OutViewComponent>(); try { int id = Integer.parseInt(orderid); returnValue = DataManager.getInstance().getComponentsForView(id); } catch (Exception e) { System.out.println(e.getMessage()); } return returnValue; }
/** * M�todo - Servicio Web REST que sirve para remover registros a la base de datos * * @param id, parametro enviado al metodo con tipo de dato: Integer * @return Tipo de retorno String */ @DELETE @Path(value = "Persona/{id}") @Produces(value = "text/plain") public String remover(@PathParam("id") Integer id) { String mensaje = "OK"; try { personaEJBLocal.remover(id); } catch (Exception e) { mensaje = "BAD"; e.printStackTrace(); } finally { } return mensaje; }
/** * M�todo - Servicio Web REST que sirve para insertar registros a la base de datos * * @param persona, parametro enviado al metodo con tipo de dato: Persona * @return Tipo de retorno String */ @POST @Path(value = "Persona") @Produces(value = "text/plain") @Consumes(value = "application/json") public String insertar(Persona persona) { String mensaje = "OK"; try { personaEJBLocal.insertar(persona); } catch (Exception e) { mensaje = "BAD"; e.printStackTrace(); } finally { } return mensaje; }
@GET @Path("/gettypes/{groupid}") @Produces(MediaType.APPLICATION_JSON) public List<String> getTypesByGroup(@PathParam("groupid") String groupid) { List<String> returnValue = new ArrayList<String>(); try { for (Types type : DataManager.getInstance().getTypes(groupid)) { returnValue.add(type.getCode()); } } catch (Exception e) { System.out.println(e.getMessage()); } return returnValue; }
@GET @Path("/getgroups/{weightid}") @Produces(MediaType.APPLICATION_JSON) public List<String> getGroupsByWeight(@PathParam("weightid") String weightid) { List<String> returnValue = new ArrayList<String>(); try { for (Groups group : DataManager.getInstance().getGroups(weightid)) { returnValue.add(group.getCode()); } } catch (Exception e) { System.out.println(e.getMessage()); } return returnValue; }
@GET @Produces(MediaType.TEXT_HTML) public String returnData(@PathParam("param") String msg) throws Exception { PreparedStatement query = null; String myString = null; String returnString = null; Connection conn = null; try { Class.forName(driver); conn = DriverManager.getConnection(url, userName, passwrod); query = conn.prepareStatement("select * from WATCH_DATA where _id = " + msg); ResultSet rs = query.executeQuery(); while (rs.next()) { myString = "<p> id : " + rs.getInt(1) + " brand : " + rs.getString(2) + " model : " + rs.getString(3) + " color : " + rs.getString(4) + " gender : " + rs.getString(5) + " price : " + rs.getString(6) + " warrenty : " + rs.getString(7) + " image : " + rs.getString(8) + "</p>"; } query.close(); returnString = "<p>Database search</p>" + "<p>Date return: </p>" + myString; } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) conn.close(); } return returnString; }
@GET @Path("/getresult/{orderid}/{componentid}") @Produces(MediaType.APPLICATION_JSON) public List<OutViewResult> getResultByOrderComponent( @PathParam("orderid") String orderid, @PathParam("componentid") String componentid) { List<OutViewResult> returnValue = new ArrayList<OutViewResult>(); try { int ordId = Integer.parseInt(orderid); int cmpId = Integer.parseInt(componentid); returnValue = DataManager.getInstance().getResultsForView(ordId, cmpId); } catch (Exception e) { System.out.println(e.getMessage()); } return returnValue; }
@POST @Path("/update") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response update(String jsonString) { ObjectMapper mapper = new ObjectMapper(); UpdateResult result = null; try { result = mapper.readValue(jsonString, UpdateResult.class); DAOManager.getInstance().getResultDAO().updateResult(result); } catch (Exception e) { System.out.println(e.getMessage()); } return Response.status(200).build(); }
@DELETE @Path("{route_id}") @Produces(MediaType.APPLICATION_JSON) public String deletePlace(@PathParam("route_id") String routeID) { syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO)); JSONObject reply = new JSONObject(); try { syncCache.delete(routeID); return reply .append("status", "OK") .append("message", "successfully deleted route " + routeID + " from " + "memcache") .toString(); } catch (Exception e) { return new JSONObject().append("status", "fail").append("message", e.getMessage()).toString(); } }
@DELETE @Path("delete") public String delete(@QueryParam("key") String key) { try { MemcachedClient client = MccFactory.getConst("localhost").getMemcachedClient(); String keys = (String) client.get("mykeys"); keys = (keys == null) ? "" : keys; keys = keys.replace(key + "/", ""); client.replace("mykeys", 30000, keys); client.delete(key); } catch (Exception e) { e.printStackTrace(); return getStringStackTrace(e); } return "Removed value at " + key; }
@GET @Path("list") public String list() { try { String result = ""; MemcachedClient client = MccFactory.getConst("localhost").getMemcachedClient(); String s = (String) client.get("mykeys"); String[] keys = s.split("/"); for (String key : keys) { if (key == null || key.length() < 1) continue; String ss = (String) client.get(key); if (ss != null) result += key + " " + ss + "<br/>"; } return (result.length() > 0) ? result : "No data found"; } catch (Exception e) { e.printStackTrace(); return getStringStackTrace(e); } }
@GET @Path("public") public Response getPublicSpaces(@Context SecurityContext sc, @Context UriInfo uriInfo) { try { String userId = getUserId(sc, uriInfo); if (userId == null) { return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build(); } SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); ListAccess<Space> publicSpaces = spaceService.getPublicSpacesWithListAccess(userId); JSONArray jsonArray = new JSONArray(); Space[] spaces = publicSpaces.load(0, publicSpaces.getSize()); if (spaces != null && spaces.length > 0) { for (Space space : spaces) { if (space.getVisibility().equals(Space.HIDDEN)) continue; if (space.getRegistration().equals(Space.CLOSE)) continue; JSONObject json = new JSONObject(); json.put("name", space.getName()); json.put("displayName", space.getDisplayName()); json.put("spaceId", space.getId()); jsonArray.put(json); } } return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON) .cacheControl(cacheControl) .build(); } catch (Exception e) { log.error("Error in space invitation rest service: " + e.getMessage(), e); return Response.ok("error").cacheControl(cacheControl).build(); } }
@GET @Path("myspaces") public Response request(@Context SecurityContext sc, @Context UriInfo uriInfo) { try { String userId = getUserId(sc, uriInfo); if (userId == null) { return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build(); } SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); List<Space> mySpaces = spaceService.getAccessibleSpaces(userId); JSONArray jsonArray = new JSONArray(); for (Space space : mySpaces) { JSONObject json = new JSONObject(); json.put("name", space.getName()); json.put("spaceId", space.getId()); json.put("displayName", space.getDisplayName()); json.put("spaceUrl", space.getUrl()); json.put("members", space.getMembers().length); jsonArray.put(json); } return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON) .cacheControl(cacheControl) .build(); } catch (Exception e) { log.error("Error in space deny rest service: " + e.getMessage(), e); return Response.ok("error").cacheControl(cacheControl).build(); } }
@GET @Path("suggestions") public Response getSuggestions(@Context SecurityContext sc, @Context UriInfo uriInfo) { try { String userId = getUserId(sc, uriInfo); if (userId == null) { return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build(); } SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); List<Space> suggestedSpaces = spaceService.getPublicSpaces(userId); IdentityManager identityManager = (IdentityManager) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(IdentityManager.class); Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId); List<Identity> connections = identityManager.getConnections(identity); JSONArray jsonArray = new JSONArray(); for (Space space : suggestedSpaces) { if (space.getVisibility().equals(Space.HIDDEN)) continue; if (space.getRegistration().equals(Space.CLOSE)) continue; List<Identity> identityListMember = new ArrayList<Identity>(); String avatar = space.getAvatarUrl(); if (avatar == null) { avatar = "/social-resources/skin/ShareImages/SpaceImages/SpaceLogoDefault_61x61.gif"; } for (String mem : space.getMembers()) { Identity identityMem = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, mem); identityListMember.add(identityMem); } int k = 0; for (Identity i : identityListMember) { for (Identity j : connections) { if (j.equals(i)) { k++; } } } String spaceType = ""; if (space.getRegistration().equals(Space.OPEN)) { spaceType = "Public"; } else { spaceType = "Private"; } JSONObject json = new JSONObject(); json.put("name", space.getName()); json.put("spaceId", space.getId()); json.put("displayName", space.getDisplayName()); json.put("spaceUrl", space.getUrl()); json.put("avatarUrl", avatar); json.put("registration", space.getRegistration()); json.put("members", space.getMembers().length); json.put("privacy", spaceType); json.put("number", k); jsonArray.put(json); } return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON) .cacheControl(cacheControl) .build(); } catch (Exception e) { log.error("Error in space invitation rest service: " + e.getMessage(), e); return Response.ok("error").cacheControl(cacheControl).build(); } }