Beispiel #1
0
  @RouteMapping(method = RouteMethod.GET)
  public Handler<RoutingContext> getAll() {
    return ctx -> {
      JDBCClient client = AppUtil.getJdbcClient(Vertx.vertx());

      client.getConnection(
          conn -> {
            if (conn.failed()) {
              LOGGER.error(conn.cause().getMessage(), conn.cause());
              ctx.fail(400);
            }

            SQLUtil.query(
                conn.result(),
                "select * from patient",
                rs -> {
                  JsonArray patients = new JsonArray();
                  for (JsonObject row : rs.getRows()) {
                    patients.add(row);
                  }

                  SQLUtil.close(conn.result());
                  ctx.response().end(patients.encode());
                });
          });
    };
  }
 private void queryBudget(RoutingContext context, SQLConnection connection) {
   connection.query(
       "SELECT budget FROM preferences WHERE username = '******'",
       res2 -> {
         if (res2.succeeded()) {
           // System.out.println("Able to get budget query");
           ResultSet resultSet = res2.result();
           for (JsonArray line : res2.result().getResults()) {
             Budget = line.encode();
             Budget = Budget.replaceAll("[^a-zA-Z,' ']", "");
             // System.out.println("Budget: "+Budget);
           }
           queryHotels(context, connection);
         } else {
           log.error("Could not select budget from pref table table");
         }
       });
 }
 private void queryHotels(RoutingContext context, SQLConnection connection) {
   // Retrieve Hotels
   connection.query(
       "SELECT name FROM hotel ",
       res2 -> {
         if (res2.succeeded()) {
           // System.out.println("Able to get hotel query");
           for (JsonArray line : res2.result().getResults()) {
             Hotel[Hotelcounter] = line.encode();
             Hotel[Hotelcounter] = Hotel[Hotelcounter].replaceAll("[^a-zA-Z' ']", "");
             Hotelcounter++;
           }
           Hotelcounter = 0;
           queryHotelPricing(context, connection);
         } else {
           log.error("Could not select from the user table");
         }
       });
 }
 /*
  * (non-Javadoc)
  *
  * @see de.braintags.io.vertx.pojomapper.json.typehandler.handler.ArrayTypeHandler#intoStore(java.lang.Object,
  * de.braintags.io.vertx.pojomapper.mapping.IField, io.vertx.core.Handler)
  */
 @Override
 public void intoStore(
     Object javaValues, IField field, Handler<AsyncResult<ITypeHandlerResult>> handler) {
   super.intoStore(
       javaValues,
       field,
       result -> {
         if (result.failed()) {
           handler.handle(result);
           return;
         }
         JsonArray resultArray = (JsonArray) result.result().getResult();
         try {
           String arrayString = resultArray.encode();
           success(arrayString, handler);
         } catch (Exception e) {
           fail(e, handler);
         }
       });
 }
  private void queryLocation(RoutingContext context, AsyncResult<SQLConnection> connectionRes) {
    // Get and set locations of user for future queries
    SQLConnection connection = connectionRes.result();
    // System.out.println("SELECT Location FROM preferences WHERE username = '******'");
    connection.query(
        "SELECT Location FROM preferences WHERE username = '******'",
        res2 -> {
          if (res2.succeeded()) {
            // System.out.println("Able to get query location");
            ResultSet resultSet = res2.result();
            for (JsonArray line : res2.result().getResults()) {
              Location = line.encode();
              Location = Location.replaceAll("[^a-zA-Z,' ']", "");
              // System.out.println("userLocation:"+Location);
            }
            context.session().put("location", Location);
            queryBudget(context, connection);

          } else {
            log.error("Could not select from the user table");
          }
        });
  }
  private void queryActivites(RoutingContext context, SQLConnection connection) {
    // Retrieve Activies
    connection.query(
        "SELECT name FROM activities",
        res5 -> {
          if (res5.succeeded()) {
            // System.out.println("Able to get activities query");
            for (JsonArray line3 : res5.result().getResults()) {
              // System.out.println("Activities: "+line3.encode());
              String ActTemp = line3.encode();
              ActTemp = ActTemp.replaceAll("[^a-zA-Z,' '0-9]", "");
              Act[Actcounter] = ActTemp;
              Actcounter++;
            }
            Actcounter = 0;
            context.session().put("activities", Act);

            context.next();
          } else {
            log.error("could not select form the activites table");
          }
        });
  }
  private void queryResturants(final RoutingContext context, final SQLConnection connection) {
    // Retrieve Resturants
    connection.query(
        "SELECT name FROM resturant",
        res4 -> {
          if (res4.succeeded()) {
            // System.out.println("Able to get resturant query");
            for (JsonArray line2 : res4.result().getResults()) {
              // System.out.println("resturant: "+line2.encode());
              String Resttemp = line2.encode();
              Resttemp = Resttemp.replaceAll("[^a-zA-Z,' '0-9]", "");
              Rest[Restcounter] = Resttemp;
              Restcounter++;
            }
            Restcounter = 0;
            context.session().put("resturants", Rest);

            queryActivites(context, connection);
          } else {
            log.error("could not select form resturant table");
          }
        });
  }
 private void queryHotelPricing(RoutingContext context, SQLConnection connection) {
   // Retrieve Hotel Pricing
   connection.query(
       "SELECT price FROM hotel",
       res3 -> {
         if (res3.succeeded()) {
           // System.out.println("Able to get hotel pricing");
           Hotelcounter = 0;
           for (JsonArray line1 : res3.result().getResults()) {
             String temp = Hotel[Hotelcounter];
             temp = temp.concat("   ($" + line1.encode() + ")");
             temp = temp.replaceAll("[^a-zA-Z,' '0-9$()]", "");
             Hotel[Hotelcounter] = temp;
             // System.out.println("hotel with price: " + Hotel[Hotelcounter]);
             Hotelcounter++;
           }
           context.session().put("hotels", Hotel);
           queryResturants(context, connection);
           Hotelcounter = 0;
         } else {
           log.error("could not select from user table above");
         }
       });
 }