Search in sources :

Example 1 with Request

use of org.jbei.ice.storage.model.Request in project ice by JBEI.

the class RequestRetriever method updateStatus.

public SampleRequest updateStatus(String userId, long requestId, SampleRequestStatus newStatus) {
    Request request = dao.get(requestId);
    if (request == null)
        return null;
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    if (!request.getAccount().getEmail().equalsIgnoreCase(userId) && account.getType() != AccountType.ADMIN) {
        throw new PermissionException("No permissions for request");
    }
    if (request.getStatus() == newStatus)
        return request.toDataTransferObject();
    request.setStatus(newStatus);
    request.setUpdated(new Date());
    return dao.update(request).toDataTransferObject();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Request(org.jbei.ice.storage.model.Request)

Example 2 with Request

use of org.jbei.ice.storage.model.Request in project ice by JBEI.

the class RequestRetriever method removeSampleFromCart.

public SampleRequest removeSampleFromCart(String userId, long requestId) {
    try {
        Request request = dao.get(requestId);
        if (request == null)
            return null;
        if (!request.getAccount().getEmail().equalsIgnoreCase(userId))
            return null;
        Logger.info(userId + ": Removing sample from cart for entry " + request.getEntry().getId());
        dao.delete(request);
        return request.toDataTransferObject();
    } catch (DAOException de) {
        Logger.error(de);
        return null;
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Request(org.jbei.ice.storage.model.Request)

Example 3 with Request

use of org.jbei.ice.storage.model.Request in project ice by JBEI.

the class RequestDAO method getCount.

public int getCount(Account account) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Request> from = query.from(Request.class);
        query.select(getBuilder().countDistinct(from.get("id")));
        if (account != null)
            query.where(getBuilder().equal(from.get("account"), account));
        return currentSession().createQuery(query).uniqueResult().intValue();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Example 4 with Request

use of org.jbei.ice.storage.model.Request in project ice by JBEI.

the class RequestDAO method getSampleRequestInCart.

public Request getSampleRequestInCart(Account account, Entry entry) {
    try {
        CriteriaQuery<Request> query = getBuilder().createQuery(Request.class);
        Root<Request> from = query.from(Request.class);
        query.where(getBuilder().and(getBuilder().equal(from.get("status"), SampleRequestStatus.IN_CART), getBuilder().equal(from.get("entry"), entry), getBuilder().equal(from.get("account"), account)));
        List<Request> list = currentSession().createQuery(query).list();
        if (list.isEmpty())
            return null;
        HashSet<Request> inCart = new HashSet<>(list);
        if (inCart.size() > 1) {
            Logger.error("Multiple sample requests found for entry " + entry.getId());
        }
        return (Request) inCart.toArray()[0];
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest) HashSet(java.util.HashSet)

Example 5 with Request

use of org.jbei.ice.storage.model.Request in project ice by JBEI.

the class RequestDAO method getCount.

public int getCount(SampleRequestStatus status, String filter) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Request> from = query.from(Request.class);
        query.select(getBuilder().countDistinct(from.get("id")));
        List<Predicate> predicates = createPredicates(from, filter, status);
        if (!predicates.isEmpty())
            query.where(predicates.toArray(new Predicate[predicates.size()]));
        return currentSession().createQuery(query).uniqueResult().intValue();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest) Predicate(javax.persistence.criteria.Predicate)

Aggregations

Request (org.jbei.ice.storage.model.Request)13 DAOException (org.jbei.ice.storage.DAOException)8 HibernateException (org.hibernate.HibernateException)6 SampleRequest (org.jbei.ice.lib.dto.sample.SampleRequest)6 Account (org.jbei.ice.storage.model.Account)5 Predicate (javax.persistence.criteria.Predicate)2 Entry (org.jbei.ice.storage.model.Entry)2 CSVWriter (com.opencsv.CSVWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashSet (java.util.HashSet)1 PermissionException (org.jbei.ice.lib.access.PermissionException)1 StorageLocation (org.jbei.ice.lib.dto.StorageLocation)1