Search in sources :

Example 6 with SampleRequest

use of org.jbei.ice.lib.dto.sample.SampleRequest in project ice by JBEI.

the class FolderContents method getContents.

/**
 * Retrieves the folder specified in the parameter and contents
 *
 * @param userId         unique identifier for user making request. If null, folder must have public read privs
 * @param folderId       unique identifier for folder to be retrieved
 * @param pageParameters paging parameters
 * @return wrapper around list of folder entries if folder is found, null otherwise
 * @throws PermissionException if user does not have read permissions on folder
 */
public FolderDetails getContents(String userId, long folderId, PageParameters pageParameters, List<String> fields) {
    Folder folder = folderDAO.get(folderId);
    if (folder == null)
        return null;
    // should have permission to read folder
    folderAuthorization.expectRead(userId, folder);
    // check if folder doesn't exist on this instance and has to be retrieved from another
    if (folder.getType() == FolderType.REMOTE)
        return getRemoteContents(userId, folder, pageParameters);
    boolean visibleOnly = showVisibleOnlyEntries(userId, folder);
    FolderDetails details = folder.toDataTransferObject();
    // all local entries at this point
    long folderSize = folderDAO.getFolderSize(folderId, pageParameters.getFilter(), visibleOnly);
    details.setCount(folderSize);
    if (userId != null) {
        List<AccessPermission> permissions = getAndFilterFolderPermissions(userId, folder);
        details.setAccessPermissions(permissions);
        boolean canEdit = folderAuthorization.canWrite(userId, folder);
        details.setCanEdit(canEdit);
    }
    details.setPublicReadAccess(permissionsController.isPublicVisible(folder));
    Account owner = DAOFactory.getAccountDAO().getByEmail(folder.getOwnerEmail());
    if (owner != null)
        details.setOwner(owner.toDataTransferObject());
    // check for sample request information
    if (folder.getType() == FolderType.SAMPLE) {
        SampleCreateModel model = DAOFactory.getSampleCreateModelDAO().getByFolder(folder);
        if (model != null) {
            SampleRequest request = new SampleRequest();
            request.setStatus(model.getStatus());
            request.setId(model.getId());
            details.setSampleRequest(request);
        }
    }
    // retrieve folder contents
    List<Long> results = folderDAO.retrieveFolderContents(folderId, pageParameters, visibleOnly);
    for (Long entryId : results) {
        PartData info = ModelToInfoFactory.createTableView(entryId, fields);
        details.getEntries().add(info);
    }
    return details;
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Aggregations

SampleRequest (org.jbei.ice.lib.dto.sample.SampleRequest)6 EntryType (org.jbei.ice.lib.dto.entry.EntryType)2 PartData (org.jbei.ice.lib.dto.entry.PartData)2 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)2 DAOException (org.jbei.ice.storage.DAOException)2 Account (org.jbei.ice.storage.model.Account)2 Request (org.jbei.ice.storage.model.Request)2 Date (java.util.Date)1 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)1 Entry (org.jbei.ice.storage.model.Entry)1 Folder (org.jbei.ice.storage.model.Folder)1 SampleCreateModel (org.jbei.ice.storage.model.SampleCreateModel)1