Search in sources :

Example 76 with Account

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

the class GroupControllerTest method testRetrieveGroupMembers.

@Test
public void testRetrieveGroupMembers() throws Exception {
    Account a1 = AccountCreator.createTestAccount("testRetrieveGroupMembers1", false);
    AccountCreator.createTestAccount("testRetrieveGroupMembers2", false);
    AccountCreator.createTestAccount("testRetrieveGroupMembers3", false);
    UserGroup user = new UserGroup();
    user.setDescription("desc");
    user.setLabel("label");
    user.setType(GroupType.PRIVATE);
    // create group
    user = controller.createGroup(a1.getEmail(), user);
    Assert.assertNotNull(user);
}
Also used : Account(org.jbei.ice.storage.model.Account) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 77 with Account

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

the class FolderAuthorization method canRead.

public boolean canRead(String userId, Folder folder) {
    if (controller.isPublicVisible(folder))
        return true;
    Account account = getAccount(userId);
    if (account == null)
        return false;
    if (folder.getType() == FolderType.PUBLIC)
        return true;
    if (super.canRead(userId, folder))
        return true;
    // now check actual permissions
    Set<Folder> folders = new HashSet<>();
    folders.add(folder);
    if (controller.groupHasReadPermission(new ArrayList<>(account.getGroups()), folders) || controller.groupHasWritePermission(new ArrayList<>(account.getGroups()), folders))
        return true;
    return controller.accountHasReadPermission(account, folders) || controller.accountHasWritePermission(account, folders);
}
Also used : Account(org.jbei.ice.storage.model.Account) ArrayList(java.util.ArrayList) Folder(org.jbei.ice.storage.model.Folder) HashSet(java.util.HashSet)

Example 78 with Account

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

the class PartDefaults method get.

/**
     * Retrieves and sets the default values for the entry. Some of these values (e.g. PI, and Funding Source)
     * are set by individual users as part of their personal preferences
     *
     * @param type entry type
     * @return PartData object with the retrieve part defaults
     */
public PartData get(EntryType type) {
    PartData partData = new PartData(type);
    PreferencesController preferencesController = new PreferencesController();
    // pi defaults
    String value = preferencesController.getPreferenceValue(userId, PreferenceKey.PRINCIPAL_INVESTIGATOR.name());
    if (value != null) {
        Account piAccount = this.accountDAO.getByEmail(value);
        if (piAccount == null) {
            partData.setPrincipalInvestigator(value);
        } else {
            partData.setPrincipalInvestigator(piAccount.getFullName());
            partData.setPrincipalInvestigatorEmail(piAccount.getEmail());
            partData.setPrincipalInvestigatorId(piAccount.getId());
        }
    }
    // funding source defaults
    value = preferencesController.getPreferenceValue(userId, PreferenceKey.FUNDING_SOURCE.name());
    if (value != null) {
        partData.setFundingSource(value);
    }
    // owner and creator details
    Account account = this.accountDAO.getByEmail(userId);
    if (account != null) {
        partData.setOwner(account.getFullName());
        partData.setOwnerEmail(account.getEmail());
        partData.setCreator(partData.getOwner());
        partData.setCreatorEmail(partData.getOwnerEmail());
    }
    // set the entry type defaults
    return EntryUtil.setPartDefaults(partData);
}
Also used : Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData) PreferencesController(org.jbei.ice.lib.account.PreferencesController)

Example 79 with Account

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

the class EntryPermissionTask method addPermissions.

protected void addPermissions(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;
        }
        // does the permissions already exists
        if (permissionDAO.hasPermission(entry, null, null, account, group, access.isCanRead(), access.isCanWrite()))
            return;
        // add the permission if not
        Permission permission = new Permission();
        permission.setEntry(entry);
        entry.getPermissions().add(permission);
        permission.setGroup(group);
        permission.setFolder(null);
        permission.setUpload(null);
        permission.setAccount(account);
        permission.setCanRead(access.isCanRead());
        permission.setCanWrite(access.isCanWrite());
        permissionDAO.create(permission);
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) Permission(org.jbei.ice.storage.model.Permission) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 80 with Account

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

the class SBOLParser method createNewEntry.

protected long createNewEntry(TopLevel moduleDefinition, SBOLDocument document) {
    String identity = moduleDefinition.getIdentity().toString();
    String description = moduleDefinition.getDescription();
    String name = moduleDefinition.getName();
    Part part = new Part();
    part.setOwner(partData.getOwner());
    part.setOwnerEmail(partData.getOwnerEmail());
    part.setCreator(partData.getCreator());
    part.setCreatorEmail(partData.getCreatorEmail());
    part.setPrincipalInvestigator(partData.getPrincipalInvestigator());
    part.setPrincipalInvestigatorEmail(partData.getPrincipalInvestigatorEmail());
    part.setBioSafetyLevel(partData.getBioSafetyLevel());
    part.setStatus(partData.getStatus());
    description = StringUtils.isEmpty(description) ? partData.getShortDescription() : description;
    name = StringUtils.isEmpty(name) ? moduleDefinition.getDisplayId() : name;
    part.setShortDescription(description);
    part.setName(name);
    EntryCreator entryCreator = new EntryCreator();
    Account account = DAOFactory.getAccountDAO().getByEmail(part.getCreatorEmail());
    Entry entry = entryCreator.createEntry(account, part, null);
    parseToGenBank(document, entry.getName(), entry, moduleDefinition.getIdentity().toString());
    identityEntryMap.put(identity, entry.getId());
    return entry.getId();
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) Part(org.jbei.ice.storage.model.Part) EntryCreator(org.jbei.ice.lib.entry.EntryCreator)

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