Search in sources :

Example 1 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class CertificatesManagerImpl method getCertificatesForNotifications.

@Override
public List<Certificate> getCertificatesForNotifications(Identity identity, RepositoryEntry entry, Date lastNews) {
    Roles roles = securityManager.getRoles(identity);
    RepositoryEntrySecurity security = repositoryManager.isAllowed(identity, roles, entry);
    if (!security.isEntryAdmin() && !security.isCourseCoach() && !security.isGroupCoach() && !security.isCourseParticipant() && !security.isGroupParticipant()) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select cer from certificate cer").append(" inner join fetch cer.identity ident").append(" where cer.olatResource.key=:resourceKey and cer.last=true ");
    // must be some kind of restrictions
    boolean securityCheck = false;
    List<Long> baseGroupKeys = null;
    if (!security.isEntryAdmin()) {
        sb.append(" and (");
        boolean or = false;
        if (security.isCourseCoach()) {
            or = or(sb, or);
            sb.append(" exists (select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ").append("   where ident.key=membership.identity.key and rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'").append(" )");
            securityCheck = true;
        }
        if (security.isGroupCoach()) {
            SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
            List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, entry, 0, -1);
            if (groups.size() > 0) {
                or = or(sb, or);
                sb.append(" exists (select membership.identity.key from bgroupmember membership ").append("   where ident.key=membership.identity.key and membership.group.key in (:groups) and membership.role='").append(GroupRole.participant).append("'").append(" )");
                baseGroupKeys = new ArrayList<>(groups.size());
                for (BusinessGroup group : groups) {
                    baseGroupKeys.add(group.getBaseGroup().getKey());
                }
                securityCheck = true;
            }
        }
        if (security.isCourseParticipant() || security.isGroupParticipant()) {
            or = or(sb, or);
            sb.append(" ident.key=:identityKey");
            securityCheck = true;
        }
        sb.append(")");
    } else {
        securityCheck = true;
    }
    if (!securityCheck) {
        return Collections.emptyList();
    }
    sb.append(" order by cer.creationDate");
    TypedQuery<Certificate> certificates = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Certificate.class).setParameter("resourceKey", entry.getOlatResource().getKey());
    if (!security.isEntryAdmin()) {
        if (security.isCourseCoach()) {
            certificates.setParameter("repoKey", entry.getKey());
        }
        if (security.isCourseParticipant() || security.isGroupParticipant()) {
            certificates.setParameter("identityKey", identity.getKey());
        }
    }
    if (baseGroupKeys != null && !baseGroupKeys.isEmpty()) {
        certificates.setParameter("groups", baseGroupKeys);
    }
    return certificates.getResultList();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) Roles(org.olat.core.id.Roles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Certificate(org.olat.course.certificate.Certificate)

Example 2 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupImportExportTest method importLearningGroupsWithResource.

@Test
public void importLearningGroupsWithResource() throws URISyntaxException {
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_2.xml");
    File importXml = new File(input.toURI());
    businessGroupService.importGroups(resource, importXml);
    dbInstance.commitAndCloseSession();
    // check if all three groups are imported
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(3, groups.size());
    // get first group (members true, true, false) (no collaboration tools)
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    params.setExactName("Export group 1");
    List<BusinessGroup> group1List = businessGroupService.findBusinessGroups(params, resource, 0, -1);
    Assert.assertNotNull(group1List);
    Assert.assertEquals(1, group1List.size());
    // check settings of the first group
    BusinessGroup group1 = group1List.get(0);
    Assert.assertEquals("Export group 1", group1.getName());
    Assert.assertEquals("<p>Export group 1</p>", group1.getDescription());
    Assert.assertFalse(group1.getAutoCloseRanksEnabled().booleanValue());
    Assert.assertFalse(group1.getWaitingListEnabled().booleanValue());
    // check display members settings
    Assert.assertTrue(group1.isOwnersVisibleIntern());
    Assert.assertTrue(group1.isParticipantsVisibleIntern());
    Assert.assertFalse(group1.isWaitingListVisibleIntern());
    // check collaboration tools
    CollaborationTools toolGroup1 = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(group1);
    Assert.assertNotNull(toolGroup1);
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CHAT));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CONTACT));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_FOLDER));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_FORUM));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_NEWS));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
    Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_WIKI));
    // get third group (members true, true, true) (all collaboration tools)
    params.setExactName("Export group 3");
    List<BusinessGroup> group3List = businessGroupService.findBusinessGroups(params, resource, 0, -1);
    Assert.assertNotNull(group3List);
    Assert.assertEquals(1, group3List.size());
    // check settings of the first group
    BusinessGroup group3 = group3List.get(0);
    Assert.assertEquals("Export group 3", group3.getName());
    Assert.assertEquals("<p>Export group 2</p>", group3.getDescription());
    Assert.assertFalse(group3.getAutoCloseRanksEnabled().booleanValue());
    Assert.assertTrue(group3.getWaitingListEnabled().booleanValue());
    Assert.assertEquals(new Integer(25), group3.getMaxParticipants());
    // check display members settings
    Assert.assertTrue(group3.isOwnersVisibleIntern());
    Assert.assertTrue(group3.isParticipantsVisibleIntern());
    Assert.assertTrue(group3.isWaitingListVisibleIntern());
    // check collaboration tools
    CollaborationTools toolGroup3 = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(group3);
    Assert.assertNotNull(toolGroup3);
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
    // Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CHAT)); chat is not enabled during unit tests
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CONTACT));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_FOLDER));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_FORUM));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_NEWS));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
    Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_WIKI));
    Assert.assertEquals("<p>Hello Mitglied</p>", toolGroup3.lookupNews());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URL(java.net.URL) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Example 3 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method findAndCountBusinessGroups.

