Search in sources :

Example 1 with ClientErrorException

use of uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException in project miso-lims by miso-lims.

the class AttachmentRestController method bulkLinkFile.

@PostMapping("/{entityType}/shared")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void bulkLinkFile(@PathVariable String entityType, @RequestParam(name = "fromEntityType", required = true) String fromEntityType, @RequestParam(name = "fromEntityId", required = true) long fromEntityId, @RequestParam(name = "attachmentId", required = true) long attachmentId, @RequestParam(name = "entityIds", required = true) String entityIds) throws IOException {
    List<Attachable> items = new ArrayList<>();
    for (Long id : LimsUtils.parseIds(entityIds)) {
        Attachable item = fileAttachmentService.get(entityType, id);
        if (item == null) {
            throw new ClientErrorException(String.format("%s %d not found", entityType, id));
        } else {
            items.add(item);
        }
    }
    // This lookup will ensure that the user has read access to the source item (and its attachments)
    Attachable sourceItem = getAttachable(fromEntityType, fromEntityId, false);
    FileAttachment attachment = sourceItem.getAttachments().stream().filter(att -> att.getId() == attachmentId).findFirst().orElseThrow(() -> new RestException("Attachment not found", Status.BAD_REQUEST));
    fileAttachmentService.addLinks(items, attachment);
}
Also used : FileAttachment(uk.ac.bbsrc.tgac.miso.core.data.impl.FileAttachment) ArrayList(java.util.ArrayList) ClientErrorException(uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException) Attachable(uk.ac.bbsrc.tgac.miso.core.data.Attachable) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 2 with ClientErrorException

use of uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException in project miso-lims by miso-lims.

the class AttachmentController method acceptSharedUpload.

@PostMapping(value = "/{entityType}/shared")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void acceptSharedUpload(@PathVariable String entityType, @RequestParam String entityIds, @RequestParam(required = false) Long categoryId, @RequestParam("files") MultipartFile[] files) throws IOException {
    List<Attachable> items = new ArrayList<>();
    for (Long id : LimsUtils.parseIds(entityIds)) {
        Attachable item = fileAttachmentService.get(entityType, id);
        if (item == null) {
            throw new ClientErrorException(String.format("%s %d not found", entityType, id));
        } else {
            items.add(item);
        }
    }
    AttachmentCategory category = getCategory(categoryId);
    for (MultipartFile fileItem : files) {
        fileAttachmentService.addShared(items, fileItem, category);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ArrayList(java.util.ArrayList) ClientErrorException(uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException) AttachmentCategory(uk.ac.bbsrc.tgac.miso.core.data.impl.AttachmentCategory) Attachable(uk.ac.bbsrc.tgac.miso.core.data.Attachable) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 3 with ClientErrorException

use of uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException 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 4 with ClientErrorException

use of uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException in project miso-lims by miso-lims.

the class EditLibraryTemplateController method create.

@GetMapping("/new")
public ModelAndView create(@RequestParam(name = "projectId", required = false) Long projectId, ModelMap model) throws IOException {
    LibraryTemplate template = isDetailedSampleEnabled() ? new DetailedLibraryTemplate() : new LibraryTemplate();
    if (projectId != null) {
        Project project = projectService.get(projectId);
        if (project == null) {
            throw new ClientErrorException("No project found with ID: " + projectId);
        }
        template.getProjects().add(project);
    }
    model.put(PageMode.PROPERTY, PageMode.CREATE.getLabel());
    model.put("title", "New Library Template");
    return libraryTemplatePage(template, model);
}
Also used : Project(uk.ac.bbsrc.tgac.miso.core.data.Project) DetailedLibraryTemplate(uk.ac.bbsrc.tgac.miso.core.data.impl.DetailedLibraryTemplate) ClientErrorException(uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException) DetailedLibraryTemplate(uk.ac.bbsrc.tgac.miso.core.data.impl.DetailedLibraryTemplate) LibraryTemplate(uk.ac.bbsrc.tgac.miso.core.data.impl.LibraryTemplate)

Example 5 with ClientErrorException

use of uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException in project miso-lims by miso-lims.

the class EditPoolOrderController method create.

@GetMapping("/new")
public ModelAndView create(@RequestParam(name = "aliquotIds", required = false) String aliquotIds, ModelMap model) throws IOException {
    model.put("title", "New Pool Order");
    model.put(PageMode.PROPERTY, PageMode.CREATE.getLabel());
    PoolOrder order = new PoolOrder();
    if (aliquotIds != null) {
        for (Long aliquotId : LimsUtils.parseIds(aliquotIds)) {
            LibraryAliquot ali = libraryAliquotService.get(aliquotId);
            if (ali == null) {
                throw new ClientErrorException("Library aliquot " + aliquotId + " not found");
            }
            OrderLibraryAliquot orderLib = new OrderLibraryAliquot();
            orderLib.setAliquot(ali);
            order.getOrderLibraryAliquots().add(orderLib);
        }
    }
    return orderPage(order, model);
}
Also used : PoolOrder(uk.ac.bbsrc.tgac.miso.core.data.impl.PoolOrder) OrderLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot) ClientErrorException(uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException) OrderLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot) LibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.LibraryAliquot) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ClientErrorException (uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException)12 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 ArrayList (java.util.ArrayList)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 NotFoundException (org.springframework.security.acls.model.NotFoundException)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 Attachable (uk.ac.bbsrc.tgac.miso.core.data.Attachable)2 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)2 Group (com.eaglegenomics.simlims.core.Group)1 User (com.eaglegenomics.simlims.core.User)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1 Box (uk.ac.bbsrc.tgac.miso.core.data.Box)1 BoxPosition (uk.ac.bbsrc.tgac.miso.core.data.BoxPosition)1 Index (uk.ac.bbsrc.tgac.miso.core.data.Index)1 IndexFamily (uk.ac.bbsrc.tgac.miso.core.data.IndexFamily)1 Instrument (uk.ac.bbsrc.tgac.miso.core.data.Instrument)1