Search in sources :

Example 11 with Request

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

the class RequestRetriever method setRequestsStatus.

public boolean setRequestsStatus(String userId, ArrayList<Long> ids, SampleRequestStatus status) {
    boolean sendEmail = status == SampleRequestStatus.PENDING;
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    for (long id : ids) {
        Request request = dao.get(id);
        if (request == null)
            continue;
        if (!request.getAccount().getEmail().equalsIgnoreCase(userId) && account.getType() != AccountType.ADMIN)
            continue;
        request.setStatus(status);
        request.setRequested(new Date());
        dao.update(request);
    }
    // send email to strain archivist
    if (sendEmail) {
        String email = Utils.getConfigValue(ConfigurationKey.BULK_UPLOAD_APPROVER_EMAIL);
        if (email != null && !email.isEmpty()) {
            String subject = "Sample request";
            String body = "A sample request has been received from " + account.getFullName() + " for " + ids.size();
            if (ids.size() == 1)
                body += " sample";
            else
                body += " samples";
            body += "\n\nPlease go to the following link to review pending requests.\n\n";
            body += Utils.getConfigValue(ConfigurationKey.URI_PREFIX) + "/admin/samples";
            EmailFactory.getEmail().send(email, subject, body);
        }
    }
    return true;
}
Also used : Account(org.jbei.ice.storage.model.Account) Request(org.jbei.ice.storage.model.Request)

Example 12 with Request

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

the class RequestRetriever method getRequests.

public UserSamples getRequests(String userId, int start, int limit, String sort, boolean asc, SampleRequestStatus status, String filter) {
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    if (account.getType() != AccountType.ADMIN)
        return getUserSamples(userId, null, start, limit, sort, asc);
    int count = dao.getCount(status, filter);
    UserSamples samples = new UserSamples();
    samples.setCount(count);
    List<Request> results = dao.get(start, limit, sort, asc, status, filter);
    SampleService sampleService = new SampleService();
    for (Request request : results) {
        SampleRequest sampleRequest = request.toDataTransferObject();
        List<PartSample> location = sampleService.retrieveEntrySamples(userId, Long.toString(request.getEntry().getId()));
        sampleRequest.setLocation(location);
        samples.getRequests().add(sampleRequest);
    }
    return samples;
}
Also used : Account(org.jbei.ice.storage.model.Account) Request(org.jbei.ice.storage.model.Request)

Example 13 with Request

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

the class RequestRetriever method getUserSamples.

public UserSamples getUserSamples(String userId, SampleRequestStatus status, int start, int limit, String sort, boolean asc) {
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    UserSamples samples = new UserSamples();
    int count = dao.getCount(account);
    samples.setCount(count);
    List<Request> requestList = dao.getAccountRequests(account, status, start, limit, sort, asc);
    for (Request request : requestList) samples.getRequests().add(request.toDataTransferObject());
    return samples;
}
Also used : Account(org.jbei.ice.storage.model.Account) Request(org.jbei.ice.storage.model.Request)

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