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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations