Search in sources :

Example 1 with Array

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

the class Dtos method to.

public static final ArrayRun to(@Nonnull ArrayRunDto from) {
    ArrayRun run = new ArrayRun();
    if (from.getId() != null) {
        run.setId(from.getId());
    }
    run.setAlias(from.getAlias());
    run.setDescription(nullifyStringIfBlank(from.getDescription()));
    run.setFilePath(nullifyStringIfBlank(from.getFilePath()));
    setObject(run::setInstrument, InstrumentImpl::new, from.getInstrumentId());
    setObject(run::setArray, Array::new, from.getArrayId());
    run.setHealth(HealthType.get(from.getStatus()));
    setDate(run::setStartDate, from.getStartDate());
    setDate(run::setCompletionDate, from.getCompletionDate());
    setDate(run::setLastModified, from.getLastModified());
    return run;
}
Also used : Array(uk.ac.bbsrc.tgac.miso.core.data.Array) InstrumentImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.InstrumentImpl) ArrayRun(uk.ac.bbsrc.tgac.miso.core.data.ArrayRun)

Example 2 with Array

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

the class DefaultArrayService method applyChanges.

private void applyChanges(Array from, Array to) throws IOException {
    to.setAlias(from.getAlias());
    to.setSerialNumber(from.getSerialNumber());
    to.setDescription(from.getDescription());
    // have to add/remove samples individually to avoid unnecessary "sample removed; sample added" changelogs for non-changes
    Map<String, Sample> toSamples = to.getSamples();
    Set<String> removePositions = toSamples.keySet().stream().filter(key -> !from.getSamples().containsKey(key)).collect(Collectors.toSet());
    for (String key : removePositions) {
        recordRemoval(to, toSamples.get(key).getName(), key);
        toSamples.remove(key);
    }
    from.getSamples().forEach((key, val) -> {
        Sample current = toSamples.get(key);
        if (toSamples.get(key) == null || current.getId() != val.getId()) {
            toSamples.put(key, val);
        }
    });
}
Also used : AuthorizationManager(uk.ac.bbsrc.tgac.miso.core.security.AuthorizationManager) PaginationFilter(uk.ac.bbsrc.tgac.miso.core.util.PaginationFilter) ArrayModelService(uk.ac.bbsrc.tgac.miso.core.service.ArrayModelService) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ArrayChangeLog(uk.ac.bbsrc.tgac.miso.core.data.impl.changelog.ArrayChangeLog) ArrayList(java.util.ArrayList) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Service(org.springframework.stereotype.Service) LimsUtils(uk.ac.bbsrc.tgac.miso.core.util.LimsUtils) Map(java.util.Map) Array(uk.ac.bbsrc.tgac.miso.core.data.Array) Pluralizer(uk.ac.bbsrc.tgac.miso.core.util.Pluralizer) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) SampleService(uk.ac.bbsrc.tgac.miso.core.service.SampleService) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationResult) Set(java.util.Set) DeletionStore(uk.ac.bbsrc.tgac.miso.core.store.DeletionStore) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayRunService(uk.ac.bbsrc.tgac.miso.core.service.ArrayRunService) Consumer(java.util.function.Consumer) ArrayStore(uk.ac.bbsrc.tgac.miso.persistence.ArrayStore) List(java.util.List) ChangeLogService(uk.ac.bbsrc.tgac.miso.core.service.ChangeLogService) Entry(java.util.Map.Entry) ArrayService(uk.ac.bbsrc.tgac.miso.core.service.ArrayService) Transactional(org.springframework.transaction.annotation.Transactional) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample)

Example 3 with Array

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

the class ArrayRestController method removeSample.

@DeleteMapping(value = "/{arrayId}/positions/{position}")
@ResponseBody
public ArrayDto removeSample(@PathVariable(name = "arrayId", required = true) long arrayId, @PathVariable(name = "position", required = true) String position) throws IOException {
    Array array = arrayService.get(arrayId);
    if (array == null) {
        throw new RestException(ERROR_NOTFOUND, Status.NOT_FOUND);
    } else if (!array.isPositionValid(position)) {
        throw new RestException("Invalid array position", Status.BAD_REQUEST);
    }
    if (array.getSample(position) == null) {
        // already empty - do nothing
        return Dtos.asDto(array);
    }
    array.setSample(position, null);
    arrayService.update(array);
    Array saved = arrayService.get(arrayId);
    return Dtos.asDto(saved);
}
Also used : Array(uk.ac.bbsrc.tgac.miso.core.data.Array) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Array

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

the class EditArrayController method setupForm.

@RequestMapping("/{arrayId}")
public ModelAndView setupForm(@PathVariable(name = "arrayId", required = true) long arrayId, ModelMap model) throws IOException {
    model.addAttribute(PageMode.PROPERTY, PageMode.EDIT.getLabel());
    Array array = arrayService.get(arrayId);
    if (array == null) {
        throw new NotFoundException("Array not found");
    }
    model.addAttribute(MODEL_ATTR_ARRAYRUNS, arrayRunService.listByArrayId(arrayId).stream().map(Dtos::asDto).collect(Collectors.toList()));
    ObjectMapper mapper = new ObjectMapper();
    model.addAttribute(MODEL_ATTR_JSON, mapper.writer().writeValueAsString(Dtos.asDto(array)));
    return new ModelAndView(JSP, model);
}
Also used : Array(uk.ac.bbsrc.tgac.miso.core.data.Array) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) ModelAndView(org.springframework.web.servlet.ModelAndView) NotFoundException(org.springframework.security.acls.model.NotFoundException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Array

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

the class HibernateArrayDaoIT method testSaveNew.

@Test
public void testSaveNew() throws Exception {
    Session session = sessionFactory.getCurrentSession();
    ArrayModel model = (ArrayModel) session.get(ArrayModel.class, 1L);
    User user = (User) session.get(UserImpl.class, 1L);
    Date now = new Date();
    Array a = new Array();
    a.setAlias("Test Array");
    a.setArrayModel(model);
    a.setDescription("Array for test");
    a.setSerialNumber("12345");
    a.setCreator(user);
    a.setCreationTime(now);
    a.setLastModifier(user);
    a.setLastModified(now);
    long savedId = sut.save(a);
    Array saved = sut.get(savedId);
    assertNotNull(saved);
    assertEquals(a.getAlias(), saved.getAlias());
}
Also used : Array(uk.ac.bbsrc.tgac.miso.core.data.Array) User(com.eaglegenomics.simlims.core.User) UserImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.UserImpl) ArrayModel(uk.ac.bbsrc.tgac.miso.core.data.ArrayModel) Date(java.util.Date) Session(org.hibernate.Session) Test(org.junit.Test) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest)

Aggregations

Array (uk.ac.bbsrc.tgac.miso.core.data.Array)17 Criteria (org.hibernate.Criteria)5 Test (org.junit.Test)5 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)5 Date (java.util.Date)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ArrayModel (uk.ac.bbsrc.tgac.miso.core.data.ArrayModel)2 Sample (uk.ac.bbsrc.tgac.miso.core.data.Sample)2 User (com.eaglegenomics.simlims.core.User)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Session (org.hibernate.Session)1