Search in sources :

Example 1 with PartSample

use of org.jbei.ice.lib.dto.sample.PartSample 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 2 with PartSample

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

the class Sample method toDataTransferObject.

@Override
public PartSample toDataTransferObject() {
    PartSample sample = new PartSample();
    sample.setLabel(label);
    if (entry != null)
        sample.setPartId(entry.getId());
    sample.setCreationTime(creationTime.getTime());
    if (this.getStorage() != null)
        sample.setLocation(this.getStorage().toDataTransferObject());
    return sample;
}
Also used : PartSample(org.jbei.ice.lib.dto.sample.PartSample)

Example 3 with PartSample

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

Example 4 with PartSample

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

the class SampleServiceTest method testCreateSample.

@Test
public void testCreateSample() throws Exception {
    Account account = AccountCreator.createTestAccount("SampleServiceTest.testCreateSample", false);
    String userId = account.getEmail();
    // create 96 strains
    Map<Long, String> idPartNumberMap = new HashMap<>();
    for (int i = 0; i < 96; i += 1) {
        Strain strain = TestEntryCreator.createTestStrain(account);
        Assert.assertNotNull(strain);
        idPartNumberMap.put(strain.getId(), strain.getPartNumber());
    }
    Assert.assertEquals(96, idPartNumberMap.size());
    String mainPlate = "0000000001";
    // create main plate
    createPlateSamples(userId, mainPlate, idPartNumberMap);
    List<Storage> storageList = DAOFactory.getStorageDAO().retrieveStorageByIndex(mainPlate, SampleType.PLATE96);
    Assert.assertNotNull(storageList);
    Assert.assertEquals(1, storageList.size());
    // retrieve samples for entries
    int i = 0;
    for (String partNumber : idPartNumberMap.values()) {
        List<PartSample> samples = service.retrieveEntrySamples(userId, partNumber);
        Assert.assertNotNull(samples);
        Assert.assertTrue(samples.size() == 1);
        verifyMainPlate(samples.get(0), i, mainPlate);
        i += 1;
    }
    // create backup 1
    String backUp1Plate = "0000000002";
    createPlateSamples(userId, backUp1Plate, idPartNumberMap);
    storageList = DAOFactory.getStorageDAO().retrieveStorageByIndex(backUp1Plate, SampleType.PLATE96);
    Assert.assertNotNull(storageList);
    Assert.assertEquals(1, storageList.size());
    // retrieve samples for entries
    i = 0;
    for (String partNumber : idPartNumberMap.values()) {
        List<PartSample> samples = service.retrieveEntrySamples(userId, partNumber);
        Assert.assertNotNull(samples);
        Assert.assertTrue(samples.size() == 2);
        verifyMainPlate(samples.get(0), i, mainPlate, backUp1Plate);
        verifyMainPlate(samples.get(1), i, mainPlate, backUp1Plate);
        i += 1;
    }
    // create backup 2
    String backUp2Plate = "0000000003";
    createPlateSamples(userId, backUp2Plate, idPartNumberMap);
    storageList = DAOFactory.getStorageDAO().retrieveStorageByIndex(backUp1Plate, SampleType.PLATE96);
    Assert.assertNotNull(storageList);
    Assert.assertEquals(1, storageList.size());
    // retrieve samples for entries
    i = 0;
    for (String partNumber : idPartNumberMap.values()) {
        List<PartSample> samples = service.retrieveEntrySamples(userId, partNumber);
        Assert.assertNotNull(samples);
        Assert.assertTrue(samples.size() == 3);
        verifyMainPlate(samples.get(0), i, mainPlate, backUp1Plate, backUp2Plate);
        verifyMainPlate(samples.get(1), i, mainPlate, backUp1Plate, backUp2Plate);
        verifyMainPlate(samples.get(2), i, mainPlate, backUp1Plate, backUp2Plate);
        i += 1;
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Storage(org.jbei.ice.storage.model.Storage) HashMap(java.util.HashMap) PartSample(org.jbei.ice.lib.dto.sample.PartSample) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Example 5 with PartSample

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

the class SampleServiceTest method createPlateSamples.

protected void createPlateSamples(String userId, String plate, Map<Long, String> idPartNumberMap) {
    int i = 0;
    for (Long entryId : idPartNumberMap.keySet()) {
        // for each entry
        PartSample partSample = new PartSample();
        StorageLocation plateLocation = new StorageLocation();
        plateLocation.setType(SampleType.PLATE96);
        plateLocation.setDisplay(plate);
        StorageLocation well = new StorageLocation();
        well.setType(SampleType.WELL);
        String wellDisplay = numberToPosition(i);
        Assert.assertNotNull(wellDisplay);
        // e.g. "AO1"
        well.setDisplay(wellDisplay);
        plateLocation.setChild(well);
        StorageLocation tube = new StorageLocation();
        tube.setType(SampleType.TUBE);
        String index = UUID.randomUUID().toString().split("-")[0];
        tube.setDisplay(index);
        well.setChild(tube);
        partSample.setLocation(plateLocation);
        String partNumber = idPartNumberMap.get(entryId);
        Assert.assertNotNull(partNumber);
        // part number of part_number_backup 1/2
        partSample.setLabel(partNumber);
        partSample = service.createSample(userId, partNumber, partSample, null);
        Assert.assertNotNull(partSample);
        Assert.assertNotNull(partSample.getLabel());
        i += 1;
    }
}
Also used : PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

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