コード例 #1
0
 @PUT
 @Path("/edit/{id}")
 @Consumes(MediaType.APPLICATION_JSON)
 public void editNote(String inputData, @PathParam("id") int id) {
   JSONObject inputJSON = new JSONObject(inputData);
   if ((inputJSON.has("sessionID"))
       && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
     Note newNote = resolveNoteData(inputJSON);
     if (inputJSON.has("noteID")) inputJSON.remove("noteID"); // na wszelki wypadek - ID podano
     hibernate.controllers.NotesController notesController =
         new hibernate.controllers.NotesController();
     if (newNote != null) notesController.updateNote(newNote, id);
   }
 }
コード例 #2
0
 @PUT
 @Path("/edit")
 @Consumes(MediaType.APPLICATION_JSON)
 public void editNote(String inputData) {
   JSONObject inputJSON = new JSONObject(inputData);
   if ((inputJSON.has("sessionID"))
       && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
     if (inputJSON.has("noteID")) {
       int id = Integer.parseInt(inputJSON.getString("noteID"));
       editNote(inputData, id);
     }
     // w przeciwnym wypadku nic nie robi
   }
 }
コード例 #3
0
 @POST
 @Path("/create")
 @Consumes(MediaType.APPLICATION_JSON)
 public void createNote(String inputData) {
   JSONObject inputJSON = new JSONObject(inputData);
   if ((inputJSON.has("sessionID"))
       && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
     if (inputJSON.has("noteID"))
       inputJSON.remove("noteID"); // na wszelki wypadek - chcemy generowaæ ID automatycznie
     Note newNote = resolveNoteData(inputJSON);
     hibernate.controllers.NotesController notesController =
         new hibernate.controllers.NotesController();
     if (newNote != null) notesController.addNote(newNote);
   }
 }
コード例 #4
0
  private Note resolveNoteData(JSONObject inputJSON) {
    if (!((inputJSON.has("noteTitle"))
        && (inputJSON.has("noteURL"))
        && (inputJSON.has("subjectID"))
        && (inputJSON.has("userID")))) {
      return null;
    } else {
      try {
        hibernate.controllers.SubjectsController subjectsController =
            new hibernate.controllers.SubjectsController();
        Subject subject =
            subjectsController.readSubject(Integer.parseInt(inputJSON.get("subjectID").toString()));

        hibernate.controllers.UsersController usersController =
            new hibernate.controllers.UsersController();
        User user = usersController.readUser(Integer.parseInt(inputJSON.get("userID").toString()));

        return new Note(
            inputJSON.getString("noteTitle"), inputJSON.getString("noteURL"), subject, user);
      } catch (NullPointerException ex) {
        return null;
      }
    }
  }
コード例 #5
0
 @POST
 @Path("/view/{id}")
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public String viewNote(String inputData, @PathParam("id") int id) {
   JSONObject inputJSON = new JSONObject(inputData);
   if ((inputJSON.has("sessionID"))
       && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
     hibernate.controllers.NotesController notesController =
         new hibernate.controllers.NotesController();
     Note note = notesController.readNote(id);
     if (note != null) {
       JSONObject jsonNote = getJSONNote(note);
       return jsonNote.toString();
     } else {
       return "No subject of ID == " + id + "!";
     }
   } else return "Invalid session!";
 }
コード例 #6
0
  @DELETE
  @Path("/{id}")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces("text/plain")
  public String deleteNote(String inputData, @PathParam("id") int id) {
    JSONObject inputJSON = new JSONObject(inputData);
    if ((inputJSON.has("sessionID"))
        && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
      try {
        hibernate.controllers.NotesController notesController =
            new hibernate.controllers.NotesController();
        notesController.deleteNote(id);

        return "OK";
      } catch (Exception ex) {
        return ex.getMessage();
      }
    } else return "Invalid session!";
  }
コード例 #7
0
 @POST
 @Path("/view")
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public String viewAllNotes(String inputData) {
   JSONObject inputJSON = new JSONObject(inputData);
   if ((inputJSON.has("sessionID"))
       && UsersController.checkLogin(inputJSON.getString("sessionID"))) {
     hibernate.controllers.NotesController notesController =
         new hibernate.controllers.NotesController();
     List<Note> notes = notesController.readAllNotes();
     JSONArray results = new JSONArray();
     JSONObject jsonNote;
     for (Note note : notes) {
       jsonNote = getJSONNote(note);
       results.put(jsonNote);
     }
     return results.toString();
   } else return "Invalid session!";
 }