Search in sources :

Example 6 with FolderDetails

use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.

the class FolderContents method remotelyAddEntrySelection.

// adds a specified entry to a folder. The entry was transferred earlier so already exists
public boolean remotelyAddEntrySelection(String remoteUserId, long folderId, String remoteUserToken, EntrySelection selection, RegistryPartner requestingPartner) {
    // folder that the entry is contained in
    Folder folder = folderDAO.get(folderId);
    if (folder == null)
        return false;
    RemotePartner remotePartner = DAOFactory.getRemotePartnerDAO().getByUrl(requestingPartner.getUrl());
    // check that the remote user has the right token
    RemoteShareModel shareModel = DAOFactory.getRemoteShareModelDAO().get(remoteUserId, remotePartner, folder);
    if (shareModel == null) {
        Logger.error("Could not retrieve share model");
        return false;
    }
    // folder must match
    Permission permission = shareModel.getPermission();
    if (permission.getFolder().getId() != folderId || !permission.isCanWrite()) {
        throw new PermissionException("permission could not be verified");
    }
    // validate access token
    TokenHash tokenHash = new TokenHash();
    String secret = tokenHash.encrypt(remotePartner.getUrl() + remoteUserId, remoteUserToken);
    if (!secret.equals(shareModel.getSecret())) {
        throw new PermissionException("Secret does not match");
    }
    List<Long> entries = selection.getEntries();
    DAOFactory.getEntryDAO().setEntryVisibility(entries, Visibility.OK);
    // good to go?
    FolderDetails details = addEntriesToTransferredFolder(entries, folder);
    return details != null;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) TokenHash(org.jbei.ice.lib.account.TokenHash)

Example 7 with FolderDetails

use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.

the class FolderController method getSharedUserFolders.

/**
     * Retrieves folders that have been shared with specified user as an individual or as part of a group.
     *
     * @param userId User whose shared folders are being retrieved
     * @return list of folders meeting the shared criteria
     */
