Search in sources :

Example 26 with ProjectUserJoin

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

the class ProjectServiceImplTest method testAddUserToProject.

@Test
public void testAddUserToProject() {
    User u = new User("test", "test@nowhere.com", "PASSWOD!1", "Test", "User", "1234");
    u.setId(new Long(1111));
    Project p = project();
    ProjectRole r = ProjectRole.PROJECT_USER;
    ProjectUserJoin join = new ProjectUserJoin(p, u, r);
    when(pujRepository.save(join)).thenReturn(join);
    projectService.addUserToProject(p, u, r);
    verify(pujRepository).save(join);
}
Also used : 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) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Example 27 with ProjectUserJoin

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

the class ProjectServiceImplTest method testGetProjectsForUser.

@Test
public void testGetProjectsForUser() {
    final User u = new User();
    final Project p1 = new Project("p1");
    final Project p2 = new Project("p2");
    final UserGroup ug = new UserGroup("group");
    final ProjectUserJoin puj = new ProjectUserJoin(p1, u, ProjectRole.PROJECT_OWNER);
    final UserGroupProjectJoin ugpj = new UserGroupProjectJoin(p2, ug, ProjectRole.PROJECT_OWNER);
    when(pujRepository.getProjectsForUser(u)).thenReturn(ImmutableList.of(puj));
    when(ugpjRepository.findProjectsByUser(u)).thenReturn(ImmutableList.of(ugpj));
    final List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
    assertEquals("User should be in 2 projects.", 2, projects.size());
    assertTrue("Should have found user project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p1)));
    assertTrue("Should have found group project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p2)));
}
Also used : ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) ConstraintViolationImpl(org.hibernate.validator.internal.engine.ConstraintViolationImpl) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Path(java.nio.file.Path) ConstraintViolation(javax.validation.ConstraintViolation) ReferenceFileRepository(ca.corefacility.bioinformatics.irida.repositories.referencefile.ReferenceFileRepository) UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) Set(java.util.Set) Validator(javax.validation.Validator) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) SampleSequencingObjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleSequencingObjectJoinRepository) Matchers.any(org.mockito.Matchers.any) ProjectUserJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectUserJoinRepository) List(java.util.List) Specification(org.springframework.data.jpa.domain.Specification) Assert.assertFalse(org.junit.Assert.assertFalse) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectAnalysisSubmissionJoinRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.ProjectAnalysisSubmissionJoinRepository) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) PageImpl(org.springframework.data.domain.PageImpl) Mockito.mock(org.mockito.Mockito.mock) ProjectServiceImpl(ca.corefacility.bioinformatics.irida.service.impl.ProjectServiceImpl) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SampleRepository(ca.corefacility.bioinformatics.irida.repositories.sample.SampleRepository) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserGroupProjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.UserGroupProjectJoinRepository) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ProjectReferenceFileJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectReferenceFileJoinRepository) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) RelatedProjectRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.RelatedProjectRepository) ProjectRepository(ca.corefacility.bioinformatics.irida.repositories.ProjectRepository) Before(org.junit.Before) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Mockito.when(org.mockito.Mockito.when) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Mockito.verify(org.mockito.Mockito.verify) ConstraintViolationException(javax.validation.ConstraintViolationException) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) Assert.assertEquals(org.junit.Assert.assertEquals) 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) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) 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) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Test(org.junit.Test)

Example 28 with ProjectUserJoin

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

the class UserControllerTest method testGetUserProjects.

@Test
public void testGetUserProjects() {
    // set up expectations
    String username = "fbristow";
    User u = new User();
    u.setUsername(username);
    List<Join<Project, User>> projects = new ArrayList<>();
    Project p = TestDataFactory.constructProject();
    Join<Project, User> join = new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER);
    projects.add(join);
    // set up mocks
    when(userService.getUserByUsername(username)).thenReturn(u);
    when(projectService.getProjectsForUser(u)).thenReturn(projects);
    // run the test
    ModelMap output = controller.getUserProjects(username);
    @SuppressWarnings("unchecked") ResourceCollection<Project> pulledProjects = (ResourceCollection<Project>) output.get("projectResources");
    List<Project> projectResources = pulledProjects.getResources();
    assertEquals(1, projectResources.size());
    Project resource = projectResources.get(0);
    assertEquals(p.getName(), resource.getName());
    assertEquals(1, resource.getLinks().size());
    Link link = resource.getLinks().get(0);
    assertEquals(Link.REL_SELF, link.getRel());
    assertTrue(link.getHref().contains(p.getId().toString()));
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ModelMap(org.springframework.ui.ModelMap) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Link(org.springframework.hateoas.Link) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) Test(org.junit.Test)

Example 29 with ProjectUserJoin

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

the class ProjectUsersControllerTest method testGetUsersForProject.

@Test
public void testGetUsersForProject() throws ProjectWithoutOwnerException {
    String username = "fbristow";
    User u = new User();
    u.setUsername(username);
    u.setId(1L);
    Project p = TestDataFactory.constructProject();
    Join<Project, User> join = new ProjectUserJoin(p, u, ProjectRole.PROJECT_OWNER);
    @SuppressWarnings("unchecked") List<Join<Project, User>> relationships = Lists.newArrayList(join);
    when(userService.getUsersForProject(p)).thenReturn(relationships);
    when(projectService.read(p.getId())).thenReturn(p);
    ModelMap map = controller.getUsersForProject(p.getId());
    verify(projectService, times(1)).read(p.getId());
    verify(userService, times(1)).getUsersForProject(p);
    Object o = map.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull(o);
    assertTrue(o instanceof ResourceCollection);
    @SuppressWarnings("unchecked") ResourceCollection<User> users = (ResourceCollection<User>) o;
    assertEquals(1, users.size());
    User ur = users.iterator().next();
    assertTrue(ur.getLink("self").getHref().endsWith(username));
    Link relationship = ur.getLink(RESTGenericController.REL_RELATIONSHIP);
    assertNotNull(relationship);
    assertEquals("http://localhost/api/projects/" + p.getId() + "/users/" + username, relationship.getHref());
    assertTrue(users.getLink("self").getHref().contains(p.getId().toString()));
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ModelMap(org.springframework.ui.ModelMap) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Link(org.springframework.hateoas.Link) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) Test(org.junit.Test)

Example 30 with ProjectUserJoin

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

the class ProjectEventEmailScheduledTaskImpl method emailUserTasks.

/**
 * {@inheritDoc}
 */
@Override
public void emailUserTasks() {
    if (emailController.isMailConfigured()) {
        logger.trace("Checking for users with subscriptions");
        List<User> usersWithEmailSubscriptions = userService.getUsersWithEmailSubscriptions();
        Date lastTime = getPriorDateFromCronString(scheduledCronString);
        logger.trace("Getting events after " + lastTime);
        for (User user : usersWithEmailSubscriptions) {
            logger.trace("Checking for events for user " + user.getUsername());
            List<ProjectEvent> eventsToEmailToUser = eventService.getEventsForUserAfterDate(user, lastTime);
            // Get the set of projects the user is subscribed to
            Set<Project> projectsWithSubscription = projectService.getProjectsForUser(user).stream().filter(j -> {
                ProjectUserJoin puj = (ProjectUserJoin) j;
                return puj.isEmailSubscription();
            }).map(j -> j.getSubject()).collect(Collectors.toSet());
            // filter the events to ensure the user is subscribed
            eventsToEmailToUser = eventsToEmailToUser.stream().filter(e -> projectsWithSubscription.contains(e.getProject())).collect(Collectors.toList());
            if (!eventsToEmailToUser.isEmpty()) {
                logger.trace("Sending subscription email to " + user.getUsername() + " with " + eventsToEmailToUser.size() + " events");
                emailController.sendSubscriptionUpdateEmail(user, eventsToEmailToUser);
            }
        }
    }
}
Also used : Logger(org.slf4j.Logger) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Component(org.springframework.stereotype.Component) Calendar(java.util.Calendar) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) ProjectEventEmailScheduledTask(ca.corefacility.bioinformatics.irida.service.ProjectEventEmailScheduledTask) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectEventService(ca.corefacility.bioinformatics.irida.service.ProjectEventService) CronSequenceGenerator(org.springframework.scheduling.support.CronSequenceGenerator) EmailController(ca.corefacility.bioinformatics.irida.service.EmailController) User(ca.corefacility.bioinformatics.irida.model.user.User) 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) Date(java.util.Date) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)

Aggregations

ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)34 Project (ca.corefacility.bioinformatics.irida.model.project.Project)26 User (ca.corefacility.bioinformatics.irida.model.user.User)23 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)20 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)12 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)8 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)7 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)7 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 Authentication (org.springframework.security.core.Authentication)6 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)4 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 ProjectWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)3 ProjectReferenceFileJoin (ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin)3 DTUser (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser)3 List (java.util.List)3 Locale (java.util.Locale)3