Search in sources :

Example 21 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class EntryCreator method createEntry.

/**
     * Create an entry in the database.
     * <p/>
     * Generates a new Part Number, the record id (UUID), version id, and timestamps.
     * Optionally set the record globally visible or schedule an index rebuild.
     *
     * @param account           account of user creating entry
     * @param entry             entry record being created
     * @param accessPermissions list of permissions to associate with created entry
     * @return entry that was saved in the database.
     */
public Entry createEntry(Account account, Entry entry, ArrayList<AccessPermission> accessPermissions) {
    if (entry.getRecordId() == null) {
        entry.setRecordId(Utils.generateUUID());
        entry.setVersionId(entry.getRecordId());
    }
    entry.setCreationTime(Calendar.getInstance().getTime());
    entry.setModificationTime(entry.getCreationTime());
    if (StringUtils.isEmpty(entry.getOwner()))
        entry.setOwner(account.getFullName());
    if (StringUtils.isEmpty(entry.getOwnerEmail()))
        entry.setOwnerEmail(account.getEmail());
    if (entry.getSelectionMarkers() != null) {
        for (SelectionMarker selectionMarker : entry.getSelectionMarkers()) {
            selectionMarker.setEntry(entry);
        }
    }
    if (entry.getLinks() != null) {
        for (Link link : entry.getLinks()) {
            link.setEntry(entry);
        }
    }
    if (entry.getStatus() == null)
        entry.setStatus("");
    if (entry.getBioSafetyLevel() == null)
        entry.setBioSafetyLevel(0);
    entry = dao.create(entry);
    // check for pi
    String piEmail = entry.getPrincipalInvestigatorEmail();
    if (StringUtils.isNotEmpty(piEmail)) {
        Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail);
        if (pi != null) {
            // add write permission for the PI
            addWritePermission(pi, entry);
        }
    }
    // add write permissions for owner
    addWritePermission(account, entry);
    // add read permission for all public groups
    ArrayList<Group> groups = new GroupController().getAllPublicGroupsForAccount(account);
    for (Group group : groups) {
        addReadPermission(null, group, entry);
    }
    if (accessPermissions != null) {
        for (AccessPermission accessPermission : accessPermissions) {
            if (accessPermission.getArticle() == AccessPermission.Article.ACCOUNT) {
                Account accessAccount = DAOFactory.getAccountDAO().get(accessPermission.getArticleId());
                // add account read permission
                addReadPermission(accessAccount, null, entry);
            } else {
                // add group read permission
                Group group = DAOFactory.getGroupDAO().get(accessPermission.getArticleId());
                addReadPermission(null, group, entry);
            }
        }
    }
    // rebuild blast database
    if (sequenceDAO.hasSequence(entry.getId())) {
        BlastPlus.scheduleBlastIndexRebuildTask(true);
    }
    return entry;
}
Also used : GroupController(org.jbei.ice.lib.group.GroupController) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 22 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission 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 23 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class EntryPermissions method add.

/**
     * Adds a new permission to the specified entry. If the entry does not exist, a new one is created
     *
     * @param access permissions to be added to the entry
     * @return created permission if successful, null otherwise
     * @throws PermissionException if the requesting user does not have write permissions on the entry
     */
public AccessPermission add(AccessPermission access) {
    if (access == null)
        return null;
    authorization.expectWrite(userId, entry);
    Permission permission = addPermission(access, entry, null, null);
    if (permission == null)
        return null;
    return permission.toDataTransferObject();
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) Permission(org.jbei.ice.storage.model.Permission)

Example 24 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class FolderPermissionsTest method testCreateFolderPermission.

@Test
public void testCreateFolderPermission() throws Exception {
    Account account = AccountCreator.createTestAccount("FolderPermissionsTest.testCreateFolderPermission", false);
    String userId = account.getEmail();
    Folder folder = new Folder();
    folder.setOwnerEmail(userId);
    folder.setType(FolderType.PRIVATE);
    folder.setDescription("test folder");
    folder.setName("test");
    folder = DAOFactory.getFolderDAO().create(folder);
    Assert.assertNotNull(folder);
    FolderPermissions folderPermissions = new FolderPermissions(userId, folder.getId());
    AccessPermission accessPermission = new AccessPermission();
    // create a new account
    Account account2 = AccountCreator.createTestAccount("FolderPermissionsTest.testCreateFolderPermission2", false);
    // give read permission to folder for account
    accessPermission.setArticle(AccessPermission.Article.ACCOUNT);
    accessPermission.setType(AccessPermission.Type.READ_FOLDER);
    accessPermission.setArticleId(account2.getId());
    accessPermission.setTypeId(folder.getId());
    Assert.assertNotNull(folderPermissions.createPermission(accessPermission));
}
Also used : Account(org.jbei.ice.storage.model.Account) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) Folder(org.jbei.ice.storage.model.Folder) Test(org.junit.Test)

Example 25 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class PermissionsController method addPermission.

protected Permission addPermission(AccessPermission access, Entry entry, Folder folder, BulkUpload upload) {
    // 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 (dao.hasPermission(entry, folder, upload, account, group, access.isCanRead(), access.isCanWrite())) {
        return dao.retrievePermission(entry, folder, upload, account, group, access.isCanRead(), access.isCanWrite());
    }
    // add the permission if not
    Permission permission = new Permission();
    permission.setEntry(entry);
    if (entry != null)
        entry.getPermissions().add(permission);
    permission.setGroup(group);
    permission.setFolder(folder);
    permission.setUpload(upload);
    permission.setAccount(account);
    permission.setCanRead(access.isCanRead());
    permission.setCanWrite(access.isCanWrite());
    return dao.create(permission);
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Aggregations

AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)34 Account (org.jbei.ice.storage.model.Account)8 Test (org.junit.Test)6 PermissionsController (org.jbei.ice.lib.access.PermissionsController)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)5 ArrayList (java.util.ArrayList)4 GroupController (org.jbei.ice.lib.group.GroupController)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 Group (org.jbei.ice.storage.model.Group)3 Permission (org.jbei.ice.storage.model.Permission)3 Date (java.util.Date)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 FolderAuthorization (org.jbei.ice.lib.dto.folder.FolderAuthorization)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 EntryPermissionTask (org.jbei.ice.lib.entry.EntryPermissionTask)1 Collections (org.jbei.ice.lib.folder.collection.Collections)1 Folder (org.jbei.ice.storage.model.Folder)1 Plasmid (org.jbei.ice.storage.model.Plasmid)1 RemotePartner (org.jbei.ice.storage.model.RemotePartner)1 Strain (org.jbei.ice.storage.model.Strain)1