Search in sources :

Example 1 with PageParameters

use of org.jbei.ice.lib.dto.common.PageParameters in project ice by JBEI.

the class FolderContentsTest method testGetContents.

@Test
public void testGetContents() throws Exception {
    FolderContents folderContents = new FolderContents();
    // test with null id
    folderContents.getContents(null, 0, new PageParameters(0, 10, ColumnField.PART_ID, false, null));
    Account account = AccountCreator.createTestAccount("testRetrieveFolderContents", false);
    String userId = account.getEmail();
    FolderDetails folderDetails = new FolderDetails();
    folderDetails.setName("test");
    // create folder
    FolderDetails folder = createPersonalFolder(userId, folderDetails);
    Assert.assertNotNull(folder);
    final short size = 105;
    // create 100 test strains
    HashMap<String, Entry> parts = new HashMap<>();
    List<Long> entryList = new ArrayList<>();
    for (int i = 0; i < size; i += 1) {
        Strain strain = TestEntryCreator.createTestStrain(account);
        Assert.assertNotNull(strain);
        parts.put(strain.getPartNumber(), strain);
        entryList.add(strain.getId());
    }
    Assert.assertEquals(size, parts.size());
    // add to folder
    List<FolderDetails> foldersToAdd = new ArrayList<>();
    foldersToAdd.add(folder);
    foldersToAdd = folderContents.addEntriesToFolders(account.getEmail(), entryList, foldersToAdd);
    Assert.assertNotNull(foldersToAdd);
    // keep track to find duplicates
    HashSet<Long> set = new HashSet<>();
    // retrieve (supported sort types created, status, name, part_id, type)
    FolderDetails details = folderContents.getContents(account.getEmail(), folder.getId(), new PageParameters(0, 15, ColumnField.PART_ID, false, null));
    Assert.assertNotNull(details);
    short pageSize = 15;
    int it = 1;
    while (!details.getEntries().isEmpty()) {
        Assert.assertEquals(pageSize, details.getEntries().size());
        for (PartData partData : details.getEntries()) {
            Assert.assertNotNull(parts.remove(partData.getPartId()));
            Assert.assertFalse(set.contains(partData.getId()));
            set.add(partData.getId());
        }
        // check remaining
        Assert.assertEquals((size - (it * pageSize)), parts.size());
        details = folderContents.getContents(account.getEmail(), folder.getId(), new PageParameters(pageSize * it, pageSize, ColumnField.PART_ID, false, null));
        it += 1;
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PageParameters(org.jbei.ice.lib.dto.common.PageParameters) Strain(org.jbei.ice.storage.model.Strain) Entry(org.jbei.ice.storage.model.Entry) PartData(org.jbei.ice.lib.dto.entry.PartData) Test(org.junit.Test)

Example 2 with PageParameters

use of org.jbei.ice.lib.dto.common.PageParameters in project ice by JBEI.

the class FolderDAOTest method testRetrieveFolderContents.

@Test
public void testRetrieveFolderContents() throws Exception {
    Account account = AccountCreator.createTestAccount("FolderDAOTest.testRetrieveFolderContents", false);
    String email = account.getEmail();
    Folder folder = createFolderObject(email);
    folder = dao.create(folder);
    Assert.assertNotNull(folder);
    // add entries to folder
    EntryCreator creator = new EntryCreator();
    List<Entry> entries = new ArrayList<>();
    for (int i = 1; i <= 9; i += 1) {
        Part part = new Part();
        part.setName("name" + i);
        part.setOwnerEmail(email);
        part.setAlias("alias" + i);
        part.setShortDescription("short description");
        Entry entry = creator.createEntry(account, part, null);
        entries.add(entry);
    }
    // add to folder
    folder = dao.addFolderContents(folder, entries);
    Assert.assertNotNull(folder);
    List<Entry> result = dao.retrieveFolderContents(folder.getId(), new PageParameters(0, 15, ColumnField.NAME, true, null), false);
    Assert.assertNotNull(result);
    for (int i = 1; i <= 9; i += 1) {
        Entry entry = result.get(i - 1);
        Assert.assertEquals(entry.getName(), "name" + i);
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) EntryCreator(org.jbei.ice.lib.entry.EntryCreator) Part(org.jbei.ice.storage.model.Part) ArrayList(java.util.ArrayList) PageParameters(org.jbei.ice.lib.dto.common.PageParameters) Folder(org.jbei.ice.storage.model.Folder) Test(org.junit.Test)

Example 3 with PageParameters

use of org.jbei.ice.lib.dto.common.PageParameters in project ice by JBEI.

the class FolderResource method read.

/**
     * Retrieves the entries for specified folder. Handles request
     * from a local client (ui) or from a remote ice instance
     *
     * @return list of retrieved entries wrapped in folder object
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entries")
public FolderDetails read(@PathParam("id") final String folderId, @DefaultValue("0") @QueryParam("offset") final int offset, @DefaultValue("15") @QueryParam("limit") final int limit, @DefaultValue("created") @QueryParam("sort") final String sort, @DefaultValue("false") @QueryParam("asc") final boolean asc, @DefaultValue("") @QueryParam("filter") String filter, // todo: move to headers
@QueryParam("token") String token, // todo : ditto
@QueryParam("userId") String remoteUserId, @QueryParam("fields") List<String> queryParam) {
    try {
        final ColumnField field = ColumnField.valueOf(sort.toUpperCase());
        if (folderId.equalsIgnoreCase("public")) {
            // todo : move to separate rest resource path
            RegistryPartner registryPartner = requireWebPartner();
            // return public entries
            log(registryPartner.getUrl(), "requesting public entries");
            return this.controller.getPublicEntries(field, offset, limit, asc);
        }
        // userId can be empty for public folders
        String userId = super.getUserId();
        try {
            final long id = Long.decode(folderId);
            String message = "retrieving folder " + id + " entries";
            if (filter.length() > 0)
                message += " filtered by \"" + filter + "\"";
            FolderContents folderContents = new FolderContents();
            PageParameters pageParameters = new PageParameters(offset, limit, field, asc, filter);
            if (StringUtils.isEmpty(userId)) {
                if (// todo :verify partner?
                StringUtils.isEmpty(token))
                    return folderContents.getContents(userId, id, pageParameters);
                // get registry partner
                RegistryPartner partner = requireWebPartner();
                log(partner.getUrl(), message);
                return folderContents.getRemotelySharedContents(remoteUserId, token, partner, id, pageParameters);
            } else {
                log(userId, message);
                return folderContents.getContents(userId, id, pageParameters);
            }
        } catch (final NumberFormatException nfe) {
            Logger.error("Passed folder id " + folderId + " is not a number");
            return null;
        }
    } catch (PermissionException e) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) ColumnField(org.jbei.ice.lib.shared.ColumnField) PageParameters(org.jbei.ice.lib.dto.common.PageParameters)

Aggregations

PageParameters (org.jbei.ice.lib.dto.common.PageParameters)3 Account (org.jbei.ice.storage.model.Account)2 Entry (org.jbei.ice.storage.model.Entry)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 PermissionException (org.jbei.ice.lib.access.PermissionException)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)1 ColumnField (org.jbei.ice.lib.shared.ColumnField)1 Folder (org.jbei.ice.storage.model.Folder)1 Part (org.jbei.ice.storage.model.Part)1 Strain (org.jbei.ice.storage.model.Strain)1