Search in sources :

Example 1 with StorageLocation

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

the class SampleService method createShelfStorage.

protected Storage createShelfStorage(String depositor, StorageLocation shelf) {
    // expecting [SHELF, BOX, WELL, TUBE]. ultimately the children of the main location
    try {
        StorageLocation box = shelf.getChild();
        StorageLocation well = box.getChild();
        well.getChild();
    } catch (Exception e) {
        return null;
    }
    // should contain type and therefore allow for general hierarchy and more intelligence
    // where it checks if the location is already taken
    // create storage locations
    Storage currentStorage = createStorage(depositor, shelf.getDisplay(), shelf.getType());
    currentStorage = createChildrenStorage(shelf, storageDAO.create(currentStorage), depositor);
    return currentStorage;
}
Also used : StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 2 with StorageLocation

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

the class SampleService method retrieveEntrySamples.

public List<PartSample> retrieveEntrySamples(String userId, String entryId) {
    Entry entry = super.getEntry(entryId);
    if (entry == null)
        return null;
    entryAuthorization.expectRead(userId, entry);
    // samples
    List<Sample> entrySamples = dao.getSamplesByEntry(entry);
    ArrayList<PartSample> samples = new ArrayList<>();
    if (entrySamples == null)
        return samples;
    boolean inCart = false;
    if (userId != null) {
        Account userAccount = accountDAO.getByEmail(userId);
        inCart = DAOFactory.getRequestDAO().getSampleRequestInCart(userAccount, entry) != null;
    }
    ArrayList<Sample> siblingSamples = new ArrayList<>();
    for (Sample sample : entrySamples) {
        Storage storage = sample.getStorage();
        if (storage == null)
            continue;
        if (storage.getParent() != null && storage.getParent().getParent() != null) {
            siblingSamples.addAll(dao.getSamplesByStorage(storage.getParent().getParent()));
        }
    }
    entrySamples.addAll(siblingSamples);
    Set<Sample> unique = new HashSet<>(entrySamples);
    entrySamples = new ArrayList<>(unique);
    for (Sample sample : entrySamples) {
        // convert sample to info
        Storage storage = sample.getStorage();
        if (storage == null) {
            // dealing with sample with no storage
            PartSample generic = sample.toDataTransferObject();
            StorageLocation location = new StorageLocation();
            location.setType(SampleType.GENERIC);
            location.setDisplay(sample.getLabel());
            generic.setLocation(location);
            generic = setAccountInfo(generic, sample.getDepositor());
            samples.add(generic);
            continue;
        }
        StorageLocation storageLocation = storage.toDataTransferObject();
        while (storage.getParent() != null) {
            storage = storage.getParent();
            StorageLocation parentLocation = storage.toDataTransferObject();
            parentLocation.setChild(storageLocation);
            storageLocation = parentLocation;
            boolean isParent = (storageLocation.getType() != null && storageLocation.getType().isTopLevel());
            if (isParent)
                break;
        }
        // get specific sample type and details about it
        PartSample partSample = new PartSample();
        partSample.setId(sample.getId());
        partSample.setPartId(sample.getEntry().getId());
        partSample.setLocation(storageLocation);
        partSample.setPartName(sample.getEntry().getName());
        partSample.setLabel(sample.getLabel());
        if (sample.getEntry().getId() == entry.getId()) {
            partSample.setCreationTime(sample.getCreationTime().getTime());
            partSample.setInCart(inCart);
            partSample.setCanEdit(sampleAuthorization.canWrite(userId, sample));
            if (sample.getComments() != null) {
                for (Comment comment : sample.getComments()) {
                    UserComment userComment = new UserComment();
                    userComment.setId(comment.getId());
                    userComment.setMessage(comment.getBody());
                    partSample.getComments().add(userComment);
                }
            }
        } else {
            partSample.setCanEdit(false);
        }
        partSample = setAccountInfo(partSample, sample.getDepositor());
        samples.add(partSample);
    }
    return samples;
}
Also used : UserComment(org.jbei.ice.lib.dto.comment.UserComment) UserComment(org.jbei.ice.lib.dto.comment.UserComment) PartSample(org.jbei.ice.lib.dto.sample.PartSample) ArrayList(java.util.ArrayList) HasEntry(org.jbei.ice.lib.entry.HasEntry) PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation) HashSet(java.util.HashSet)

