Search in sources :

Example 26 with Box

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() + "}");
}
Also used : Box(uk.ac.bbsrc.tgac.miso.core.data.Box) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File)

Example 27 with Box

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 28 with Box

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());
            }
        }
    }
}
Also used : TransferLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibraryAliquot) TransferPool(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferPool) TransferLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibrary) ClientErrorException(uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) BoxPosition(uk.ac.bbsrc.tgac.miso.core.data.BoxPosition)

Example 29 with Box

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);
}
Also used : NotFoundException(org.springframework.security.acls.model.NotFoundException) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 30 with Box

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;
}
Also used : Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) HashMap(java.util.HashMap) TransferDto(uk.ac.bbsrc.tgac.miso.dto.TransferDto) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) StorageLocation(uk.ac.bbsrc.tgac.miso.core.data.impl.StorageLocation) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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