Search in sources :

Example 26 with ProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.

the class ProjectEventServiceImplIT method testGetEventsForProject.

@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testGetEventsForProject() {
    Project project1 = projectService.read(1L);
    Project project3 = projectService.read(3L);
    Page<ProjectEvent> eventsForProject1 = projectEventService.getEventsForProject(project1, new PageRequest(0, 10));
    Page<ProjectEvent> eventsForProject2 = projectEventService.getEventsForProject(project3, new PageRequest(0, 10));
    assertEquals(0L, eventsForProject1.getTotalElements());
    assertEquals(1L, eventsForProject2.getTotalElements());
    ProjectEvent event2 = eventsForProject2.iterator().next();
    assertEquals(project3, event2.getProject());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 27 with ProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.

the class ProjectEventServiceImplIT method testGetEmptyEventsAfterDate.

@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testGetEmptyEventsAfterDate() throws ParseException {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date beginning = formatter.parse("2013-07-18 15:00:00");
    User user = userService.read(3L);
    List<ProjectEvent> events = projectEventService.getEventsForUserAfterDate(user, beginning);
    assertTrue("no events should be found", events.isEmpty());
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 28 with ProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent 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)

Example 29 with ProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.

the class ProjectEventsController method getRecentEventsForProject.

/**
 * Get recent {@link ProjectEvent}s for the given {@link Project}
 *
 * @param projectId
 *            The ID of the {@link Project} to get events for
 * @param model
 *            Model for the view. Contains a list named "events". This will
 *            be a map which will contain "name" which is the name of the
 *            view fragment to use, and "event" which is a reference to the
 *            event itself
 * @param size
 *            Number of events to show
 * @return The name of the events view
 */
@RequestMapping("/project/{projectId}")
public String getRecentEventsForProject(@PathVariable Long projectId, Model model, @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer size) {
    Project project = projectService.read(projectId);
    Page<ProjectEvent> events = eventService.getEventsForProject(project, new PageRequest(0, size, Direction.DESC, "createdDate"));
    List<Map<String, Object>> eventInfo = buildEventsListFromPage(events);
    model.addAttribute("events", eventInfo);
    return EVENTS_VIEW;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent) UserGroupRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with ProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.

the class ProjectEventsController method buildEventsListFromPage.

/**
 * Convert the Page of events to the list expected in the model
 *
 * @param events
 *            Page of {@link ProjectEvent}s
 * @return A List<Map<String,Object>> containing the events and fragment
 *         names
 */
private List<Map<String, Object>> buildEventsListFromPage(Page<ProjectEvent> events) {
    List<Map<String, Object>> eventInfo = new ArrayList<>();
    for (ProjectEvent e : events) {
        if (FRAGMENT_NAMES.containsKey(e.getClass())) {
            Map<String, Object> info = new HashMap<>();
            info.put("name", FRAGMENT_NAMES.get(e.getClass()));
            info.put("event", e);
            eventInfo.add(info);
        }
    }
    return eventInfo;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent) UserGroupRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)

Aggregations

ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)30 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)29 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)23 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)23 Test (org.junit.Test)23 Project (ca.corefacility.bioinformatics.irida.model.project.Project)21 User (ca.corefacility.bioinformatics.irida.model.user.User)16 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)13 PageRequest (org.springframework.data.domain.PageRequest)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)8 Map (java.util.Map)8 Date (java.util.Date)7 List (java.util.List)7 UserGroupRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent)5 SampleRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent)5 UserGroupRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent)5 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)5 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)5 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)4