Search in sources :

Example 56 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class CustomFieldsTest method testGetPartsByFields.

@Test
public void testGetPartsByFields() throws Exception {
    // create part
    Account account = AccountCreator.createTestAccount("testGetPartsByFields", false);
    final String userId = account.getEmail();
    Strain strain = TestEntryCreator.createTestStrain(account);
    Assert.assertNotNull(strain);
    // create fields for strain
    long strainId = strain.getId();
    fields.createField(userId, strainId, new CustomField(strainId, "type", "promoter"));
    fields.createField(userId, strainId, new CustomField(strainId, "strength", "weak"));
    // search for strength:weak
    List<CustomField> searchFields = new ArrayList<>();
    searchFields.add(new CustomField("strength", "weak"));
    List<PartData> results = fields.getPartsByFields(userId, searchFields);
    Assert.assertEquals(1, results.size());
    // create additional entry
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    Assert.assertNotNull(plasmid);
    long plasmidId = plasmid.getId();
    fields.createField(userId, plasmidId, new CustomField(plasmidId, "type", "promoter"));
    fields.createField(userId, plasmidId, new CustomField(plasmidId, "strength", "strong"));
    searchFields.clear();
    searchFields.add(new CustomField("strength", "strong"));
    results = fields.getPartsByFields(userId, searchFields);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(plasmid.getId(), results.get(0).getId());
    // search for type:promoter
    searchFields.clear();
    searchFields.add(new CustomField("type", "promoter"));
    results = fields.getPartsByFields(userId, searchFields);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(strain.getId() == results.get(0).getId() || results.get(1).getId() == strain.getId());
    // test two
    searchFields.clear();
    searchFields.add(new CustomField(strainId, "type", "promoter"));
    searchFields.add(new CustomField(strainId, "strength", "weak"));
    results = fields.getPartsByFields(userId, searchFields);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.size() == 1);
    Assert.assertEquals(strain.getId(), results.get(0).getId());
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) ArrayList(java.util.ArrayList) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Example 57 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class CustomFieldsTest method testGetFieldsForPart.

@Test
public void testGetFieldsForPart() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetFieldsForPart", false);
    Assert.assertNotNull(account);
    final String userId = account.getEmail();
    Strain strain = TestEntryCreator.createTestStrain(account);
    Assert.assertNotNull(strain);
    HashSet<Long> ids = new HashSet<>();
    for (int i = 1; i <= 10; i += 1) {
        CustomField field = new CustomField(strain.getId(), "name" + i, "value" + i);
        long id = fields.createField(userId, strain.getId(), field).getId();
        ids.add(id);
    }
    List<CustomField> result = fields.getFieldsForPart(userId, strain.getId());
    Assert.assertNotNull(result);
    Assert.assertTrue(result.size() == 10);
    for (CustomField field : result) {
        Assert.assertTrue(ids.contains(field.getId()));
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Strain(org.jbei.ice.storage.model.Strain) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 58 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class BulkUploadControllerTest method testAutoUpdateBulkUpload.

@Test
public void testAutoUpdateBulkUpload() throws Exception {
    EntryType type = EntryType.STRAIN;
    Account account = AccountCreator.createTestAccount("testAutoUpdateBulkUpload", false);
    BulkUploadAutoUpdate autoUpdate = new BulkUploadAutoUpdate(EntryType.STRAIN);
    autoUpdate.getKeyValue().put(EntryField.LINKS, "google");
    // first auto update. expect it to create a new bulk upload and entry
    autoUpdate = controller.autoUpdateBulkUpload(account.getEmail(), autoUpdate, type);
    Assert.assertNotNull(autoUpdate);
    long entryId = autoUpdate.getEntryId();
    long bulkId = autoUpdate.getBulkUploadId();
    Assert.assertTrue(entryId > 0);
    Assert.assertTrue(bulkId > 0);
    BulkUploadInfo bulkUploadInfo = controller.getBulkImport(account.getEmail(), bulkId, 0, 1000);
    Assert.assertNotNull(bulkUploadInfo);
    EntryDAO dao = DAOFactory.getEntryDAO();
    Entry entry = dao.get(entryId);
    Assert.assertNotNull(entry);
    Assert.assertNotNull(entry.getLinks());
    Assert.assertEquals(1, entry.getLinks().size());
    autoUpdate = new BulkUploadAutoUpdate(EntryType.PLASMID);
    // auto update: expect plasmid and bulk upload with no fields set
    autoUpdate = controller.autoUpdateBulkUpload(account.getEmail(), autoUpdate, type);
    Assert.assertNotNull(autoUpdate);
    entryId = autoUpdate.getEntryId();
    bulkId = autoUpdate.getBulkUploadId();
    Assert.assertTrue(entryId > 0);
    Assert.assertTrue(bulkId > 0);
    entry = dao.get(entryId);
    Assert.assertNotNull(entry);
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) EntryType(org.jbei.ice.lib.dto.entry.EntryType) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO) Test(org.junit.Test)

Example 59 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class BulkUploadControllerTest method testRevertSubmitted.

