use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class BoxRestController method exportBoxContentsForm.
private JSONObject exportBoxContentsForm(Long boxId) throws IOException {
Box box = boxService.get(boxId);
List<List<String>> boxContents = getBoxContents(box);
String name = box.getName();
String alias = box.getAlias();
File f = misoFileManager.getNewFile(Box.class, "forms", "BoxContentsForm-" + getCurrentDateAsString() + ".xlsx");
if (detailedSampleEnabled) {
createDetailedBoxSpreadsheet(f, name, alias, boxContents);
} else {
createPlainBoxSpreadsheet(f, name, alias, boxContents);
}
return JSONObject.fromObject("{hashCode: " + f.getName().hashCode() + "}");
}
use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class BoxRestController method createFragmentAnalyserSheet.
@GetMapping("/{boxId}/fragmentAnalyser")
public HttpEntity<byte[]> createFragmentAnalyserSheet(@PathVariable("boxId") Long boxId, HttpServletResponse response) throws IOException {
Box box = getBox(boxId);
if (box.getSize().getRows() != 8 || box.getSize().getColumns() != 12) {
throw new RestException("Invalid box size for fragment analyzer. Must be 8 x 12", Status.BAD_REQUEST);
}
Map<String, String> aliasByPosition = boxService.getBoxContents(boxId).stream().collect(Collectors.toMap(BoxableView::getBoxPosition, BoxableView::getAlias));
StringBuilder sb = new StringBuilder();
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 12; col++) {
String pos = BoxUtils.getPositionString(row, col);
sb.append(pos).append("\t");
if (col == 11 && row == 7) {
sb.append("Ladder");
} else {
sb.append(aliasByPosition.containsKey(pos) ? aliasByPosition.get(pos) : "EMPTY").append("\n");
}
}
}
String sheet = sb.toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
response.setHeader("Content-Disposition", String.format("attachment; filename=FA-%s.txt", box.getAlias().replace(' ', '_')));
return new HttpEntity<>(sheet.getBytes(), headers);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Box 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.Box in project miso-lims by miso-lims.
the class EditBoxController method setupForm.
@GetMapping(value = "/{boxId}")
public ModelAndView setupForm(@PathVariable Long boxId, ModelMap model) throws IOException {
Box box = boxService.get(boxId);
if (box == null)
throw new NotFoundException("No box found for ID " + boxId.toString());
if (box.getSize().getRows() == 8 && box.getSize().getColumns() == 12) {
model.put("fragmentAnalyserCompatible", true);
}
model.put("title", "Box " + box.getId());
model.put(PageMode.PROPERTY, PageMode.EDIT.getLabel());
return setupForm(box, model);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class TransferRestController method update.
@PutMapping("/{id}")
@ResponseBody
public TransferDto update(@RequestBody TransferDto dto, @PathVariable long id) throws IOException {
TransferDto updated = RestUtils.updateObject("Transfer", id, dto, Dtos::to, transferService, Dtos::asDto);
Map<Long, Long> boxMoves = new HashMap<>();
dto.getItems().forEach(item -> {
if (item.getNewBoxLocationId() != null) {
if (boxMoves.containsKey(item.getBoxId()) && !item.getNewBoxLocationId().equals(boxMoves.get(item.getBoxId()))) {
throw new RestException("Multiple locations specified for the same box", Status.BAD_REQUEST);
}
boxMoves.put(item.getBoxId(), item.getNewBoxLocationId());
}
});
for (Entry<Long, Long> entry : boxMoves.entrySet()) {
Box box = boxService.get(entry.getKey());
if (box == null) {
throw new RestException("No box found with ID " + entry.getKey(), Status.BAD_REQUEST);
}
StorageLocation location = storageLocationService.get(entry.getValue());
if (location == null) {
throw new RestException("No location found with ID " + entry.getKey(), Status.BAD_REQUEST);
}
box.setStorageLocation(location);
boxService.update(box);
}
return updated;
}
Aggregations