Search in sources :

Example 1 with SampleCreateModel

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

the class RequestRetriever method getFolderRequests.

public UserSamples getFolderRequests(String userId, int start, int limit, String sort, boolean asc, String folderNameFilter) {
    // admin feature
    if (!new AccountController().isAdministrator(userId))
        throw new PermissionException("Admin privileges required for this action");
    List<SampleCreateModel> models = DAOFactory.getSampleCreateModelDAO().list(start, limit, sort, asc, folderNameFilter);
    UserSamples result = new UserSamples();
    for (SampleCreateModel model : models) {
        SampleRequest request = new SampleRequest();
        request.setId(model.getId());
        request.setStatus(model.getStatus());
        FolderDetails details = model.getFolder().toDataTransferObject();
        details.setCount(DAOFactory.getFolderDAO().getFolderSize(details.getId(), null, true));
        request.setFolderDetails(details);
        request.setRequester(model.getAccount().toDataTransferObject());
        request.setRequestTime(model.getRequested().getTime());
        request.setUpdateTime(model.getUpdated().getTime());
        result.getRequests().add(request);
    }
    long available = DAOFactory.getSampleCreateModelDAO().availableCount(folderNameFilter);
    result.setCount(Long.valueOf(available).intValue());
    return result;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) SampleCreateModel(org.jbei.ice.storage.model.SampleCreateModel) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) AccountController(org.jbei.ice.lib.account.AccountController)

Example 2 with SampleCreateModel

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

the class RequestRetriever method updateFolderRequest.

private SampleRequest updateFolderRequest(long requestId, SampleRequestStatus newStatus) {
    SampleCreateModel model = DAOFactory.getSampleCreateModelDAO().get(requestId);
    if (model == null)
        return null;
    model.setStatus(newStatus);
    model.setUpdated(new Date());
    model = DAOFactory.getSampleCreateModelDAO().update(model);
    SampleRequest request = new SampleRequest();
    request.setId(model.getId());
    request.setUpdateTime(model.getUpdated().getTime());
    request.setStatus(model.getStatus());
    return request;
}
Also used : SampleCreateModel(org.jbei.ice.storage.model.SampleCreateModel)

Example 3 with SampleCreateModel

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

the class SampleCreateModelDAO method getByFolder.

public SampleCreateModel getByFolder(Folder folder) {
    try {
        CriteriaQuery<SampleCreateModel> query = getBuilder().createQuery(SampleCreateModel.class);
        Root<SampleCreateModel> from = query.from(SampleCreateModel.class);
        query.where(getBuilder().equal(from.get("folder"), folder));
        return currentSession().createQuery(query).uniqueResult();
    } catch (Exception he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) SampleCreateModel(org.jbei.ice.storage.model.SampleCreateModel) DAOException(org.jbei.ice.storage.DAOException)

Example 4 with SampleCreateModel

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

the class UserFolders method get.

public FolderDetails get(long folderId) {
    Folder folder = this.dao.get(folderId);
    if (folder == null)
        throw new IllegalArgumentException("Folder with id " + folderId + " does not exist");
    authorization.expectRead(this.userId, folder);
    FolderDetails folderDetails = folder.toDataTransferObject();
    List<String> types = dao.getContentTypes(folderId);
    if (!types.isEmpty()) {
        for (String type : types) {
            EntryType entryType = EntryType.nameToType(type);
            if (entryType != null)
                folderDetails.getContentTypes().add(entryType);
        }
    }
    Account owner = accountDAO.getByEmail(folder.getOwnerEmail());
    if (owner != null) {
        folderDetails.setOwner(owner.toDataTransferObject());
    }
    // get sample details
    if (folder.getType() == FolderType.SAMPLE) {
        SampleCreateModel model = DAOFactory.getSampleCreateModelDAO().getByFolder(folder);
        if (model != null) {
            SampleRequest request = new SampleRequest();
            request.setId(model.getId());
            request.setStatus(model.getStatus());
            folderDetails.setSampleRequest(request);
        }
    }
    return folderDetails;
}
Also used : Account(org.jbei.ice.storage.model.Account) EntryType(org.jbei.ice.lib.dto.entry.EntryType) SampleCreateModel(org.jbei.ice.storage.model.SampleCreateModel) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Aggregations

SampleCreateModel (org.jbei.ice.storage.model.SampleCreateModel)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)2 PermissionException (org.jbei.ice.lib.access.PermissionException)1 AccountController (org.jbei.ice.lib.account.AccountController)1 EntryType (org.jbei.ice.lib.dto.entry.EntryType)1 SampleRequest (org.jbei.ice.lib.dto.sample.SampleRequest)1 DAOException (org.jbei.ice.storage.DAOException)1 Account (org.jbei.ice.storage.model.Account)1 Folder (org.jbei.ice.storage.model.Folder)1