use of org.jbei.ice.lib.dto.folder.FolderDetails 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.folder.FolderDetails 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);
}
use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class Folders method getCanEditFolders.
/**
* Retrieves list of folders that specified user has write privileges on
*
* @return list of folders
*/
public ArrayList<FolderDetails> getCanEditFolders() {
Account account = this.accountDAO.getByEmail(userId);
Set<Group> accountGroups = new HashSet<>(account.getGroups());
GroupController controller = new GroupController();
Group everybodyGroup = controller.createOrRetrievePublicGroup();
accountGroups.add(everybodyGroup);
List<Folder> folders = dao.getCanEditFolders(account, accountGroups);
folders.addAll(dao.getFoldersByOwner(account));
ArrayList<FolderDetails> result = new ArrayList<>();
for (Folder folder : folders) {
FolderDetails details = folder.toDataTransferObject();
if (folder.getType() == FolderType.REMOTE) {
RemoteAccessModel model = remoteAccessModelDAO.getByFolder(account, folder);
if (model == null) {
result.add(details);
continue;
}
AccountTransfer owner = new AccountTransfer();
owner.setEmail(model.getRemoteClientModel().getEmail());
details.setOwner(owner);
RemotePartner remotePartner = model.getRemoteClientModel().getRemotePartner();
details.setRemotePartner(remotePartner.toDataTransferObject());
}
result.add(details);
}
return result;
}
use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class UserFolder method getFolder.
public FolderDetails getFolder(long folderId) {
Folder folder = DAOFactory.getFolderDAO().get(folderId);
if (folder == null)
throw new IllegalArgumentException("Folder with id " + folderId + " does not exist");
FolderAuthorization folderAuthorization = new FolderAuthorization();
folderAuthorization.expectRead(this.userId, folder);
FolderDetails folderDetails = folder.toDataTransferObject();
Account owner = DAOFactory.getAccountDAO().getByEmail(folder.getOwnerEmail());
if (owner != null) {
folderDetails.setOwner(owner.toDataTransferObject());
}
return folderDetails;
}
use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class FolderController method getTransferredFolders.
public ArrayList<FolderDetails> getTransferredFolders(String userId) {
if (!accountController.isAdministrator(userId))
return new ArrayList<>();
List<Folder> transferredFolders = dao.getFoldersByType(FolderType.TRANSFERRED);
ArrayList<FolderDetails> folderDetails = new ArrayList<>();
for (Folder folder : transferredFolders) {
FolderDetails details = folder.toDataTransferObject();
long folderSize = dao.getFolderSize(folder.getId(), null, false);
details.setCount(folderSize);
if (folder.getCreationTime() != null)
details.setCreationTime(folder.getCreationTime().getTime());
folderDetails.add(details);
}
return folderDetails;
}
Aggregations