use of org.jbei.ice.storage.model.RemoteAccessModel in project ice by JBEI.
the class RemoteAccessModelDAO method getByFolder.
public RemoteAccessModel getByFolder(Account account, Folder folder) {
try {
CriteriaQuery<RemoteAccessModel> query = getBuilder().createQuery(RemoteAccessModel.class);
Root<RemoteAccessModel> from = query.from(RemoteAccessModel.class);
Join<RemoteAccessModel, Permission> permission = from.join("permission");
query.where(getBuilder().equal(permission.get("folder"), folder), getBuilder().equal(permission.get("account"), account));
return currentSession().createQuery(query).uniqueResult();
} catch (Exception he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.RemoteAccessModel 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.storage.model.RemoteAccessModel in project ice by JBEI.
the class RemoteEntries method getEntryDetails.
public PartData getEntryDetails(String userId, long folderId, long partId) {
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
Folder folder = DAOFactory.getFolderDAO().get(folderId);
RemoteAccessModel remoteAccessModel = DAOFactory.getRemoteAccessModelDAO().getByFolder(account, folder);
if (remoteAccessModel == null) {
Logger.error("Could not retrieve remote access for folder " + folder.getId());
return null;
}
RemotePartner remotePartner = remoteAccessModel.getRemoteClientModel().getRemotePartner();
String url = remotePartner.getUrl();
String token = remoteAccessModel.getToken();
long remoteFolderId = Long.decode(remoteAccessModel.getIdentifier());
return remoteContact.getRemoteEntry(url, userId, partId, remoteFolderId, token, remotePartner.getApiKey());
}
use of org.jbei.ice.storage.model.RemoteAccessModel in project ice by JBEI.
the class RemoteEntries method retrieveRemoteToolTip.
// contact the remote partner to get the tool tip
public PartData retrieveRemoteToolTip(String userId, long folderId, long partId) {
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
Folder folder = DAOFactory.getFolderDAO().get(folderId);
RemoteAccessModel remoteAccessModel = DAOFactory.getRemoteAccessModelDAO().getByFolder(account, folder);
if (remoteAccessModel == null) {
Logger.error("Could not retrieve remote access for folder " + folder.getId());
return null;
}
RemotePartner remotePartner = remoteAccessModel.getRemoteClientModel().getRemotePartner();
String url = remotePartner.getUrl();
String token = remoteAccessModel.getToken();
return remoteContact.getToolTipDetails(url, userId, partId, token, remotePartner.getApiKey());
}
use of org.jbei.ice.storage.model.RemoteAccessModel in project ice by JBEI.
the class RemoteEntries method getSequence.
public FeaturedDNASequence getSequence(String userId, long folderId, String entryId) {
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
Folder folder = DAOFactory.getFolderDAO().get(folderId);
RemoteAccessModel remoteAccessModel = DAOFactory.getRemoteAccessModelDAO().getByFolder(account, folder);
if (remoteAccessModel == null) {
Logger.error("Could not retrieve remote access for folder " + folder.getId());
return null;
}
RemotePartner remotePartner = remoteAccessModel.getRemoteClientModel().getRemotePartner();
String token = remoteAccessModel.getToken();
long remoteFolderId = Long.decode(remoteAccessModel.getIdentifier());
return remoteContact.getSequence(remotePartner.getUrl(), userId, entryId, remoteFolderId, token, remotePartner.getApiKey());
}
Aggregations