@Test
public void testRevertSubmitted() throws Exception {
    Account account = AccountCreator.createTestAccount("testRevertSubmitted", false);
    Account admin = AccountCreator.createTestAccount("testRevertSubmitted+Admin", true);
    BulkUploadAutoUpdate autoUpdate = new BulkUploadAutoUpdate(EntryType.ARABIDOPSIS);
    autoUpdate.getKeyValue().put(EntryField.NAME, "JBEI-0001");
    autoUpdate.getKeyValue().put(EntryField.SUMMARY, "this is a test");
    autoUpdate.getKeyValue().put(EntryField.PI, "test");
    autoUpdate.getKeyValue().put(EntryField.STATUS, StatusType.COMPLETE.toString());
    autoUpdate.getKeyValue().put(EntryField.BIO_SAFETY_LEVEL, BioSafetyOption.LEVEL_TWO.getValue());
    autoUpdate.getKeyValue().put(EntryField.SELECTION_MARKERS, "test");
    autoUpdate = controller.autoUpdateBulkUpload(account.getEmail(), autoUpdate, EntryType.ARABIDOPSIS);
    Assert.assertNotNull(autoUpdate);
    Assert.assertTrue(autoUpdate.getEntryId() > 0);
    Assert.assertTrue(autoUpdate.getBulkUploadId() > 0);
    Assert.assertTrue(autoUpdate.getLastUpdate() != null);
    Assert.assertNotNull(controller.getBulkImport(account.getEmail(), autoUpdate.getBulkUploadId(), 0, 0));
    // try to revert. not submitted
    Assert.assertFalse(controller.revertSubmitted(admin, autoUpdate.getBulkUploadId()));
    // actual submission (update status)
    BulkEntryCreator bulkEntryCreator = new BulkEntryCreator();
    bulkEntryCreator.updateStatus(account.getEmail(), autoUpdate.getBulkUploadId(), BulkUploadStatus.PENDING_APPROVAL);
    BulkUploadInfo info = controller.getBulkImport(account.getEmail(), autoUpdate.getBulkUploadId(), 0, 0);
    Assert.assertNotNull(info);
    Assert.assertTrue(controller.revertSubmitted(admin, autoUpdate.getBulkUploadId()));
}
Also used : Account(org.jbei.ice.storage.model.Account) Test(org.junit.Test)

Example 60 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class BulkUploadControllerTest method testApproveBulkImport.

@Test
public void testApproveBulkImport() throws Exception {
    Account account = AccountCreator.createTestAccount("testApproveBulkImport", true);
    //
    // test strain with plasmid
    //
    // create bulk upload draft
    String userId = account.getEmail();
    BulkUploadInfo testInfo = new BulkUploadInfo();
    testInfo.setName("testing");
    testInfo.setType(EntryType.STRAIN.getName());
    testInfo = controller.create(userId, testInfo);
    Assert.assertNotNull(testInfo);
    // create entry for upload
    BulkEntryCreator creator = new BulkEntryCreator();
    PartData strainData = new PartData(EntryType.STRAIN);
    strainData.setName("testStrain");
    ArrayList<String> selectionMarkers = new ArrayList<>();
    selectionMarkers.add("Spectinomycin");
    strainData.setSelectionMarkers(selectionMarkers);
    strainData.setBioSafetyLevel(1);
    strainData.setStatus("Complete");
    strainData.setShortDescription("testing bulk upload");
    strainData.setCreator(account.getFullName());
    strainData.setCreatorEmail(account.getEmail());
    strainData.setPrincipalInvestigator("PI");
    PartData plasmidData = new PartData(EntryType.PLASMID);
    plasmidData.setName("testPlasmid");
    selectionMarkers.clear();
    selectionMarkers.add("Spectinomycin");
    plasmidData.setSelectionMarkers(selectionMarkers);
    plasmidData.setBioSafetyLevel(1);
    //        plasmidData.setStatus("In Progress");
    plasmidData.setShortDescription("testing bulk upload with strain with plasmid");
    plasmidData.setCreator(account.getFullName());
    plasmidData.setCreatorEmail(account.getEmail());
    plasmidData.setPrincipalInvestigator("PI");
    strainData.getLinkedParts().add(plasmidData);
    PartData returnStrainData = creator.createEntry(userId, testInfo.getId(), strainData);
    Assert.assertNotNull(returnStrainData);
    plasmidData.setStatus("In Progress");
    plasmidData = creator.updateEntry(userId, testInfo.getId(), returnStrainData.getLinkedParts().get(0).getId(), plasmidData);
    Assert.assertNotNull(plasmidData);
//        testInfo = controller.submitBulkImportDraft(userId, testInfo.getId());
//        Assert.assertNotNull(testInfo);
//        Assert.assertEquals(testInfo.getStatus(), BulkUploadStatus.PENDING_APPROVAL);
}
Also used : Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Account (org.jbei.ice.storage.model.Account)153 Test (org.junit.Test)71 Group (org.jbei.ice.storage.model.Group)24 Entry (org.jbei.ice.storage.model.Entry)21 Strain (org.jbei.ice.storage.model.Strain)20 PartData (org.jbei.ice.lib.dto.entry.PartData)18 Folder (org.jbei.ice.storage.model.Folder)18 ArrayList (java.util.ArrayList)16 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 PermissionException (org.jbei.ice.lib.access.PermissionException)11 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)10 Plasmid (org.jbei.ice.storage.model.Plasmid)10 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)8 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 DAOException (org.jbei.ice.storage.DAOException)8 RemotePartner (org.jbei.ice.storage.model.RemotePartner)8 HibernateException (org.hibernate.HibernateException)7 HashSet (java.util.HashSet)6 Part (org.jbei.ice.storage.model.Part)6