use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class Permission method toDataTransferObject.
@Override
public AccessPermission toDataTransferObject() {
AccessPermission access = new AccessPermission();
access.setId(id);
if (group != null) {
access.setArticle(AccessPermission.Article.GROUP);
access.setArticleId(group.getId());
access.setGroup(group.toDataTransferObject());
access.setDisplay(group.getLabel());
} else if (account != null) {
access.setArticle(AccessPermission.Article.ACCOUNT);
access.setArticleId(account.getId());
access.setAccount(account.toDataTransferObject());
access.setDisplay(getAccount().getFullName());
}
AccessPermission.Type type = null;
long id = 0;
if (entry != null) {
type = isCanWrite() ? AccessPermission.Type.WRITE_ENTRY : AccessPermission.Type.READ_ENTRY;
id = getEntry().getId();
} else if (getFolder() != null) {
type = isCanWrite() ? AccessPermission.Type.WRITE_FOLDER : AccessPermission.Type.READ_FOLDER;
id = getFolder().getId();
} else if (upload != null) {
type = isCanWrite() ? AccessPermission.Type.WRITE_UPLOAD : AccessPermission.Type.READ_UPLOAD;
id = upload.getId();
}
access.setType(type);
access.setTypeId(id);
return access;
}
use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class BulkUploadControllerTest method testAddPermission.
@Test
public void testAddPermission() throws Exception {
Account account = AccountCreator.createTestAccount("testAddPermission", false);
BulkUploadInfo info = new BulkUploadInfo();
info.setAccount(account.toDataTransferObject());
info.setType(EntryType.PART.toString());
BulkUploadInfo uploadInfo = controller.create(account.getEmail(), info);
Assert.assertNotNull(uploadInfo);
Account accountFriend = AccountCreator.createTestAccount("testAddPermission2", false);
long id = uploadInfo.getId();
AccessPermission permission = new AccessPermission();
permission.setArticle(AccessPermission.Article.ACCOUNT);
permission.setArticleId(accountFriend.getId());
permission.setType(AccessPermission.Type.READ_UPLOAD);
permission.setTypeId(id);
controller.addPermission(account.getEmail(), id, permission);
List<AccessPermission> permissions = controller.getUploadPermissions(account.getEmail(), id);
Assert.assertNotNull(permissions);
Assert.assertTrue(permissions.size() == 1);
AccessPermission returnedPermission = permissions.get(0);
Assert.assertEquals(returnedPermission.getArticle(), AccessPermission.Article.ACCOUNT);
Assert.assertEquals(returnedPermission.getArticleId(), accountFriend.getId());
Assert.assertEquals(returnedPermission.getType(), AccessPermission.Type.READ_UPLOAD);
Assert.assertEquals(returnedPermission.getTypeId(), id);
}
use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class EntryController method update.
public void update(String userId, Entry entry) {
if (entry == null) {
return;
}
authorization.expectWrite(userId, entry);
entry.setModificationTime(Calendar.getInstance().getTime());
if (entry.getVisibility() == null)
entry.setVisibility(Visibility.OK.getValue());
entry = dao.update(entry);
// check pi email
String piEmail = entry.getPrincipalInvestigatorEmail();
if (StringUtils.isNotEmpty(piEmail)) {
Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail);
if (pi != null) {
// add write permission for the PI (method also checks to see if permission already exists)
AccessPermission accessPermission = new AccessPermission();
accessPermission.setArticle(AccessPermission.Article.ACCOUNT);
accessPermission.setArticleId(pi.getId());
accessPermission.setType(AccessPermission.Type.WRITE_ENTRY);
accessPermission.setTypeId(entry.getId());
permissionsController.addPermission(userId, accessPermission);
}
}
}
use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class RemoteAccessTest method testAdd.
@Test
public void testAdd() throws Exception {
Account account = AccountCreator.createTestAccount("RemoteAccessTest.testAdd", false);
RemoteAccess remoteAccess = new RemoteAccess();
RemotePartner partner = new RemotePartner();
partner.setUrl("registry.jbei.org");
partner = DAOFactory.getRemotePartnerDAO().create(partner);
// create permission to share with this user
AccessPermission permission = new AccessPermission();
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setEmail("I wanna share from far away");
permission.setAccount(accountTransfer);
permission.setDisplay("Folder Name");
permission.setUserId(account.getEmail());
permission.setType(AccessPermission.Type.READ_FOLDER);
permission.setSecret("supersekrit");
remoteAccess.add(partner.toDataTransferObject(), permission);
Collections collections = new Collections(account.getEmail());
List<FolderDetails> subFolders = collections.getSubFolders(CollectionType.SHARED);
Assert.assertEquals(1, subFolders.size());
}
Aggregations