Search in sources :

Example 16 with Box

use of uk.ac.bbsrc.tgac.miso.core.data.Box 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 17 with Box

use of uk.ac.bbsrc.tgac.miso.core.data.Box 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)

Example 18 with Box

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

the class DefaultBoxService method throwIfBoxPositionIsFilled.

@Override
public void throwIfBoxPositionIsFilled(Boxable boxable) throws IOException {
    if (boxable.getBox() == null || boxable.getBoxPosition() == null)
        return;
    Box box = get(boxable.getBox().getId());
    BoxPosition bp = box.getBoxPositions().get(boxable.getBoxPosition());
    if (bp == null)
        return;
    if (!bp.getBoxableId().equals(new BoxableId(boxable.getEntityType(), boxable.getId()))) {
        throw new ValidationException(new ValidationError("boxPosition", "Position is not available"));
    }
}
Also used : BoxableId(uk.ac.bbsrc.tgac.miso.core.data.BoxableId) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)

Example 19 with Box

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

the class BoxRestController method toBoxWithOriginalContents.

private Box toBoxWithOriginalContents(BoxDto dto) throws IOException {
    Box original = getBox(dto.getId());
    Box box = Dtos.to(dto);
    // reset contents in-case they were changed while the box was being edited
    box.setBoxPositions(original.getBoxPositions());
    return box;
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box)

Example 20 with Box

use of uk.ac.bbsrc.tgac.miso.core.data.Box 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)

Aggregations

Box (uk.ac.bbsrc.tgac.miso.core.data.Box)65 Test (org.junit.Test)23 BoxPosition (uk.ac.bbsrc.tgac.miso.core.data.BoxPosition)21 BoxImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.BoxImpl)17 BoxableId (uk.ac.bbsrc.tgac.miso.core.data.BoxableId)16 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 PostMapping (org.springframework.web.bind.annotation.PostMapping)11 BoxPage (uk.ac.bbsrc.tgac.miso.webapp.integrationtest.page.BoxPage)11 BoxableView (uk.ac.bbsrc.tgac.miso.core.data.impl.view.box.BoxableView)10 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)9 BoxVisualization (uk.ac.bbsrc.tgac.miso.webapp.integrationtest.page.BoxVisualization)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 List (java.util.List)8 IOException (java.io.IOException)7 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 Autowired (org.springframework.beans.factory.annotation.Autowired)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)6