Search in sources :

Example 6 with ArrayRun

use of uk.ac.bbsrc.tgac.miso.core.data.ArrayRun in project miso-lims by miso-lims.

the class HibernateArrayRunDao method listByArrayId.

@Override
public List<ArrayRun> listByArrayId(long arrayId) throws IOException {
    Criteria criteria = currentSession().createCriteria(ArrayRun.class);
    criteria.add(Restrictions.eq("array.id", arrayId));
    @SuppressWarnings("unchecked") List<ArrayRun> list = criteria.list();
    return list;
}
Also used : ArrayRun(uk.ac.bbsrc.tgac.miso.core.data.ArrayRun) Criteria(org.hibernate.Criteria)

Example 7 with ArrayRun

use of uk.ac.bbsrc.tgac.miso.core.data.ArrayRun in project miso-lims by miso-lims.

the class DefaultArrayRunService method validateChange.

/**
 * Checks submitted data for validity, throwing a ValidationException containing all of the errors if invalid
 *
 * @param arrayRun submitted Array Run to validate
 * @param beforeChange the already-persisted Array Run before changes
 * @throws IOException
 */
private void validateChange(ArrayRun arrayRun, ArrayRun beforeChange) throws IOException {
    List<ValidationError> errors = new ArrayList<>();
    if (arrayRun.isSaved() && beforeChange == null) {
        errors.add(new ValidationError("Array Run not found"));
    }
    if (isStringEmptyOrNull(arrayRun.getAlias())) {
        errors.add(new ValidationError("alias", "Alias cannot be blank"));
    }
    if (arrayRun.getInstrument() == null) {
        errors.add(new ValidationError("instrument", "An instrument must be selected"));
    } else if (arrayRun.getInstrument().getInstrumentModel().getInstrumentType() != InstrumentType.ARRAY_SCANNER) {
        errors.add(new ValidationError("instrument", "Instrument must be an array scanner"));
    }
    if (beforeChange == null || !arrayRun.getAlias().equals(beforeChange.getAlias())) {
        ArrayRun duplicateAlias = arrayRunStore.getByAlias(arrayRun.getAlias());
        if (duplicateAlias != null) {
            errors.add(new ValidationError("alias", "There is already an array run with this alias"));
        }
    }
    if (arrayRun.getArray() != null && arrayRun.getArray().getAlias() == null) {
        errors.add(new ValidationError("array", "Array not found"));
    }
    validateStartDate(arrayRun, beforeChange, errors);
    validateStatusAndCompletion(arrayRun, beforeChange, errors);
    if (!errors.isEmpty()) {
        throw new ValidationException(errors);
    }
}
Also used : ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) ArrayList(java.util.ArrayList) ArrayRun(uk.ac.bbsrc.tgac.miso.core.data.ArrayRun) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)

Example 8 with ArrayRun

use of uk.ac.bbsrc.tgac.miso.core.data.ArrayRun in project miso-lims by miso-lims.

the class HibernateArrayRunDaoIT method testSaveExisting.

@Test
public void testSaveExisting() throws Exception {
    long runId = 1L;
    String alias = "NewAlias";
    String desc = "NewDesc";
    ArrayRun run = sut.get(runId);
    assertNotNull(run.getArray());
    assertNotEquals(alias, run.getAlias());
    assertNotEquals(desc, run.getDescription());
    run.setArray(null);
    run.setAlias(alias);
    run.setDescription(desc);
    long savedId = sut.save(run);
    assertEquals(runId, savedId);
    ArrayRun saved = sut.get(savedId);
    assertNotNull(saved);
    assertNull(saved.getArray());
    assertEquals(alias, run.getAlias());
    assertEquals(desc, run.getDescription());
}
Also used : ArrayRun(uk.ac.bbsrc.tgac.miso.core.data.ArrayRun) Test(org.junit.Test) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest)

Example 9 with ArrayRun

use of uk.ac.bbsrc.tgac.miso.core.data.ArrayRun in project miso-lims by miso-lims.

the class HibernateArrayRunDaoIT method testSaveNew.

@Test
public void testSaveNew() throws Exception {
    ArrayRun run = new ArrayRun();
    run.setAlias("TestArrayRun");
    Instrument inst = (Instrument) sessionFactory.getCurrentSession().get(InstrumentImpl.class, 3L);
    run.setInstrument(inst);
    run.setHealth(HealthType.Running);
    Date now = new Date();
    run.setStartDate(now);
    User user = (User) sessionFactory.getCurrentSession().get(UserImpl.class, 1L);
    run.setCreator(user);
    run.setCreationTime(now);
    run.setLastModifier(user);
    run.setLastModified(now);
    long savedId = sut.save(run);
    ArrayRun saved = sut.get(savedId);
    assertNotNull(saved);
    assertEquals(run.getAlias(), saved.getAlias());
    assertEquals(run.getInstrument().getId(), saved.getInstrument().getId());
    assertEquals(run.getHealth(), saved.getHealth());
    assertEquals(LimsUtils.formatDate(run.getStartDate()), LimsUtils.formatDate(saved.getStartDate()));
}
Also used : InstrumentImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.InstrumentImpl) User(com.eaglegenomics.simlims.core.User) ArrayRun(uk.ac.bbsrc.tgac.miso.core.data.ArrayRun) Instrument(uk.ac.bbsrc.tgac.miso.core.data.Instrument) UserImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.UserImpl) Date(java.util.Date) Test(org.junit.Test) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest)

Example 10 with ArrayRun

use of uk.ac.bbsrc.tgac.miso.core.data.ArrayRun in project miso-lims by miso-lims.

the class HibernateArrayRunDaoIT method testGetByAlias.

@Test
public void testGetByAlias() throws Exception {
    String alias = "ArrayRun_1";
    ArrayRun run = sut.getByAlias(alias);
    assertNotNull(run);
    assertEquals(alias, run.getAlias());
}
Also used : ArrayRun(uk.ac.bbsrc.tgac.miso.core.data.ArrayRun) Test(org.junit.Test) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest)

Aggregations

ArrayRun (uk.ac.bbsrc.tgac.miso.core.data.ArrayRun)12 Criteria (org.hibernate.Criteria)4 Test (org.junit.Test)4 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)4 InstrumentImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.InstrumentImpl)2 User (com.eaglegenomics.simlims.core.User)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 NotFoundException (org.springframework.security.acls.model.NotFoundException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 Array (uk.ac.bbsrc.tgac.miso.core.data.Array)1 Instrument (uk.ac.bbsrc.tgac.miso.core.data.Instrument)1 UserImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.UserImpl)1 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)1 ValidationException (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException)1