use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class RemoteAccessTest method testAdd.
@Test
public void testAdd() throws Exception {
new ConfigurationSettings().setPropertyValue(ConfigurationKey.JOIN_WEB_OF_REGISTRIES, "true");
// this tests the scenario where a WoR partner shares a remote resource (folder or entry) with a user
// on another instance
Account account = AccountCreator.createTestAccount("RemoteAccessTest.testAdd", false);
RemoteAccess remoteAccess = new RemoteAccess();
// create mock remote partner
RemotePartner partner = new RemotePartner();
partner.setUrl("remote-test.jbei.org");
partner = DAOFactory.getRemotePartnerDAO().create(partner);
// create permission to share with this user
AccessPermission permission = new AccessPermission();
AccountTransfer accountTransfer = new AccountTransfer();
// person sharing
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.setTypeId(Integer.MAX_VALUE);
permission.setSecret("supersekrit");
AccessPermission accessPermission = remoteAccess.add(partner.toDataTransferObject(), permission);
Folder folder = DAOFactory.getFolderDAO().get(accessPermission.getTypeId());
RemoteAccessModel model = DAOFactory.getRemoteAccessModelDAO().getByFolder(account, folder);
Assert.assertNotNull(model);
// shared folder should be in list of shared collection
Collections collections = new Collections(account.getEmail());
List<FolderDetails> subFolders = collections.getSubFolders(CollectionType.SHARED);
boolean found = false;
for (FolderDetails details : subFolders) {
found = details.getName().equalsIgnoreCase(permission.getDisplay()) && Long.toString(permission.getTypeId()).equals(details.getDescription());
if (found)
break;
}
Assert.assertTrue(found);
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class Account method toDataTransferObject.
public AccountTransfer toDataTransferObject() {
AccountTransfer info = new AccountTransfer();
info.setEmail(email);
info.setFirstName(firstName);
info.setLastName(lastName);
info.setInstitution(institution);
info.setDescription(description);
if (lastLoginTime != null)
info.setLastLogin(lastLoginTime.getTime());
if (this.type != null)
info.setAccountType(this.type);
else
info.setAccountType(AccountType.NORMAL);
if (this.creationTime != null)
info.setRegisterDate(this.creationTime.getTime());
info.setId(id);
return info;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class FolderController method createTransferredFolder.
public FolderDetails createTransferredFolder(FolderDetails folderDetails) {
Folder folder = new Folder(folderDetails.getName());
AccountTransfer owner = folderDetails.getOwner();
if (owner != null)
folder.setOwnerEmail(owner.getEmail());
else
folder.setOwnerEmail("transferred");
folder.setType(FolderType.TRANSFERRED);
folder.setCreationTime(new Date(folderDetails.getCreationTime()));
folder = dao.create(folder);
return folder.toDataTransferObject();
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class FolderContents method getRemoteContents.
/**
* Retrieves contents of a folder that has been shared remotely with this instance
*
* @param userId user folder is shared with
* @param folder remote shared folder
* @return wrapper around entries conforming to specified parameters
* @throws IllegalArgumentException if the folder is not of type <code>REMOTE</code>
*/
private FolderDetails getRemoteContents(String userId, Folder folder, PageParameters pageParameters) {
if (folder.getType() != FolderType.REMOTE) {
String errorMessage = "Folder " + folder.getId() + " is not remote and therefore cannot retrieve contents";
Logger.error(errorMessage);
throw new IllegalArgumentException(errorMessage);
}
// get remote access
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
RemoteAccessModel remoteAccessModel = remoteAccessModelDAO.getByFolder(account, folder);
if (remoteAccessModel == null) {
Logger.error("Could not find access model for folder " + folder.getId() + " and user " + userId);
return null;
}
FolderDetails details = folder.toDataTransferObject();
RemoteClientModel remoteClientModel = remoteAccessModel.getRemoteClientModel();
AccountTransfer owner = new AccountTransfer();
owner.setEmail(remoteClientModel.getEmail());
details.setOwner(owner);
RemotePartner remotePartner = remoteClientModel.getRemotePartner();
details.setRemotePartner(remotePartner.toDataTransferObject());
String token = remoteAccessModel.getToken();
// todo : currently folder id only
long remoteFolderId = Long.decode(remoteAccessModel.getIdentifier());
// retrieve entries from remote partner (ends up in the call below)
FolderDetails remoteDetails = remoteContact.getRemoteContents(remotePartner.getUrl(), userId, remoteFolderId, token, pageParameters, remotePartner.getApiKey());
if (remoteDetails == null) {
Logger.error("Could not retrieve remote shared folder " + remoteFolderId + " from " + remotePartner.getUrl());
return null;
}
details.setCount(remoteDetails.getCount());
details.setEntries(remoteDetails.getEntries());
return details;
}
use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.
the class Folders method getCanEditFolders.
/**
* Retrieves list of folders that specified user has write privileges on.
* This excludes folders that are of type <code>SAMPLE</code>
*
* @return list of folders
*/
public List<FolderDetails> getCanEditFolders() {
Account account = this.accountDAO.getByEmail(userId);
Set<Group> accountGroups = getAccountGroups(account);
List<Folder> folders = dao.getCanEditFolders(account, accountGroups);
ArrayList<FolderDetails> result = new ArrayList<>();
for (Folder folder : folders) {
FolderDetails details = folder.toDataTransferObject();
if (folder.getType() == FolderType.REMOTE) {
RemoteAccessModel model = remoteAccessModelDAO.getByFolder(account, folder);
if (model == null) {
result.add(details);
continue;
}
AccountTransfer owner = new AccountTransfer();
owner.setEmail(model.getRemoteClientModel().getEmail());
details.setOwner(owner);
RemotePartner remotePartner = model.getRemoteClientModel().getRemotePartner();
details.setRemotePartner(remotePartner.toDataTransferObject());
}
result.add(details);
}
return result;
}
Aggregations