Search in sources :

Example 51 with PartData

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));
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) PartData(org.jbei.ice.lib.dto.entry.PartData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 52 with PartData

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());
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) PartData(org.jbei.ice.lib.dto.entry.PartData) Test(org.junit.Test)

Example 53 with PartData

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());
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Example 54 with PartData

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());
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Example 55 with PartData

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;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData) ParsedEntryId(org.jbei.ice.lib.dto.entry.ParsedEntryId)

Aggregations

PartData (org.jbei.ice.lib.dto.entry.PartData)62 Entry (org.jbei.ice.storage.model.Entry)22 Account (org.jbei.ice.storage.model.Account)18 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 Results (org.jbei.ice.lib.dto.common.Results)5 EntryField (org.jbei.ice.lib.dto.entry.EntryField)4 Group (org.jbei.ice.storage.model.Group)4 Strain (org.jbei.ice.storage.model.Strain)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 PermissionException (org.jbei.ice.lib.access.PermissionException)3 SearchResult (org.jbei.ice.lib.dto.search.SearchResult)3 SearchResults (org.jbei.ice.lib.dto.search.SearchResults)3 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)3 GroupController (org.jbei.ice.lib.group.GroupController)3 EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)3 Plasmid (org.jbei.ice.storage.model.Plasmid)3 RemotePartner (org.jbei.ice.storage.model.RemotePartner)3