Search in sources :

Example 21 with Box

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

the class BoxRestController method removeMultipleItems.

@PostMapping("/{boxId}/bulk-remove")
@ResponseBody
public BoxDto removeMultipleItems(@PathVariable long boxId, @RequestBody List<String> positions) throws IOException {
    Box box = getBox(boxId);
    for (String position : positions) {
        if (box.getBoxPositions().containsKey(position)) {
            box.getBoxPositions().remove(position);
        }
    }
    boxService.save(box);
    return getBoxDtoWithBoxables(boxId);
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with Box

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

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

the class BoxRestController method removeSingleItem.

@DeleteMapping("/{boxId}/positions/{position}")
@ResponseBody
public BoxDto removeSingleItem(@PathVariable long boxId, @PathVariable String position) throws IOException {
    Box box = getBox(boxId);
    box.getBoxPositions().remove(position);
    boxService.save(box);
    return getBoxDtoWithBoxables(boxId);
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with Box

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

the class BoxRestController method discardSingleItem.

@PostMapping("/{boxId}/positions/{position}/discard")
@ResponseBody
public BoxDto discardSingleItem(@PathVariable long boxId, @PathVariable String position) throws IOException {
    Box box = getBox(boxId);
    boxService.discardSingleItem(box, position);
    return getBoxDtoWithBoxables(boxId);
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with Box

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

the class BoxRestController method discardEntireBox.

@PostMapping(value = "/{boxId}/discard-all")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void discardEntireBox(@PathVariable long boxId) throws IOException {
    Box box = getBox(boxId);
    boxService.discardAllContents(box);
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box) 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