use of org.jbei.ice.storage.model.Request in project ice by JBEI.
the class RequestDAO method getAccountRequests.
public List<Request> getAccountRequests(Account account, SampleRequestStatus status, int start, int limit, String sort, boolean asc) {
try {
CriteriaQuery<Request> query = getBuilder().createQuery(Request.class);
Root<Request> from = query.from(Request.class);
if (status != null) {
query.where(getBuilder().equal(from.get("account"), account), getBuilder().equal(from.get("status"), status));
} else {
query.where(getBuilder().equal(from.get("account"), account));
}
query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
return currentSession().createQuery(query).setFirstResult(start).setMaxResults(limit).list();
} 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 getSampleRequestByStatus.
public List<Request> getSampleRequestByStatus(Account account, Entry entry, SampleRequestStatus status) {
try {
CriteriaQuery<Request> query = getBuilder().createQuery(Request.class);
Root<Request> from = query.from(Request.class);
query.where(getBuilder().and(getBuilder().equal(from.get("status"), status), getBuilder().equal(from.get("entry"), entry), getBuilder().equal(from.get("account"), account)));
return currentSession().createQuery(query).list();
} 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 get.
public List<Request> get(int start, int limit, String sort, boolean asc, SampleRequestStatus status, String filter) {
try {
CriteriaQuery<Request> query = getBuilder().createQuery(Request.class).distinct(true);
Root<Request> from = query.from(Request.class);
List<Predicate> predicates = createPredicates(from, filter, status);
if (!predicates.isEmpty())
query.where(predicates.toArray(new Predicate[predicates.size()]));
query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
return currentSession().createQuery(query).setMaxResults(limit).setFirstResult(start).list();
} 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 RequestRetriever method generateCSVFile.
public ByteArrayOutputStream generateCSVFile(String userId, ArrayList<Long> ids) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter streamWriter = new OutputStreamWriter(out);
try (CSVWriter writer = new CSVWriter(streamWriter)) {
SampleService sampleService = new SampleService();
Set<Long> idSet = new HashSet<>(ids);
for (long id : idSet) {
Request request = dao.get(id);
if (request == null)
continue;
String[] line = new String[3];
Entry entry = request.getEntry();
line[0] = entry.getName();
List<PartSample> samples = sampleService.retrieveEntrySamples(userId, Long.toString(request.getEntry().getId()));
String plate = null;
String well = null;
if (samples.size() == 1) {
if (samples.get(0).getLocation().getType() == SampleType.GENERIC) {
plate = "generic";
well = "";
}
} else {
for (PartSample partSample : samples) {
if (partSample.getLabel().contains("backup"))
continue;
// get plate
StorageLocation location = partSample.getLocation();
if (location == null)
continue;
if (location.getType() == SampleType.PLATE96) {
plate = location.getDisplay().replaceFirst("^0+(?!$)", "");
}
StorageLocation child = location.getChild();
while (child != null) {
if (child.getType() == SampleType.WELL) {
well = child.getDisplay();
break;
}
child = child.getChild();
}
if (!StringUtils.isEmpty(well) && !StringUtils.isEmpty(plate))
break;
}
}
if (plate == null || well == null)
continue;
String email = request.getAccount().getEmail();
int index = email.indexOf('@');
char typeChar = request.getType() == SampleRequestType.LIQUID_CULTURE ? 'L' : 'A';
line[1] = typeChar + " " + plate + " " + well + " " + email.substring(0, index);
line[1] = line[1].trim().replaceAll(" +", " ");
line[2] = request.getPlateDescription().trim().replaceAll(" +", " ");
if (request.getGrowthTemperature() != null)
line[2] += " " + request.getGrowthTemperature();
writer.writeNext(line);
}
}
return out;
}
use of org.jbei.ice.storage.model.Request in project ice by JBEI.
the class RequestRetriever method placeSampleInCart.
/**
* Creates a new sample request for the specified user and specified entry.
* The default status is "IN CART"
*/
public boolean placeSampleInCart(String userId, SampleRequest sampleRequest) {
long partId = sampleRequest.getPartData().getId();
Entry entry = entryDAO.get(sampleRequest.getPartData().getId());
if (entry == null)
throw new IllegalArgumentException("Cannot find entry with id: " + partId);
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
// check if sample is already in cart with status of "IN CART"
try {
List<Request> requests = dao.getSampleRequestByStatus(account, entry, SampleRequestStatus.IN_CART);
if (requests != null && !requests.isEmpty())
return true;
Request request = new Request();
request.setAccount(account);
request.setGrowthTemperature(sampleRequest.getGrowthTemperature());
request.setEntry(entry);
if (sampleRequest.getRequestType() == null)
sampleRequest.setRequestType(SampleRequestType.LIQUID_CULTURE);
request.setType(sampleRequest.getRequestType());
request.setRequested(new Date(System.currentTimeMillis()));
request.setUpdated(request.getRequested());
request.setPlateDescription(sampleRequest.getPlateDescription());
return dao.create(request) != null;
} catch (DAOException e) {
Logger.error(e);
return false;
}
}
Aggregations