Ejemplo n.º 1
0
  @GET
  @Produces({MediaType.APPLICATION_JSON})
  public Spieler getSpielerDetail(@QueryParam("username") String username) {

    Spieler retVal = null;
    ResultSet rs = null;

    try {
      rs =
          connection.getData(
              "select s.uname, d.id  from spieler s inner join dorf d on d.owner = s.uname where s.uname = '"
                  + username
                  + "'");

      if (rs.next()) {
        retVal = new Spieler(rs.getString(1));
        retVal.getDoerfer().add(rs.getInt(2));

        while (rs.next()) {
          retVal.getDoerfer().add(rs.getInt(2));
        }
      } else {
        retVal = new Spieler();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      return new Spieler();
    }

    return retVal;
  }
Ejemplo n.º 2
0
  @GET
  @Produces({MediaType.APPLICATION_JSON})
  public ResponseObject currentRekrutEvents(
      @QueryParam("dorfId") int dorfId, @QueryParam("sessionid") int sessionId) {

    ResponseObject retVal = new ResponseObject();
    retVal.prepareRO();
    ResultSet rs = null;
    RekrutEventList rel = new RekrutEventList();
    SessionDB sdb = SessionDB.newInstance();

    try {
      if (!sdb.checkSession(sessionId)) {
        throw new Exception("no such active session");
      }

      rs = connection.getOwnerFromDorfById(dorfId);
      if (!rs.next()) {
        throw new Exception("dorf doesn't exist");
      }

      if (!rs.getString(1).trim().equals(sdb.getSession_User(sessionId).getUname().trim())) {
        throw new Exception("you have no permission on this village");
      }

      rs = connection.getCurrentRekrutEvents(dorfId);

      while (rs.next()) {
        rel.getRekrutEvents()
            .add(
                new RekrutEvent(
                    rs.getInt(1),
                    new Truppen(rs.getInt(3), rs.getInt(4), rs.getInt(5), rs.getInt(6))));
      }

      retVal.setData(rel);
      retVal.setOk(true);

    } catch (Exception e) {
      e.printStackTrace();

      retVal.setErrormsg(e.getMessage());
      retVal.setOk(false);
    }

    return retVal;
  }