use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ProjectMembersController method getProjectUserMembers.
/**
* Get a page of users on the project for display in a DataTable.
*
* @param params
* the datatables parameters for this DataTable
* @param projectId
* the id of the project we're looking at
* @return a {@link DataTablesResponseModel} of users on the project
*/
@RequestMapping(value = "/{projectId}/settings/ajax/members")
@ResponseBody
public DataTablesResponse getProjectUserMembers(@DataTablesRequest DataTablesParams params, @PathVariable final Long projectId) {
final Project project = projectService.read(projectId);
final Page<Join<Project, User>> usersForProject = userService.searchUsersForProject(project, params.getSearchValue(), params.getCurrentPage(), params.getLength(), params.getSort());
List<DataTablesResponseModel> modelList = new ArrayList<>();
for (Join<Project, User> join : usersForProject) {
modelList.add(new DTProjectMember((ProjectUserJoin) join));
}
return new DataTablesResponse(params, usersForProject, modelList);
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ProjectSamplesController method getSampleNamesNotInProject.
/**
* Get a listing of sample names not found in the current project based on a list.
*
* @param projectId {@link Project} identifier for project
* @param sampleNames {@link List} of sample names
* @param projects List of associated {@link Project} identifiers
* @param locale {@link Locale} local of current user
* @return {@link Map} of Samples not in the current project
*/
@RequestMapping("/projects/{projectId}/ajax/samples/missing")
@ResponseBody
public Map<String, Object> getSampleNamesNotInProject(@PathVariable Long projectId, @RequestParam(value = "projects[]", defaultValue = "") List<Long> projects, @RequestParam(value = "sampleNames[]") List<String> sampleNames, Locale locale) {
// Need to keep the count for comparison after.
int originalCount = sampleNames.size();
// Get a list of all samples for all projects
projects.add(0, projectId);
for (Long id : projects) {
List<Join<Project, Sample>> psj = sampleService.getSamplesForProject(projectService.read(id));
// See if the name is there
for (Join<Project, Sample> join : psj) {
Sample sample = join.getObject();
if (sampleNames.contains(sample.getLabel())) {
sampleNames.remove(sample.getLabel());
}
if (sampleNames.size() == 0) {
break;
}
}
if (sampleNames.size() == 0) {
break;
}
}
Map<String, Object> result = new HashMap<>();
if (sampleNames.size() > 0) {
result.put("missingNames", sampleNames);
result.put("message", messageSource.getMessage("project.sample.filterByFile.error", new Object[] { originalCount - sampleNames.size(), originalCount }, locale));
} else {
result.put("success", messageSource.getMessage("project.sample.filterByFile.success", new Object[] {}, locale));
}
return result;
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join 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.joins.Join 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.joins.Join in project irida by phac-nml.
the class ProjectServiceImplTest method testUpdateProjectUserJoinIllegalChange.
@Test(expected = ProjectWithoutOwnerException.class)
public void testUpdateProjectUserJoinIllegalChange() throws ProjectWithoutOwnerException {
Project project = new Project("Project 1");
User user = new User();
ProjectRole projectRole = ProjectRole.PROJECT_USER;
ProjectUserJoin oldJoin = new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER);
@SuppressWarnings("unchecked") List<Join<Project, User>> owners = Lists.newArrayList(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER));
when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(oldJoin);
when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(owners);
projectService.updateUserProjectRole(project, user, projectRole);
}
Aggregations