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;
}
}
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);
}
}
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);
}
}
Aggregations