use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class CartController method removeProject.
/**
* Delete an entire project from the cart
*
* @param projectId
* The ID of the {@link Project} to delete
* @return a map stating success
*/
@RequestMapping(value = "/project/{projectId}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, Object> removeProject(@PathVariable Long projectId) {
Project project = projectService.read(projectId);
selected.remove(project);
return ImmutableMap.of("success", true);
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class CartController method addProject.
/**
* Add an entire {@link Project} to the cart
*
* @param projectId
* The ID of the {@link Project}
* @return a map stating success
*/
@RequestMapping(value = "/project/{projectId}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Object> addProject(@PathVariable Long projectId) {
Project project = projectService.read(projectId);
List<Join<Project, Sample>> samplesForProject = sampleService.getSamplesForProject(project);
Set<Sample> samples = samplesForProject.stream().map((j) -> {
return j.getObject();
}).collect(Collectors.toSet());
getSelectedSamplesForProject(project).addAll(samples);
return ImmutableMap.of("success", true);
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ReferenceFileController method deleteReferenceFile.
/**
* Delete a reference file. This will remove it from the project.
*
* @param fileId
* The id of the file to remove.
* @param projectId
* the project to delete the reference file for.
* @param response
* {@link HttpServletResponse} required for returning an error
* state.
* @param locale
* the locale specified by the browser.
*
* @return Success or error based on the result of deleting the file.
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> deleteReferenceFile(@RequestParam Long fileId, @RequestParam Long projectId, HttpServletResponse response, Locale locale) {
Map<String, Object> result = new HashMap<>();
Project project = projectService.read(projectId);
ReferenceFile file = referenceFileService.read(fileId);
try {
logger.info("Removing file with id of : " + fileId);
projectService.removeReferenceFileFromProject(project, file);
result.put("result", "success");
result.put("msg", messageSource.getMessage("projects.meta.reference-file.delete-success", new Object[] { file.getLabel(), project.getName() }, locale));
} catch (EntityNotFoundException e) {
// This is required else the client does not know that an error was thrown!
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
logger.error("Failed to upload reference file, reason unknown.", e);
result.put("result", "error");
result.put("msg", messageSource.getMessage("projects.meta.reference-file.delete-error", new Object[] { file.getLabel(), project.getName() }, locale));
}
return result;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ModifyProjectPermission method customPermissionAllowed.
/**
* {@inheritDoc}
*/
public boolean customPermissionAllowed(Authentication authentication, Project p) {
logger.trace("Testing permission for [" + authentication + "] can modify project [" + p + "]");
// check if the user is a project owner for this project
User u = userRepository.loadUserByUsername(authentication.getName());
List<Join<Project, User>> projectUsers = pujRepository.getUsersForProjectByRole(p, ProjectRole.PROJECT_OWNER);
for (Join<Project, User> projectUser : projectUsers) {
if (projectUser.getObject().equals(u)) {
logger.trace("Permission GRANTED for [" + authentication + "] on project [" + p + "]");
// this user is an owner for the project.
return true;
}
}
// if we've made it this far, then that means that the user isn't
// directly added to the project, so check if the user is in any groups
// added to the project.
final Collection<UserGroupProjectJoin> groups = ugpjRepository.findGroupsByProject(p);
for (final UserGroupProjectJoin group : groups) {
if (group.getProjectRole().equals(ProjectRole.PROJECT_OWNER)) {
final Collection<UserGroupJoin> groupMembers = ugRepository.findUsersInGroup(group.getObject());
final boolean inGroup = groupMembers.stream().anyMatch(j -> j.getSubject().equals(u));
if (inGroup) {
logger.trace("Permission GRANTED for [" + authentication + "] on project [" + p + "] by group membership in [" + group.getLabel() + "]");
return true;
}
} else {
logger.trace("Group is not PROJECT_OWNER, checking next project.");
}
}
logger.trace("Permission DENIED for [" + authentication + "] on project [" + p + "]");
return false;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectEventEmailScheduedTaskImplTest method testEmailUserPartialSubscriptoinTasks.
@SuppressWarnings("unchecked")
@Test
public void testEmailUserPartialSubscriptoinTasks() {
User tom = new User("tom", null, null, null, null, null);
Project p = new Project("testproject");
Project p2 = new Project("testproject2");
List<User> users = Lists.newArrayList(tom);
ProjectUserJoin join = new ProjectUserJoin(p, tom, ProjectRole.PROJECT_OWNER);
join.setEmailSubscription(true);
ProjectUserJoin notSubscribed = new ProjectUserJoin(p2, tom, ProjectRole.PROJECT_OWNER);
List<ProjectEvent> events = Lists.newArrayList(new UserRoleSetProjectEvent(join), new UserRoleSetProjectEvent(notSubscribed));
when(userService.getUsersWithEmailSubscriptions()).thenReturn(users);
when(eventService.getEventsForUserAfterDate(eq(tom), any(Date.class))).thenReturn(events);
when(projectService.getProjectsForUser(tom)).thenReturn(Lists.newArrayList(join, notSubscribed));
task.emailUserTasks();
verify(userService).getUsersWithEmailSubscriptions();
verify(eventService).getEventsForUserAfterDate(eq(tom), any(Date.class));
@SuppressWarnings("rawtypes") ArgumentCaptor<List> eventCaptor = ArgumentCaptor.forClass(List.class);
verify(emailController).sendSubscriptionUpdateEmail(eq(tom), eventCaptor.capture());
List<ProjectEvent> sentEvents = eventCaptor.getValue();
assertEquals("should send 1 event", 1, sentEvents.size());
ProjectEvent sentEvent = sentEvents.iterator().next();
assertEquals("should have sent from subscribed project", p, sentEvent.getProject());
}
Aggregations