use of org.jbei.ice.lib.dto.sample.PartSample in project ice by JBEI.
the class SampleService method createSample.
public PartSample createSample(String userId, String entryId, PartSample partSample, String strainNamePrefix) {
Entry entry = super.getEntry(entryId);
if (entry == null) {
Logger.error("Could not retrieve entry with id " + entryId + ". Skipping sample creation");
return null;
}
entryAuthorization.expectWrite(userId, entry);
Sample sample = SampleCreator.createSampleObject(partSample.getLabel(), userId, "");
sample.setEntry(entry);
String depositor;
if (partSample.getDepositor() == null) {
depositor = userId;
} else {
depositor = partSample.getDepositor().getEmail();
}
StorageLocation mainLocation = partSample.getLocation();
// check and create the storage locations
if (mainLocation != null) {
Storage currentStorage;
switch(mainLocation.getType()) {
case ADDGENE:
currentStorage = createStorage(depositor, mainLocation.getDisplay(), mainLocation.getType());
currentStorage = storageDAO.create(currentStorage);
break;
case PLATE96:
currentStorage = createPlate96Location(depositor, mainLocation);
break;
case SHELF:
currentStorage = createShelfStorage(depositor, mainLocation);
break;
default:
currentStorage = storageDAO.get(mainLocation.getId());
if (currentStorage == null) {
currentStorage = createStorage(userId, mainLocation.getDisplay(), mainLocation.getType());
currentStorage = storageDAO.create(currentStorage);
}
currentStorage = createChildrenStorage(mainLocation, currentStorage, depositor);
}
if (currentStorage == null)
return null;
sample.setStorage(currentStorage);
}
// create sample. If main location is null then sample is created without location
sample = dao.create(sample);
String name = entry.getName();
if (strainNamePrefix != null && name != null && !name.startsWith(strainNamePrefix)) {
entryDAO.generateNextStrainNameForEntry(entry, strainNamePrefix);
}
return sample.toDataTransferObject();
}
use of org.jbei.ice.lib.dto.sample.PartSample in project ice by JBEI.
the class SampleService method getSamplesByBarcode.
public ArrayList<PartSample> getSamplesByBarcode(String userId, String barcode) {
Storage storage = storageDAO.retrieveStorageTube(barcode);
if (storage == null)
return null;
List<Sample> samples = dao.getSamplesByStorage(storage);
ArrayList<PartSample> partSamples = new ArrayList<>();
for (Sample sample : samples) {
Entry entry = sample.getEntry();
if (entry == null)
continue;
Logger.info(entry.getName());
if (!entryAuthorization.canRead(userId, entry))
continue;
partSamples.add(sample.toDataTransferObject());
}
return partSamples;
}
Aggregations