class FolderServiceImpl extends RemoteServiceServlet implements FolderService {

	@Override
	public void rename(long folderId, String name) throws ServerException {
		Session session = ServiceUtil.validateSession(getThreadLocalRequest());

		FolderDAO dao = (FolderDAO) Context.get().getBean(FolderDAO.class);
		try {
			List<Folder> folders = dao.findByNameAndParentId(name, dao.findById(folderId).getParentId());
			if (folders.size() > 0 && folders.get(0).getId() != folderId) {
				return;
			}
			// To avoid a 'org.hibernate.StaleObjectStateException', we
			// must retrieve the folder from database.
			Folder folder = dao.findById(folderId);
			dao.initialize(folder);

			// Add a folder history entry
			FolderHistory history = new FolderHistory();
			history.setFilenameOld(folder.getName());
			history.setPathOld(dao.computePathExtended(folderId));
			history.setEvent(FolderEvent.RENAMED.toString());
			history.setSession(session);

			folder.setName(name.trim());
			dao.store(folder, history);
		} catch (Throwable t) {
			ServiceUtil.throwServerException(session, log, t);
		}
	}

}