use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventHandlerTest method testDelegateUserRole.
@Test
public void testDelegateUserRole() {
Class<? extends ProjectEvent> clazz = UserRoleSetProjectEvent.class;
Project project = new Project();
User user = new User();
ProjectUserJoin returnValue = new ProjectUserJoin(project, user, ProjectRole.PROJECT_USER);
Object[] args = { project, user, ProjectRole.PROJECT_USER };
MethodEvent methodEvent = new MethodEvent(clazz, returnValue, args);
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new UserRoleSetProjectEvent(returnValue));
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository).save(captor.capture());
ProjectEvent event = captor.getValue();
assertTrue(event instanceof UserRoleSetProjectEvent);
verify(projectRepository).save(any(Project.class));
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventHandler method delegate.
/**
* Handle translation of a {@link MethodEvent} into the correct
* {@link ProjectEvent} subclass
*
* @param methodEvent
* Information from a method return annotated with
* {@link LaunchesProjectEvent}
*/
public void delegate(MethodEvent methodEvent) {
Class<? extends ProjectEvent> eventClass = methodEvent.getEventClass();
final Date eventDate = new Date();
Collection<ProjectEvent> events = new ArrayList<>();
if (eventClass.equals(SampleAddedProjectEvent.class)) {
events.addAll(handleSampleAddedProjectEvent(methodEvent));
} else if (eventClass.equals(UserRemovedProjectEvent.class)) {
events.add(handleUserRemovedEvent(methodEvent));
} else if (eventClass.equals(UserRoleSetProjectEvent.class)) {
events.add(handleUserRoleSetProjectEvent(methodEvent));
} else if (eventClass.equals(DataAddedToSampleProjectEvent.class)) {
final Collection<DataAddedToSampleProjectEvent> dataAddedEvents = handleSequenceFileAddedEvent(methodEvent);
/*
* We want the sample to show modification when these events are
* added, so update mod date
*/
for (final DataAddedToSampleProjectEvent e : dataAddedEvents) {
final Sample s = e.getSample();
s.setModifiedDate(eventDate);
sampleRepository.save(s);
}
events.addAll(dataAddedEvents);
} else if (eventClass.equals(UserGroupRoleSetProjectEvent.class)) {
events.add(handleUserGroupRoleSetProjectEvent(methodEvent));
} else if (eventClass.equals(UserGroupRemovedProjectEvent.class)) {
events.add(handleUserGroupRemovedEvent(methodEvent));
} else if (eventClass.equals(SampleRemovedProjectEvent.class)) {
events.addAll(handleSampleRemovedEvent(methodEvent));
} else {
logger.warn("No handler found for event class " + eventClass.getName());
}
for (ProjectEvent e : events) {
Project project = e.getProject();
project.setModifiedDate(eventDate);
projectRepository.save(project);
}
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventHandler method handleUserGroupRemovedEvent.
/**
* Create a {@link UserRemovedProjectEvent}. The method arguments must
* contain a {@link Project} and {@link User}
*
* @param event
* The {@link MethodEvent} that this event is being launched from
*/
private ProjectEvent handleUserGroupRemovedEvent(MethodEvent event) {
final Optional<Object> user = Arrays.stream(event.getArgs()).filter(e -> e instanceof UserGroup).findAny();
final Optional<Object> project = Arrays.stream(event.getArgs()).filter(e -> e instanceof Project).findAny();
if (!user.isPresent() || !project.isPresent()) {
throw new IllegalArgumentException("Project or user group cannot be found on method annotated with @LaunchesProjectEvent(UserGroupRemovedProjectEvent.class)");
}
return eventRepository.save(new UserGroupRemovedProjectEvent((Project) project.get(), (UserGroup) user.get()));
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventsControllerTest method testUnknownEvent.
@Test
public void testUnknownEvent() {
Long projectId = 1L;
Project project = new Project();
ExtendedModelMap model = new ExtendedModelMap();
ProjectEvent event = new ProjectEvent() {
@Override
public String getLabel() {
return "an unmapped event";
}
};
Page<ProjectEvent> page = new PageImpl<>(Lists.newArrayList(event));
when(projectService.read(projectId)).thenReturn(project);
when(eventService.getEventsForProject(eq(project), any(Pageable.class))).thenReturn(page);
String recentEventsForProject = controller.getRecentEventsForProject(projectId, model, 10);
assertEquals(ProjectEventsController.EVENTS_VIEW, recentEventsForProject);
assertTrue(model.containsAttribute("events"));
@SuppressWarnings("unchecked") List<Map<String, Object>> events = (List<Map<String, Object>>) model.get("events");
assertEquals(0, events.size());
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventServiceImplIT method testAddProjectSample.
@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testAddProjectSample() {
Project project = projectService.read(1L);
Sample sample = sampleService.read(2L);
projectService.addSampleToProject(project, sample, true);
Page<ProjectEvent> eventsForProject = projectEventService.getEventsForProject(project, new PageRequest(0, 10));
assertEquals(1, eventsForProject.getTotalElements());
ProjectEvent event = eventsForProject.iterator().next();
assertTrue(event instanceof SampleAddedProjectEvent);
SampleAddedProjectEvent userEvent = (SampleAddedProjectEvent) event;
assertEquals(project, userEvent.getProject());
assertEquals(sample, userEvent.getSample());
}
Aggregations