Search in sources :

Example 26 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class ReadSamplePermissionTest method testGrantPermission.

@Test
public void testGrantPermission() {
    String username = "fbristow";
    User u = new User();
    u.setUsername(username);
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, User>> projectUsers = new ArrayList<>();
    projectUsers.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER));
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sampleRepository.findOne(1L)).thenReturn(s);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertTrue("permission was not granted.", readSamplePermission.isAllowed(auth, 1L));
    verify(sampleRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
    verify(readProjectPermission).isAllowed(any(), eq(p));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 27 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class UsersControllerTest method testGetUserSpecificPage.

@SuppressWarnings("rawtypes")
@Test
public void testGetUserSpecificPage() {
    Principal principal = () -> USER_NAME;
    Long userId = 1L;
    String roleString = "User";
    ExtendedModelMap model = new ExtendedModelMap();
    User user = new User(userId, USER_NAME, null, null, null, null, null);
    user.setSystemRole(Role.ROLE_USER);
    @SuppressWarnings("unchecked") List<Join<Project, User>> joins = Lists.newArrayList(new ProjectUserJoin(new Project("good project"), user, ProjectRole.PROJECT_USER));
    when(userService.read(userId)).thenReturn(user);
    when(userService.getUserByUsername(USER_NAME)).thenReturn(user);
    when(messageSource.getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class))).thenReturn(roleString);
    when(projectService.getProjectsForUser(user)).thenReturn(joins);
    String userSpecificPage = controller.getUserSpecificPage(userId, true, model, principal);
    assertEquals(USERS_DETAILS_PAGE, userSpecificPage);
    assertEquals(user, model.get("user"));
    assertEquals(roleString, model.get("systemRole"));
    assertEquals(true, model.get("canEditUser"));
    assertEquals(joins.size(), ((List) model.get("projects")).size());
    verify(userService).read(userId);
    verify(userService).getUserByUsername(USER_NAME);
    verify(messageSource).getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class));
    verify(projectService).getProjectsForUser(user);
}
Also used : Locale(java.util.Locale) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DTUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Principal(java.security.Principal) Test(org.junit.Test)

Example 28 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class ProjectSynchronizationService method syncProject.

/**
 * Synchronize a given {@link Project} to the local installation.
 *
 * @param project
 *            the {@link Project} to synchronize. This should have been read
 *            from a remote api.
 */
private void syncProject(Project project) {
    project.getRemoteStatus().setSyncStatus(SyncStatus.UPDATING);
    projectService.update(project);
    String projectURL = project.getRemoteStatus().getURL();
    Project readProject = projectRemoteService.read(projectURL);
    // ensure we use the same IDs
    readProject = updateIds(project, readProject);
    // if project was updated remotely, update it here
    if (checkForChanges(project.getRemoteStatus(), readProject)) {
        logger.debug("found changes for project " + readProject.getSelfHref());
        // need to keep the status and frequency of the local project
        RemoteStatus originalStatus = project.getRemoteStatus();
        readProject.getRemoteStatus().setSyncStatus(originalStatus.getSyncStatus());
        readProject.setSyncFrequency(project.getSyncFrequency());
        project = projectService.update(readProject);
    }
    List<Join<Project, Sample>> localSamples = sampleService.getSamplesForProject(project);
    // get all the samples by their url
    Map<String, Sample> samplesByUrl = new HashMap<>();
    localSamples.forEach(j -> {
        Sample sample = j.getObject();
        // If a user has added a sample for some reason, ignore it
        if (sample.getRemoteStatus() != null) {
            String url = sample.getRemoteStatus().getURL();
            samplesByUrl.put(url, sample);
        } else {
            logger.warn("Sample " + sample.getId() + " is not a remote sample.  It will not be synchronized.");
        }
    });
    List<Sample> readSamplesForProject = sampleRemoteService.getSamplesForProject(readProject);
    for (Sample s : readSamplesForProject) {
        s.setId(null);
        s = syncSampleMetadata(s);
        syncSample(s, project, samplesByUrl);
    }
    project.setRemoteStatus(readProject.getRemoteStatus());
    project.getRemoteStatus().setSyncStatus(SyncStatus.SYNCHRONIZED);
    projectService.update(project);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)

