Search in sources :

Example 16 with Group

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;
}
Also used : Group(com.eaglegenomics.simlims.core.Group) IonTorrentRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IonTorrentRunDto) QcHierarchyNodeDto(uk.ac.bbsrc.tgac.miso.dto.dashi.QcHierarchyNodeDto) RunPositionDto(uk.ac.bbsrc.tgac.miso.dto.run.RunPositionDto) PacBioRunDto(uk.ac.bbsrc.tgac.miso.dto.run.PacBioRunDto) Ls454RunDto(uk.ac.bbsrc.tgac.miso.dto.run.Ls454RunDto) IlluminaNotificationDto(ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto) OxfordNanoporeRunDto(uk.ac.bbsrc.tgac.miso.dto.run.OxfordNanoporeRunDto) IlluminaRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IlluminaRunDto) NotificationDto(ca.on.oicr.gsi.runscanner.dto.NotificationDto) OxfordNanoporeNotificationDto(ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto) RunDto(uk.ac.bbsrc.tgac.miso.dto.run.RunDto) SolidRunDto(uk.ac.bbsrc.tgac.miso.dto.run.SolidRunDto) OrderAliquotDto(uk.ac.bbsrc.tgac.miso.dto.PoolOrderDto.OrderAliquotDto)

Example 17 with Group

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);
}
Also used : Group(com.eaglegenomics.simlims.core.Group) SampleAliquotSingleCellDto(uk.ac.bbsrc.tgac.miso.dto.SampleAliquotSingleCellDto) Project(uk.ac.bbsrc.tgac.miso.core.data.Project) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleAliquotDto(uk.ac.bbsrc.tgac.miso.dto.SampleAliquotDto) LibraryDto(uk.ac.bbsrc.tgac.miso.dto.LibraryDto) DetailedLibraryDto(uk.ac.bbsrc.tgac.miso.dto.DetailedLibraryDto) ClientErrorException(uk.ac.bbsrc.tgac.miso.webapp.controller.component.ClientErrorException) SampleAliquotRnaDto(uk.ac.bbsrc.tgac.miso.dto.SampleAliquotRnaDto) DetailedLibraryDto(uk.ac.bbsrc.tgac.miso.dto.DetailedLibraryDto) SampleDto(uk.ac.bbsrc.tgac.miso.dto.SampleDto) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 18 with Group

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);
}
Also used : Project(uk.ac.bbsrc.tgac.miso.core.data.Project) Group(com.eaglegenomics.simlims.core.Group) RestException(uk.ac.bbsrc.tgac.miso.webapp.controller.rest.RestException) DetailedSampleDto(uk.ac.bbsrc.tgac.miso.dto.DetailedSampleDto) SampleDto(uk.ac.bbsrc.tgac.miso.dto.SampleDto) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 19 with Group

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));
    }
}
Also used : Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBoxPosition(uk.ac.bbsrc.tgac.miso.core.data.AbstractBoxPosition) GroupService(uk.ac.bbsrc.tgac.miso.core.service.GroupService) BigDecimal(java.math.BigDecimal) Project(uk.ac.bbsrc.tgac.miso.core.data.Project) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Box(uk.ac.bbsrc.tgac.miso.core.data.Box) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) SampleService(uk.ac.bbsrc.tgac.miso.core.service.SampleService) TransferNotification(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferNotification) Set(java.util.Set) DeletionStore(uk.ac.bbsrc.tgac.miso.core.store.DeletionStore) Objects(java.util.Objects) List(java.util.List) TransferPool(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferPool) Boxable(uk.ac.bbsrc.tgac.miso.core.data.Boxable) PoolService(uk.ac.bbsrc.tgac.miso.core.service.PoolService) ChangeLogService(uk.ac.bbsrc.tgac.miso.core.service.ChangeLogService) TransferLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibrary) AbstractSaveService(uk.ac.bbsrc.tgac.miso.service.AbstractSaveService) SaveDao(uk.ac.bbsrc.tgac.miso.persistence.SaveDao) TransferChangeLog(uk.ac.bbsrc.tgac.miso.core.data.impl.changelog.TransferChangeLog) TransferItem(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferItem) User(com.eaglegenomics.simlims.core.User) AuthorizationManager(uk.ac.bbsrc.tgac.miso.core.security.AuthorizationManager) TransferNotificationService(uk.ac.bbsrc.tgac.miso.core.service.TransferNotificationService) TransferService(uk.ac.bbsrc.tgac.miso.core.service.TransferService) ProviderService(uk.ac.bbsrc.tgac.miso.core.service.ProviderService) Function(java.util.function.Function) Supplier(java.util.function.Supplier) LibraryAliquotService(uk.ac.bbsrc.tgac.miso.core.service.LibraryAliquotService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lab(uk.ac.bbsrc.tgac.miso.core.data.Lab) LibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.LibraryAliquot) LibraryAliquotBoxPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.boxposition.LibraryAliquotBoxPosition) LabService(uk.ac.bbsrc.tgac.miso.core.service.LabService) Service(org.springframework.stereotype.Service) Group(com.eaglegenomics.simlims.core.Group) LimsUtils(uk.ac.bbsrc.tgac.miso.core.util.LimsUtils) BiConsumer(java.util.function.BiConsumer) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) PoolBoxPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.boxposition.PoolBoxPosition) SampleBoxPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.boxposition.SampleBoxPosition) Iterator(java.util.Iterator) LibraryService(uk.ac.bbsrc.tgac.miso.core.service.LibraryService) IOException(java.io.IOException) BoxService(uk.ac.bbsrc.tgac.miso.core.service.BoxService) Consumer(java.util.function.Consumer) TransferLibraryAliquot(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferLibraryAliquot) LibraryBoxPosition(uk.ac.bbsrc.tgac.miso.core.data.impl.boxposition.LibraryBoxPosition) TransferStore(uk.ac.bbsrc.tgac.miso.persistence.TransferStore) Transfer(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.Transfer) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) Transactional(org.springframework.transaction.annotation.Transactional) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)

Example 20 with Group

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");
}
Also used : Group(com.eaglegenomics.simlims.core.Group) Transfer(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.Transfer) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) Test(org.junit.Test)

Aggregations

Group (com.eaglegenomics.simlims.core.Group)29 Test (org.junit.Test)13 Transfer (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.Transfer)10 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)7 User (com.eaglegenomics.simlims.core.User)6 ValidationError (uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)6 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Lab (uk.ac.bbsrc.tgac.miso.core.data.Lab)3 LabImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.LabImpl)3 UserImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.UserImpl)3 IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)2 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)2 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)2 Criteria (org.hibernate.Criteria)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 Library (uk.ac.bbsrc.tgac.miso.core.data.Library)2 Pool (uk.ac.bbsrc.tgac.miso.core.data.Pool)2 Sample (uk.ac.bbsrc.tgac.miso.core.data.Sample)2