Guest User

Untitled

a guest
Feb 8th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. @GET
  2. @Path("getRetailProductList")
  3. @Produces("application/json")
  4. public Response getRetailProductList(@QueryParam("countryID") Long countryID) {
  5. System.out.println("RESTful: getRetailProductList() called with countryID " + countryID);
  6. try {
  7. List<RetailProduct> list = new ArrayList<>();
  8. String stmt = "";
  9. PreparedStatement ps;
  10. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/islandfurniture-it07?zeroDateTimeBehavior=convertToNull&user=root&password=12345");
  11.  
  12. if (countryID == null) {
  13. stmt = "SELECT i.ID as id, i.NAME as name, rp.IMAGEURL as imageURL, i.SKU as sku, i.DESCRIPTION as description, i.TYPE as type, i.CATEGORY as category FROM retailproductentity rp, itementity i where rp.ID=i.ID and i.ISDELETED=FALSE;";
  14. ps = conn.prepareStatement(stmt);
  15. } else {
  16. stmt = "SELECT i.ID as id, i.NAME as name, rp.IMAGEURL as imageURL, i.SKU as sku, i.DESCRIPTION as description, i.TYPE as type, i.CATEGORY as category, ic.RETAILPRICE as price FROM retailproductentity rp, itementity i, item_countryentity ic where rp.ID=i.ID and i.id=ic.ITEM_ID and i.ISDELETED=FALSE and ic.COUNTRY_ID=?;";
  17. ps = conn.prepareStatement(stmt);
  18. ps.setLong(1, countryID);
  19. }
  20.  
  21. ResultSet rs = ps.executeQuery();
  22. while (rs.next()) {
  23. RetailProduct rp = new RetailProduct();
  24.  
  25. rp.setSKU(rs.getString("sku"));
  26. rp.setId(rs.getLong("id"));
  27. rp.setImageUrl(rs.getString("imageURL"));
  28. rp.setType(rs.getString("type"));
  29. rp.setDescription(rs.getString("description"));
  30. rp.setCategory(rs.getString("category"));
  31. rp.setName(rs.getString("name"));
  32.  
  33. if (countryID != null) {
  34. rp.setPrice(rs.getDouble("price"));
  35. }
  36.  
  37.  
  38. list.add(rp);
  39. }
  40. GenericEntity<List<RetailProduct>> entity = new GenericEntity<List<RetailProduct>>(list) {
  41. };
  42. return Response
  43. .status(200)
  44. .header("Access-Control-Allow-Origin", "*")
  45. .header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization")
  46. .header("Access-Control-Allow-Credentials", "true")
  47. .header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD")
  48. .header("Access-Control-Max-Age", "1209600")
  49. .entity(entity)
  50. .build();
  51. } catch (Exception ex) {
  52. ex.printStackTrace();
  53. return Response.status(Response.Status.NOT_FOUND).build();
  54. }
  55. }
Add Comment
Please, Sign In to add comment