Esempio n. 1
0
  @Override
  public Boolean addGame(
      String campusSession, String nameGame, int idGame, int idCategory, Date creationDate) {
    try {
      // Add the game if user exists, game does not exists, there is a name, there is a creation
      // date and category exists
      if (sBo.validateSession(campusSession) != null
          && gDao.getGame(idGame) == null
          && cDao.getCategory(idCategory) != null
          && gDao.getGameByName(nameGame) == null
          && !nameGame.equals("")) {
        Game objGame = new Game();
        objGame.setIdGame(idGame);
        objGame.setName(nameGame);
        objGame.setPublicAcces(1);
        objGame.setSecretGame(Security.getIdGame());
        objGame.setPrivateKey(Security.getIdSession());
        objGame.setIdCategory(idCategory);
        objGame.setCreationDate(creationDate);

        gDao.addGame(objGame);
      } else return false;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
Esempio n. 2
0
  @Override
  public List<Game> listGames(String campusSession) {

    if (sBo.validateSession(campusSession) != null) {
      return gDao.getAllGames();
    }

    return null;
  }
Esempio n. 3
0
  @Override
  public List<Game> listUserGames(String username, String campusSession) {

    if (sBo.validateSession(campusSession) != null) {
      return gDao.getUserGames(username);
    }

    List<Game> list = new ArrayList<Game>();
    Game game = new Game();
    game.setIdGame(1);
    list.add(game);
    return list;
  }
Esempio n. 4
0
 @Override
 public Boolean delGame(String campusSession, int idGame) {
   try {
     if (sBo.validateSession(campusSession) != null) {
       // TODO Delete all dependencies: comments, tags, likeGames, instances, records...
       Game objGame = gDao.getGame(idGame);
       gDao.delGame(objGame);
     }
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
   return true;
 }
Esempio n. 5
0
 @Override
 public Response delScoreGame(String campusSession, String uidGame) {
   try {
     User objUser = sBo.validateSession(campusSession);
     if (objUser != null) {
       Game objGame = gBo.getGame(uidGame, null);
       GameScore objScore = scDao.getScoreGame(objGame.getIdGame(), objUser.getIdUser());
       scDao.delScoreGame(objScore);
     }
   } catch (Exception e) {
     e.printStackTrace();
     return Response.status(404).entity("ERROR SCORE DELETE").build();
   }
   return Response.status(200).entity("DEL SCORE OK").build();
 }
Esempio n. 6
0
  @Override
  public Boolean addGame(String campusSession, String nameGame, int idGame) {
    try {
      if (sBo.validateSession(campusSession) != null) {
        Game objGame = new Game();
        objGame.setIdGame(idGame);
        objGame.setName(nameGame);
        objGame.setPublicAcces(1);
        objGame.setSecretGame(Security.getIdGame());
        objGame.setPrivateKey(Security.getIdSession());

        gDao.addGame(objGame);
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
Esempio n. 7
0
  @Override
  public Game getGame(String idGame, String campusSession) {
    Game objGame = null;

    try {
      if (Security.isIdGame(idGame)) objGame = gDao.getGameUid(idGame);
      else {
        if (sBo.validateSession(campusSession) != null) {
          objGame = gDao.getGame(Integer.parseInt(idGame));
        } else {
          return null;
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
    return objGame;
  }
Esempio n. 8
0
  @Override
  public Response addScoreGame(String campusSession, String uidGame, String point) {
    try {
      User objUser = sBo.validateSession(campusSession);

      if (objUser != null) {
        Game objGame = gBo.getGame(uidGame, null);
        GameScore objScore = scDao.getScoreGame(objGame.getIdGame(), objUser.getIdUser());
        if (objScore == null) {
          objScore = new GameScore();
          objScore.setIdGame(objGame.getIdGame());
          objScore.setIdUser(objUser.getIdUser());
        }
        objScore.setPoints(Integer.parseInt(point));
        scDao.addScoreGame(objScore);
      }
    } catch (Exception e) {
      e.printStackTrace();
      return Response.status(404).entity("ERROR SCORE SAVE").build();
    }
    return Response.status(200).entity("ADD SCORE OK").build();
  }
Esempio n. 9
0
  @Override
  public List<Game> listGames(
      String campusSession,
      int idOrderer,
      int idFilterer,
      List<String> fields,
      List<String> values) {

    if (sBo.validateSession(campusSession) != null) {

      // Transform fields and values into Map
      if (fields.size() != values.size()) return null;
      Map<String, String> fields_values = new HashMap<String, String>();
      for (int i = 0; i < fields.size(); i++) {
        String field = fields.get(i);
        if (field != null && !field.trim().equals("")) {
          fields_values.put(
              field, values.get(i)); // No duplicated fields validation. Will be overwritten.
        }
      }

      /*---- Validating fields and values -----*/
      try {
        switch (idFilterer) {
          case 1: // By category.
            if (!fields_values.containsKey("idCategory")
                || fields_values.get("idCategory").trim().equals("")) {
              return null;
            }
            Integer.parseInt(fields_values.get("idCategory"));
            break;
          case 2: // By game name.
            if (!fields_values.containsKey("name") || fields_values.get("name").trim().equals("")) {
              return null;
            }
            break;
          case 3: // By similar games.
            if (!fields_values.containsKey("idGame")
                || fields_values.get("idGame").trim().equals("")) {
              return null;
            }
            Integer.parseInt(fields_values.get("idGame"));
            break;
        }
      } catch (NumberFormatException e) {
        return null;
      }

      // Getting the list
      List<GameView> gamesView = gvDao.getAllGameViews(idFilterer, idOrderer, fields_values);
      if (gamesView == null) return null;

      // Transform GameView list into GameList for returning
      List<Game> games = new ArrayList<Game>();
      for (GameView gameView : gamesView) {
        games.add(GameView.getGame(gameView));
      }
      return games;
    }

    return null;
  }