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