use of com.eaglegenomics.simlims.core.Group in project miso-lims by miso-lims.
the class Dtos method to.
public static Group to(@Nonnull GroupDto dto) {
Group to = new Group();
setLong(to::setId, dto.getId(), false);
setString(to::setName, dto.getName());
setString(to::setDescription, dto.getDescription());
return to;
}
use of com.eaglegenomics.simlims.core.Group in project miso-lims by miso-lims.
the class EditLibraryController method receiveBulkLibraries.
@PostMapping(value = "/bulk/receive")
public ModelAndView receiveBulkLibraries(@RequestParam Map<String, String> form, ModelMap model) throws IOException {
Integer quantity = getIntegerInput("quantity", form, true);
Long aliquotClassId = getLongInput("sampleClassId", form, isDetailedSampleEnabled());
Long projectId = getLongInput("projectId", form, false);
Long boxId = getLongInput("boxId", form, false);
LibraryDto libDto = null;
Project project = null;
if (projectId != null) {
project = projectService.get(projectId);
if (project == null)
throw new ClientErrorException("No project found for ID " + projectId);
}
SampleClass aliquotClass = null;
if (isDetailedSampleEnabled()) {
aliquotClass = sampleClassService.get(aliquotClassId);
if (aliquotClass == null)
throw new ClientErrorException("No sample class found for ID " + aliquotClassId);
DetailedLibraryDto detailedDto = new DetailedLibraryDto();
libDto = detailedDto;
SampleAliquotDto samDto = null;
if (SampleAliquotSingleCell.SUBCATEGORY_NAME.equals(aliquotClass.getSampleSubcategory())) {
samDto = new SampleAliquotSingleCellDto();
} else if (SampleAliquotRna.SUBCATEGORY_NAME.equals(aliquotClass.getSampleSubcategory())) {
samDto = new SampleAliquotRnaDto();
} else {
samDto = new SampleAliquotDto();
}
detailedDto.setSample(samDto);
samDto.setSampleClassId(aliquotClassId);
detailedDto.setParentSampleClassId(aliquotClassId);
} else {
libDto = new LibraryDto();
libDto.setSample(new SampleDto());
}
if (boxId != null) {
libDto.setBox(Dtos.asDto(boxService.get(boxId), true));
}
Set<Group> recipientGroups = authorizationManager.getCurrentUser().getGroups();
return new BulkReceiveLibraryBackend(libDto, quantity, project, aliquotClass, defaultSciName, libraryTemplateService, recipientGroups).create(model);
}
use of com.eaglegenomics.simlims.core.Group in project miso-lims by miso-lims.
the class EditSampleController method createBulkSamples.
/**
* Used to create new samples.
* <ul>
* <li>Detailed Sample: create new samples of a given sample class. Root identities will be found or created.</li>
* <li>Plain Sample: create new samples.</li>
* </ul>
* Sends Dtos objects which will then be used for editing in grid.
*/
@PostMapping(value = "/bulk/new")
public ModelAndView createBulkSamples(@RequestParam Map<String, String> form, ModelMap model) throws IOException {
Integer quantity = getIntegerInput("quantity", form, true);
String targetCategory = getStringInput("targetCategory", form, isDetailedSampleEnabled());
Long projectId = getLongInput("projectId", form, false);
Long boxId = getLongInput("boxId", form, false);
if (quantity == null || quantity <= 0)
throw new RestException("Must specify quantity of samples to create", Status.BAD_REQUEST);
final SampleDto template;
if (isDetailedSampleEnabled()) {
// create new detailed samples
confirmClassesExist(targetCategory);
template = getCorrectDetailedSampleDto(targetCategory);
} else {
template = new SampleDto();
}
final Project project;
if (projectId == null) {
project = null;
} else {
project = projectService.get(projectId);
template.setProjectId(projectId);
}
if (boxId != null) {
template.setBox(Dtos.asDto(boxService.get(boxId), true));
}
Set<Group> recipientGroups = authorizationManager.getCurrentUser().getGroups();
return new BulkCreateSampleBackend(template.getClass(), template, quantity, project, targetCategory, recipientGroups).create(model);
}
use of com.eaglegenomics.simlims.core.Group in project miso-lims by miso-lims.
the class DefaultTransferService method validateItems.
private <T extends Boxable, U extends TransferItem<T>> void validateItems(Transfer transfer, Transfer beforeChange, Function<Transfer, Set<U>> getItems, List<ValidationError> errors) throws IOException {
Set<U> items = getItems.apply(transfer);
Set<U> beforeChangeItems = beforeChange == null ? null : getItems.apply(beforeChange);
if (items.stream().anyMatch(item -> Boolean.FALSE.equals(item.isQcPassed()) && LimsUtils.isStringEmptyOrNull(item.getQcNote()))) {
errors.add(new ValidationError("items", ERROR_QC_NOTE_REQUIRED));
}
if (beforeChange != null && !authorizationManager.isAdminUser() && transfer.getSenderGroup() != null && !authorizationManager.isGroupMember(transfer.getSenderGroup()) && (items.size() != beforeChangeItems.size() || items.stream().anyMatch(item -> beforeChangeItems.stream().noneMatch(beforeItem -> beforeItem.getItem().getId() == item.getItem().getId())))) {
errors.add(new ValidationError("items", ERROR_UNAUTHORIZED_ITEM_MODIFY));
}
if (!authorizationManager.isAdminUser()) {
if (beforeChange == null) {
if (transfer.getRecipientGroup() != null && !authorizationManager.isGroupMember(transfer.getRecipientGroup())) {
if (items.stream().anyMatch(item -> item.isQcPassed() != null || item.getQcNote() != null)) {
errors.add(new ValidationError("items", ERROR_UNAUTHORIZED_QC));
}
if (items.stream().anyMatch(item -> item.isReceived() != null)) {
errors.add(new ValidationError("items", ERROR_UNAUTHORIZED_RECEIPT));
}
}
} else {
if (!authorizationManager.isGroupMember(transfer.getRecipientGroup()) && items.stream().anyMatch(item -> {
U beforeChangeItem = beforeChangeItems.stream().filter(before -> before.getItem().getId() == item.getItem().getId()).findFirst().orElse(null);
return beforeChangeItem != null && isChanged(item, beforeChangeItem);
})) {
errors.add(new ValidationError("items", "Only administrators and members of the recipient group can mark receipt and QC results"));
}
}
}
if (transfer.isDistribution() && items.stream().anyMatch(item -> !Boolean.TRUE.equals(item.isReceived()))) {
errors.add(new ValidationError("items", ERROR_DISTRIBUTION_NOT_RECEIVED));
}
if (transfer.getSenderLab() != null) {
if (items.stream().map(TransferItem::getItem).anyMatch(item -> item.getTransferViews().stream().anyMatch(itemTransfer -> itemTransfer.isReceipt() && (!transfer.isSaved() || itemTransfer.getId() != transfer.getId())))) {
errors.add(new ValidationError("items", ERROR_MULTIPLE_RECEIPT));
}
} else if (transfer.getRecipient() != null && items.stream().map(TransferItem::getItem).anyMatch(item -> item.getTransferViews().stream().anyMatch(itemTransfer -> itemTransfer.isDistribution() && (!transfer.isSaved() || itemTransfer.getId() != transfer.getId())))) {
errors.add(new ValidationError("items", ERROR_MULTIPLE_DISTRIBUTION));
}
}
use of com.eaglegenomics.simlims.core.Group in project miso-lims by miso-lims.
the class DefaultTransferServiceTest method validateSenderGroupChangeAllowed.
@Test
public void validateSenderGroupChangeAllowed() throws Exception {
Group group1 = makeGroup(1L);
Group group2 = makeGroup(2L);
setUser(false, group1, group2);
Transfer before = makeTransfer(group1, "Recipient");
Transfer updated = copyTransfer(before);
updated.setSenderGroup(group2);
List<ValidationError> errors = validate(updated, before);
assertNoError(errors, "Only administrators and members of the sender group can change sender group");
assertNoError(errors, "Sender group must be a group that you are a member of");
}
Aggregations