Search in sources :

Example 11 with Dtos

use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.

the class EditPoolController method setupForm.

@GetMapping(value = "/{poolId}")
public ModelAndView setupForm(@PathVariable Long poolId, ModelMap model) throws IOException {
    Pool pool = null;
    if (poolId == null) {
        pool = new PoolImpl();
        model.put("title", "New Pool");
    } else {
        pool = poolService.get(poolId);
        model.put("title", "Pool " + poolId);
    }
    if (pool == null)
        throw new NotFoundException("No pool found for ID " + poolId.toString());
    PoolDto poolDto = Dtos.asDto(pool, true, false, indexChecker);
    ObjectMapper mapper = new ObjectMapper();
    model.put("pool", pool);
    if (poolId == null) {
        model.put("partitions", Collections.emptyList());
        model.put("poolDto", "{}");
        model.put("runs", Collections.emptyList());
        model.put("orders", Collections.emptyList());
    } else {
        model.put("partitions", containerService.listPartitionsByPoolId(poolId).stream().map(partition -> Dtos.asDto(partition, indexChecker)).collect(Collectors.toList()));
        model.put("poolDto", mapper.writeValueAsString(poolDto));
        model.put("runs", Dtos.asRunDtos(runService.listByPoolId(poolId)));
        model.put("orders", Dtos.asSequencingOrderDtos(sequencingOrderService.getByPool(pool), indexChecker));
    }
    model.put("poolorders", poolOrderService.getAllByPoolId(pool.getId()).stream().map(order -> Dtos.asDto(order)).collect(Collectors.toList()));
    model.put("duplicateIndicesSequences", mapper.writeValueAsString(poolDto.getDuplicateIndicesSequences()));
    model.put("nearDuplicateIndicesSequences", mapper.writeValueAsString(poolDto.getNearDuplicateIndicesSequences()));
    model.put("poolTransfers", pool.getTransferViews().stream().map(Dtos::asDto).collect(Collectors.toList()));
    return new ModelAndView("/WEB-INF/pages/editPool.jsp", model);
}
Also used : Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) ModelAndView(org.springframework.web.servlet.ModelAndView) NotFoundException(org.springframework.security.acls.model.NotFoundException) PoolDto(uk.ac.bbsrc.tgac.miso.dto.PoolDto) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) PoolImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.PoolImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 12 with Dtos

use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.

the class TransferRestController method addNotification.

@PostMapping("/{transferId}/notifications")
@ResponseBody
public TransferNotificationDto addNotification(@PathVariable long transferId, @RequestBody TransferNotificationDto dto, @RequestParam(defaultValue = "false") boolean saveContact) throws IOException {
    Transfer transfer = RestUtils.retrieve("Transfer", transferId, transferService);
    TransferNotificationDto result = RestUtils.createObject("Notification", dto, from -> {
        TransferNotification notification = Dtos.to(from);
        notification.setTransfer(transfer);
        return notification;
    }, transferNotificationService, Dtos::asDto);
    if (saveContact) {
        Contact contact = new Contact();
        contact.setName(result.getRecipientName());
        contact.setEmail(result.getRecipientEmail());
        contactService.create(contact);
    }
    return result;
}
Also used : Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) TransferNotificationDto(uk.ac.bbsrc.tgac.miso.dto.TransferNotificationDto) TransferNotification(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification) Transfer(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.Transfer) Contact(uk.ac.bbsrc.tgac.miso.core.data.impl.Contact) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with Dtos

use of uk.ac.bbsrc.tgac.miso.dto.Dtos 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)

Example 14 with Dtos

use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.

the class UserRestController method update.

@PutMapping("/{userId}")
@ResponseBody
public UserDto update(@PathVariable long userId, @RequestBody UserDto dto) throws IOException {
    if (!securityManager.canCreateNewUser()) {
        throw new RestException("Cannot modify users in MISO directly.", Status.BAD_REQUEST);
    }
    return RestUtils.updateObject("User", userId, dto, d -> {
        User user = Dtos.to(d);
        // null password has the effect of keeping the current password in DefaultUserService
        user.setPassword(null);
        return user;
    }, userService, Dtos::asDto);
}
Also used : User(com.eaglegenomics.simlims.core.User) Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with Dtos

use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.

the class AttachmentsTag method doStartTagInternal.

@Override
protected int doStartTagInternal() throws Exception {
    Attachable attachable = (Attachable) this.item;
    ObjectMapper mapper = new ObjectMapper();
    String projectConfig = projectId == null ? "" : (", projectId: " + projectId);
    pageContext.getOut().append(String.format("<br/><h1>Attachments</h1><table id='attachments' class='display no-border ui-widget-content'></table><script type='text/javascript'>jQuery(document).ready(function () { ListUtils.createStaticTable('attachments', ListTarget.attachment, {entityType: '%1$s', entityId: %2$s" + projectConfig + "}, %3$s);});</script>", attachable.getAttachmentsTarget(), attachable.getId(), mapper.writeValueAsString(attachable.getAttachments().stream().map(Dtos::asDto).collect(Collectors.toList()))));
    return SKIP_BODY;
}
Also used : Dtos(uk.ac.bbsrc.tgac.miso.dto.Dtos) Attachable(uk.ac.bbsrc.tgac.miso.core.data.Attachable) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Dtos (uk.ac.bbsrc.tgac.miso.dto.Dtos)29 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)14 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 ModelAndView (org.springframework.web.servlet.ModelAndView)11 NotFoundException (org.springframework.security.acls.model.NotFoundException)10 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 PutMapping (org.springframework.web.bind.annotation.PutMapping)7 IOException (java.io.IOException)6 Collectors (java.util.stream.Collectors)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Controller (org.springframework.stereotype.Controller)6 PathVariable (org.springframework.web.bind.annotation.PathVariable)6 User (com.eaglegenomics.simlims.core.User)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Objects (java.util.Objects)4 Stream (java.util.stream.Stream)4