Example 3 with StorageLocation

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

the class SampleService method createPlate96Location.

/**
     * Creates location records for a sample contained in a 96 well plate
     * Provides support for 2-D barcoded systems. Validates the storage hierarchy before creating.
     *
     * @param sampleDepositor userID - unique identifier for user performing action
     * @param mainLocation    96 well plate location
     * @return sample storage with a complete hierarchy or null
     */
protected Storage createPlate96Location(String sampleDepositor, StorageLocation mainLocation) {
    // validate: expected format is [PLATE96, WELL, (optional - TUBE)]
    StorageLocation well = mainLocation.getChild();
    StorageLocation tube;
    if (well != null) {
        tube = well.getChild();
        if (tube != null) {
            // just check the barcode
            String barcode = tube.getDisplay();
            Storage existing = storageDAO.retrieveStorageTube(barcode);
            if (existing != null) {
                List<Sample> samples = dao.getSamplesByStorage(existing);
                if (samples != null && !samples.isEmpty()) {
                    Logger.error("Barcode \"" + barcode + "\" already has a sample associated with it");
                    return null;
                }
            }
        }
    } else {
        return null;
    }
    if (tube == null) {
        return null;
    }
    // create storage locations
    Storage currentStorage;
    List<Storage> storageList = storageDAO.retrieveStorageByIndex(mainLocation.getDisplay(), SampleType.PLATE96);
    if (storageList != null && storageList.size() > 0) {
        currentStorage = storageList.get(0);
        // check if there is a sample in that well
        Set<Storage> wells = currentStorage.getChildren();
        for (Storage thisWell : wells) {
            if (thisWell.getIndex().equals(well.getDisplay()) && thisWell.getChildren() != null) {
                Logger.error("Plate " + mainLocation.getDisplay() + " already has a well storage at " + well.getDisplay());
                return null;
            }
        }
    } else {
        currentStorage = createStorage(sampleDepositor, mainLocation.getDisplay(), mainLocation.getType());
        currentStorage = storageDAO.create(currentStorage);
    }
    currentStorage = createChildrenStorage(mainLocation, currentStorage, sampleDepositor);
    return currentStorage;
}
Also used : PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 4 with StorageLocation

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

the class Storage method toDataTransferObject.

@Override
public StorageLocation toDataTransferObject() {
    StorageLocation location = new StorageLocation();
    location.setDisplay(index);
    location.setId(id);
    location.setType(SampleType.toSampleType(storageType.name()));
    location.setName(name);
    return location;
}
Also used : StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 5 with StorageLocation

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

the class SampleServiceTest method testGetSamplesByBarcode.

@Test
public void testGetSamplesByBarcode() throws Exception {
    Account account = AccountCreator.createTestAccount("SampleServiceTest.testGetSamplesByBarcode", false);
    String userId = account.getEmail();
    Strain strain = TestEntryCreator.createTestStrain(account);
    PartSample partSample = new PartSample();
    partSample.setLabel("test");
    StorageLocation location = new StorageLocation();
    location.setDisplay("tube");
    location.setType(SampleType.TUBE);
    partSample.setLocation(location);
    partSample = service.createSample(userId, Long.toString(strain.getId()), partSample, null);
    Assert.assertNotNull(partSample);
    List<PartSample> partSamples = service.getSamplesByBarcode(userId, location.getDisplay());
    Assert.assertNotNull(partSamples);
    Assert.assertEquals(1, partSamples.size());
}
Also used : Account(org.jbei.ice.storage.model.Account) PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Aggregations

StorageLocation (org.jbei.ice.lib.dto.StorageLocation)14 PartSample (org.jbei.ice.lib.dto.sample.PartSample)7 Account (org.jbei.ice.storage.model.Account)3 Strain (org.jbei.ice.storage.model.Strain)3 Test (org.junit.Test)3 UserComment (org.jbei.ice.lib.dto.comment.UserComment)2 HasEntry (org.jbei.ice.lib.entry.HasEntry)2 CSVWriter (com.opencsv.CSVWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Entry (org.jbei.ice.storage.model.Entry)1 Request (org.jbei.ice.storage.model.Request)1