use of org.jbei.ice.storage.model.Audit in project ice by JBEI.
the class EntryHistory method delete.
public boolean delete(long historyId) {
Audit audit = dao.get(historyId);
if (audit == null)
return true;
dao.delete(audit);
return true;
}
use of org.jbei.ice.storage.model.Audit in project ice by JBEI.
the class EntryHistory method get.
public Results<History> get(int limit, int offset, boolean asc, String sort) {
entryAuthorization.expectWrite(userId, entry);
List<Audit> list = dao.getAuditsForEntry(entry, limit, offset, asc, sort);
Results<History> results = new Results<>();
AccountDAO accountDAO = DAOFactory.getAccountDAO();
for (Audit audit : list) {
History history = audit.toDataTransferObject();
if (history.getPartner() == null) {
Account account = accountDAO.getByEmail(history.getUserId());
if (account != null)
history.setAccount(account.toDataTransferObject());
}
results.getData().add(history);
}
long count = dao.getHistoryCount(this.entry);
results.setResultCount(count);
return results;
}
use of org.jbei.ice.storage.model.Audit in project ice by JBEI.
the class EntryHistory method add.
/**
* Adds a read history object for the specified user and entry
*
* @return true if the object was successfully added, false otherwise
*/
public boolean add() {
Audit audit = new Audit();
audit.setAction(AuditType.READ.getAbbrev());
audit.setEntry(entry);
audit.setUserId(userId);
audit.setTime(new Date());
return dao.create(audit) != null;
}
use of org.jbei.ice.storage.model.Audit in project ice by JBEI.
the class AuditDAO method getAuditsForEntry.
public List<Audit> getAuditsForEntry(Entry entry, int limit, int offset, boolean asc, String sort) {
try {
if (sort == null)
sort = "id";
CriteriaQuery<Audit> query = getBuilder().createQuery(Audit.class);
Root<Audit> from = query.from(Audit.class);
query.where(getBuilder().equal(from.get("entry"), entry));
query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(limit).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.Audit in project ice by JBEI.
the class AuditDAO method deleteAll.
public int deleteAll(Entry entry) {
try {
CriteriaDelete<Audit> query = getBuilder().createCriteriaDelete(Audit.class);
Root<Audit> from = query.from(Audit.class);
query.where(getBuilder().equal(from.get("entry"), entry));
return currentSession().createQuery(query).executeUpdate();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations