Search in sources :

Example 26 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner 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());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemotePartner(org.jbei.ice.storage.model.RemotePartner) Folder(org.jbei.ice.storage.model.Folder) RemoteAccessModel(org.jbei.ice.storage.model.RemoteAccessModel)

Example 27 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner 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());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemotePartner(org.jbei.ice.storage.model.RemotePartner) Folder(org.jbei.ice.storage.model.Folder) RemoteAccessModel(org.jbei.ice.storage.model.RemoteAccessModel)

Example 28 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner 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());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemotePartner(org.jbei.ice.storage.model.RemotePartner) Folder(org.jbei.ice.storage.model.Folder) RemoteAccessModel(org.jbei.ice.storage.model.RemoteAccessModel)

Example 29 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class Groups method setGroupMembers.

protected void setGroupMembers(Group group, List<AccountTransfer> members, List<RemoteUser> remoteUsers) {
    // 
    // deal with local members
    // 
    Set<String> memberHash = new HashSet<>();
    for (Account member : group.getMembers()) {
        memberHash.add(member.getEmail());
    }
    for (AccountTransfer accountTransfer : members) {
        String email = accountTransfer.getEmail();
        // do not add if found in set
        if (memberHash.remove(email))
            continue;
        // not found so add
        Account memberToAdd = accountDAO.getByEmail(email);
        if (memberToAdd == null) {
            Logger.error("Could not find account " + email + " to add to group");
            continue;
        }
        group.getMembers().add(memberToAdd);
        memberToAdd.getGroups().add(group);
        accountDAO.update(memberToAdd);
    }
    // all emails remaining should be removed
    for (String memberEmail : memberHash) {
        Account memberAccount = accountDAO.getByEmail(memberEmail);
        if (memberAccount == null)
            continue;
        memberAccount.getGroups().remove(group);
        group.getMembers().remove(memberAccount);
        accountDAO.update(memberAccount);
    }
    // 
    // deal with remote users
    // 
    Map<String, RemoteClientModel> remoteMembers = new HashMap<>();
    // get remote members
    List<RemoteClientModel> clients = remoteClientModelDAO.getClientsForGroup(group);
    for (RemoteClientModel clientModel : clients) {
        // technically the same email can be at different instances so adding partner id
        String identifier = (clientModel.getEmail() + clientModel.getRemotePartner().getUrl()).toLowerCase();
        remoteMembers.put(identifier, clientModel);
    }
    for (RemoteUser remoteUser : remoteUsers) {
        String identifier = (remoteUser.getUser().getEmail() + remoteUser.getPartner().getUrl()).toLowerCase();
        // do not add if found in set (already exists)
        if (remoteMembers.remove(identifier) != null)
            continue;
        // add   // todo : duplicates line 147. move to separate method
        RemotePartner remotePartner = remotePartnerDAO.getByUrl(remoteUser.getPartner().getUrl());
        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);
    }
    // remove all remaining
    if (remoteMembers.isEmpty())
        return;
    for (String identifier : remoteMembers.keySet()) {
        RemoteClientModel remoteClientModel = remoteMembers.get(identifier);
        remoteClientModel.getGroups().remove(group);
        remoteClientModelDAO.update(remoteClientModel);
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 30 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class WebPartners method getPartners.

/**
 * Retrieves list of partners for this instance
 *
 * @return list of partners available for this ICE instance or an empty list if this instance is not in web of
 * registries
 */
public List<RegistryPartner> getPartners() {
    if (!isInWebOfRegistries())
        return new ArrayList<>();
    List<RemotePartner> partners = dao.getRegistryPartners();
    List<RegistryPartner> registryPartners = new ArrayList<>();
    if (partners == null)
        return registryPartners;
    for (RemotePartner remotePartner : partners) {
        registryPartners.add(remotePartner.toDataTransferObject());
    }
    return registryPartners;
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) ArrayList(java.util.ArrayList)

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