use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectSamplesController method getAllProjectSampleIds.
/**
* Get a list of all {@link Sample} ids in a {@link Project}
*
* @param projectId Identifier for the current project
* @param sampleNames {@link List} of sample names that the {@link Project} {@link Sample}s is currently filtered by.
* @param associatedProjectIds {@link List} of associated {@link Project} identifiers
* @param search The global filter for the table
* @param filter The specific attribute filters applied to the table.
* @return {@link Map} of {@link Project} identifiers and associated {@link Sample} identifiers available.
*/
@RequestMapping(value = "/projects/{projectId}/ajax/sampleIds", method = RequestMethod.POST)
@ResponseBody
public Map<String, List<String>> getAllProjectSampleIds(@PathVariable Long projectId, @RequestParam(required = false, defaultValue = "", value = "sampleNames[]") List<String> sampleNames, @RequestParam(value = "associated[]", required = false, defaultValue = "") List<Long> associatedProjectIds, @RequestParam(required = false, defaultValue = "") String search, UISampleFilter filter) {
// Add the current project to the associatedProjectIds list.
associatedProjectIds.add(projectId);
// Get the actual projects.
List<Project> projects = new ArrayList<>((Collection<? extends Project>) projectService.readMultiple(associatedProjectIds));
Sort sort = new Sort(Direction.ASC, "id");
final Page<ProjectSampleJoin> page = sampleService.getFilteredSamplesForProjects(projects, sampleNames, filter.getName(), search, filter.getOrganism(), filter.getStartDate(), filter.getEndDate(), 0, Integer.MAX_VALUE, sort);
// Converting everything to a string for consumption by the UI.
Map<String, List<String>> result = new HashMap<>();
for (ProjectSampleJoin join : page) {
String pId = join.getSubject().getId().toString();
if (!result.containsKey(pId)) {
result.put(pId, new ArrayList<>());
}
result.get(pId).add(join.getObject().getId().toString());
}
return result;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectSamplesController method getMergeSamplesInProjectModal.
/**
* Create a modal dialog to merge samples in a project.
*
* @param projectId current {@link Project} identifier
* @param ids {@link List} List of {@link Long} identifiers for {@link Sample} to merge.
* @param model UI Model
* @return Path to merge modal template
*/
@RequestMapping(value = "/projects/{projectId}/templates/merge-modal", produces = MediaType.TEXT_HTML_VALUE)
public String getMergeSamplesInProjectModal(@PathVariable Long projectId, @RequestParam(name = "sampleIds[]") List<Long> ids, Model model) {
Project project = projectService.read(projectId);
List<Sample> samples = new ArrayList<>();
List<Sample> locked = new ArrayList<>();
// check for locked samples
ids.forEach(i -> {
ProjectSampleJoin join = sampleService.getSampleForProject(project, i);
samples.add(join.getObject());
if (!join.isOwner()) {
locked.add(join.getObject());
}
});
model.addAttribute("project", project);
model.addAttribute("samples", samples);
model.addAttribute("locked", locked);
return PROJECT_TEMPLATE_DIR + "merge-modal.tmpl";
}
use of ca.corefacility.bioinformatics.irida.model.project.Project 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.project.Project in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method getPotentialAssociatedProjects.
/**
* Get {@link Project}s that could be associated with this project
*
* @param projectId
* The current project ID
* @param principal
* The logged in user
* @param page
* The page to request
* @param count
* The number of elements in the page
* @param sortedBy
* The property to sort by
* @param sortDir
* The direction to sort in
* @param projectName
* The project name to search for
*
* @return A {@code Map<String,Object>} of elements for a datatable
*/
@RequestMapping("/ajax/available")
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#projectId, 'isProjectOwner')")
@ResponseBody
public Map<String, Object> getPotentialAssociatedProjects(@PathVariable Long projectId, final Principal principal, @RequestParam Integer page, @RequestParam Integer count, @RequestParam String sortedBy, @RequestParam String sortDir, @RequestParam(value = "name", required = false, defaultValue = "") String projectName) {
Project project = projectService.read(projectId);
Sort.Direction sortDirection = sortDir.equals("asc") ? Sort.Direction.ASC : Sort.Direction.DESC;
List<RelatedProjectJoin> relatedProjectJoins = projectService.getRelatedProjects(project);
List<Project> projects;
long totalElements;
int totalPages;
final Page<Project> search = projectService.getUnassociatedProjects(project, projectName, page, count, sortDirection, sortedBy);
totalElements = search.getTotalElements();
totalPages = search.getTotalPages();
projects = search.getContent();
Map<String, Object> map = getProjectsDataMap(projects, relatedProjectJoins);
map.put("totalAssociated", totalElements);
map.put("totalPages", totalPages);
return map;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method removeAssociatedProject.
/**
* Delete an associated project to a project
*
* @param projectId The subject project id
* @param associatedProjectId The associated project id
* @param locale Locale of the logged in user
* @return "success" if the request was successful
*/
@RequestMapping(value = "", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> removeAssociatedProject(@PathVariable Long projectId, @RequestParam Long associatedProjectId, Locale locale) {
Project project = projectService.read(projectId);
Project associatedProject = projectService.read(associatedProjectId);
projectService.removeRelatedProject(project, associatedProject);
return ImmutableMap.of("result", "success", "message", messageSource.getMessage("project.associated.removed", new Object[] {}, locale));
}
Aggregations