Example 29 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class AssemblyFileProcessor method shouldAssemble.

/**
 * Check whether any {@link Project} associated with the
 * {@link SequencingObject} is set to assemble
 *
 * @param object
 *            {@link SequencingObject} to check ot assemble
 * @return true if it should assemble, false otherwise
 */
private boolean shouldAssemble(SequencingObject object) {
    boolean assemble = false;
    SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(object);
    /*
		 * This is something that should only ever happen in tests, but added
		 * check with a warning
		 */
    if (sampleForSequencingObject != null) {
        List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(sampleForSequencingObject.getSubject());
        assemble = projectForSample.stream().anyMatch(j -> j.getSubject().getAssembleUploads());
    } else {
        logger.warn("Cannot find sample for sequencing object.  Not assembling");
    }
    return assemble;
}
Also used : ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) Logger(org.slf4j.Logger) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) IridaWorkflowsService(ca.corefacility.bioinformatics.irida.service.workflow.IridaWorkflowsService) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UUID(java.util.UUID) SampleSequencingObjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleSequencingObjectJoinRepository) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sets(com.google.common.collect.Sets) List(java.util.List) Component(org.springframework.stereotype.Component) User(ca.corefacility.bioinformatics.irida.model.user.User) Builder(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission.Builder) AnalysisSubmissionRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.AnalysisSubmissionRepository) Transactional(org.springframework.transaction.annotation.Transactional) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)

Example 30 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class SistrTypingFileProcessor method shouldTypeWithSISTR.

/**
 * Check whether any {@link Project} associated with the
 * {@link SequencingObject} is set to type with SISTR.
 *
 * @param object {@link SequencingObject} to check to type with SISTR.
 * @return true if it should type with SISTR, false otherwise
 */
private Project.AutomatedSISTRSetting shouldTypeWithSISTR(SequencingObject object) {
    Project.AutomatedSISTRSetting type = Project.AutomatedSISTRSetting.OFF;
    SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(object);
    /*
		 * This is something that should only ever happen in tests, but added
		 * check with a warning
		 */
    if (sampleForSequencingObject != null) {
        List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(sampleForSequencingObject.getSubject());
        Set<Project.AutomatedSISTRSetting> sistrOptions = projectForSample.stream().map(j -> j.getSubject().getSistrTypingUploads()).collect(Collectors.toSet());
        if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO_METADATA)) {
            return Project.AutomatedSISTRSetting.AUTO_METADATA;
        } else if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO))
            return Project.AutomatedSISTRSetting.AUTO;
    } else {
        logger.warn("Cannot find sample for sequencing object.  Not typing with SISTR");
    }
    return type;
}
Also used : ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) Logger(org.slf4j.Logger) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) IridaWorkflowsService(ca.corefacility.bioinformatics.irida.service.workflow.IridaWorkflowsService) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Set(java.util.Set) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SampleSequencingObjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleSequencingObjectJoinRepository) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sets(com.google.common.collect.Sets) List(java.util.List) Component(org.springframework.stereotype.Component) User(ca.corefacility.bioinformatics.irida.model.user.User) Builder(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission.Builder) AnalysisSubmissionRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.AnalysisSubmissionRepository) Transactional(org.springframework.transaction.annotation.Transactional) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)

Aggregations

Join (ca.corefacility.bioinformatics.irida.model.joins.Join)65 Project (ca.corefacility.bioinformatics.irida.model.project.Project)60 Test (org.junit.Test)40 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)35 User (ca.corefacility.bioinformatics.irida.model.user.User)35 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)34 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)26 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)23 ArrayList (java.util.ArrayList)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)20 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)16 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)14 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)13 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)13 List (java.util.List)12 Set (java.util.Set)12 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 ProjectSampleJoinRepository (ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository)10 ProjectService (ca.corefacility.bioinformatics.irida.service.ProjectService)10