class DocumentServiceImpl extends RemoteServiceServlet implements DocumentService {

	@Override
	public long addNote(long docId, String message) throws ServerException {
		Session session = ServiceUtil.validateSession(getThreadLocalRequest());

		try {
			DocumentNote note = new DocumentNote();
			note.setTenantId(session.getTenantId());
			note.setDocId(docId);
			note.setUserId(session.getUserId());
			note.setUsername(session.getUser().getFullName());
			note.setDate(new Date());
			note.setMessage(message);

			DocumentDAO docDao = (DocumentDAO) Context.get().getBean(DocumentDAO.class);
			Document document = docDao.findDocument(docId);
			if (document == null)
				throw new ServerException("Unexisting document " + docId);

			note.setFileName(document.getFileName());
			note.setFileVersion(document.getFileVersion());

			DocumentHistory transaction = new DocumentHistory();
			transaction.setSession(session);

			DocumentNoteDAO dao = (DocumentNoteDAO) Context.get().getBean(DocumentNoteDAO.class);
			dao.store(note, transaction);

			return note.getId();
		} catch (Throwable t) {
			return (Integer) ServiceUtil.throwServerException(session, log, t);
		}
	}

}