Search in sources :

Example 1 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class Entries method updateVisibility.

public boolean updateVisibility(List<Long> entryIds, Visibility visibility) {
    Account account = accountDAO.getByEmail(userId);
    List<Group> accountGroups = new GroupController().getAllGroups(account);
    if (!new AccountController().isAdministrator(userId) && !permissionDAO.canWrite(account, accountGroups, entryIds))
        return false;
    for (long entryId : entryIds) {
        Entry entry = dao.get(entryId);
        if (entry.getVisibility() == visibility.getValue())
            continue;
        entry.setVisibility(visibility.getValue());
        dao.update(entry);
    }
    return true;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) AccountController(org.jbei.ice.lib.account.AccountController)

Example 2 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class OwnerEntries method retrieveOwnerEntries.

public List<PartData> retrieveOwnerEntries(ColumnField sort, boolean asc, int start, int limit, String filter) {
    List<Entry> entries;
    if (this.isAdmin || this.isSelf) {
        entries = entryDAO.retrieveOwnerEntries(this.ownerAccount.getEmail(), sort, asc, start, limit, filter);
    } else {
        Set<Group> accountGroups = new HashSet<>(account.getGroups());
        GroupController controller = new GroupController();
        Group everybodyGroup = controller.createOrRetrievePublicGroup();
        accountGroups.add(everybodyGroup);
        // retrieve entries for user that can be read by others
        entries = entryDAO.retrieveUserEntries(account, this.ownerAccount.getEmail(), accountGroups, sort, asc, start, limit, filter);
    }
    ArrayList<PartData> data = new ArrayList<>();
    for (Entry entry : entries) {
        PartData info = ModelToInfoFactory.createTableViewData(account.getEmail(), entry, false);
        data.add(info);
    }
    return data;
}
Also used : Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData) HashSet(java.util.HashSet)

Example 3 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class SharedEntries method getEntries.

public List<PartData> getEntries(ColumnField field, boolean asc, int start, int limit, String filter) {
    GroupController groupController = new GroupController();
    Group publicGroup = groupController.createOrRetrievePublicGroup();
    Set<Group> accountGroups = account.getGroups();
    accountGroups.remove(publicGroup);
    List<Entry> entries = this.entryDAO.sharedWithUserEntries(account, accountGroups, field, asc, start, limit, filter);
    ArrayList<PartData> data = new ArrayList<>();
    for (Entry entry : entries) {
        PartData info = ModelToInfoFactory.createTableViewData(account.getEmail(), entry, false);
        data.add(info);
    }
    return data;
}
Also used : Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData)

Example 4 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class BulkUploadController method create.

/**
     * Creates a new bulk upload. If upload type is not bulk edit, then the status is set to in progress.
     * Default permissions consisting of read permissions for the public groups that the requesting user is
     * a part of are added
     *
     * @param userId identifier for user making request
     * @param info   bulk upload data
     * @return created upload
     */
public BulkUploadInfo create(String userId, BulkUploadInfo info) {
    Account account = accountController.getByEmail(userId);
    BulkUpload upload = new BulkUpload();
    upload.setName(info.getName());
    upload.setAccount(account);
    upload.setCreationTime(new Date());
    upload.setLastUpdateTime(upload.getCreationTime());
    if (info.getStatus() == BulkUploadStatus.BULK_EDIT) {
        // only one instance of bulk edit is allowed to remain
        clearBulkEdits(userId);
        upload.setStatus(BulkUploadStatus.BULK_EDIT);
    } else
        upload.setStatus(BulkUploadStatus.IN_PROGRESS);
    upload.setImportType(info.getType());
    // set default permissions
    GroupController groupController = new GroupController();
    ArrayList<Group> publicGroups = groupController.getAllPublicGroupsForAccount(account);
    for (Group group : publicGroups) {
        Permission permission = new Permission();
        permission.setCanRead(true);
        permission.setUpload(upload);
        permission.setGroup(group);
        permission = DAOFactory.getPermissionDAO().create(permission);
        upload.getPermissions().add(permission);
    }
    upload = dao.create(upload);
    if (info.getEntryList() != null) {
        for (PartData data : info.getEntryList()) {
            Entry entry = entryDAO.get(data.getId());
            // todo if entry is in another bulk upload, then update will fail
            if (entry == null)
                continue;
            upload.getContents().add(entry);
        }
    }
    dao.update(upload);
    return upload.toDataTransferObject();
}
Also used : GroupController(org.jbei.ice.lib.group.GroupController) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 5 with GroupController

use of org.jbei.ice.lib.group.GroupController 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

GroupController (org.jbei.ice.lib.group.GroupController)25 Group (org.jbei.ice.storage.model.Group)12 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 PartData (org.jbei.ice.lib.dto.entry.PartData)8 HashSet (java.util.HashSet)6 Entry (org.jbei.ice.storage.model.Entry)6 ArrayList (java.util.ArrayList)5 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Account (org.jbei.ice.storage.model.Account)4 CSVWriter (com.opencsv.CSVWriter)3 Path (java.nio.file.Path)3 AccountController (org.jbei.ice.lib.account.AccountController)3 EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)3 ZipEntry (java.util.zip.ZipEntry)2 PermissionException (org.jbei.ice.lib.access.PermissionException)2 EntryFieldLabel (org.jbei.ice.lib.dto.entry.EntryFieldLabel)2 RebuildBlastIndexTask (org.jbei.ice.lib.search.blast.RebuildBlastIndexTask)2 ZipOutputStream (java.util.zip.ZipOutputStream)1 PermissionsController (org.jbei.ice.lib.access.PermissionsController)1 ConfigurationSettings (org.jbei.ice.lib.config.ConfigurationSettings)1