Search in sources :

Example 1 with EntrySelection

use of org.jbei.ice.lib.entry.EntrySelection in project ice by JBEI.

the class FolderContents method addToRemoteFolder.

// transfer entries to remote partner and add to folder
protected void addToRemoteFolder(Account account, Folder folder, List<Long> entries) {
    RemoteAccessModel remoteAccessModel = remoteAccessModelDAO.getByFolder(account, folder);
    if (remoteAccessModel == null) {
        Logger.error("Could not retrieve remote access for folder " + folder.getId());
        return;
    }
    RemotePartner remotePartner = remoteAccessModel.getRemoteClientModel().getRemotePartner();
    RemoteTransfer remoteTransfer = new RemoteTransfer();
    List<PartData> results = remoteTransfer.getPartsForTransfer(entries);
    List<Long> remoteIds = remoteTransfer.transferEntries(remotePartner.getId(), results);
    FolderDetails remoteFolder = new FolderDetails();
    remoteFolder.setId(Long.decode(remoteAccessModel.getIdentifier()));
    // add transferred entries to the folder
    EntrySelection selection = new EntrySelection();
    selection.getEntries().addAll(remoteIds);
    selection.getDestination().add(remoteFolder);
    selection.setSelectionType(EntrySelectionType.FOLDER);
    String token = remoteAccessModel.getToken();
    remoteContact.addTransferredEntriesToFolder(remotePartner.getUrl(), account.getEmail(), selection, remoteFolder.getId(), token, remotePartner.getApiKey());
}
Also used : EntrySelection(org.jbei.ice.lib.entry.EntrySelection) RemoteTransfer(org.jbei.ice.lib.net.RemoteTransfer) PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails)

Example 2 with EntrySelection

use of org.jbei.ice.lib.entry.EntrySelection in project ice by JBEI.

the class FolderContentsTest method testAddEntrySelection.

@Test
public void testAddEntrySelection() throws Exception {
    // create account
    Account account = AccountCreator.createTestAccount("FolderContentsTest.testAddEntrySelection", true);
    String userId = account.getEmail();
    Account user = AccountCreator.createTestAccount("FolderContentsTest.testAddEntrySelection2", false);
    // create folder
    FolderDetails folderDetails = new FolderDetails();
    folderDetails.setName("testAdd");
    folderDetails.setOwner(user.toDataTransferObject());
    FolderController controller = new FolderController();
    folderDetails = controller.createPersonalFolder(userId, folderDetails);
    Assert.assertNotNull(folderDetails);
    // check folder ownership
    Assert.assertEquals(1, controller.getUserFolders(user.getEmail()).size());
    // entry selection context for adding to folder
    EntrySelection selection = new EntrySelection();
    selection.setSelectionType(EntrySelectionType.FOLDER);
    selection.getDestination().add(folderDetails);
    // create entries
    long id = TestEntryCreator.createTestPart(userId);
    selection.getEntries().add(id);
    id = TestEntryCreator.createTestPart(userId);
    selection.getEntries().add(id);
    // add to folder
    FolderContents folderContents = new FolderContents();
    List<FolderDetails> folders = folderContents.addEntrySelection(userId, selection);
    Assert.assertNotNull(folders);
}
Also used : Account(org.jbei.ice.storage.model.Account) EntrySelection(org.jbei.ice.lib.entry.EntrySelection) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Test(org.junit.Test)

Example 3 with EntrySelection

use of org.jbei.ice.lib.entry.EntrySelection 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;
}
Also used : EntrySelection(org.jbei.ice.lib.entry.EntrySelection) RemotePartner(org.jbei.ice.storage.model.RemotePartner) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails)

Aggregations

FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 EntrySelection (org.jbei.ice.lib.entry.EntrySelection)3 PartData (org.jbei.ice.lib.dto.entry.PartData)1 RemoteTransfer (org.jbei.ice.lib.net.RemoteTransfer)1 Account (org.jbei.ice.storage.model.Account)1 RemotePartner (org.jbei.ice.storage.model.RemotePartner)1 Test (org.junit.Test)1