@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);
   }
 }
 @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
   }
 }
 @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);
   }
 }
  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;
      }
    }
  }
 @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!";
 }
  @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!";
  }
 @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!";
 }