use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class WebEntries method getSequence.
public FeaturedDNASequence getSequence(String entryId) {
String recordId;
try {
long id = Long.decode(entryId);
Entry entry = this.entryDAO.get(id);
if (entry == null)
recordId = entryId;
else
recordId = entry.getRecordId();
} catch (NumberFormatException ex) {
recordId = entryId;
}
List<RemotePartner> partners = this.remotePartnerDAO.getRegistryPartners();
for (RemotePartner partner : partners) {
if (partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
continue;
FeaturedDNASequence sequence = this.remoteContact.getPublicEntrySequence(partner.getUrl(), recordId, partner.getApiKey());
if (sequence != null)
return sequence;
}
return null;
}
use of org.jbei.ice.storage.model.RemotePartner 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.RemotePartner in project ice by JBEI.
the class RemoteTransfer method transferFolder.
public FolderDetails transferFolder(long remoteId, FolderDetails folderDetails, List<Long> remoteIds) {
RemotePartner partner = this.remotePartnerDAO.get(remoteId);
if (partner == null)
throw new IllegalArgumentException("Invalid remote host id: " + remoteId);
FolderDetails details = remoteContact.transferFolder(partner.getUrl(), folderDetails);
if (folderDetails == null) {
Logger.error("Could not create remote folder");
return null;
}
if (remoteIds == null || remoteIds.isEmpty()) {
Logger.info("Skipping transfer of entries. List is empty");
return details;
}
// move entries to the transferred entries
EntrySelection entrySelection = new EntrySelection();
entrySelection.getEntries().addAll(remoteIds);
entrySelection.getDestination().add(details);
entrySelection.setSelectionType(EntrySelectionType.FOLDER);
remoteContact.addTransferredEntriesToFolder(partner.getUrl(), entrySelection);
return details;
}
use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class WoRController method getRegistryPartners.
public WebOfRegistries getRegistryPartners(boolean approvedOnly) {
WebOfRegistries webOfRegistries = new WebOfRegistries();
webOfRegistries.setWebEnabled(isWebEnabled());
// retrieve actual partners
List<RemotePartner> partners = dao.getRegistryPartners();
ArrayList<RegistryPartner> registryPartners = new ArrayList<>();
for (RemotePartner partner : partners) {
if (approvedOnly && partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
continue;
registryPartners.add(partner.toDataTransferObject());
}
webOfRegistries.setPartners(registryPartners);
return webOfRegistries;
}
use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class RemoteContact method handleRemoteRemoveRequest.
public boolean handleRemoteRemoveRequest(String worToken, String url) {
if (StringUtils.isEmpty(worToken) || StringUtils.isEmpty(url))
return false;
RemotePartner partner = dao.getByUrl(url);
if (partner == null)
return false;
if (!partner.getAuthenticationToken().equals(tokenHash.encrypt(worToken, partner.getSalt()))) {
Logger.error("Attempt to remove remote partner " + url + " with invalid worToken " + worToken);
return false;
}
Logger.info("Deleting partner '" + url + "' at their request");
// todo : contact other instances (if this is a master node)
dao.delete(partner);
return true;
}
Aggregations