Search in sources :

Example 41 with Project

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 42 with Project

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);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Controller(org.springframework.stereotype.Controller) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) Scope(org.springframework.context.annotation.Scope) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) ArrayList(java.util.ArrayList) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) Model(org.springframework.ui.Model) Locale(java.util.Locale) Map(java.util.Map) RESTSampleSequenceFilesController(ca.corefacility.bioinformatics.irida.web.controller.api.samples.RESTSampleSequenceFilesController) MessageSource(org.springframework.context.MessageSource) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) ImmutableMap(com.google.common.collect.ImmutableMap) RESTProjectSamplesController(ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectSamplesController) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) Project(ca.corefacility.bioinformatics.irida.model.project.Project) List(java.util.List) Principal(java.security.Principal) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 43 with Project

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) HashMap(java.util.HashMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 44 with Project

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)

Example 45 with Project

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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) List(java.util.List) Date(java.util.Date) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)331 Test (org.junit.Test)190 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)120 User (ca.corefacility.bioinformatics.irida.model.user.User)88 WithMockUser (org.springframework.security.test.context.support.WithMockUser)80 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)71 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)37 ArrayList (java.util.ArrayList)34 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)30 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)30 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)27 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)25 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)23 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)22 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)22 List (java.util.List)22 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)21 ImmutableMap (com.google.common.collect.ImmutableMap)21