public ArrayList<FolderDetails> getSharedUserFolders(String userId) {
    Account account = getAccount(userId);
    ArrayList<FolderDetails> folderDetails = new ArrayList<>();
    Set<Group> groups = account.getGroups();
    groups.remove(groupController.createOrRetrievePublicGroup());
    List<Folder> sharedFolders = DAOFactory.getPermissionDAO().retrieveFolderPermissions(account, groups);
    if (sharedFolders == null)
        return null;
    for (Folder folder : sharedFolders) {
        FolderDetails details = folder.toDataTransferObject();
        details.setType(folder.getType());
        long folderSize = dao.getFolderSize(folder.getId(), null, true);
        details.setCount(folderSize);
        if (folder.getCreationTime() != null)
            details.setCreationTime(folder.getCreationTime().getTime());
        folderDetails.add(details);
    }
    return folderDetails;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Example 8 with FolderDetails

use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.

the class FolderController method delete.

/**
     * Deletes either a user folder or bulk upload (which is represented as a folder to the user)
     *
     * @param userId   unique identifier for user requesting delete action
     * @param folderId unique identifier for folder to be deleted
     * @param type     type of folder to be deleted (either "UPLOAD" or "PRIVATE")
     * @return delete folder details
     */
public FolderDetails delete(String userId, long folderId, FolderType type) {
    switch(type) {
        case UPLOAD:
            BulkUploadController controller = new BulkUploadController();
            BulkUploadInfo info = controller.deleteDraftById(userId, folderId);
            if (info == null) {
                Logger.error("Could not locate bulk upload id " + folderId + " for deletion");
                return null;
            }
            FolderDetails details = new FolderDetails();
            details.setId(info.getId());
            return details;
        case PRIVATE:
        case TRANSFERRED:
        case SHARED:
            Folder folder = dao.get(folderId);
            if (folder == null)
                return null;
            if (!accountController.isAdministrator(userId) && !folder.getOwnerEmail().equalsIgnoreCase(userId)) {
                String errorMsg = userId + ": insufficient permissions to delete folder " + folderId;
                Logger.warn(errorMsg);
                throw new PermissionException(errorMsg);
            }
            details = folder.toDataTransferObject();
            long folderSize = dao.getFolderSize(folderId, null, true);
            details.setCount(folderSize);
            permissionDAO.clearPermissions(folder);
            dao.delete(folder);
            return details;
        default:
            Logger.error("Cannot delete folder of type " + type);
            return null;
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) BulkUploadController(org.jbei.ice.lib.bulkupload.BulkUploadController) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Example 9 with FolderDetails

use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.

the class FolderContents method getRemotelySharedContents.

// remote request for shared contents
public FolderDetails getRemotelySharedContents(String remoteUserId, String token, RegistryPartner partner, long folderId, PageParameters pageParameters) {
    RemotePartner remotePartner = DAOFactory.getRemotePartnerDAO().getByUrl(partner.getUrl());
    if (remotePartner == null) {
        Logger.error("Cannot retrieve remote partner " + partner.getUrl());
        return null;
    }
    Folder folder = folderDAO.get(folderId);
    if (folder == null) {
        Logger.error("Cannot retrieve folder with id " + folderId);
        return null;
    }
    RemoteShareModelDAO shareModelDAO = DAOFactory.getRemoteShareModelDAO();
    RemoteShareModel shareModel = shareModelDAO.get(remoteUserId, remotePartner, folder);
    if (shareModel == null) {
        Logger.error("Could not retrieve share model");
        return null;
    }
    //verify access
    TokenHash tokenHash = new TokenHash();
    String secret = tokenHash.encrypt(folderId + remotePartner.getUrl() + remoteUserId, token);
    if (!secret.equals(shareModel.getSecret())) {
        Logger.error("Authorization failed for remote folder retrieve");
        return null;
    }
    boolean canEdit = shareModel.getPermission().isCanWrite();
    // todo : move everything above to folder permissions and folder authorization
    FolderDetails details = folder.toDataTransferObject();
    details.setCanEdit(canEdit);
    long folderSize = folderDAO.getFolderSize(folderId, pageParameters.getFilter(), true);
    details.setCount(folderSize);
    // retrieve folder contents
    List<Entry> results = folderDAO.retrieveFolderContents(folderId, pageParameters, true);
    for (Entry entry : results) {
        PartData info = ModelToInfoFactory.createTableViewData(null, entry, false);
        info.setCanEdit(canEdit);
        details.getEntries().add(info);
    }
    return details;
}
Also used : PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) TokenHash(org.jbei.ice.lib.account.TokenHash)

Example 10 with FolderDetails

use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.

the class FolderController method getPendingBulkUploads.

/**
     * Retrieves information about submitted bulk uploads that have status "PENDING". Administrator only function
     *
     * @param userId unique identifier for user performing action. Must have admin privileges
     * @return list of information about pending bulk uploads is user has administrative privileges, null otherwise
     */
public ArrayList<FolderDetails> getPendingBulkUploads(String userId) {
    ArrayList<FolderDetails> folders = new ArrayList<>();
    ArrayList<BulkUploadInfo> list = bulkUploadController.getPendingUploads(userId);
    for (BulkUploadInfo info : list) {
        FolderDetails details = new FolderDetails();
        String name = info.getAccount() != null ? info.getAccount().getEmail() : info.getName();
        details.setName(name);
        details.setCount(info.getCount());
        details.setId(info.getId());
        details.setType(FolderType.UPLOAD);
        folders.add(details);
    }
    return folders;
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo)

Aggregations

FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)35 Folder (org.jbei.ice.storage.model.Folder)11 PartData (org.jbei.ice.lib.dto.entry.PartData)8 Account (org.jbei.ice.storage.model.Account)8 PermissionException (org.jbei.ice.lib.access.PermissionException)6 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)5 Test (org.junit.Test)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)4 GroupController (org.jbei.ice.lib.group.GroupController)4 ArrayList (java.util.ArrayList)3 BulkUploadInfo (org.jbei.ice.lib.bulkupload.BulkUploadInfo)3 EntrySelection (org.jbei.ice.lib.entry.EntrySelection)3 Group (org.jbei.ice.storage.model.Group)3 RemotePartner (org.jbei.ice.storage.model.RemotePartner)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 TokenHash (org.jbei.ice.lib.account.TokenHash)2 Entries (org.jbei.ice.lib.entry.Entries)2 Entry (org.jbei.ice.storage.model.Entry)2 HashSet (java.util.HashSet)1