Search in sources :

Example 31 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class TransferredPartsTest method testReceiveTransferredEntry.

@Test
public void testReceiveTransferredEntry() throws Exception {
    Account account = AccountCreator.createTestAccount("testReceivedTransferredEntry", false);
    Strain strain = createStrainObject(account);
    Plasmid plasmid = createPlasmidObject(account);
    // link the two
    PartData strainData = strain.toDataTransferObject();
    PartData plasmidData = plasmid.toDataTransferObject();
    strainData.getLinkedParts().add(plasmidData);
    strainData = parts.receiveTransferredEntry(strainData);
    Assert.assertNotNull(strainData);
    strain = (Strain) DAOFactory.getEntryDAO().get(strainData.getId());
    Assert.assertNotNull(strain);
    Assert.assertTrue(strain.getVisibility() == Visibility.TRANSFERRED.getValue());
    plasmid = (Plasmid) DAOFactory.getEntryDAO().get(strainData.getLinkedParts().get(0).getId());
    Assert.assertNotNull(plasmid);
    Assert.assertTrue(plasmid.getVisibility() == Visibility.TRANSFERRED.getValue());
    Assert.assertTrue(strain.getLinkedEntries().contains(plasmid));
    // create new plasmid
    Plasmid plasmid2 = createPlasmidObject(account);
    strainData.getLinkedParts().add(plasmid2.toDataTransferObject());
    Assert.assertEquals(2, strainData.getLinkedParts().size());
    // transfer strain (with 2 linked plasmids)
    PartData received = parts.receiveTransferredEntry(strainData);
    Assert.assertNotNull(received);
    // check return
    strain = (Strain) DAOFactory.getEntryDAO().get(strainData.getId());
    Assert.assertNotNull(strain);
    plasmid = (Plasmid) DAOFactory.getEntryDAO().get(strainData.getLinkedParts().get(0).getId());
    Assert.assertNotNull(plasmid);
    Assert.assertTrue(strain.getLinkedEntries().contains(plasmid));
    plasmid2 = (Plasmid) DAOFactory.getEntryDAO().get(strainData.getLinkedParts().get(1).getId());
    Assert.assertNotNull(plasmid2);
    Assert.assertTrue(strain.getLinkedEntries().contains(plasmid2));
}
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 32 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class EntryDAOTest method testGetByUniqueName.

@Test
public void testGetByUniqueName() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetByUniqueName", false);
    PartData data = new PartData(EntryType.PART);
    data.setShortDescription("summary for test");
    String uniqueName = "pTest" + account.getEmail();
    data.setName(uniqueName);
    data.setBioSafetyLevel(1);
    EntryCreator creator = new EntryCreator();
    creator.createPart(account.getEmail(), data);
    List<Entry> entries = entryDAO.getByName("pTest");
    Assert.assertTrue(entries == null || entries.isEmpty());
    entries = entryDAO.getByName(uniqueName);
    Assert.assertNotNull(entries);
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) EntryCreator(org.jbei.ice.lib.entry.EntryCreator) TestEntryCreator(org.jbei.ice.lib.TestEntryCreator) PartData(org.jbei.ice.lib.dto.entry.PartData) Test(org.junit.Test)

Example 33 with PartData

use of org.jbei.ice.lib.dto.entry.PartData 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)

Example 34 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class EntryCreator method createPart.

/**
     * Creates a new entry using the passed data
     *
     * @param userId unique identifier for user creating entry
     * @param part   data used to create new part
     * @return new part data id and record id information
     */
public PartData createPart(String userId, PartData part) {
    Entry entry = InfoToModelFactory.infoToEntry(part);
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    // linked entries can be a combination of new and existing parts
    if (part.getLinkedParts() != null) {
        for (PartData data : part.getLinkedParts()) {
            Entry linked;
            if (data.getId() > 0) {
                linked = dao.get(data.getId());
                if (linked == null || !entryAuthorization.canRead(userId, linked)) {
                    continue;
                }
                // TODO : may contain new information e.g. if the sequence is uploaded before
                // TODO : this entry was created then the general information is added here
                linked = InfoToModelFactory.updateEntryField(data, linked);
                linked.setVisibility(Visibility.OK.getValue());
                if (entryAuthorization.canWrite(userId, linked)) {
                // then update
                }
            } else {
                // create new linked (can only do one deep)
                Entry linkedEntry = InfoToModelFactory.infoToEntry(data);
                linked = createEntry(account, linkedEntry, data.getAccessPermissions());
            }
            entry.getLinkedEntries().add(linked);
        }
    }
    entry = createEntry(account, entry, part.getAccessPermissions());
    PartData partData = new PartData(part.getType());
    partData.setId(entry.getId());
    partData.setRecordId(entry.getRecordId());
    return partData;
}
Also used : PartData(org.jbei.ice.lib.dto.entry.PartData)

Example 35 with PartData

use of org.jbei.ice.lib.dto.entry.PartData in project ice by JBEI.

the class PartDefaults method get.

/**
     * Retrieves and sets the default values for the entry. Some of these values (e.g. PI, and Funding Source)
     * are set by individual users as part of their personal preferences
     *
     * @param type entry type
     * @return PartData object with the retrieve part defaults
     */
public PartData get(EntryType type) {
    PartData partData = new PartData(type);
    PreferencesController preferencesController = new PreferencesController();
    // pi defaults
    String value = preferencesController.getPreferenceValue(userId, PreferenceKey.PRINCIPAL_INVESTIGATOR.name());
    if (value != null) {
        Account piAccount = this.accountDAO.getByEmail(value);
        if (piAccount == null) {
            partData.setPrincipalInvestigator(value);
        } else {
            partData.setPrincipalInvestigator(piAccount.getFullName());
            partData.setPrincipalInvestigatorEmail(piAccount.getEmail());
            partData.setPrincipalInvestigatorId(piAccount.getId());
        }
    }
    // funding source defaults
    value = preferencesController.getPreferenceValue(userId, PreferenceKey.FUNDING_SOURCE.name());
    if (value != null) {
        partData.setFundingSource(value);
    }
    // owner and creator details
    Account account = this.accountDAO.getByEmail(userId);
    if (account != null) {
        partData.setOwner(account.getFullName());
        partData.setOwnerEmail(account.getEmail());
        partData.setCreator(partData.getOwner());
        partData.setCreatorEmail(partData.getOwnerEmail());
    }
    // set the entry type defaults
    return EntryUtil.setPartDefaults(partData);
}
Also used : Account(org.jbei.ice.storage.model.Account) PartData(org.jbei.ice.lib.dto.entry.PartData) PreferencesController(org.jbei.ice.lib.account.PreferencesController)

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