Search in sources :

Example 1 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method addSampleToProject.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(SampleAddedProjectEvent.class)
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SEQUENCER') or (hasPermission(#project, 'isProjectOwner'))")
public ProjectSampleJoin addSampleToProject(Project project, Sample sample, boolean owner) {
    logger.trace("Adding sample to project.");
    // project already
    if (sampleRepository.getSampleBySampleName(project, sample.getSampleName()) != null) {
        throw new EntityExistsException("Sample with sequencer id '" + sample.getSampleName() + "' already exists in project " + project.getId());
    }
    // the relationshipRepository.
    if (sample.getId() == null) {
        logger.trace("Going to validate and persist sample prior to creating relationship.");
        // validate the sample, then persist it:
        Set<ConstraintViolation<Sample>> constraintViolations = validator.validate(sample);
        if (constraintViolations.isEmpty()) {
            sample = sampleRepository.save(sample);
        } else {
            throw new ConstraintViolationException(constraintViolations);
        }
    }
    ProjectSampleJoin join = new ProjectSampleJoin(project, sample, owner);
    try {
        return psjRepository.save(join);
    } catch (DataIntegrityViolationException e) {
        throw new EntityExistsException("Sample [" + sample.getId() + "] has already been added to project [" + project.getId() + "]");
    }
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method removeUserGroupFromProject.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(UserGroupRemovedProjectEvent.class)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canManageLocalProjectSettings')")
public void removeUserGroupFromProject(Project project, UserGroup userGroup) throws ProjectWithoutOwnerException {
    final UserGroupProjectJoin j = ugpjRepository.findByProjectAndUserGroup(project, userGroup);
    if (!allowRoleChange(project, j.getProjectRole())) {
        throw new ProjectWithoutOwnerException("Removing this user group would leave the project without an owner.");
    }
    ugpjRepository.delete(j);
}
Also used : ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method removeUserFromProject.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(UserRemovedProjectEvent.class)
@PreAuthorize("hasPermission(#project, 'canManageLocalProjectSettings')")
public void removeUserFromProject(Project project, User user) throws ProjectWithoutOwnerException {
    ProjectUserJoin projectJoinForUser = pujRepository.getProjectJoinForUser(project, user);
    if (!allowRoleChange(projectJoinForUser.getSubject(), projectJoinForUser.getProjectRole())) {
        throw new ProjectWithoutOwnerException("Removing this user would leave the project without an owner");
    }
    pujRepository.delete(projectJoinForUser);
}
Also used : ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method moveSamples.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(SampleAddedProjectEvent.class)
@PreAuthorize("hasPermission(#source, 'isProjectOwner') and hasPermission(#destination, 'isProjectOwner') " + "and hasPermission(#samples, 'canReadSample') " + "and ((not #giveOwner) or hasPermission(#samples, 'canUpdateSample') )")
public List<ProjectSampleJoin> moveSamples(Project source, Project destination, Collection<Sample> samples, boolean giveOwner) {
    List<ProjectSampleJoin> newJoins = new ArrayList<>();
    for (Sample sample : samples) {
        ProjectSampleJoin newJoin = moveSampleBetweenProjects(source, destination, sample, giveOwner);
        logger.trace("Moved sample " + sample.getId() + " to project " + destination.getId());
        newJoins.add(newJoin);
    }
    return newJoins;
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent 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);
    }
}
Also used : UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) Date(java.util.Date) UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent) UserGroupRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)

Aggregations

LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Transactional (org.springframework.transaction.annotation.Transactional)10 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)6 ProjectWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 ArrayList (java.util.ArrayList)4 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)3 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)3 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)2 UserGroupRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent)2 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)2 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)2 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)2 SampleRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent)2 UserGroupRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent)2 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)2 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)2 Project (ca.corefacility.bioinformatics.irida.model.project.Project)2 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)2