use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class CourseGroupManagementTest method testHasRightIsInMethodsByArea.
/**
* rights tests
*/
@Test
public void testHasRightIsInMethodsByArea() {
RepositoryEntry course1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waitinglist
BusinessGroup g1 = businessGroupService.createBusinessGroup(null, "g1", null, 0, 10, false, false, course1);
BusinessGroup g2 = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, course1);
// members
businessGroupRelationDao.addRole(id1, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id1, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, g2, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id3, g1, GroupRoles.coach.name());
// areas
BGArea a1 = areaManager.createAndPersistBGArea("a1", "desca1", course1.getOlatResource());
BGArea a2 = areaManager.createAndPersistBGArea("a2", null, course1.getOlatResource());
BGArea a3 = areaManager.createAndPersistBGArea("a3", null, course1.getOlatResource());
areaManager.addBGToBGArea(g1, a1);
areaManager.addBGToBGArea(g2, a1);
areaManager.addBGToBGArea(g1, a2);
areaManager.addBGToBGArea(g2, a3);
// groups
BusinessGroup g3 = businessGroupService.createBusinessGroup(null, "g3", null, -1, -1, false, false, course1);
BusinessGroup g4 = businessGroupService.createBusinessGroup(null, "g4", null, -1, -1, false, false, course1);
// members
businessGroupRelationDao.addRole(id1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id1, g4, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id3, g4, GroupRoles.participant.name());
// rights
rightManager.addBGRight(CourseRights.RIGHT_ARCHIVING, g3, BGRightsRole.participant);
rightManager.addBGRight(CourseRights.RIGHT_COURSEEDITOR, g3, BGRightsRole.participant);
rightManager.addBGRight(CourseRights.RIGHT_ARCHIVING, g4, BGRightsRole.participant);
rightManager.addBGRight(CourseRights.RIGHT_GROUPMANAGEMENT, g4, BGRightsRole.participant);
// simulate user clicks
DBFactory.getInstance().closeSession();
// test groups
CourseGroupManager gm = PersistingCourseGroupManager.getInstance(course1.getOlatResource());
// test areas
DBFactory.getInstance().closeSession();
assertTrue(gm.isIdentityInLearningArea(id1, a1.getKey()));
assertTrue(gm.isIdentityInLearningArea(id1, a2.getKey()));
assertTrue(gm.isIdentityInLearningArea(id1, a3.getKey()));
assertTrue(gm.isIdentityInLearningArea(id2, a1.getKey()));
assertTrue(gm.isIdentityInLearningArea(id2, a2.getKey()));
assertTrue(gm.isIdentityInLearningArea(id2, a3.getKey()));
DBFactory.getInstance().closeSession();
assertTrue(gm.isIdentityInLearningArea(id3, a1.getKey()));
assertTrue(gm.isIdentityInLearningArea(id3, a2.getKey()));
assertFalse(gm.isIdentityInLearningArea(id3, a3.getKey()));
DBFactory.getInstance().closeSession();
// TODO
// Assert.assertEquals(2, gm.getAreasOfBusinessGroup(g1.getName()).size());
// Assert.assertEquals(2, gm.getAreasOfBusinessGroup(g2.getName()).size());
// test rights
DBFactory.getInstance().closeSession();
assertTrue(gm.hasRight(id1, CourseRights.RIGHT_ARCHIVING));
assertTrue(gm.hasRight(id1, CourseRights.RIGHT_COURSEEDITOR));
assertTrue(gm.hasRight(id1, CourseRights.RIGHT_GROUPMANAGEMENT));
assertFalse(gm.hasRight(id1, CourseRights.RIGHT_ASSESSMENT));
assertTrue(gm.hasRight(id1, CourseRights.RIGHT_COURSEEDITOR));
assertTrue(gm.hasRight(id1, CourseRights.RIGHT_COURSEEDITOR));
assertFalse(gm.hasRight(id2, CourseRights.RIGHT_COURSEEDITOR));
// test context
DBFactory.getInstance().closeSession();
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class PersistingCourseGroupManager method getUniqueAreaNames.
/**
* @see org.olat.course.groupsandrights.CourseGroupManager#getUniqueAreaNames()
*/
public List<String> getUniqueAreaNames() {
List<BGArea> areas = getAllAreas();
List<String> areaNames = new ArrayList<String>();
for (BGArea area : areas) {
if (!areaNames.contains(area.getName())) {
areaNames.add(area.getName().trim());
}
}
Collections.sort(areaNames);
return areaNames;
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class PersistingCourseGroupManager method getBusinessGroupEnvironment.
/**
* This operation load all business groups and areas. Use with caution, costly!
* @param resource
* @param fGroupExportXML
* @return
*/
public CourseEnvironmentMapper getBusinessGroupEnvironment() {
CourseEnvironmentMapper env = new CourseEnvironmentMapper();
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, getCourseEntry(), 0, -1);
for (BusinessGroup group : groups) {
env.getGroups().add(new BusinessGroupReference(group));
}
List<BGArea> areas = areaManager.findBGAreasInContext(getCourseResource());
for (BGArea area : areas) {
env.getAreas().add(new BGAreaReference(area));
}
return env;
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class PersistingCourseGroupManager method deleteCourseGroupmanagement.
@Override
public void deleteCourseGroupmanagement() {
// delete permission group to course
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(getCourseResource(), false);
if (re != null) {
businessGroupService.removeResource(re);
// delete areas
List<BGArea> areas = getAllAreas();
for (BGArea area : areas) {
areaManager.deleteBGArea(area);
}
log.audit("Deleting course groupmanagement for " + re.toString());
}
}
use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.
the class ENEditGroupAreaFormController method validateGroupFields.
private boolean validateGroupFields() {
boolean retVal = true;
List<Long> activeGroupSelection = null;
List<Long> activeAreaSelection = null;
easyAreaList.clearError();
easyGroupList.clearError();
if (!isEmpty(easyGroupList)) {
// check whether groups exist
activeGroupSelection = getKeys(easyGroupList);
Set<Long> missingGroups = new HashSet<Long>();
List<BusinessGroupShort> existingGroups = businessGroupService.loadShortBusinessGroups(activeGroupSelection);
a_a: for (Long activeGroupKey : activeGroupSelection) {
for (BusinessGroupShort group : existingGroups) {
if (group.getKey().equals(activeGroupKey)) {
continue a_a;
}
}
missingGroups.add(activeGroupKey);
}
if (missingGroups.size() > 0) {
retVal = false;
String labelKey = missingGroups.size() == 1 ? "error.notfound.name" : "error.notfound.names";
String csvMissGrps = toString(missingGroups);
String[] params = new String[] { "-", csvMissGrps };
// create error with link to fix it
String vc_errorPage = velocity_root + "/erroritem.html";
FormLayoutContainer errorGroupItemLayout = FormLayoutContainer.createCustomFormLayout("errorgroupitem", getTranslator(), vc_errorPage);
easyGroupList.setErrorComponent(errorGroupItemLayout, this.flc);
// FIXING LINK ONLY IF A DEFAULTCONTEXT EXISTS
fixGroupError = new FormLinkImpl("error.fix", "create");
// link
fixGroupError.setCustomEnabledLinkCSS("btn btn-default");
errorGroupItemLayout.add(fixGroupError);
fixGroupError.setErrorKey(labelKey, params);
fixGroupError.showError(true);
fixGroupError.showLabel(false);
// String[].lenght > 1 -> show bulkmode creation group
if (missingGroups.size() > 1) {
fixGroupError.setUserObject(new String[] { csvMissGrps, "dummy" });
} else {
fixGroupError.setUserObject(new String[] { csvMissGrps });
}
easyGroupList.showError(true);
}
}
if (!isEmpty(easyAreaList)) {
// check whether areas exist
activeAreaSelection = getKeys(easyAreaList);
List<Long> missingAreas = new ArrayList<Long>();
List<BGArea> cnt = areaManager.loadAreas(activeAreaSelection);
a_a: for (Long activeAreaKey : activeAreaSelection) {
for (BGArea element : cnt) {
if (element.getKey().equals(activeAreaKey)) {
continue a_a;
}
}
missingAreas.add(activeAreaKey);
}
if (missingAreas.size() > 0) {
retVal = false;
String labelKey = missingAreas.size() == 1 ? "error.notfound.name" : "error.notfound.names";
String csvMissAreas = toString(missingAreas);
String[] params = new String[] { "-", csvMissAreas };
// create error with link to fix it
String vc_errorPage = velocity_root + "/erroritem.html";
FormLayoutContainer errorAreaItemLayout = FormLayoutContainer.createCustomFormLayout("errorareaitem", getTranslator(), vc_errorPage);
easyAreaList.setErrorComponent(errorAreaItemLayout, this.flc);
// FXINGIN LINK ONLY IF DEFAULT CONTEXT EXISTS
// erstellen
fixAreaError = new FormLinkImpl("error.fix", "create");
// link
fixAreaError.setCustomEnabledLinkCSS("btn btn-default");
errorAreaItemLayout.add(fixAreaError);
fixAreaError.setErrorKey(labelKey, params);
fixAreaError.showError(true);
fixAreaError.showLabel(false);
// String[].lenght > 1 -> show bulkmode creation group
if (missingAreas.size() > 1) {
fixAreaError.setUserObject(new String[] { csvMissAreas, "dummy" });
} else {
fixAreaError.setUserObject(new String[] { csvMissAreas });
}
easyAreaList.showError(true);
}
}
boolean easyGroupOK = activeGroupSelection != null && activeGroupSelection.size() > 0;
boolean easyAreaOK = activeAreaSelection != null && activeAreaSelection.size() > 0;
if (!easyGroupOK && !easyAreaOK) {
// error concerns both fields -> set it as switch error
easyGroupList.setErrorKey("form.noGroupsOrAreas", null);
retVal = false;
}
// raise error if someone removed all groups and areas from form
if (!retVal && !easyGroupOK && !easyAreaOK) {
easyGroupList.setErrorKey("form.noGroupsOrAreas", null);
}
return retVal;
}
Aggregations