Search in sources :

Example 6 with BoxPosition

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

the class BoxRestController method bulkUpdatePositions.

@PostMapping(value = "/{boxId}/bulk-update")
@ResponseBody
public BoxDto bulkUpdatePositions(@PathVariable long boxId, @RequestBody List<BulkUpdateRequestItem> items) throws IOException {
    Box box = boxService.get(boxId);
    if (box == null) {
        throw new RestException("Box " + boxId + " not found", Status.NOT_FOUND);
    }
    ValidationResult validation = new ValidationResult();
    Map<String, BoxableView> updates = new HashMap<>();
    for (BulkUpdateRequestItem item : items) {
        if (!box.isValidPosition(item.getPosition())) {
            validation.addError(new ValidationError("Invalid position given: " + item.getPosition()));
        }
        if (item.getSearchString() == null) {
            box.getBoxPositions().remove(item.getPosition());
            continue;
        }
        List<BoxableView> searchResults = boxService.getBoxableViewsBySearch(item.getSearchString());
        if (searchResults == null || searchResults.isEmpty()) {
            validation.addError(new ValidationError("No item found by searching '" + item.getSearchString() + "' for position " + item.getPosition()));
        } else if (searchResults.size() > 1) {
            validation.addError(new ValidationError("Multiple items matched search '" + item.getSearchString() + "' for position " + item.getPosition()));
        } else {
            BoxableView boxable = searchResults.get(0);
            // if the selected item is already in the box, remove it here and add it to the correct position in next step
            if (Long.valueOf(box.getId()).equals(boxable.getBoxId())) {
                box.getBoxPositions().remove(boxable.getBoxPosition());
            }
            updates.put(item.getPosition(), boxable);
        }
    }
    for (Entry<String, BoxableView> entry : updates.entrySet()) {
        // if an item already exists at this position, its location will be set to unknown.
        BoxableId id = new BoxableId(entry.getValue().getEntityType(), entry.getValue().getId());
        BoxPosition bp = new BoxPosition(box, entry.getKey(), id);
        box.getBoxPositions().put(entry.getKey(), bp);
    }
    validation.throwIfInvalid();
    boxService.save(box);
    Box updated = boxService.get(boxId);
    List<BoxableView> updatedContents = boxService.getBoxContents(boxId);
    return Dtos.asDtoWithBoxables(updated, updatedContents);
}
Also used : HashMap(java.util.HashMap) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationResult) BoxableView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.box.BoxableView) BoxableId(uk.ac.bbsrc.tgac.miso.core.data.BoxableId) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with BoxPosition

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

the class TransferController method addBoxItems.

private <T extends Boxable, U extends TransferItem<T>> void addBoxItems(String idString, Transfer transfer) throws IOException {
    if (idString == null) {
        return;
    }
    for (Long id : LimsUtils.parseIds(idString)) {
        Box box = boxService.get(id);
        if (box == null) {
            throw new ClientErrorException(String.format("No box found for ID: %d", id));
        }
        for (BoxPosition item : box.getBoxPositions().values()) {
            long itemId = item.getBoxableId().getTargetId();
            switch(item.getBoxableId().getTargetType()) {
                case SAMPLE:
                    TransferSample transferSample = new TransferSample();
                    transferSample.setItem(sampleService.get(itemId));
                    transfer.getSampleTransfers().add(transferSample);
                    break;
                case LIBRARY:
                    TransferLibrary transferLibrary = new TransferLibrary();
                    transferLibrary.setItem(libraryService.get(itemId));
                    transfer.getLibraryTransfers().add(transferLibrary);
                    break;
                case LIBRARY_ALIQUOT:
                    TransferLibraryAliquot transferLibraryAliquot = new TransferLibraryAliquot();
                    transferLibraryAliquot.setItem(libraryAliquotService.get(itemId));
                    transfer.getLibraryAliquotTransfers().add(transferLibraryAliquot);
                    break;
                case POOL:
                    TransferPool transferPool = new TransferPool();
                    transferPool.setItem(poolService.get(itemId));
                    transfer.getPoolTransfers().add(transferPool);
                    break;
                default:
                    throw new IllegalArgumentException("Unexpected boxable type: " + item.getBoxableId().getTargetType());
            }
        }
    }
}
Also used : TransferLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibraryAliquot) TransferPool(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferPool) TransferLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibrary) ClientErrorException(uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition)

