Search in sources :

Example 1 with Group

use of org.jbei.ice.storage.model.Group 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 Group

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

the class VisibleEntries method getEntries.

public List<PartData> getEntries(ColumnField field, boolean asc, int start, int limit, String filter) {
    List<Entry> results;
    if (isAdmin) {
        // no filters
        results = dao.retrieveAllEntries(field, asc, start, limit, filter);
    } else {
        // retrieve groups for account and filter by permission
        Set<Group> accountGroups = new HashSet<>(account.getGroups());
        accountGroups.add(everybodyGroup);
        results = dao.retrieveVisibleEntries(account, accountGroups, field, asc, start, limit, filter);
    }
    ArrayList<PartData> data = new ArrayList<>();
    for (Entry entry : results) {
        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) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData) HashSet(java.util.HashSet)

Example 3 with Group

use of org.jbei.ice.storage.model.Group 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 4 with Group

use of org.jbei.ice.storage.model.Group 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 5 with Group

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

the class GroupController method getAllAccountGroups.

/**
     * Retrieve all parent {@link Group}s of a given {@link Account}.
     *
     * @param account Account to query on.
     * @return Set of Group ids.
     */
protected Set<Long> getAllAccountGroups(Account account) {
    HashSet<Long> accountGroups = new HashSet<>();
    for (Group group : account.getGroups()) {
        accountGroups = getParentGroups(group, accountGroups);
    }
    // Everyone belongs to the everyone group
    Group everybodyGroup = createOrRetrievePublicGroup();
    accountGroups.add(everybodyGroup.getId());
    return accountGroups;
}
Also used : Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) HashSet(java.util.HashSet)

Aggregations

Group (org.jbei.ice.storage.model.Group)62 Account (org.jbei.ice.storage.model.Account)26 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 DAOException (org.jbei.ice.storage.DAOException)15 GroupController (org.jbei.ice.lib.group.GroupController)12 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)9 PartData (org.jbei.ice.lib.dto.entry.PartData)9 PermissionException (org.jbei.ice.lib.access.PermissionException)7 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)7 Entry (org.jbei.ice.storage.model.Entry)7 Test (org.junit.Test)7 HibernateException (org.hibernate.HibernateException)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)4 NativeQuery (org.hibernate.query.NativeQuery)3 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)3 Results (org.jbei.ice.lib.dto.common.Results)3