Search in sources :

Example 1 with BoxPosition

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

the class BoxPageIT method testMoveItemWithinBox.

@Test
public void testMoveItemWithinBox() {
    final String initialPosition = "F10";
    final String finalPosition = "F12";
    Library lib = (Library) getSession().get(LibraryImpl.class, 505L);
    assertNotNull(lib);
    BoxableId libBoxableId = new BoxableId(lib.getEntityType(), lib.getId());
    // confirm positions pre-move
    Box initial = (Box) getSession().get(BoxImpl.class, 500L);
    BoxPosition itemAtInitialPosition = initial.getBoxPositions().get(initialPosition);
    assertNotNull(itemAtInitialPosition);
    assertNull(initial.getBoxPositions().get(finalPosition));
    assertEquals(libBoxableId, itemAtInitialPosition.getBoxableId());
    BoxPage page = getBoxPage(500L);
    BoxVisualization visualization = page.getVisualization();
    assertFalse("checking that library is in position F10", visualization.isEmptyPosition(initialPosition));
    assertTrue("checking which library is in position F10", visualization.getPositionTitle(initialPosition).contains(lib.getAlias()));
    assertTrue("checking that no tube is in position F12", visualization.isEmptyPosition(finalPosition));
    visualization.selectPosition(finalPosition);
    visualization.searchBoxables(lib.getIdentificationBarcode());
    visualization.updatePosition(false);
    // confirm positions post-move
    Box updated = (Box) getSession().get(BoxImpl.class, 500L);
    assertNull(updated.getBoxPositions().get(initialPosition));
    BoxPosition updatedAtFinalPosition = updated.getBoxPositions().get(finalPosition);
    assertNotNull(updatedAtFinalPosition);
    assertEquals(libBoxableId, updatedAtFinalPosition.getBoxableId());
    BoxPage afterSave = getBoxPage(500L);
    BoxVisualization afterVisualization = afterSave.getVisualization();
    assertTrue("checking that no tube is in position F10", afterVisualization.isEmptyPosition(initialPosition));
    assertFalse("checking that library is in position F12", afterVisualization.isEmptyPosition(finalPosition));
    assertTrue("checking which library is in position F12", afterVisualization.getPositionTitle(finalPosition).contains(lib.getAlias()));
}
Also used : BoxableId(uk.ac.bbsrc.tgac.miso.core.data.BoxableId) BoxVisualization(uk.ac.bbsrc.tgac.miso.webapp.integrationtest.page.BoxVisualization) LibraryImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.LibraryImpl) BoxImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.BoxImpl) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition) BoxPage(uk.ac.bbsrc.tgac.miso.webapp.integrationtest.page.BoxPage) Test(org.junit.Test)

Example 2 with BoxPosition

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

the class BoxRestController method recreateBoxFromPrefix.

@PostMapping("/{boxId}/positions/fill-by-pattern")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void recreateBoxFromPrefix(@PathVariable long boxId, @RequestParam(name = "prefix", required = true) String prefix, @RequestParam(name = "suffix", required = true) String suffix) throws IOException {
    Box box = getBox(boxId);
    if (!SUFFIXES.containsKey(suffix)) {
        throw new RestException("Invalid suffix", Status.BAD_REQUEST);
    }
    BiFunction<Integer, Integer, String> suffixGenerator = SUFFIXES.get(suffix).apply(box.getSize());
    Map<String, String> positionToBarcode = new HashMap<>();
    for (int row = 0; row < box.getSize().getRows(); row++) {
        for (int column = 0; column < box.getSize().getColumns(); column++) {
            positionToBarcode.put(BoxUtils.getPositionString(row, column), prefix + suffixGenerator.apply(row, column));
        }
    }
    Map<String, BoxableView> barcodesToBoxables = boxService.getViewsFromBarcodeList(positionToBarcode.values()).stream().collect(Collectors.toMap(BoxableView::getIdentificationBarcode, Function.identity()));
    box.setBoxPositions(positionToBarcode.entrySet().stream().filter(entry -> barcodesToBoxables.containsKey(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, entry -> {
        BoxableView boxable = barcodesToBoxables.get(entry.getValue());
        BoxableId id = new BoxableId(boxable.getEntityType(), boxable.getId());
        return new BoxPosition(box, entry.getKey(), id);
    })));
    boxService.save(box);
}
Also used : HashMap(java.util.HashMap) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) BoxableView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.box.BoxableView) BoxableId(uk.ac.bbsrc.tgac.miso.core.data.BoxableId) Entry(java.util.Map.Entry) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 3 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 4 with BoxPosition

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

the class DefaultBoxService method discardAllContents.

@Override
public void discardAllContents(Box box) throws IOException {
    Box managed = get(box.getId());
    addBoxContentsChangeLog(managed, String.format("Discarded all box contents (%d items)", managed.getBoxPositions().size()));
    for (BoxPosition bp : managed.getBoxPositions().values()) {
        discardBoxable(bp.getBoxableId());
    }
    managed.getBoxPositions().clear();
    boxStore.save(managed);
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition)

Example 5 with BoxPosition

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

the class DefaultBoxService method discardSingleItem.

@Override
public void discardSingleItem(Box box, String position) throws IOException {
    Box managed = boxStore.get(box.getId());
    BoxPosition bp = managed.getBoxPositions().get(position);
    if (bp == null) {
        throw new IllegalArgumentException("No item in the specified box position");
    }
    Boxable target = boxStore.getBoxable(bp.getBoxableId());
    addBoxContentsChangeLog(managed, String.format("Discarded %s (%s) from %s", target.getAlias(), target.getName(), target.getBoxPosition()));
    discardBoxable(bp.getBoxableId());
    managed.getBoxPositions().remove(position);
    boxStore.save(managed);
}
Also used : Boxable(uk.ac.bbsrc.tgac.miso.core.data.Boxable) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition)

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