use of org.olat.group.right.BGRights in project OpenOLAT by OpenOLAT.
the class GroupsAndRightsController method loadModel.
private void loadModel() {
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, courseEntry, 0, -1);
List<Group> baseGroups = getAllBaseGroups(groups);
List<BGRights> currentRights = rightManager.findBGRights(baseGroups, courseEntry.getOlatResource());
Map<Group, BGRights> tutorToRightsMap = new HashMap<>();
Map<Group, BGRights> participantToRightsMap = new HashMap<>();
for (BGRights right : currentRights) {
if (right.getRole() == BGRightsRole.tutor) {
tutorToRightsMap.put(right.getBaseGroup(), right);
} else if (right.getRole() == BGRightsRole.participant) {
participantToRightsMap.put(right.getBaseGroup(), right);
}
}
List<BGRightsRow> options = new ArrayList<>();
String courseName = courseEntry.getDisplayname();
Group defGroup = repositoryService.getDefaultGroup(courseEntry);
options.add(getRightsOption(defGroup, courseName, tutorToRightsMap.get(defGroup), BGRightsRole.tutor, BGRightsResourceType.repositoryEntry));
options.add(getRightsOption(defGroup, courseName, participantToRightsMap.get(defGroup), BGRightsRole.participant, BGRightsResourceType.repositoryEntry));
for (BusinessGroup group : groups) {
String name = group.getName();
Group bGroup = group.getBaseGroup();
options.add(getRightsOption(bGroup, name, tutorToRightsMap.get(bGroup), BGRightsRole.tutor, BGRightsResourceType.businessGroup));
options.add(getRightsOption(bGroup, name, participantToRightsMap.get(bGroup), BGRightsRole.participant, BGRightsResourceType.businessGroup));
}
tableDataModel.setObjects(options);
}
use of org.olat.group.right.BGRights in project OpenOLAT by OpenOLAT.
the class GroupsAndRightsController method doSaveChanges.
private void doSaveChanges() {
// collect group
List<BGRightsRow> options = tableDataModel.getObjects();
List<Group> groups = getAllBaseGroups();
// collect current rights
List<BGRights> currentRights = rightManager.findBGRights(groups, courseEntry.getOlatResource());
Map<Group, BGRights> tutorToRightsMap = new HashMap<>();
Map<Group, BGRights> participantToRightsMap = new HashMap<>();
for (BGRights right : currentRights) {
if (right.getRole() == BGRightsRole.tutor) {
tutorToRightsMap.put(right.getBaseGroup(), right);
} else if (right.getRole() == BGRightsRole.participant) {
participantToRightsMap.put(right.getBaseGroup(), right);
}
}
for (BGRightsRow option : options) {
List<String> newPermissions = option.getSelectedPermissions();
BGRights rights = null;
if (option.getRole() == BGRightsRole.tutor) {
rights = tutorToRightsMap.get(option.getBaseGroup());
} else if (option.getRole() == BGRightsRole.participant) {
rights = participantToRightsMap.get(option.getBaseGroup());
}
if (rights == null && newPermissions.isEmpty()) {
// nothing to do
continue;
}
List<String> currentPermissions = (rights == null ? Collections.<String>emptyList() : rights.getRights());
if (newPermissions.containsAll(currentPermissions) && currentPermissions.containsAll(newPermissions)) {
// nothing to do
continue;
}
List<String> newPermissionsTmp = new ArrayList<>(newPermissions);
newPermissionsTmp.removeAll(currentPermissions);
for (String newPermission : newPermissionsTmp) {
rightManager.addBGRight(newPermission, option.getBaseGroup(), courseEntry.getOlatResource(), option.getRole());
}
currentPermissions.removeAll(newPermissions);
for (String currentPermission : currentPermissions) {
rightManager.removeBGRight(currentPermission, option.getBaseGroup(), courseEntry.getOlatResource(), option.getRole());
}
}
}
use of org.olat.group.right.BGRights in project openolat by klemens.
the class BGRightManagerTest method findBGRights_wrapped.
@Test
public void findBGRights_wrapped() {
// create
RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry resource3 = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource1);
businessGroupService.addResourceTo(group1, resource2);
BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource3);
rightManager.addBGRight("bgr.fr1", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
rightManager.addBGRight("bgr.fr2", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.participant);
rightManager.addBGRight("bgr.fr3", group2.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
rightManager.addBGRight("bgr.fr4", group2.getBaseGroup(), resource2.getOlatResource(), BGRightsRole.tutor);
rightManager.addBGRight("bgr.fr5", group2.getBaseGroup(), resource3.getOlatResource(), BGRightsRole.participant);
dbInstance.commitAndCloseSession();
// check
List<BGRights> rights1_1 = rightManager.findBGRights(Collections.singletonList(group1.getBaseGroup()), resource1.getOlatResource());
Assert.assertNotNull(rights1_1);
Assert.assertEquals(2, rights1_1.size());
List<BGRights> rights2_2 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource2.getOlatResource());
Assert.assertNotNull(rights2_2);
Assert.assertEquals(1, rights2_2.size());
List<BGRights> rights2_3 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource3.getOlatResource());
Assert.assertNotNull(rights2_3);
Assert.assertEquals(1, rights2_3.size());
List<Group> groups = new ArrayList<>();
groups.add(group1.getBaseGroup());
groups.add(group2.getBaseGroup());
List<BGRights> rightsAll_1 = rightManager.findBGRights(groups, resource1.getOlatResource());
Assert.assertNotNull(rightsAll_1);
Assert.assertEquals(3, rightsAll_1.size());
}
use of org.olat.group.right.BGRights in project openolat by klemens.
the class GroupsAndRightsController method loadModel.
private void loadModel() {
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, courseEntry, 0, -1);
List<Group> baseGroups = getAllBaseGroups(groups);
List<BGRights> currentRights = rightManager.findBGRights(baseGroups, courseEntry.getOlatResource());
Map<Group, BGRights> tutorToRightsMap = new HashMap<>();
Map<Group, BGRights> participantToRightsMap = new HashMap<>();
for (BGRights right : currentRights) {
if (right.getRole() == BGRightsRole.tutor) {
tutorToRightsMap.put(right.getBaseGroup(), right);
} else if (right.getRole() == BGRightsRole.participant) {
participantToRightsMap.put(right.getBaseGroup(), right);
}
}
List<BGRightsRow> options = new ArrayList<>();
String courseName = courseEntry.getDisplayname();
Group defGroup = repositoryService.getDefaultGroup(courseEntry);
options.add(getRightsOption(defGroup, courseName, tutorToRightsMap.get(defGroup), BGRightsRole.tutor, BGRightsResourceType.repositoryEntry));
options.add(getRightsOption(defGroup, courseName, participantToRightsMap.get(defGroup), BGRightsRole.participant, BGRightsResourceType.repositoryEntry));
for (BusinessGroup group : groups) {
String name = group.getName();
Group bGroup = group.getBaseGroup();
options.add(getRightsOption(bGroup, name, tutorToRightsMap.get(bGroup), BGRightsRole.tutor, BGRightsResourceType.businessGroup));
options.add(getRightsOption(bGroup, name, participantToRightsMap.get(bGroup), BGRightsRole.participant, BGRightsResourceType.businessGroup));
}
tableDataModel.setObjects(options);
}
use of org.olat.group.right.BGRights in project openolat by klemens.
the class GroupsAndRightsController method doSaveChanges.
private void doSaveChanges() {
// collect group
List<BGRightsRow> options = tableDataModel.getObjects();
List<Group> groups = getAllBaseGroups();
// collect current rights
List<BGRights> currentRights = rightManager.findBGRights(groups, courseEntry.getOlatResource());
Map<Group, BGRights> tutorToRightsMap = new HashMap<>();
Map<Group, BGRights> participantToRightsMap = new HashMap<>();
for (BGRights right : currentRights) {
if (right.getRole() == BGRightsRole.tutor) {
tutorToRightsMap.put(right.getBaseGroup(), right);
} else if (right.getRole() == BGRightsRole.participant) {
participantToRightsMap.put(right.getBaseGroup(), right);
}
}
for (BGRightsRow option : options) {
List<String> newPermissions = option.getSelectedPermissions();
BGRights rights = null;
if (option.getRole() == BGRightsRole.tutor) {
rights = tutorToRightsMap.get(option.getBaseGroup());
} else if (option.getRole() == BGRightsRole.participant) {
rights = participantToRightsMap.get(option.getBaseGroup());
}
if (rights == null && newPermissions.isEmpty()) {
// nothing to do
continue;
}
List<String> currentPermissions = (rights == null ? Collections.<String>emptyList() : rights.getRights());
if (newPermissions.containsAll(currentPermissions) && currentPermissions.containsAll(newPermissions)) {
// nothing to do
continue;
}
List<String> newPermissionsTmp = new ArrayList<>(newPermissions);
newPermissionsTmp.removeAll(currentPermissions);
for (String newPermission : newPermissionsTmp) {
rightManager.addBGRight(newPermission, option.getBaseGroup(), courseEntry.getOlatResource(), option.getRole());
}
currentPermissions.removeAll(newPermissions);
for (String currentPermission : currentPermissions) {
rightManager.removeBGRight(currentPermission, option.getBaseGroup(), courseEntry.getOlatResource(), option.getRole());
}
}
}
Aggregations