Пример #1
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;
  }