Search in sources :

Example 6 with RemotePartner

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);
}
Also used : HashMap(java.util.HashMap) Results(org.jbei.ice.lib.dto.common.Results) RemotePartner(org.jbei.ice.storage.model.RemotePartner) PartData(org.jbei.ice.lib.dto.entry.PartData) PartnerEntries(org.jbei.ice.lib.dto.web.PartnerEntries) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 7 with RemotePartner

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;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) RemotePartner(org.jbei.ice.storage.model.RemotePartner) PartData(org.jbei.ice.lib.dto.entry.PartData) SequenceAsString(org.jbei.ice.lib.entry.sequence.SequenceAsString) IOException(java.io.IOException)

Example 8 with RemotePartner

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();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 9 with RemotePartner

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);
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) IceRestClient(org.jbei.ice.services.rest.IceRestClient)

Example 10 with RemotePartner

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());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Test(org.junit.Test)

Aggregations

RemotePartner (org.jbei.ice.storage.model.RemotePartner)34 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)10 Account (org.jbei.ice.storage.model.Account)8 PermissionException (org.jbei.ice.lib.access.PermissionException)7 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)6 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteAccessModel (org.jbei.ice.storage.model.RemoteAccessModel)4 Test (org.junit.Test)4 PartData (org.jbei.ice.lib.dto.entry.PartData)3 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)3 Entry (org.jbei.ice.storage.model.Entry)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HibernateException (org.hibernate.HibernateException)2 AccountController (org.jbei.ice.lib.account.AccountController)2 IceRestClient (org.jbei.ice.services.rest.IceRestClient)2 DAOException (org.jbei.ice.storage.DAOException)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2