Search in sources :

Example 1 with Storage

use of org.jbei.ice.storage.model.Storage in project ice by JBEI.

the class StorageDAO method retrieveStorageByIndex.

/**
     * Retrieve a {@link Storage} object by its index and {@link SampleType} fields.
     *
     * @param index index value
     * @param type  storage type
     * @return List of Storage objects
     */
public List<Storage> retrieveStorageByIndex(String index, SampleType type) {
    try {
        CriteriaQuery<Storage> query = getBuilder().createQuery(Storage.class);
        Root<Storage> from = query.from(Storage.class);
        query.where(getBuilder().equal(from.get("index"), index), getBuilder().equal(from.get("storageType"), type));
        return currentSession().createQuery(query).list();
    } catch (Exception e) {
        String msg = "Could not get Storage by index: " + index + " " + e.toString();
        Logger.error(msg, e);
        throw new DAOException(msg);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Storage(org.jbei.ice.storage.model.Storage) DAOException(org.jbei.ice.storage.DAOException)

Example 2 with Storage

use of org.jbei.ice.storage.model.Storage 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 3 with Storage

use of org.jbei.ice.storage.model.Storage in project ice by JBEI.

the class SampleServiceTest method createStorage.

@Test
public void createStorage() throws Exception {
    Storage storage = service.createStorage("user1", "test1", SampleType.ADDGENE);
    Assert.assertNotNull(storage);
    Assert.assertEquals(storage.getIndex(), "test1");
    Assert.assertEquals(storage.getOwnerEmail(), "user1");
    Assert.assertEquals(storage.getStorageType().name(), SampleType.ADDGENE.name());
}
Also used : Storage(org.jbei.ice.storage.model.Storage) Test(org.junit.Test)

Aggregations

Storage (org.jbei.ice.storage.model.Storage)3 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 PartSample (org.jbei.ice.lib.dto.sample.PartSample)1 DAOException (org.jbei.ice.storage.DAOException)1 Account (org.jbei.ice.storage.model.Account)1 Strain (org.jbei.ice.storage.model.Strain)1