Search in sources :

Example 1 with FolderDetails

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

the class RemoteEntries method getPublicEntries.

public PartnerEntries getPublicEntries(long remoteId, int offset, int limit, String sort, boolean asc) {
    if (!hasRemoteAccessEnabled())
        return null;
    RemotePartner partner = this.remotePartnerDAO.get(remoteId);
    if (partner == null)
        return null;
    FolderDetails details;
    try {
        final String restPath = "rest/folders/public/entries";
        HashMap<String, Object> queryParams = new HashMap<>();
        queryParams.put("offset", offset);
        queryParams.put("limit", limit);
        queryParams.put("asc", asc);
        queryParams.put("sort", sort);
        details = this.remoteContact.getFolderEntries(partner.getUrl(), restPath, queryParams, partner.getApiKey());
        if (details == null)
            return null;
    } catch (Exception e) {
        Logger.error(e);
        return null;
    }
    Results<PartData> results = new Results<>();
    results.setData(details.getEntries());
    results.setResultCount(details.getCount());
    return new PartnerEntries(partner.toDataTransferObject(), results);
}
Also used : HashMap(java.util.HashMap) Results(org.jbei.ice.lib.dto.common.Results) RemotePartner(org.jbei.ice.storage.model.RemotePartner) PartData(org.jbei.ice.lib.dto.entry.PartData) PartnerEntries(org.jbei.ice.lib.dto.web.PartnerEntries) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 2 with FolderDetails

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

the class FolderResource method update.

/**
     * Updates the specified folder resource
     *
     * @param folderId resource identifier of folder to be updated
     * @param details  details for update
     */
@PUT
@Path("/{id}")
public Response update(@PathParam("id") final long folderId, final FolderDetails details) {
    final String userId = requireUserId();
    log(userId, "update folder \"" + folderId + "\"");
    final FolderDetails resp = controller.update(userId, folderId, details);
    return super.respond(resp);
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails)

Example 3 with FolderDetails

use of org.jbei.ice.lib.dto.folder.FolderDetails 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) {
    Folder folder = folderDAO.get(folderId);
    if (folder == null)
        return null;
    // should have permission to read folder
    folderAuthorization.expectRead(userId, folder);
    if (folder.getType() == FolderType.REMOTE)
        return getRemoteContents(userId, folder, pageParameters);
    boolean visibleOnly = folder.getType() != FolderType.TRANSFERRED;
    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 = permissionsController.hasWritePermission(userId, folder);
        details.setCanEdit(canEdit);
    }
    details.setPublicReadAccess(permissionsController.isPublicVisible(folder));
    Account owner = DAOFactory.getAccountDAO().getByEmail(folder.getOwnerEmail());
    if (owner != null)
        details.setOwner(owner.toDataTransferObject());
    // retrieve folder contents
    List<Entry> results = folderDAO.retrieveFolderContents(folderId, pageParameters, visibleOnly);
    for (Entry entry : results) {
        PartData info = ModelToInfoFactory.createTableViewData(userId, entry, false);
        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)

Example 4 with FolderDetails

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

the class FolderController method createPersonalFolder.

public FolderDetails createPersonalFolder(String userId, FolderDetails folderDetails) {
    if (folderDetails.getName() == null)
        return null;
    Folder folder = new Folder(folderDetails.getName());
    AccountTransfer owner = folderDetails.getOwner();
    if (owner != null && !StringUtils.isEmpty(owner.getEmail()) && accountController.isAdministrator(userId))
        folder.setOwnerEmail(owner.getEmail());
    else
        folder.setOwnerEmail(userId);
    folder.setType(FolderType.PRIVATE);
    folder.setCreationTime(new Date());
    folder = dao.create(folder);
    FolderDetails details = folder.toDataTransferObject();
    details.setCanEdit(true);
    return details;
}
Also used : FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 5 with FolderDetails

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

the class FolderController method getPublicEntries.

/**
     * Retrieves entries that are made available publicly
     *
     * @param sort   order of retrieval for the entries
     * @param offset start of retrieval
     * @param limit  maximum number of entries to retrieve
     * @param asc    whether to retrieve the entries in ascending order
     * @return wrapper around the retrieved entries
     */
public FolderDetails getPublicEntries(ColumnField sort, int offset, int limit, boolean asc) {
    Group publicGroup = new GroupController().createOrRetrievePublicGroup();
    Set<Group> groups = new HashSet<>();
    groups.add(publicGroup);
    EntryDAO entryDAO = DAOFactory.getEntryDAO();
    List<Entry> results = entryDAO.retrieveVisibleEntries(null, groups, sort, asc, offset, limit, null);
    long visibleCount = entryDAO.visibleEntryCount(null, groups, null);
    FolderDetails details = new FolderDetails();
    details.setCount(visibleCount);
    for (Entry entry : results) {
        try {
            PartData info = ModelToInfoFactory.createTableViewData(null, entry, false);
            info.setPublicRead(true);
            details.getEntries().add(info);
        } catch (Exception e) {
            Logger.error(e);
        }
    }
    return details;
}
Also used : Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionException(org.jbei.ice.lib.access.PermissionException) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

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