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