Search in sources :

Example 6 with Account

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

the class EntryPermissionTask method removePermissions.

protected void removePermissions(Entry entry) {
    for (AccessPermission access : permissions) {
        // account or group
        Account account = null;
        Group group = null;
        switch(access.getArticle()) {
            case ACCOUNT:
            default:
                account = accountDAO.get(access.getArticleId());
                break;
            case GROUP:
                group = groupDAO.get(access.getArticleId());
                break;
        }
        permissionDAO.removePermission(entry, null, null, account, group, access.isCanRead(), access.isCanWrite());
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 7 with Account

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

the class EntryPermissionTask method execute.

@Override
public void execute() {
    // check if user has write privileges on entries
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    List<Group> accountGroups = new GroupController().getAllGroups(account);
    boolean checkIndividual = false;
    if (account.getType() != AccountType.ADMIN && !permissionDAO.canWrite(account, accountGroups, entries)) {
        checkIndividual = true;
    }
    EntryDAO entryDAO = DAOFactory.getEntryDAO();
    EntryAuthorization entryAuthorization = new EntryAuthorization();
    for (long entryId : entries) {
        Entry entry = entryDAO.get(entryId);
        if (entry == null)
            continue;
        // check permission on individual entries
        if (checkIndividual && !entryAuthorization.canWrite(userId, entry)) {
            continue;
        }
        // add or remove permissions
        if (this.isAdd) {
            addPermissions(entry);
        } else {
            removePermissions(entry);
        }
    }
}
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) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Example 8 with Account

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

the class EntryHistory method get.

public Results<History> get(int limit, int offset, boolean asc, String sort) {
    entryAuthorization.expectWrite(userId, entry);
    List<Audit> list = dao.getAuditsForEntry(entry, limit, offset, asc, sort);
    Results<History> results = new Results<>();
    AccountDAO accountDAO = DAOFactory.getAccountDAO();
    for (Audit audit : list) {
        History history = audit.toDataTransferObject();
        if (history.getPartner() == null) {
            Account account = accountDAO.getByEmail(history.getUserId());
            if (account != null)
                history.setAccount(account.toDataTransferObject());
        }
        results.getData().add(history);
    }
    long count = dao.getHistoryCount(this.entry);
    results.setResultCount(count);
    return results;
}
Also used : Audit(org.jbei.ice.storage.model.Audit) Account(org.jbei.ice.storage.model.Account) Results(org.jbei.ice.lib.dto.common.Results) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) History(org.jbei.ice.lib.dto.History)

Example 9 with Account

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

the class Messages method send.

/**
     * Sends message contained in the MessageInfo to the specified recipients. It some of the
     * recipients do not exist, the routine does its best to deliver as many as possible
     *
     * @param info details of message including recipient(s)
     * @return false if the message fails to be sent to all the intended recipients
     */
public boolean send(MessageInfo info) {
    if (info == null || info.getAccounts().isEmpty() && info.getUserGroups().isEmpty())
        return false;
    boolean success = true;
    Message message = new Message();
    message.setDateSent(new Date());
    message.setFromEmail(this.userId);
    message.setMessage(info.getMessage());
    message.setTitle(info.getTitle());
    if (info.getAccounts() != null) {
        for (AccountTransfer accountTransfer : info.getAccounts()) {
            Account account = accountDAO.getByEmail(accountTransfer.getEmail());
            if (account == null) {
                success = false;
                continue;
            }
            message.getDestinationAccounts().add(account);
        }
    }
    if (info.getUserGroups() != null) {
        for (UserGroup userGroup : info.getUserGroups()) {
            Group group = DAOFactory.getGroupDAO().get(userGroup.getId());
            if (group == null) {
                Logger.warn("Could not retrieve group with id " + userGroup.getId() + " to send message");
                success = false;
                continue;
            }
            message.getDestinationGroups().add(group);
        }
    }
    if (!success)
        return false;
    if (message.getDestinationAccounts().isEmpty() && message.getDestinationGroups().isEmpty())
        return false;
    return dao.create(message) != null;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Message(org.jbei.ice.storage.model.Message) Date(java.util.Date) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 10 with Account

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

the class Messages method get.

public Results<MessageInfo> get(int start, int limit) {
    Account account = accountDAO.getByEmail(this.userId);
    List<Group> groups = DAOFactory.getGroupDAO().retrieveMemberGroups(account);
    List<Message> messages = new ArrayList<>(dao.retrieveMessages(account, groups, start, limit));
    Results<MessageInfo> results = new Results<>();
    for (Message message : messages) {
        Account from = accountDAO.getByEmail(message.getFromEmail());
        if (from == null)
            continue;
        MessageInfo info = new MessageInfo();
        info.setId(message.getId());
        info.setFrom(message.getFromEmail());
        info.setTitle(message.getTitle());
        info.setRead(message.isRead());
        info.setSent(message.getDateSent().getTime());
        results.getData().add(info);
    }
    int totalSize = dao.retrieveMessageCount(account, groups);
    results.setResultCount(totalSize);
    return results;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Message(org.jbei.ice.storage.model.Message) Results(org.jbei.ice.lib.dto.common.Results) ArrayList(java.util.ArrayList) MessageInfo(org.jbei.ice.lib.dto.message.MessageInfo)

Aggregations

Account (org.jbei.ice.storage.model.Account)153 Test (org.junit.Test)71 Group (org.jbei.ice.storage.model.Group)24 Entry (org.jbei.ice.storage.model.Entry)21 Strain (org.jbei.ice.storage.model.Strain)20 PartData (org.jbei.ice.lib.dto.entry.PartData)18 Folder (org.jbei.ice.storage.model.Folder)18 ArrayList (java.util.ArrayList)16 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 PermissionException (org.jbei.ice.lib.access.PermissionException)11 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)10 Plasmid (org.jbei.ice.storage.model.Plasmid)10 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)8 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 DAOException (org.jbei.ice.storage.DAOException)8 RemotePartner (org.jbei.ice.storage.model.RemotePartner)8 HibernateException (org.hibernate.HibernateException)7 HashSet (java.util.HashSet)6 Part (org.jbei.ice.storage.model.Part)6