Search in sources :

Example 21 with Account

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

the class GroupController method retrieveAccountGroupUUIDs.

public Set<String> retrieveAccountGroupUUIDs(String userId) {
    Account account = accountController.getByEmail(userId);
    Set<String> uuids = new HashSet<>();
    if (account != null) {
        uuids.addAll(dao.getMemberGroupUUIDs(account));
    }
    uuids.add(PUBLIC_GROUP_UUID);
    return uuids;
}
Also used : Account(org.jbei.ice.storage.model.Account) HashSet(java.util.HashSet)

Example 22 with Account

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

the class GroupController method createGroup.

// create group without parent
public UserGroup createGroup(String userId, UserGroup info) {
    if (info.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
        String errMsg = "Non admin " + userId + " attempting to create public group";
        Logger.error(errMsg);
        return null;
    }
    if (info.getType() == null)
        info.setType(GroupType.PRIVATE);
    Account account = accountController.getByEmail(userId);
    Group group = new Group();
    group.setLabel(info.getLabel());
    group.setDescription(info.getDescription() == null ? "" : info.getDescription());
    group.setType(info.getType());
    group.setOwner(account);
    group = save(group);
    for (AccountTransfer accountTransfer : info.getMembers()) {
        Account memberAccount = accountController.getByEmail(accountTransfer.getEmail());
        if (memberAccount == null)
            continue;
        memberAccount.getGroups().add(group);
        accountController.save(memberAccount);
    }
    info = group.toDataTransferObject();
    for (Account addedAccount : group.getMembers()) {
        info.getMembers().add(addedAccount.toDataTransferObject());
    }
    info.setMemberCount(info.getMembers().size());
    return info;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 23 with Account

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

the class Collection method getBulkUploadFolder.

/**
     * Retrieves bulk import and entries associated with it that are referenced by the
     * id in the parameter. Only owners or administrators are allowed to retrieve bulk imports
     *
     * @param id     unique identifier for bulk import
     * @param offset offset for upload entries (start)
     * @param limit  maximum number of entries to return with the upload
     * @return data transfer object with the retrieved bulk import data and associated entries
     * @throws PermissionException
     */
protected AbstractFolder getBulkUploadFolder(long id, int offset, int limit) {
    BulkUploadDAO uploadDAO = DAOFactory.getBulkUploadDAO();
    BulkUploadAuthorization authorization = new BulkUploadAuthorization();
    BulkUpload draft = uploadDAO.get(id);
    if (draft == null)
        return null;
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    authorization.expectRead(account.getEmail(), draft);
    // retrieve the entries associated with the bulk import
    BulkUploadInfo info = draft.toDataTransferObject();
    List<Entry> list = uploadDAO.retrieveDraftEntries(id, offset, limit);
    for (Entry entry : list) {
        PartData partData = setFileData(userId, entry, ModelToInfoFactory.getInfo(entry));
        // check if any links and convert
        if (!entry.getLinkedEntries().isEmpty()) {
            Entry linked = (Entry) entry.getLinkedEntries().toArray()[0];
            PartData linkedData = partData.getLinkedParts().remove(0);
            linkedData = setFileData(userId, linked, linkedData);
            partData.getLinkedParts().add(linkedData);
        }
        info.getEntryList().add(partData);
    }
    info.setCount(uploadDAO.retrieveSavedDraftCount(id));
    return info;
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) BulkUploadAuthorization(org.jbei.ice.lib.bulkupload.BulkUploadAuthorization) PartData(org.jbei.ice.lib.dto.entry.PartData) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo) BulkUpload(org.jbei.ice.storage.model.BulkUpload) BulkUploadDAO(org.jbei.ice.storage.hibernate.dao.BulkUploadDAO)

Example 24 with Account

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

the class TransferTask method execute.

public void execute() {
    RemoteTransfer transfer = new RemoteTransfer();
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    if (account.getType() != AccountType.ADMIN)
        return;
    Entries retriever = new Entries(account.getEmail());
    List<Long> entries = retriever.getEntriesFromSelectionContext(entrySelection);
    Logger.info(userId + ": requesting transfer to " + remoteId);
    List<PartData> dataList = transfer.getPartsForTransfer(entries);
    List<Long> remoteIds = transfer.transferEntries(remoteId, dataList);
    // check folder
    if (StringUtils.isEmpty(this.entrySelection.getFolderId()))
        return;
    // create remoteFolder
    long folderId = Long.decode(this.entrySelection.getFolderId());
    Folder folder = DAOFactory.getFolderDAO().get(folderId);
    Logger.info("Adding " + remoteIds.size() + " transferred entries to remote folder");
    transfer.transferFolder(remoteId, folder.toDataTransferObject(), remoteIds);
}
Also used : Account(org.jbei.ice.storage.model.Account) RemoteTransfer(org.jbei.ice.lib.net.RemoteTransfer) PartData(org.jbei.ice.lib.dto.entry.PartData) Entries(org.jbei.ice.lib.entry.Entries) Folder(org.jbei.ice.storage.model.Folder)

Example 25 with Account

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

the class UserSessions method getUserAccount.

/**
     * Retrieves the account object associated with the session identifier.
     * If the requesting user is not the same as the user associated with the session, then the requesting
     * user is required to have administrative privileges on their account
     *
     * @param requestingUser unique identifier for user making request
     * @param token          unique session identifier
     * @return account associated with the session token/identifier  or null if no account is located
     * @throws PermissionException if the user Id associated with the session token is not the same as the requesting
     *                             user but the requesting user's account does not have administrative privileges
     */
public static AccountTransfer getUserAccount(String requestingUser, String token) {
    String userId = getUserIdBySession(token);
    if (StringUtils.isEmpty(userId))
        return null;
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    if (account == null) {
        Logger.error("Account for userId returned by session (\"" + userId + "\") cannot be found");
        return null;
    }
    AccountController accountController = new AccountController();
    if (!requestingUser.equalsIgnoreCase(userId) && !accountController.isAdministrator(requestingUser))
        throw new PermissionException();
    AccountTransfer accountTransfer = account.toDataTransferObject();
    accountTransfer.setAdmin(accountController.isAdministrator(userId));
    return accountTransfer;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account)

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