use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.
the class EntryControllerTest method testMoveEntriesToTrash.
@Test
public void testMoveEntriesToTrash() throws Exception {
Account account = AccountCreator.createTestAccount("testMoveEntriesToTrash", false);
String email = account.getEmail();
long id1 = TestEntryCreator.createTestPart(email);
Entry entry1 = controller.getEntry(Long.toString(id1));
Assert.assertNotNull(entry1);
PartData partData1 = ModelToInfoFactory.getInfo(entry1);
Assert.assertNotNull(partData1);
ArrayList<PartData> toTrash1 = new ArrayList<>();
toTrash1.add(partData1);
Assert.assertNotNull(toTrash1);
Assert.assertEquals(toTrash1.size(), 1);
Assert.assertTrue(controller.moveEntriesToTrash(email, toTrash1));
long id2 = TestEntryCreator.createTestPart(email);
Entry entry2 = controller.getEntry(Long.toString(id2));
Assert.assertNotNull(entry2);
PartData partData2 = ModelToInfoFactory.getInfo(entry2);
Assert.assertNotNull(partData2);
long id3 = TestEntryCreator.createTestPart(email);
Entry entry3 = controller.getEntry(Long.toString(id3));
Assert.assertNotNull(entry3);
PartData partData3 = ModelToInfoFactory.getInfo(entry3);
Assert.assertNotNull(partData3);
ArrayList<PartData> toTrash2 = new ArrayList<>();
toTrash2.add(partData2);
toTrash2.add(partData3);
Assert.assertNotNull(toTrash2);
Assert.assertEquals(toTrash2.size(), 2);
Assert.assertTrue(controller.moveEntriesToTrash(email, toTrash2));
}
use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.
the class EntryControllerTest method testUpdatePart.
@Test
public void testUpdatePart() throws Exception {
Account account = AccountCreator.createTestAccount("testUpdatePart", false);
String email = account.getEmail();
long id = TestEntryCreator.createTestPart(email);
Entry entry = controller.getEntry(Long.toString(id));
Assert.assertNotNull(entry);
PartData partData = ModelToInfoFactory.getInfo(entry);
Assert.assertNotNull(partData);
partData.setAlias("testUpdatePartAlias");
long updated = controller.updatePart(email, id, partData);
Assert.assertEquals(id, updated);
entry = controller.getEntry(Long.toString(id));
Assert.assertEquals("testUpdatePartAlias", entry.getAlias());
// add links
partData.getLinks().add("a");
partData.getLinks().add("b");
controller.updatePart(email, id, partData);
entry = controller.getEntry(Long.toString(id));
Assert.assertNotNull(entry);
Assert.assertEquals(2, entry.getLinks().size());
}
use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.
the class EntryLinksTest method testGetParents.
@Test
public void testGetParents() throws Exception {
Account account = AccountCreator.createTestAccount("testGetParents", false);
String userId = account.getEmail();
// add plasmid links to strain
Strain strain = TestEntryCreator.createTestStrain(account);
EntryLinks entryLinks = new EntryLinks(userId, Long.toString(strain.getId()));
Assert.assertEquals(0, entryLinks.getParents().size());
// attempt to add as a parent (expected to fail)
Plasmid plasmid1 = TestEntryCreator.createTestPlasmid(account);
Assert.assertFalse(entryLinks.addLink(plasmid1.toDataTransferObject(), LinkType.PARENT));
// now add as a child
Assert.assertTrue(entryLinks.addLink(plasmid1.toDataTransferObject(), LinkType.CHILD));
// add second plasmid
Plasmid plasmid2 = TestEntryCreator.createTestPlasmid(account);
Assert.assertTrue(entryLinks.addLink(plasmid2.toDataTransferObject(), LinkType.CHILD));
List<PartData> children = entryLinks.getChildren();
Assert.assertEquals(2, children.size());
EntryLinks plasmidLinks = new EntryLinks(userId, Long.toString(plasmid1.getId()));
Assert.assertEquals(1, plasmidLinks.getParents().size());
EntryLinks plasmid2Links = new EntryLinks(userId, Long.toString(plasmid2.getId()));
Assert.assertEquals(1, plasmid2Links.getParents().size());
}
use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.
the class EntryLinksTest method testGetChildren.
@Test
public void testGetChildren() throws Exception {
Account account = AccountCreator.createTestAccount("testGetChildren", false);
String userId = account.getEmail();
// create alternate account
Account account2 = AccountCreator.createTestAccount("testGetChildren2", true);
// add plasmid links to strain
Strain strain = TestEntryCreator.createTestStrain(account);
EntryLinks entryLinks = new EntryLinks(userId, Long.toString(strain.getId()));
Assert.assertEquals(0, entryLinks.getChildren().size());
// attempt to add as a parent (expected to fail)
Plasmid plasmid1 = TestEntryCreator.createTestPlasmid(account);
Assert.assertFalse(entryLinks.addLink(plasmid1.toDataTransferObject(), LinkType.PARENT));
// now add as a child
Assert.assertTrue(entryLinks.addLink(plasmid1.toDataTransferObject(), LinkType.CHILD));
// add second plasmid
Plasmid plasmid2 = TestEntryCreator.createTestPlasmid(account);
Assert.assertTrue(entryLinks.addLink(plasmid2.toDataTransferObject(), LinkType.CHILD));
List<PartData> children = entryLinks.getChildren();
Assert.assertEquals(2, children.size());
// create plasmid for alternate account
Strain alternateStrain = TestEntryCreator.createTestStrain(account2);
// add as child to account's strain
EntryLinks alternateLinks = new EntryLinks(account2.getEmail(), Long.toString(strain.getId()));
Assert.assertTrue(alternateLinks.addLink(alternateStrain.toDataTransferObject(), LinkType.CHILD));
// account2 should see three children (since it is an admin)
Assert.assertEquals(3, alternateLinks.getChildren().size());
// but account should still see 2 since it does not have read permissions on account2's entry
Assert.assertEquals(2, entryLinks.getChildren().size());
}
use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.
the class Entries method validateEntries.
/**
* @param stream csv file input stream
*/
public List<ParsedEntryId> validateEntries(InputStream stream) throws IOException {
List<ParsedEntryId> accepted = new ArrayList<>();
EntryAuthorization authorization = new EntryAuthorization();
try (CSVReader reader = new CSVReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
List<String[]> results = reader.readAll();
for (String[] result : results) {
if (result[0].isEmpty())
continue;
Entry entry = dao.getByPartNumber(result[0]);
if (entry == null || !authorization.canRead(this.userId, entry)) {
accepted.add(new ParsedEntryId(result[0], null));
continue;
}
PartData partData = new PartData(EntryType.nameToType(entry.getRecordType()));
partData.setPartId(entry.getPartNumber());
partData.setId(entry.getId());
accepted.add(new ParsedEntryId(result[0], partData));
}
}
return accepted;
}
Aggregations