@Test
public void findAndCountBusinessGroups() {
    // prepare 2 resources + 3 groups with 3 owners
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("wait-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("wait-2-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("wait-3-" + UUID.randomUUID().toString());
    RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "rel-bg-part-one", "rel-bgis-1-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, resource1);
    businessGroupRelationDao.addRelationToResource(group1, resource2);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "rel-bg-part-two", "rel-bgis-2-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, resource1);
    BusinessGroup group3 = businessGroupDao.createAndPersist(id3, "rel-bg-part-three", "rel-bgis-3-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group3, resource2);
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    // check resource 1
    int count1_1 = businessGroupDao.countBusinessGroups(params, resource1);
    Assert.assertEquals(2, count1_1);
    List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroups(params, resource1, 0, -1);
    Assert.assertNotNull(groups1_1);
    Assert.assertEquals(2, groups1_1.size());
    Assert.assertTrue(groups1_1.contains(group1));
    Assert.assertTrue(groups1_1.contains(group2));
    // check owner 1 + resource 1
    SearchBusinessGroupParams paramsRestricted = new SearchBusinessGroupParams(id1, true, true);
    int count3_1 = businessGroupDao.countBusinessGroups(paramsRestricted, resource1);
    Assert.assertEquals(1, count3_1);
    List<BusinessGroup> groups3_1 = businessGroupDao.findBusinessGroups(paramsRestricted, resource1, 0, -1);
    Assert.assertNotNull(groups3_1);
    Assert.assertEquals(1, groups3_1.size());
    Assert.assertEquals(group1, groups3_1.get(0));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Example 4 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class HomeCalendarManager method getListOfCalendarsFiles.

@Override
public List<CalendarFileInfos> getListOfCalendarsFiles(Identity identity) {
    List<CalendarFileInfos> aggregatedFiles = new ArrayList<>();
    Map<CalendarKey, CalendarUserConfiguration> configMap = calendarManager.getCalendarUserConfigurationsMap(identity);
    // personal calendar
    CalendarKey personalCalendarKey = new CalendarKey(identity.getName(), CalendarManager.TYPE_USER);
    CalendarUserConfiguration personalCalendarConfig = configMap.get(personalCalendarKey);
    if (calendarModule.isEnablePersonalCalendar() && (personalCalendarConfig == null || personalCalendarConfig.isInAggregatedFeed())) {
        File iCalFile = calendarManager.getCalendarICalFile(CalendarManager.TYPE_USER, identity.getName());
        if (iCalFile != null) {
            aggregatedFiles.add(new CalendarFileInfos(identity.getName(), CalendarManager.TYPE_USER, iCalFile));
        }
        // reload every hour
        List<CalendarFileInfos> importedCalendars = importCalendarManager.getImportedCalendarInfosForIdentity(identity, true);
        aggregatedFiles.addAll(importedCalendars);
    }
    // group calendars
    if (calendarModule.isEnableGroupCalendar()) {
        SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(identity, true, true);
        groupParams.addTools(CollaborationTools.TOOL_CALENDAR);
        List<BusinessGroup> groups = businessGroupService.findBusinessGroups(groupParams, null, 0, -1);
        Set<BusinessGroup> resourceSet = new HashSet<>();
        for (BusinessGroup group : groups) {
            if (resourceSet.contains(group)) {
                continue;
            } else {
                resourceSet.add(group);
            }
            String calendarId = group.getKey().toString();
            CalendarKey key = new CalendarKey(calendarId, CalendarManager.TYPE_GROUP);
            CalendarUserConfiguration calendarConfig = configMap.get(key);
            if (calendarConfig == null || calendarConfig.isInAggregatedFeed()) {
                File iCalFile = calendarManager.getCalendarICalFile(CalendarManager.TYPE_GROUP, calendarId);
                if (iCalFile != null) {
                    aggregatedFiles.add(new CalendarFileInfos(calendarId, CalendarManager.TYPE_GROUP, iCalFile));
                }
            }
        }
    }
    if (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) {
        List<Object[]> resources = getCourses(identity);
        Set<RepositoryEntry> resourceSet = new HashSet<>();
        for (Object[] resource : resources) {
            RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
            if (resourceSet.contains(courseEntry)) {
                continue;
            } else {
                resourceSet.add(courseEntry);
            }
            String calendarId = courseEntry.getOlatResource().getResourceableId().toString();
            CalendarKey key = new CalendarKey(calendarId, CalendarManager.TYPE_COURSE);
            CalendarUserConfiguration calendarConfig = configMap.get(key);
            if (calendarConfig == null || calendarConfig.isInAggregatedFeed()) {
                File iCalFile = calendarManager.getCalendarICalFile(CalendarManager.TYPE_COURSE, calendarId);
                if (iCalFile != null) {
                    aggregatedFiles.add(new CalendarFileInfos(calendarId, CalendarManager.TYPE_COURSE, iCalFile));
                }
            }
        }
    }
    return aggregatedFiles;
}
Also used : CalendarKey(org.olat.commons.calendar.model.CalendarKey) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) CalendarFileInfos(org.olat.commons.calendar.model.CalendarFileInfos) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class AssessedIdentityListController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("title", testEntry.getDisplayname());
        RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(testEntry);
        layoutCont.contextPut("cssClass", RepositoyUIFactory.getIconCssClass(handler.getSupportedType()));
    }
    // add the table
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    if (isAdministrativeUser) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.username, "select"));
    }
    int colIndex = AssessmentToolConstants.USER_PROPS_OFFSET;
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        boolean visible = UserManager.getInstance().isMandatoryUserProperty(AssessmentToolConstants.usageIdentifyer, userPropertyHandler);
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, "select", true, "userProp-" + colIndex));
        colIndex++;
    }
    if (element.hasAttemptsConfigured()) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.attempts, "select"));
    }
    if (element.hasScoreConfigured()) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.min, "select", new ScoreCellRenderer()));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.max, "select", new ScoreCellRenderer()));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.score, "select", new ScoreCellRenderer()));
    }
    if (element.hasPassedConfigured()) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.passed, new PassedCellRenderer()));
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.assessmentStatus, new AssessmentStatusCellRenderer(getLocale())));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.initialLaunchDate, "select"));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, IdentityCourseElementCols.lastModified, "select"));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.lastUserModified, "select"));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, IdentityCourseElementCols.lastCoachModified, "select"));
    usersTableModel = new AssessedIdentityListTableModel(columnsModel, element);
    usersTableModel.setCertificateMap(new ConcurrentHashMap<>());
    tableEl = uifactory.addTableElement(getWindowControl(), "table", usersTableModel, 20, false, getTranslator(), formLayout);
    tableEl.setExportEnabled(true);
    tableEl.setSearchEnabled(new AssessedIdentityListProvider(getIdentity(), testEntry, testEntry, null, assessmentCallback), ureq.getUserSession());
    List<FlexiTableFilter> filters = new ArrayList<>();
    filters.add(new FlexiTableFilter(translate("filter.passed"), "passed"));
    filters.add(new FlexiTableFilter(translate("filter.failed"), "failed"));
    filters.add(new FlexiTableFilter(translate("filter.inProgress"), "inProgress"));
    filters.add(new FlexiTableFilter(translate("filter.inReview"), "inReview"));
    filters.add(new FlexiTableFilter(translate("filter.done"), "done"));
    tableEl.setFilters("", filters, false);
    if (assessmentCallback.canAssessBusinessGoupMembers()) {
        List<BusinessGroup> coachedGroups;
        if (assessmentCallback.isAdmin()) {
            SearchBusinessGroupParams params = new SearchBusinessGroupParams();
            coachedGroups = businessGroupService.findBusinessGroups(params, testEntry, 0, -1);
        } else {
            coachedGroups = assessmentCallback.getCoachedGroups();
        }
        if (coachedGroups.size() > 0) {
            List<FlexiTableFilter> groupFilters = new ArrayList<>();
            for (BusinessGroup coachedGroup : coachedGroups) {
                String groupName = StringHelper.escapeHtml(coachedGroup.getName());
                groupFilters.add(new FlexiTableFilter(groupName, coachedGroup.getKey().toString(), "o_icon o_icon_group"));
            }
            tableEl.setExtendedFilterButton(translate("filter.groups"), groupFilters);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) AssessedIdentityListProvider(org.olat.course.assessment.ui.tool.AssessedIdentityListProvider) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) AssessmentStatusCellRenderer(org.olat.course.assessment.ui.tool.AssessmentStatusCellRenderer) FlexiTableFilter(org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) PassedCellRenderer(org.olat.course.assessment.bulk.PassedCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)92 BusinessGroup (org.olat.group.BusinessGroup)84 Identity (org.olat.core.id.Identity)36 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)26 BusinessGroupService (org.olat.group.BusinessGroupService)18 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)16 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)16 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)16 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)16 RepositoryEntry (org.olat.repository.RepositoryEntry)16 HashSet (java.util.HashSet)12 GET (javax.ws.rs.GET)10 Produces (javax.ws.rs.Produces)10 Roles (org.olat.core.id.Roles)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)6 ICourse (org.olat.course.ICourse)6