Search in sources :

Example 6 with StorageLocation

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

Example 7 with StorageLocation

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

the class SampleServiceTest method testRetrieveEntrySamples.

@Test
public void testRetrieveEntrySamples() throws Exception {
    Account account = AccountCreator.createTestAccount("SampleServiceTest.testRetrieveEntrySamples", false);
    String userId = account.getEmail();
    Strain strain = TestEntryCreator.createTestStrain(account);
    long entryId = strain.getId();
    List<PartSample> samplesList = service.retrieveEntrySamples(userId, Long.toString(entryId));
    Assert.assertNotNull(samplesList);
    for (PartSample partSample : samplesList) {
        Assert.assertNotNull(partSample.getId());
        Assert.assertNotNull(partSample.getCreationTime());
        Assert.assertNotNull(partSample.getLabel());
        Assert.assertNotNull(partSample.getLocation());
        Assert.assertNotNull(partSample.getDepositor());
        Assert.assertNotNull(partSample.getId());
        Assert.assertNotNull(partSample.isCanEdit());
        StorageLocation location = partSample.getLocation();
        while (location.getChild() != null) {
            location = location.getChild();
            Assert.assertNotNull(location.getType());
            Assert.assertNotNull(location.getId());
            Assert.assertNotNull(location.getDisplay());
            Assert.assertNotNull(location.getName());
        }
        if (partSample.getComments() != null) {
            for (UserComment comment : partSample.getComments()) {
                Assert.assertNotNull(comment.getId());
                Assert.assertNotNull(comment.getMessage());
            }
        }
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) UserComment(org.jbei.ice.lib.dto.comment.UserComment) 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 8 with StorageLocation

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

the class SampleServiceTest method testDelete.

@Test
public void testDelete() throws Exception {
    Account account = AccountCreator.createTestAccount("testDelete", false);
    String userId = account.getEmail();
    // ----- CASE #1 -----
    Strain strain1 = TestEntryCreator.createTestStrain(account);
    PartSample partSample1 = new PartSample();
    partSample1.setLabel("testForShelfScheme1");
    // well
    StorageLocation well = new StorageLocation();
    well.setDisplay("well");
    well.setType(SampleType.WELL);
    // box
    StorageLocation box = new StorageLocation();
    box.setDisplay("box");
    box.setType(SampleType.BOX_INDEXED);
    box.setChild(well);
    // shelf
    StorageLocation shelf = new StorageLocation();
    shelf.setDisplay("shelf");
    shelf.setType(SampleType.SHELF);
    shelf.setChild(box);
    partSample1.setLocation(shelf);
    partSample1 = service.createSample(userId, strain1.getRecordId(), partSample1, null);
    Assert.assertNotNull(partSample1);
    // fetch
    List<PartSample> samples1 = service.retrieveEntrySamples(userId, Long.toString(strain1.getId()));
    Assert.assertEquals(1, samples1.size());
    StorageLocation location1 = samples1.get(0).getLocation();
    // delete
    Assert.assertTrue(service.delete(userId, strain1.getId(), samples1.get(0).getId()));
    Assert.assertNull(DAOFactory.getStorageDAO().get(location1.getId()));
    // ----- CASE 2 -----
    Strain strain2 = TestEntryCreator.createTestStrain(account);
    PartSample partSample2 = new PartSample();
    partSample2.setLabel("testForPlateScheme2");
    // tube2
    StorageLocation tube2 = new StorageLocation();
    tube2.setDisplay("tube2");
    tube2.setType(SampleType.TUBE);
    // well
    StorageLocation well2 = new StorageLocation();
    well2.setDisplay("well2");
    well2.setType(SampleType.WELL);
    well2.setChild(tube2);
    // plate2
    StorageLocation plate2 = new StorageLocation();
    plate2.setDisplay("plate2");
    plate2.setType(SampleType.PLATE96);
    plate2.setChild(well2);
    partSample2.setLocation(plate2);
    partSample2 = service.createSample(userId, Long.toString(strain2.getId()), partSample2, null);
    Assert.assertNotNull(partSample2);
    // ----- CASE 3 -----
    PartSample partSample3 = new PartSample();
    partSample3.setLabel("testForPlateScheme3");
    // tube2
    StorageLocation tube3 = new StorageLocation();
    tube3.setDisplay("tube3");
    tube3.setType(SampleType.TUBE);
    // well
    StorageLocation well3 = new StorageLocation();
    well3.setDisplay("well3");
    well3.setType(SampleType.WELL);
    well3.setChild(tube3);
    // plate2
    StorageLocation plate3 = new StorageLocation();
    plate3.setDisplay("plate3");
    plate3.setType(SampleType.PLATE96);
    plate3.setChild(well3);
    partSample3.setLocation(plate3);
    partSample3 = service.createSample(userId, Long.toString(strain2.getId()), partSample3, null);
    Assert.assertNotNull(partSample3);
    // fetch
    List<PartSample> samples3 = service.retrieveEntrySamples(userId, Long.toString(strain2.getId()));
    Assert.assertEquals(2, samples3.size());
    StorageLocation location3 = samples3.get(1).getLocation();
    // delete #2 and #3 consequently
    Assert.assertTrue(service.delete(userId, strain2.getId(), samples3.get(1).getId()));
    Assert.assertNull(DAOFactory.getStorageDAO().get(location3.getId()));
    List<PartSample> samples2 = service.retrieveEntrySamples(userId, Long.toString(strain2.getId()));
    Assert.assertEquals(1, samples2.size());
    StorageLocation location2 = samples2.get(0).getLocation();
    Assert.assertTrue(service.delete(userId, strain2.getId(), samples2.get(0).getId()));
    Assert.assertNull(DAOFactory.getStorageDAO().get(location2.getId()));
    List<PartSample> samplesEmpty = service.retrieveEntrySamples(userId, Long.toString(strain2.getId()));
    Assert.assertEquals(0, samplesEmpty.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 9 with StorageLocation

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

the class SampleServiceTest method verifyMainPlate.

protected void verifyMainPlate(PartSample sample, int index, String... mainPlate) {
    StorageLocation plate = sample.getLocation();
    Assert.assertNotNull(plate);
    Assert.assertEquals(plate.getType(), SampleType.PLATE96);
    boolean found = false;
    for (String aMainPlate : mainPlate) {
        if (plate.getDisplay().equals(aMainPlate)) {
            found = true;
            break;
        }
    }
    Assert.assertTrue(found);
    // well
    String wellLocation = numberToPosition(index);
    StorageLocation well = plate.getChild();
    Assert.assertEquals(well.getType(), SampleType.WELL);
    Assert.assertNotNull(well);
    Assert.assertEquals(well.getDisplay(), wellLocation);
    // plate
    StorageLocation tube = well.getChild();
    Assert.assertNotNull(tube);
    Assert.assertEquals(tube.getType(), SampleType.TUBE);
    Assert.assertFalse(tube.getDisplay().isEmpty());
}
Also used : StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 10 with StorageLocation

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

the class BulkCSVUpload method setPartSampleData.

protected void setPartSampleData(SampleField sampleField, PartSample partSample, String data) {
    switch(sampleField) {
        case LABEL:
            partSample.setLabel(data);
            break;
        case SHELF:
            StorageLocation storageLocation = new StorageLocation();
            storageLocation.setType(SampleType.SHELF);
            storageLocation.setDisplay(data);
            partSample.setLocation(storageLocation);
            break;
        case BOX:
            StorageLocation childLocation = new StorageLocation();
            childLocation.setDisplay(data);
            childLocation.setType(SampleType.BOX_INDEXED);
            partSample.getLocation().setChild(childLocation);
            break;
        case WELL:
            StorageLocation grandChildLocation = new StorageLocation();
            grandChildLocation.setType(SampleType.WELL);
            grandChildLocation.setDisplay(data);
            partSample.getLocation().getChild().setChild(grandChildLocation);
            break;
        default:
            throw new IllegalArgumentException("No handler for sample field " + sampleField);
    }
}
Also used : StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

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