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));
}
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);
}
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);
}
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;
}
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);
}
Aggregations