class DeleteNoteByIdAPIController {

    @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String deleteNoteById(
            @PathVariable("noteId") Long id,
            HttpSession session

    ) throws AcmObjectNotFoundException, AcmUserActionFailedException
    {
        log.info("Finding note with ID : [{}]", id);
        String ipAddress = (String) session.getAttribute("acm_ip_address");
        if (id != null)
        {
            Note note = getNoteDao().find(id);
            try
            {
                log.info("Deleting note by ID : [{}]", id);

                JSONObject objectToReturnJSON = new JSONObject();
                getNoteDao().deleteNoteById(id);

                ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", true, ipAddress);
                getNoteEventPublisher().publishNoteEvent(event);

                objectToReturnJSON.put("deletedNoteId", id);

                String objectToReturn;
                objectToReturn = objectToReturnJSON.toString();

                return objectToReturn;
            }
            catch (PersistenceException e)
            {
                ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", false, ipAddress);
                getNoteEventPublisher().publishNoteEvent(event);
                throw new AcmUserActionFailedException("Delete", "note", id, e.getMessage(), e);
            }
        }
        throw new AcmObjectNotFoundException("Note", id, "Could not find note", null);
    }

}