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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations