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);
}
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)));
}
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()));
}
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()));
}
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);
}
}
}
}
Aggregations