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();
}
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;
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations