Search in sources :

Example 11 with PartSample

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();
}
Also used : HasEntry(org.jbei.ice.lib.entry.HasEntry) PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 12 with PartSample

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;
}
Also used : HasEntry(org.jbei.ice.lib.entry.HasEntry) PartSample(org.jbei.ice.lib.dto.sample.PartSample) ArrayList(java.util.ArrayList) PartSample(org.jbei.ice.lib.dto.sample.PartSample)

Aggregations

PartSample (org.jbei.ice.lib.dto.sample.PartSample)12 StorageLocation (org.jbei.ice.lib.dto.StorageLocation)6 Account (org.jbei.ice.storage.model.Account)4 Strain (org.jbei.ice.storage.model.Strain)4 Test (org.junit.Test)4 UserComment (org.jbei.ice.lib.dto.comment.UserComment)3 HasEntry (org.jbei.ice.lib.entry.HasEntry)3 ArrayList (java.util.ArrayList)2 PartData (org.jbei.ice.lib.dto.entry.PartData)2 CSVParser (com.opencsv.CSVParser)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 LineIterator (org.apache.commons.io.LineIterator)1 AttachmentInfo (org.jbei.ice.lib.dto.entry.AttachmentInfo)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 SampleService (org.jbei.ice.lib.entry.sample.SampleService)1 Entry (org.jbei.ice.storage.model.Entry)1 Storage (org.jbei.ice.storage.model.Storage)1