Search in sources :

Example 1 with PermissionLevel

use of de.tudarmstadt.ukp.clarin.webanno.model.PermissionLevel in project webanno by webanno.

the class ProjectServiceImpl method setProjectPermissionLevels.

@Override
@Transactional(noRollbackFor = NoResultException.class)
public void setProjectPermissionLevels(User aUser, Project aProject, Collection<PermissionLevel> aLevels) {
    Set<PermissionLevel> levelsToBeGranted = new HashSet<>(aLevels);
    List<ProjectPermission> permissions = new ArrayList<>();
    try {
        permissions.addAll(listProjectPermissionLevel(aUser, aProject));
    } catch (NoResultException e) {
    // Nothing to do
    }
    // Remove permissions that no longer exist
    for (ProjectPermission permission : permissions) {
        if (!aLevels.contains(permission.getLevel())) {
            removeProjectPermission(permission);
        } else {
            levelsToBeGranted.remove(permission.getLevel());
        }
    }
    // Grant new permissions
    for (PermissionLevel level : levelsToBeGranted) {
        createProjectPermission(new ProjectPermission(aProject, aUser.getUsername(), level));
    }
}
Also used : ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException) PermissionLevel(de.tudarmstadt.ukp.clarin.webanno.model.PermissionLevel) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PermissionLevel (de.tudarmstadt.ukp.clarin.webanno.model.PermissionLevel)1 ProjectPermission (de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NoResultException (javax.persistence.NoResultException)1 Transactional (org.springframework.transaction.annotation.Transactional)1