Search in sources :

Example 1 with Audit

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;
}
Also used : Audit(org.jbei.ice.storage.model.Audit)

Example 2 with Audit

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;
}
Also used : Audit(org.jbei.ice.storage.model.Audit) Account(org.jbei.ice.storage.model.Account) Results(org.jbei.ice.lib.dto.common.Results) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) History(org.jbei.ice.lib.dto.History)

Example 3 with Audit

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;
}
Also used : Audit(org.jbei.ice.storage.model.Audit) Date(java.util.Date)

Example 4 with Audit

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Audit(org.jbei.ice.storage.model.Audit) HibernateException(org.hibernate.HibernateException)

Example 5 with Audit

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Audit(org.jbei.ice.storage.model.Audit) HibernateException(org.hibernate.HibernateException)

Aggregations

Audit (org.jbei.ice.storage.model.Audit)6 HibernateException (org.hibernate.HibernateException)3 DAOException (org.jbei.ice.storage.DAOException)3 Date (java.util.Date)1 History (org.jbei.ice.lib.dto.History)1 Results (org.jbei.ice.lib.dto.common.Results)1 AccountDAO (org.jbei.ice.storage.hibernate.dao.AccountDAO)1 Account (org.jbei.ice.storage.model.Account)1