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));
}
}
Aggregations