Example 8 with BoxPosition

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

the class HibernateBoxDaoIT method testMoveFromOtherBox.

@Test
public void testMoveFromOtherBox() throws Exception {
    // Note: move is a two-step process
    // 1. remove from previous position and save the box
    // 2. add to new position and save the box
    long fromBoxId = 1L;
    String fromPos = "A01";
    long toBoxId = 2L;
    String toPos = "A01";
    Box fromBox = dao.get(fromBoxId);
    assertNotNull(fromBox);
    BoxPosition fromBp = fromBox.getBoxPositions().get(fromPos);
    assertNotNull(fromBp);
    fromBox.getBoxPositions().remove(fromPos);
    dao.save(fromBox);
    Box toBox = dao.get(toBoxId);
    assertNotNull(toBox);
    assertNull(toBox.getBoxPositions().get(toPos));
    BoxPosition toBp = new BoxPosition(toBox, toPos, fromBp.getBoxableId());
    toBox.getBoxPositions().put(toPos, toBp);
    dao.save(toBox);
    sessionFactory.getCurrentSession().flush();
    sessionFactory.getCurrentSession().clear();
    Box saved = dao.get(toBoxId);
    assertNotNull(saved);
    assertNotNull(saved.getBoxPositions().get(toPos));
    Box original = dao.get(fromBoxId);
    assertNotNull(original);
    assertNull(original.getBoxPositions().get(fromPos));
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest) Test(org.junit.Test)

Example 9 with BoxPosition

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

the class HibernateBoxDaoIT method testRemoveBoxableViewFromBox.

@Test
public void testRemoveBoxableViewFromBox() throws Exception {
    Sample s = (Sample) sessionFactory.getCurrentSession().get(SampleImpl.class, 15L);
    Box box = dao.get(1);
    BoxPosition bp = box.getBoxPositions().get("A01");
    assertNotNull(bp);
    assertEquals(new BoxableId(s.getEntityType(), s.getId()), bp.getBoxableId());
    BoxableView item = makeBoxableView(s);
    dao.removeBoxableFromBox(item);
    sessionFactory.getCurrentSession().flush();
    sessionFactory.getCurrentSession().clear();
    Box again = dao.get(1);
    assertFalse(again.getBoxPositions().containsKey("A01"));
}
Also used : BoxableId(uk.ac.bbsrc.tgac.miso.core.data.BoxableId) BoxableView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.box.BoxableView) SampleBoxableView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.box.SampleBoxableView) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition) SampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest) Test(org.junit.Test)

Example 10 with BoxPosition

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

the class HibernateBoxDaoIT method testGetBoxById.

@Test
public void testGetBoxById() throws IOException, InterruptedException {
    Box box = dao.get(1);
    assertEquals("box1alias", box.getAlias());
    assertEquals("BOX1", box.getName());
    assertEquals(1L, box.getId());
    assertEquals("identificationbarcode1", box.getIdentificationBarcode());
    assertEquals(4, box.getSize().getRows().intValue());
    assertEquals("boxuse1", box.getUse().getAlias());
    assertEquals(2, box.getTubeCount());
    BoxPosition a1 = box.getBoxPositions().get("A01");
    assertNotNull(a1);
    assertEquals(new BoxableId(EntityType.SAMPLE, 15L), a1.getBoxableId());
    BoxPosition b2 = box.getBoxPositions().get("B02");
    assertNotNull(b2);
    assertEquals(new BoxableId(EntityType.SAMPLE, 16L), b2.getBoxableId());
}
Also used : BoxableId(uk.ac.bbsrc.tgac.miso.core.data.BoxableId) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest) Test(org.junit.Test)

Aggregations

Box (uk.ac.bbsrc.tgac.miso.core.data.Box)16 BoxPosition (uk.ac.bbsrc.tgac.miso.core.data.BoxPosition)16 BoxableId (uk.ac.bbsrc.tgac.miso.core.data.BoxableId)9 Test (org.junit.Test)6 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)5 BoxableView (uk.ac.bbsrc.tgac.miso.core.data.impl.view.box.BoxableView)5 Boxable (uk.ac.bbsrc.tgac.miso.core.data.Boxable)3 Sets (com.google.common.collect.Sets)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Sample (uk.ac.bbsrc.tgac.miso.core.data.Sample)2 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)2 Functions (com.google.common.base.Functions)1