use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class BulkUploads method deleteDraftById.
/**
* Deletes a bulk import draft referenced by a unique identifier. only owners of the bulk import
* or administrators are permitted to delete bulk imports
*
* @param userId account of user making the request
* @param draftId unique identifier for bulk import
* @return deleted bulk import
* @throws PermissionException if lacking permissions
*/
public BulkUploadInfo deleteDraftById(String userId, long draftId) throws PermissionException {
BulkUpload draft = dao.get(draftId);
if (draft == null)
return null;
Account draftAccount = draft.getAccount();
if (!userId.equals(draftAccount.getEmail()) && !accountController.isAdministrator(userId))
throw new PermissionException("No permissions to delete draft " + draftId);
BulkUploadDeleteTask task = new BulkUploadDeleteTask(userId, draftId);
IceExecutorService.getInstance().runTask(task);
BulkUploadInfo draftInfo = draft.toDataTransferObject();
AccountTransfer accountTransfer = draft.getAccount().toDataTransferObject();
draftInfo.setAccount(accountTransfer);
return draftInfo;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class RemoteAccess method add.
/**
* // todo : check if already shared
* Add access privileges for a user on this instance to enable access
* to a (currently folder only) resource on a remote ICE instance
*
* @param partner remote partner requesting add
* @param accessPermission details of access privilege, including access token and user on this instance
* that the permission is for
* @throws IllegalArgumentException if the permission details is missing some required information or has invalid
* information. e.g. the specified user does not exist on this ICE instance
* @throws PermissionException if this instance is not in a web of registries configuration or it is but
* not with the specified partner
*/
public AccessPermission add(RegistryPartner partner, AccessPermission accessPermission) {
if (!isInWebOfRegistries())
throw new PermissionException("This ICE instance doesn't have WoR enabled");
// person on this site that the permission is for
String userId = accessPermission.getUserId();
// verify that it is valid
Account account = accountDAO.getByEmail(userId);
if (account == null)
throw new IllegalArgumentException("Email address " + userId + " not on this registry instance");
// remote person doing the sharing
AccountTransfer accountTransfer = accessPermission.getAccount();
if (accountTransfer == null || StringUtils.isEmpty(accountTransfer.getEmail()))
throw new IllegalArgumentException("Remote sharer information not available");
// read or write permission
if (!accessPermission.isCanRead() && !accessPermission.isCanWrite())
throw new IllegalArgumentException("Invalid read/write values for permission. Both are false");
// verify secret token
if (StringUtils.isEmpty(accessPermission.getSecret()))
throw new IllegalArgumentException("No access token sent with permission");
// get the remote partner object
RemotePartner remotePartner = remotePartnerDAO.getByUrl(partner.getUrl());
if (remotePartner == null)
throw new IllegalArgumentException("Cannot retrieve remote partner with url " + partner.getUrl());
// email of remote user making share request
String remoteEmail = accountTransfer.getEmail();
// todo : can also be single entry sharing
// create a local folder instance that references a remote folder (can also acts like a cache)
// if remote folder already exists then retrieve it and share that
Folder folder = getOrCreateRemoteFolder(accessPermission.getDisplay(), Long.toString(accessPermission.getTypeId()), remoteEmail);
// get or create the client for the remote user who is sharing the folder
RemoteClientModel remoteClientModel = getOrCreateRemoteClient(remoteEmail, remotePartner);
// store access permission to remote folder for referenced account
Permission permission = createPermissionModel(accessPermission, folder, account);
// remote access model associated with permission and remote client for storing secret
RemoteAccessModel remoteAccessModel = createRemoteAccessModel(accessPermission, remoteClientModel, permission);
return remoteAccessModel.toDataTransferObject();
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class ApiKey method toDataTransferObject.
@Override
public AccessKey toDataTransferObject() {
AccessKey accessKey = new AccessKey();
accessKey.setId(this.id);
accessKey.setSecret(this.secret);
accessKey.setClientId(this.clientId);
accessKey.setCreationTime(this.creationTime.getTime());
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setEmail(this.ownerEmail);
if (this.allowDelegate != null)
accessKey.setAllowDelegate(this.allowDelegate);
if (this.readOnly != null)
accessKey.setReadOnly(this.readOnly);
accessKey.setAccount(accountTransfer);
return accessKey;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class BulkUpload method toDataTransferObject.
public BulkUploadInfo toDataTransferObject() {
BulkUploadInfo bulkUploadInfo = new BulkUploadInfo();
bulkUploadInfo.setCreated(creationTime);
bulkUploadInfo.setId(id);
bulkUploadInfo.setLastUpdate(lastUpdateTime);
bulkUploadInfo.setStatus(status);
bulkUploadInfo.setName(name);
bulkUploadInfo.setType(this.importType);
bulkUploadInfo.setLinkType(this.linkType);
Account draftAccount = getAccount();
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setEmail(draftAccount.getEmail());
accountTransfer.setFirstName(draftAccount.getFirstName());
accountTransfer.setLastName(draftAccount.getLastName());
bulkUploadInfo.setAccount(accountTransfer);
if (permissions != null) {
for (Permission permission : permissions) {
bulkUploadInfo.getPermissions().add(permission.toDataTransferObject());
}
}
return bulkUploadInfo;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class AccountCreator method createTestAccount.
public static Account createTestAccount(String testName, boolean admin) throws Exception {
String email = testName + "@TESTER";
AccountDAO dao = DAOFactory.getAccountDAO();
Account account = dao.getByEmail(email);
if (account != null)
throw new Exception("duplicate account");
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setFirstName("TEST_FNAME");
accountTransfer.setLastName("TEST");
accountTransfer.setEmail(email);
accountTransfer = new AccountController().createNewAccount(accountTransfer, false);
Assert.assertNotNull(accountTransfer.getPassword());
account = dao.getByEmail(email);
Assert.assertNotNull(account);
if (admin) {
account.setType(AccountType.ADMIN);
dao.update(account);
}
return account;
}
Aggregations