Search in sources :

Example 6 with QcTarget

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget in project miso-lims by miso-lims.

the class QcRestController method bulkDelete.

@PostMapping(value = "/bulk-delete")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public void bulkDelete(@RequestParam String qcTarget, @RequestBody(required = true) List<Long> ids) throws IOException {
    List<QC> items = new ArrayList<>();
    QcTarget target = null;
    try {
        target = QcTarget.valueOf(qcTarget);
    } catch (IllegalArgumentException e) {
        throw new RestException("Unsupported QC target: " + qcTarget, Status.BAD_REQUEST);
    }
    for (Long id : ids) {
        if (id == null) {
            throw new RestException("QC id cannot be null", Status.BAD_REQUEST);
        }
        QC item = qcService.get(target, id);
        if (item == null) {
            throw new RestException(String.format("No %s QC found with ID: %d", qcTarget, id), Status.BAD_REQUEST);
        }
        items.add(item);
    }
    qcService.bulkDelete(items);
}
Also used : QC(uk.ac.bbsrc.tgac.miso.core.data.qc.QC) ArrayList(java.util.ArrayList) QcTarget(uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with QcTarget

use of uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget in project miso-lims by miso-lims.

the class QcController method editBulk.

@PostMapping("/bulk/edit/{qcTarget}")
public ModelAndView editBulk(@PathVariable("qcTarget") String qcTargetLabel, @RequestParam Map<String, String> form, ModelMap model) throws IOException {
    QcTarget qcTarget = getQcTarget(qcTargetLabel);
    String qcIds = getStringInput("ids", form, true);
    int addControls = getIntegerInput("addControls", form, true);
    return new BulkEditTableBackend<QC, QcDto>("qc", QcDto.class, "QCs") {

        @Override
        protected QcDto asDto(QC model) {
            return Dtos.asDto(model);
        }

        @Override
        protected Stream<QC> load(List<Long> modelIds) throws IOException {
            return modelIds.stream().map(WhineyFunction.rethrow(id -> qcService.get(qcTarget, id)));
        }

        @Override
        protected void writeConfiguration(ObjectMapper mapper, ObjectNode config) throws IOException {
            config.putPOJO("instruments", instrumentService.list().stream().map(Dtos::asDto).collect(Collectors.toList()));
            config.put("addControls", addControls);
            config.put("qcTarget", qcTarget.getLabel());
        }

        @Override
        protected boolean isNewInterface() {
            return true;
        }
    }.edit(qcIds, model);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) QcTarget(uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget) IOException(java.io.IOException) QcDto(uk.ac.bbsrc.tgac.miso.dto.QcDto) QC(uk.ac.bbsrc.tgac.miso.core.data.qc.QC) Stream(java.util.stream.Stream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

QcTarget (uk.ac.bbsrc.tgac.miso.core.data.qc.QcTarget)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 QC (uk.ac.bbsrc.tgac.miso.core.data.qc.QC)4 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 Authentication (org.springframework.security.core.Authentication)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)1 ContainerQC (uk.ac.bbsrc.tgac.miso.core.data.qc.ContainerQC)1 LibraryQC (uk.ac.bbsrc.tgac.miso.core.data.qc.LibraryQC)1 PoolQC (uk.ac.bbsrc.tgac.miso.core.data.qc.PoolQC)1 SampleQC (uk.ac.bbsrc.tgac.miso.core.data.qc.SampleQC)1 QcType (uk.ac.bbsrc.tgac.miso.core.data.type.QcType)1