use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class RemoteEntries method getPublicEntries.
public PartnerEntries getPublicEntries(long remoteId, int offset, int limit, String sort, boolean asc) {
if (!hasRemoteAccessEnabled())
return null;
RemotePartner partner = this.remotePartnerDAO.get(remoteId);
if (partner == null)
return null;
FolderDetails details;
try {
HashMap<String, Object> queryParams = new HashMap<>();
queryParams.put("offset", offset);
queryParams.put("limit", limit);
queryParams.put("asc", asc);
queryParams.put("sort", sort);
details = this.remoteContact.getFolderEntries(partner.getUrl(), queryParams, partner.getApiKey());
if (details == null)
return null;
} catch (Exception e) {
Logger.error(e);
return null;
}
Results<PartData> results = new Results<>();
results.setData(details.getEntries());
results.setResultCount(details.getCount());
return new PartnerEntries(partner.toDataTransferObject(), results);
}
use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class RemoteTransfer method transferEntries.
/**
* Performs the transfer of the entry objects to the remote partner specified.
* It is the responsibility of the destination to ensure that the hierarchical reln is reconstructed
*
* @param remoteId unique identifier for remote partner the parts are to be transferred to
* @param entries list of entries to be transferred. Note that the entries contain the linked
* entries as well and these may or may not already exist on the recipient
* @return list of ids of the transferred entries. These are the ids on the remote recipient and not this ice instance
*/
public List<Long> transferEntries(long remoteId, List<PartData> entries) {
RemotePartner partner = this.remotePartnerDAO.get(remoteId);
if (partner == null)
throw new IllegalArgumentException("Invalid remote host id: " + remoteId);
int exceptionCount = 0;
String url = partner.getUrl();
List<Long> remoteIds = new LinkedList<>();
for (PartData data : entries) {
try {
// fetch linked parts to enable remote to create the links
if (data.getLinkedParts() != null && !data.getLinkedParts().isEmpty()) {
List<PartData> linkedParts = new ArrayList<>();
for (PartData linkedData : data.getLinkedParts()) {
Entry entry = entryDAO.get(linkedData.getId());
if (entry == null)
continue;
linkedData = ModelToInfoFactory.getInfo(entry);
linkedParts.add(linkedData);
}
data.getLinkedParts().clear();
data.getLinkedParts().addAll(linkedParts);
}
// transfer the part with information about links (if any)
PartData object = remoteContact.transferPart(url, data);
if (object == null) {
exceptionCount += 1;
continue;
}
remoteIds.add(object.getId());
if (data.getLinkedParts() != null) {
remoteIds.addAll(object.getLinkedParts().stream().map(PartData::getId).collect(Collectors.toList()));
}
// transfers attachments and sequences
performTransfer(partner, data);
} catch (Exception e) {
exceptionCount += 1;
if (exceptionCount >= 5) {
Logger.error(e);
Logger.error(exceptionCount + " exceptions encountered during transfer. Aborting");
return null;
}
Logger.error(e);
}
}
return remoteIds;
}
use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class Groups method addGroup.
/**
* Adds group to the list of groups for current user
*
* @param userGroup information about group to be added, including members (local and remote)
* @return added group
*/
public UserGroup addGroup(UserGroup userGroup) {
if (userGroup.getType() == null)
userGroup.setType(GroupType.PRIVATE);
if (userGroup.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
String errMsg = "Non admin '" + userId + "' attempting to create public group";
Logger.error(errMsg);
throw new PermissionException(errMsg);
}
Account account = accountDAO.getByEmail(userId);
Group group = new Group();
group.setUuid(Utils.generateUUID());
group.setLabel(userGroup.getLabel());
group.setDescription(userGroup.getDescription() == null ? "" : userGroup.getDescription());
group.setType(userGroup.getType());
group.setOwner(account);
group.setAutoJoin(userGroup.isAutoJoin());
group.setCreationTime(new Date());
group = dao.create(group);
// add local members
if (userGroup.getMembers() != null && !userGroup.getMembers().isEmpty()) {
for (AccountTransfer accountTransfer : userGroup.getMembers()) {
Account memberAccount = accountDAO.getByEmail(accountTransfer.getEmail());
if (memberAccount == null)
continue;
group.getMembers().add(memberAccount);
memberAccount.getGroups().add(group);
accountDAO.update(memberAccount);
}
}
// add remote members
for (RemoteUser remoteUser : userGroup.getRemoteMembers()) {
RegistryPartner partner = remoteUser.getPartner();
if (partner == null)
continue;
RemotePartner remotePartner = remotePartnerDAO.get(partner.getId());
if (remotePartner == null)
continue;
AccountTransfer accountTransfer = remoteUser.getUser();
if (accountTransfer == null || StringUtils.isEmpty(accountTransfer.getEmail()))
continue;
String email = accountTransfer.getEmail();
RemoteClientModel remoteClientModel = remoteClientModelDAO.getModel(email, remotePartner);
if (remoteClientModel == null) {
remoteClientModel = new RemoteClientModel();
remoteClientModel.setEmail(email);
remoteClientModel.setRemotePartner(remotePartner);
remoteClientModel = remoteClientModelDAO.create(remoteClientModel);
}
remoteClientModel.getGroups().add(group);
remoteClientModelDAO.update(remoteClientModel);
}
return group.toDataTransferObject();
}
use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class RemoteContact method deleteInstanceFromMaster.
/**
* Deletes this instance of ICE from the web of registries master list
*
* @return true, if the master reports correct execution of the request. false otherwise
*/
void deleteInstanceFromMaster(String thisUrl) {
final String NODE_MASTER = Utils.getConfigValue(ConfigurationKey.WEB_OF_REGISTRIES_MASTER);
RemotePartner masterPartner = DAOFactory.getRemotePartnerDAO().getByUrl(NODE_MASTER);
if (masterPartner == null)
return;
IceRestClient client = new IceRestClient(masterPartner.getUrl(), masterPartner.getApiKey());
client.delete("rest/partners/" + thisUrl);
}
use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.
the class GroupsTest method testAddGroup.
@Test
public void testAddGroup() throws Exception {
Account account = AccountCreator.createTestAccount("GroupsTest.testAddGroup", false);
String email = account.getEmail();
UserGroup group = new UserGroup();
group.setLabel("label");
group.setDescription("description");
Account account1 = AccountCreator.createTestAccount("GroupsTest.testAddGroup2", false);
group.getMembers().add(account1.toDataTransferObject());
// add remote account
RemoteUser remoteUser = new RemoteUser();
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setEmail("Remote.GroupsTest.testAddGroup3");
remoteUser.setUser(accountTransfer);
// create remote partner
RemotePartner partner = new RemotePartner();
partner.setUrl("registry-test3.jbei.org");
partner = DAOFactory.getRemotePartnerDAO().create(partner);
remoteUser.setPartner(partner.toDataTransferObject());
group.getRemoteMembers().add(remoteUser);
Groups groups = new Groups(email);
UserGroup result = groups.addGroup(group);
Assert.assertNotNull(result);
result = groups.getGroupMembers(result.getId());
Assert.assertNotNull(result);
Assert.assertEquals(1, result.getMembers().size());
Assert.assertEquals(1, result.getRemoteMembers().size());
}
Aggregations