Class SampleServiceImpl

    • Method Detail

      • readMultiple

        @Transactional(readOnly=true)
        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\', \'ROLE_SEQUENCER\') or hasPermission(#idents, \'canReadSample\')")
        public java.lang.Iterable<Sample> readMultiple​(java.lang.Iterable<java.lang.Long> idents)
        Read multiple objects by the given collection of identifiers
        Specified by:
        readMultiple in interface CRUDService<java.lang.Long,​Sample>
        Overrides:
        readMultiple in class CRUDServiceImpl<java.lang.Long,​Sample>
        Parameters:
        idents - The unique identifiers of the objects to read
        Returns:
        A collection of the requested objects
      • exists

        @Transactional(readOnly=true)
        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\', \'ROLE_SEQUENCER\') or hasPermission(#id, \'canReadSample\')")
        public java.lang.Boolean exists​(java.lang.Long id)
        Check to see if an identifier for Type exists in the database.
        Specified by:
        exists in interface CRUDService<java.lang.Long,​Sample>
        Overrides:
        exists in class CRUDServiceImpl<java.lang.Long,​Sample>
        Parameters:
        id - The identifier to check for.
        Returns:
        true if the identifier exists, false otherwise.
      • create

        @PreAuthorize("hasAnyRole(\'ROLE_USER\', \'ROLE_SEQUENCER\')")
        public Sample create​(@Valid
                             @Valid Sample s)
        Create a new object in the persistence store.
        Specified by:
        create in interface CRUDService<java.lang.Long,​Sample>
        Overrides:
        create in class CRUDServiceImpl<java.lang.Long,​Sample>
        Parameters:
        s - The object to persist.
        Returns:
        The object as it was persisted in the database. May modify the identifier of the object when returned.
      • updateFields

        @PreAuthorize("hasPermission(#id, \'canUpdateSample\')")
        public Sample updateFields​(java.lang.Long id,
                                   java.util.Map<java.lang.String,​java.lang.Object> updatedFields)
                            throws javax.validation.ConstraintViolationException,
                                   EntityExistsException,
                                   InvalidPropertyException
        Update properties of the given object by given fields. The object must have a valid identifier prior to being passed to this method.
        Specified by:
        updateFields in interface CRUDService<java.lang.Long,​Sample>
        Overrides:
        updateFields in class CRUDServiceImpl<java.lang.Long,​Sample>
        Parameters:
        id - The identifier of the object to update.
        updatedFields - the object properties that should be updated.
        Returns:
        The object as it was persisted in the database. May modify the identifier of the object when returned.
        Throws:
        javax.validation.ConstraintViolationException - If the object being persisted cannot be validated by validation rules associated with the object.
        EntityExistsException - If the object being persisted violates uniqueness constraints in the database.
        InvalidPropertyException - If the updated properties map contains a property name that does not exist on the domain model.
      • update

        @PreAuthorize("hasPermission(#object, \'canUpdateSample\')")
        public Sample update​(Sample object)
        Update an object
        Specified by:
        update in interface CRUDService<java.lang.Long,​Sample>
        Overrides:
        update in class CRUDServiceImpl<java.lang.Long,​Sample>
        Parameters:
        object - The object to update
        Returns:
        The updated object
      • getMetadataForSample

        @PreAuthorize("hasPermission(#sample, \'canReadSample\')")
        @PostFilter("hasPermission(filterObject, \'canReadMetadataEntry\')")
        public java.util.Set<MetadataEntry> getMetadataForSample​(Sample sample)
        Get the MetadataEntry set associated with the given Sample
        Specified by:
        getMetadataForSample in interface SampleService
        Parameters:
        sample - the Sample to get metadata for
        Returns:
        the metadata associated with the given sample
      • getLockedSamplesInProject

        @PreAuthorize("hasPermission(#project, \'canReadProject\')")
        public java.util.List<java.lang.Long> getLockedSamplesInProject​(Project project)
        Get a list of Sample ids that are locked in this project. This method exists as a faster way of determining ownership than getting the full ProjectSampleJoin
        Specified by:
        getLockedSamplesInProject in interface SampleService
        Parameters:
        project - the Project to check
        Returns:
        a List of locked sample IDs.
      • getMetadataForProjectSamples

        @PreAuthorize("hasPermission(#project, \'canReadProject\')")
        @PostAuthorize("hasPermission(returnObject,\'readProjectMetadataResponse\')")
        public ProjectMetadataResponse getMetadataForProjectSamples​(Project project,
                                                                    java.util.List<java.lang.Long> sampleIds,
                                                                    java.util.List<MetadataTemplateField> fields)
        Get the metadata collections for a set of samples in a project. This will return a Map of Sample ID with a Set of the MetadataEntrys
        Specified by:
        getMetadataForProjectSamples in interface SampleService
        Parameters:
        project - the Project to get metadata for
        sampleIds - the Sample ids to get metadata for
        fields - the fields to get metadata from in the project. This must not be empty.
        Returns:
        a map of metadata
      • updateSampleMetadata

        @PreAuthorize("hasPermission(#s, \'canUpdateSample\')")
        @Transactional
        public Sample updateSampleMetadata​(Sample s,
                                           java.util.Set<MetadataEntry> metadataToSet)
        Set the given set of MetadataEntry on the given Sample and save it to the database
        Specified by:
        updateSampleMetadata in interface SampleService
        Parameters:
        s - the Sample to save metadata for
        metadataToSet - the metadata to save to the sample
        Returns:
        the updated Sample
      • mergeSampleMetadata

        @PreAuthorize("hasPermission(#s, \'canUpdateSample\')")
        @Transactional
        public Sample mergeSampleMetadata​(Sample s,
                                          java.util.Set<MetadataEntry> metadataToAdd)
        Merge the given set of MetadataEntry into the given Sample. This will replace existing metadata that matches and add the new data to the sample.
        Specified by:
        mergeSampleMetadata in interface SampleService
        Parameters:
        s - the sample to update
        metadataToAdd - the metadata to add
        Returns:
        the updated Sample
      • getSampleForProject

        @Transactional(readOnly=true)
        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\',\'ROLE_SEQUENCER\') or (hasPermission(#project, \'canReadProject\') and hasPermission(#sampleId, \'canReadSample\'))")
        public ProjectSampleJoin getSampleForProject​(Project project,
                                                     java.lang.Long sampleId)
        Get a specific instance of a Sample that belongs to a Project. If the Sample is not associated to the Project (i.e., no relationship is shared between the Sample and Project, then an EntityNotFoundException will be thrown.
        Specified by:
        getSampleForProject in interface SampleService
        Parameters:
        project - the Project to get the Sample for.
        sampleId - the identifier of the Sample
        Returns:
        the ProjectSampleJoin describing the relationship between projet and sample
      • getSampleOrganismsForProject

        @PreAuthorize("hasPermission(#project, \'canReadProject\')")
        public java.util.List<java.lang.String> getSampleOrganismsForProject​(Project project)
        Get a list of the organism fields stored for all Samples in a Project
        Specified by:
        getSampleOrganismsForProject in interface SampleService
        Parameters:
        project - the Project to get sample organisms for
        Returns:
        a list of sample organisms
      • getSampleBySampleName

        @Transactional(readOnly=true)
        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\', \'ROLE_SEQUENCER\') or hasPermission(#project, \'canReadProject\')")
        public Sample getSampleBySampleName​(Project project,
                                            java.lang.String sampleName)
        Get the Sample with the given sample name
        Specified by:
        getSampleBySampleName in interface SampleService
        Parameters:
        project - the Project that the Sample belongs to.
        sampleName - The name for the requested sample
        Returns:
        A Sample with the given ID
      • getSampleIdsBySampleNameForProjects

        @Transactional(readOnly=true)
        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\', \'ROLE_SEQUENCER\') or hasPermission(#project, \'canReadProject\')")
        public java.util.Map<java.lang.String,​java.util.List<java.lang.Long>> getSampleIdsBySampleNameForProjects​(java.util.List<java.lang.Long> projectIds,
                                                                                                                        java.util.List<java.lang.String> sampleNames)
        Get the Sample identifiers with the given list of sample names from a list of projects.
        Specified by:
        getSampleIdsBySampleNameForProjects in interface SampleService
        Parameters:
        projectIds - The Project identifiers that the Sample belongs to.
        sampleNames - The list of sample names
        Returns:
        A list of Sample identifiers
      • getSamplesForProject

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#project, \'canReadProject\')")
        public java.util.List<Join<Project,​Sample>> getSamplesForProject​(Project project)
        Get the list of Sample that belongs to a specific project.
        Specified by:
        getSamplesForProject in interface SampleService
        Parameters:
        project - the Project to get samples for.
        Returns:
        the collection of samples for the Project.
      • getSamplesForProjectShallow

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#project, \'canReadProject\')")
        public java.util.List<Sample> getSamplesForProjectShallow​(Project project)
        Description copied from interface: SampleService
        Get a shallow listing of the Samples in a Project. Note: This method will not return any metadata or associated objects.
        Specified by:
        getSamplesForProjectShallow in interface SampleService
        Parameters:
        project - The Project to get samples for
        Returns:
        a List of Sample
      • getSamplesInProject

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#project, \'canReadProject\')")
        public java.util.List<Sample> getSamplesInProject​(Project project,
                                                          java.util.List<java.lang.Long> sampleIds)
        Get a list of Sample in a Project given some Sample ids.
        Specified by:
        getSamplesInProject in interface SampleService
        Parameters:
        project - Project to get samples for.
        sampleIds - List of Sample ids.
        Returns:
        List of Samples from a Project.
      • getNumberOfSamplesForProject

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#project, \'canReadProject\')")
        public java.lang.Long getNumberOfSamplesForProject​(Project project)
        Get the number of Samples for a given Project. This method will be faster than getSamplesForProjects
        Specified by:
        getNumberOfSamplesForProject in interface SampleService
        Parameters:
        project - The project to get samples for
        Returns:
        The number of Samples in a given Project
      • mergeSamples

        @Transactional
        @PreAuthorize("hasPermission(#project, \'isProjectOwner\') and hasPermission(#mergeInto, \'canUpdateSample\') and hasPermission(#toMerge, \'canUpdateSample\')")
        public Sample mergeSamples​(Project project,
                                   Sample mergeInto,
                                   java.util.Collection<Sample> toMerge)
        Merge multiple samples into one. Merging samples copies the SequenceFile references from the set of samples into one sample. The collection of samples in toMerge are marked as deleted. All samples must be associated with the specified project. The relationship between each sample in toMerge and the project p will be deleted.
        Specified by:
        mergeSamples in interface SampleService
        Parameters:
        project - the Project that all samples must belong to.
        mergeInto - the Sample to merge other samples into.
        toMerge - the collection of Sample to merge.
        Returns:
        the completely merged Sample (the persisted version of mergeInto).
      • read

        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\', \'ROLE_SEQUENCER\') or hasPermission(#id, \'canReadSample\')")
        public Sample read​(java.lang.Long id)
        Read the object type by unique identifier.
        Specified by:
        read in interface CRUDService<java.lang.Long,​Sample>
        Overrides:
        read in class CRUDServiceImpl<java.lang.Long,​Sample>
        Parameters:
        id - The unique identifier for this object.
        Returns:
        The object corresponding to the unique identifier.
      • getSamplesForProjectWithName

        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\') or hasPermission(#project, \'canReadProject\')")
        public org.springframework.data.domain.Page<ProjectSampleJoin> getSamplesForProjectWithName​(Project project,
                                                                                                    java.lang.String name,
                                                                                                    int page,
                                                                                                    int size,
                                                                                                    org.springframework.data.domain.Sort.Direction order,
                                                                                                    java.lang.String... sortProperties)
        Get the Samples for a Project in page form
        Specified by:
        getSamplesForProjectWithName in interface SampleService
        Parameters:
        project - The project to read from
        name - The sample name to search
        page - The page number
        size - The size of the page
        order - The order of the page
        sortProperties - The properties to sort on
        Returns:
        A Page of Joins between Project and Sample
      • getTotalBasesForSample

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#sample, \'canReadSample\')")
        public java.lang.Long getTotalBasesForSample​(Sample sample)
                                              throws SequenceFileAnalysisException
        Given a sample gets the total number of bases in all sequence files in this sample.
        Specified by:
        getTotalBasesForSample in interface SampleService
        Parameters:
        sample - The sample to find the total number of bases.
        Returns:
        The total number of bases in all sequence files in this sample.
        Throws:
        SequenceFileAnalysisException - If there was an error getting FastQC analyses for a sequence file.
      • estimateCoverageForSample

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#sample, \'canReadSample\')")
        public java.lang.Double estimateCoverageForSample​(Sample sample,
                                                          long referenceFileLength)
                                                   throws SequenceFileAnalysisException
        Given the length of a reference file, estimate the total coverage for this sample.
        Specified by:
        estimateCoverageForSample in interface SampleService
        Parameters:
        sample - The sample to estimate coverage for.
        referenceFileLength - The length of the reference file in bases.
        Returns:
        The estimate coverage of all sequence data in this sample.
        Throws:
        SequenceFileAnalysisException - If there was an error getting FastQC analyses for a sequence file.
      • estimateCoverageForSample

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#sample, \'canReadSample\')")
        public java.lang.Double estimateCoverageForSample​(Sample sample,
                                                          ReferenceFile referenceFile)
                                                   throws SequenceFileAnalysisException
        Given a ReferenceFile, estimate the total coverage for this sample.
        Specified by:
        estimateCoverageForSample in interface SampleService
        Parameters:
        sample - The sample to estimate coverage for.
        referenceFile - The ReferenceFile to estimate coverage for.
        Returns:
        The estimate coverage of all sequence data in this sample.
        Throws:
        SequenceFileAnalysisException - If there was an error getting FastQC analyses for a sequence file.
      • getFilteredSamplesForProjects

        @PreAuthorize("hasAnyRole(\'ROLE_ADMIN\') or hasPermission(#projects, \'canReadProject\')")
        public org.springframework.data.domain.Page<ProjectSampleJoin> getFilteredSamplesForProjects​(java.util.List<Project> projects,
                                                                                                     java.util.List<java.lang.String> sampleNames,
                                                                                                     java.lang.String sampleName,
                                                                                                     java.lang.String searchTerm,
                                                                                                     java.lang.String organism,
                                                                                                     java.util.Date minDate,
                                                                                                     java.util.Date maxDate,
                                                                                                     int currentPage,
                                                                                                     int pageSize,
                                                                                                     org.springframework.data.domain.Sort sort)
        Get a Page of ProjectSampleJoin for samples from 1 or more projects based on filtering criteria.
        Specified by:
        getFilteredSamplesForProjects in interface SampleService
        Parameters:
        projects - List of Project the Samples must be found within.
        sampleNames - List of String of Sample names to search
        sampleName - String exact name of a specific Sample
        searchTerm - String search term to search for.
        organism - String organism ter to search for.
        minDate - Date minimum date the sample was modified.
        maxDate - Date maximum date the sample was modified.
        currentPage - Integer the current page the table is on.
        pageSize - Integer the number of ProjectSampleJoin in the Page.
        sort - Sort chained sort definitions to sort page by.
        Returns:
        a Page of ProjectSampleJoin that are filtered and sorted.
      • getQCEntriesForSamples

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#samples, \'canReadSample\')")
        public java.util.Map<java.lang.Long,​java.util.List<QCEntry>> getQCEntriesForSamples​(java.util.List<Sample> samples)
        Find all the QCEntry associated with SequencingObjects in a given Sample for a list of Samples
        Specified by:
        getQCEntriesForSamples in interface SampleService
        Parameters:
        samples - the Samples to get QCEntrys for
        Returns:
        a map of sample id to QCEntrys
      • updateMultiple

        @PreAuthorize("hasPermission(#objects, \'canUpdateSample\')")
        public java.util.List<Sample> updateMultiple​(java.util.Collection<Sample> objects)
        Update multiple objects at once
        Specified by:
        updateMultiple in interface CRUDService<java.lang.Long,​Sample>
        Overrides:
        updateMultiple in class CRUDServiceImpl<java.lang.Long,​Sample>
        Parameters:
        objects - the objects to update
        Returns:
        the updated objects
      • searchSamplesForUser

        @PreAuthorize("permitAll()")
        public org.springframework.data.domain.Page<ProjectSampleJoin> searchSamplesForUser​(java.lang.String query,
                                                                                            java.lang.Integer page,
                                                                                            java.lang.Integer count,
                                                                                            org.springframework.data.domain.Sort sort)
        Search all Samples in projects the current logged in user has access to
        Specified by:
        searchSamplesForUser in interface SampleService
        Parameters:
        query - the query string to search
        page - which page to return
        count - the number of entities to return
        sort - how to sort the result
        Returns:
        a page of ProjectSampleJoin
      • searchAllSamples

        @PreAuthorize("hasRole(\'ROLE_ADMIN\')")
        public org.springframework.data.domain.Page<ProjectSampleJoin> searchAllSamples​(java.lang.String query,
                                                                                        java.lang.Integer page,
                                                                                        java.lang.Integer count,
                                                                                        org.springframework.data.domain.Sort sort)
        Search all Samples in the database on the given query
        Specified by:
        searchAllSamples in interface SampleService
        Parameters:
        query - the query string to search
        page - which page to return
        count - the number of entities to return
        sort - how to sort the result
        Returns:
        a page of ProjectSampleJoin
      • getSamplesCreated

        @PreAuthorize("hasRole(\'ROLE_ADMIN\')")
        public java.lang.Long getSamplesCreated​(java.util.Date createdDate)
        Get count of samples created in the time period
        Specified by:
        getSamplesCreated in interface SampleService
        Parameters:
        createdDate - the minimum date for samples created
        Returns:
        An Long count of samples created
      • getSamplesCreatedGrouped

        @PreAuthorize("hasRole(\'ROLE_ADMIN\')")
        public java.util.List<GenericStatModel> getSamplesCreatedGrouped​(java.util.Date createdDate,
                                                                         StatisticTimePeriod statisticTimePeriod)
        Get list of GenericStatModel of samples created in the past n time period grouped by the format provided.
        Specified by:
        getSamplesCreatedGrouped in interface SampleService
        Parameters:
        createdDate - the minimum date for samples created
        statisticTimePeriod - the enum containing format for which to group the results by
        Returns:
        An GenericStatModel list
      • getCoverageForSamplesInProject

        @Transactional(readOnly=true)
        @PreAuthorize("hasRole(\'ROLE_ADMIN\') or hasPermission(#project, \'canReadProject\')")
        public java.util.Map<java.lang.Long,​java.lang.Long> getCoverageForSamplesInProject​(Project project,
                                                                                                 java.util.List<java.lang.Long> sampleIds)
        Get Coverage for samples within a project.
        Specified by:
        getCoverageForSamplesInProject in interface SampleService
        Parameters:
        project - the Project to use to calculate the coverage
        sampleIds - the Sample ids to get coverage for
        Returns:
        a map of sample id to coverage value