class DocumentServiceImpl extends RemoteServiceServlet implements DocumentService {

	@Override
	public void delete(long[] ids) throws ServerException {
		Session session = ServiceUtil.validateSession(getThreadLocalRequest());

		if (ids.length > 0) {
			DocumentDAO dao = (DocumentDAO) Context.get().getBean(DocumentDAO.class);
			for (long id : ids) {
				try {
					Document doc = dao.findById(id);
					if (doc == null)
						continue;

					// Create the document history event
					DocumentHistory transaction = new DocumentHistory();
					transaction.setSession(session);
					transaction.setEvent(DocumentEvent.DELETED.toString());
					transaction.setComment("");

					// If it is a shortcut, we delete only the shortcut
					if (doc.getDocRef() != null) {
						transaction.setEvent(DocumentEvent.SHORTCUT_DELETED.toString());
						boolean deleted = dao.delete(doc.getId(), transaction);
						if (!deleted)
							throw new Exception("Document has not been deleted");
						continue;
					}

					// The document of the selected documentRecord must be
					// not immutable
					if (doc.getImmutable() == 1 && !transaction.getUser().isMemberOf("admin")) {
						log.debug("Document {} was not deleted because immutable", id);
						continue;
					}

					// The document must be not locked
					if (doc.getStatus() == Document.DOC_LOCKED) {
						log.debug("Document {} was not deleted because locked", id);
						continue;
					}

					// Check if there are some shortcuts associated to the
					// deleting document. All the shortcuts must be deleted.
					if (dao.findAliasIds(doc.getId()).size() > 0)
						for (Long shortcutId : dao.findAliasIds(doc.getId())) {
							dao.delete(shortcutId);
						}
					boolean deleted = dao.delete(doc.getId(), transaction);
					if (!deleted)
						throw new Exception("Document has not been deleted");
				} catch (Throwable t) {
					ServiceUtil.throwServerException(session, log, t);
				}
			}
		}
	}

}