use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class GroupIndexer method checkAccess.
@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
if (roles.isGuestOnly()) {
return false;
}
Long key = contextEntry.getOLATResourceable().getResourceableId();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup group = bgs.loadBusinessGroup(key);
if (group == null || roles.isGuestOnly()) {
return false;
}
boolean inGroup = bgs.isIdentityInBusinessGroup(identity, group);
if (inGroup) {
return super.checkAccess(contextEntry, businessControl, identity, roles) && super.checkAccess(businessControl, identity, roles);
} else {
AccessControlModule acModule = (AccessControlModule) CoreSpringFactory.getBean("acModule");
if (acModule.isEnabled()) {
ACService acService = CoreSpringFactory.getImpl(ACService.class);
OLATResource resource = group.getResource();
if (acService.isResourceAccessControled(resource, new Date())) {
return super.checkAccess(contextEntry, businessControl, identity, roles) && super.checkAccess(businessControl, identity, roles);
}
}
return false;
}
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class GroupIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
long startTime = System.currentTimeMillis();
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<BusinessGroup> groupList = bgs.loadAllBusinessGroups();
if (isLogDebugEnabled())
logDebug("GroupIndexer groupList.size=" + groupList.size());
// committing here to make sure the loadBusinessGroup below does actually
// reload from the database and not only use the session cache
// (see org.hibernate.Session.get():
// If the instance, or a proxy for the instance, is already associated with the session, return that instance or proxy.)
DBFactory.getInstance().commitAndCloseSession();
// loop over all groups
for (BusinessGroup businessGroup : groupList) {
try {
// reload the businessGroup here before indexing it to make sure it has not been deleted in the meantime
BusinessGroup reloadedBusinessGroup = bgs.loadBusinessGroup(businessGroup);
if (reloadedBusinessGroup == null) {
logInfo("doIndex: businessGroup was deleted while we were indexing. The deleted businessGroup was: " + businessGroup);
continue;
}
businessGroup = reloadedBusinessGroup;
if (isLogDebugEnabled())
logDebug("Index BusinessGroup=" + businessGroup);
SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
searchResourceContext.setBusinessControlFor(businessGroup);
Document document = GroupDocument.createDocument(searchResourceContext, businessGroup);
indexWriter.addDocument(document);
// Do index child
super.doIndex(searchResourceContext, businessGroup, indexWriter);
} catch (Exception ex) {
logError("Exception indexing group=" + businessGroup, ex);
DBFactory.getInstance().rollbackAndCloseSession();
} catch (Error err) {
logError("Error indexing group=" + businessGroup, err);
DBFactory.getInstance().rollbackAndCloseSession();
}
DBFactory.getInstance().commitAndCloseSession();
}
long indexTime = System.currentTimeMillis() - startTime;
if (isLogDebugEnabled())
logDebug("GroupIndexer finished in " + indexTime + " ms");
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class GroupWikiIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
if (!(businessObj instanceof BusinessGroup))
throw new AssertException("businessObj must be BusinessGroup");
BusinessGroup businessGroup = (BusinessGroup) businessObj;
// Index Group Wiki
if (isLogDebugEnabled())
logDebug("Analyse Wiki for Group=" + businessGroup);
CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup);
if (collabTools.isToolEnabled(CollaborationTools.TOOL_WIKI)) {
try {
Wiki wiki = WikiManager.getInstance().getOrLoadWiki(businessGroup);
// loop over all wiki pages
List<WikiPage> wikiPageList = wiki.getAllPagesWithContent();
for (WikiPage wikiPage : wikiPageList) {
SearchResourceContext wikiResourceContext = new SearchResourceContext(parentResourceContext);
wikiResourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLWIKI);
wikiResourceContext.setDocumentType(TYPE);
wikiResourceContext.setFilePath(wikiPage.getPageName());
Document document = WikiPageDocument.createDocument(wikiResourceContext, wikiPage);
indexWriter.addDocument(document);
}
} catch (NullPointerException nex) {
logWarn("NullPointerException in GroupWikiIndexer.doIndex.", nex);
}
} else {
if (isLogDebugEnabled())
logDebug("Group=" + businessGroup + " has no Wiki.");
}
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class AssessmentModeManagerTest method getAssessedIdentities_course_groups.
@Test
public void getAssessedIdentities_course_groups() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-15");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-16");
Identity coach1 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-17");
BusinessGroup businessGroup = businessGroupService.createBusinessGroup(null, "as-mode-4", "", null, null, null, null, false, false, entry);
businessGroupRelationDao.addRole(participant1, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(coach1, businessGroup, GroupRoles.coach.name());
Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-18");
Identity coach2 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-19");
repositoryEntryRelationDao.addRole(participant2, entry, GroupRoles.participant.name());
repositoryEntryRelationDao.addRole(coach2, entry, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(author, entry, GroupRoles.owner.name());
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode.setTargetAudience(AssessmentMode.Target.courseAndGroups);
mode.setApplySettingsForCoach(true);
mode = assessmentModeMgr.persist(mode);
AssessmentModeToGroup modeToGroup = assessmentModeMgr.createAssessmentModeToGroup(mode, businessGroup);
mode.getGroups().add(modeToGroup);
mode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
Set<Long> assessedIdentityKeys = assessmentModeMgr.getAssessedIdentityKeys(mode);
Assert.assertNotNull(assessedIdentityKeys);
Assert.assertEquals(4, assessedIdentityKeys.size());
Assert.assertFalse(assessedIdentityKeys.contains(author.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(coach1.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(participant1.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(coach2.getKey()));
Assert.assertTrue(assessedIdentityKeys.contains(participant2.getKey()));
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class AssessmentModeManagerTest method deleteAreaFromRepositoryEntry.
@Test
public void deleteAreaFromRepositoryEntry() {
// prepare the setup
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-14");
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-15");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode.setTargetAudience(AssessmentMode.Target.groups);
mode = assessmentModeMgr.persist(mode);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(mode);
BusinessGroup businessGroupForArea = businessGroupService.createBusinessGroup(author, "as_mode_1", "", null, null, null, null, false, false, null);
businessGroupRelationDao.addRole(participant, businessGroupForArea, GroupRoles.participant.name());
BGArea area = areaMgr.createAndPersistBGArea("little area", "My little secret area", entry.getOlatResource());
areaMgr.addBGToBGArea(businessGroupForArea, area);
dbInstance.commitAndCloseSession();
AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(mode, area);
mode.getAreas().add(modeToArea);
mode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
// check the participant modes
List<AssessmentMode> currentModes = assessmentModeMgr.getAssessmentModeFor(participant);
Assert.assertNotNull(currentModes);
Assert.assertEquals(1, currentModes.size());
Assert.assertTrue(currentModes.contains(mode));
// delete
areaMgr.deleteBGArea(area);
dbInstance.commitAndCloseSession();
// check the participant modes after deleting the area
List<AssessmentMode> afterDeleteModes = assessmentModeMgr.getAssessmentModeFor(participant);
Assert.assertNotNull(afterDeleteModes);
Assert.assertEquals(0, afterDeleteModes.size());
}
Aggregations