Search in sources :

Example 66 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class BGRightManagerImpl method removeBGRights.

@Override
public void removeBGRights(Collection<Group> groups, OLATResource resource) {
    for (Group group : groups) {
        groupDao.removeGrants(group, GroupRoles.coach.name(), resource);
        groupDao.removeGrants(group, GroupRoles.participant.name(), resource);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group)

Example 67 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class QTIStatisticsResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    CourseNode courseNode = resourceResult.getTestCourseNode();
    String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
    String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
    hres.setHeader("Content-Description", urlEncodedLabel);
    try {
        // fields separated by
        String sep = "\\t";
        // fields embedded by
        String emb = "\"";
        // carriage return
        String car = "\\r\\n";
        sep = QTIArchiver.convert2CtrlChars(sep);
        car = QTIArchiver.convert2CtrlChars(car);
        int exportType = 1;
        QTIExportFormatter formatter;
        if (QTIType.test.equals(resourceResult.getType())) {
            exportType = 1;
            formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
        } else if (QTIType.survey.equals(resourceResult.getType())) {
            exportType = 2;
            formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
        } else {
            return;
        }
        Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
        List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
        formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
        QTIResultManager qrm = QTIResultManager.getInstance();
        QTIStatisticSearchParams params = resourceResult.getSearchParams();
        List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
        List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
        QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) Group(org.olat.basesecurity.Group) QTIResultManager(org.olat.ims.qti.QTIResultManager) QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Date(java.util.Date) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) CourseNode(org.olat.course.nodes.CourseNode)

Example 68 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class EditLectureBlockController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_repo_edit_lecture_form");
    if (lectureBlock != null && StringHelper.containsNonWhitespace(lectureBlock.getManagedFlagsString())) {
        setFormWarning("form.managedflags.intro.short", null);
    }
    String title = lectureBlock == null ? null : lectureBlock.getTitle();
    titleEl = uifactory.addTextElement("title", "lecture.title", 128, title, formLayout);
    titleEl.setElementCssClass("o_sel_repo_lecture_title");
    titleEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.title));
    titleEl.setMandatory(true);
    plannedLecturesEl = uifactory.addDropdownSingleselect("planned.lectures", "planned.lectures", formLayout, plannedLecturesKeys, plannedLecturesKeys, null);
    plannedLecturesEl.setMandatory(true);
    String plannedlectures = lectureBlock == null ? "4" : Integer.toString(lectureBlock.getPlannedLecturesNumber());
    for (String plannedLecturesKey : plannedLecturesKeys) {
        if (plannedlectures.equals(plannedLecturesKey)) {
            plannedLecturesEl.select(plannedLecturesKey, true);
            break;
        }
    }
    // freeze it after roll call done
    boolean plannedLecturesEditable = (lectureBlock == null || (lectureBlock.getStatus() != LectureBlockStatus.done && lectureBlock.getRollCallStatus() != LectureRollCallStatus.closed && lectureBlock.getRollCallStatus() != LectureRollCallStatus.autoclosed)) && !lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.plannedLectures);
    plannedLecturesEl.setEnabled(plannedLecturesEditable);
    String[] onValues = new String[] { "" };
    boolean compulsory = lectureBlock == null ? true : lectureBlock.isCompulsory();
    compulsoryEl = uifactory.addCheckboxesVertical("compulsory", "lecture.compulsory", formLayout, onKeys, onValues, 1);
    compulsoryEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.compulsory));
    compulsoryEl.addActionListener(FormEvent.ONCHANGE);
    if (compulsory) {
        compulsoryEl.select(onKeys[0], true);
    }
    List<Identity> coaches = repositoryService.getMembers(entry, GroupRoles.coach.name());
    teacherKeys = new String[coaches.size() + 1];
    teacherValues = new String[coaches.size() + 1];
    for (int i = coaches.size() + 1; i-- > 1; ) {
        Identity coach = coaches.get(i - 1);
        teacherKeys[i] = coach.getKey().toString();
        teacherValues[i] = userManager.getUserDisplayName(coach);
    }
    teacherKeys[0] = "-";
    teacherValues[0] = translate("no.teachers");
    teacherEl = uifactory.addCheckboxesVertical("teacher", "lecture.teacher", formLayout, teacherKeys, teacherValues, 2);
    teacherEl.setElementCssClass("o_sel_repo_lecture_teachers");
    teacherEl.setMandatory(true);
    teacherEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.teachers));
    boolean found = false;
    if (teachers != null && teachers.size() > 0) {
        for (Identity teacher : teachers) {
            String currentTeacherKey = teacher.getKey().toString();
            for (String teacherKey : teacherKeys) {
                if (currentTeacherKey.equals(teacherKey)) {
                    teacherEl.select(currentTeacherKey, true);
                    found = true;
                }
            }
        }
    }
    if (!found) {
        teacherEl.select(teacherKeys[0], true);
    }
    Group entryBaseGroup = repositoryService.getDefaultGroup(entry);
    groupBox = new ArrayList<>();
    groupBox.add(new GroupBox(entry, entryBaseGroup));
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    List<BusinessGroup> businessGroups = businessGroupService.findBusinessGroups(params, entry, 0, -1, BusinessGroupOrder.nameAsc);
    for (BusinessGroup businessGroup : businessGroups) {
        groupBox.add(new GroupBox(businessGroup));
    }
    String[] groupKeys = new String[groupBox.size()];
    String[] groupValues = new String[groupBox.size()];
    for (int i = groupBox.size(); i-- > 0; ) {
        groupKeys[i] = Integer.toString(i);
        groupValues[i] = groupBox.get(i).getName();
    }
    groupsEl = uifactory.addCheckboxesVertical("lecture.groups", "lecture.groups", formLayout, groupKeys, groupValues, 2);
    groupsEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.groups));
    groupsEl.setMandatory(true);
    if (lectureBlock != null) {
        List<Group> selectedGroups = lectureService.getLectureBlockToGroups(lectureBlock);
        for (int i = 0; i < groupBox.size(); i++) {
            if (selectedGroups.contains(groupBox.get(i).getBaseGroup())) {
                groupsEl.select(Integer.toString(i), true);
            }
        }
    } else if (groupKeys.length == 1) {
        groupsEl.select(groupKeys[0], true);
    }
    String description = lectureBlock == null ? "" : lectureBlock.getDescription();
    descriptionEl = uifactory.addTextAreaElement("lecture.descr", 4, 72, description, formLayout);
    descriptionEl.setElementCssClass("o_sel_repo_lecture_description");
    descriptionEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.description));
    String preparation = lectureBlock == null ? "" : lectureBlock.getPreparation();
    preparationEl = uifactory.addTextAreaElement("lecture.preparation", 4, 72, preparation, formLayout);
    preparationEl.setElementCssClass("o_sel_repo_lecture_preparation");
    preparationEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.preparation));
    String location = lectureBlock == null ? "" : lectureBlock.getLocation();
    locationEl = uifactory.addTextElementWithAutoCompleter("location", "lecture.location", 128, location, formLayout);
    locationEl.setElementCssClass("o_sel_repo_lecture_location");
    locationEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.location));
    locationEl.setListProvider(new LocationListProvider(), ureq.getUserSession());
    locationEl.setMinLength(1);
    Date startDate = lectureBlock == null ? null : lectureBlock.getStartDate();
    dateEl = uifactory.addDateChooser("lecture.date", startDate, formLayout);
    dateEl.setElementCssClass("o_sel_repo_lecture_date");
    dateEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
    dateEl.setDomReplacementWrapperRequired(false);
    dateEl.setMandatory(true);
    String datePage = velocity_root + "/date_start_end.html";
    FormLayoutContainer dateCont = FormLayoutContainer.createCustomFormLayout("start_end", getTranslator(), datePage);
    dateCont.setLabel("lecture.time", null);
    formLayout.add(dateCont);
    startHourEl = uifactory.addTextElement("lecture.start.hour", null, 2, "", dateCont);
    startHourEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
    startHourEl.setDomReplacementWrapperRequired(false);
    startHourEl.setDisplaySize(2);
    startHourEl.setMandatory(true);
    startMinuteEl = uifactory.addTextElement("lecture.start.minute", null, 2, "", dateCont);
    startMinuteEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
    startMinuteEl.setDomReplacementWrapperRequired(false);
    startMinuteEl.setDisplaySize(2);
    endHourEl = uifactory.addTextElement("lecture.end.hour", null, 2, "", dateCont);
    endHourEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
    endHourEl.setDomReplacementWrapperRequired(false);
    endHourEl.setDisplaySize(2);
    endHourEl.setMandatory(true);
    endMinuteEl = uifactory.addTextElement("lecture.end.minute", null, 2, "", dateCont);
    endMinuteEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
    endMinuteEl.setDomReplacementWrapperRequired(false);
    endMinuteEl.setDisplaySize(2);
    if (lectureBlock != null) {
        Calendar cal = Calendar.getInstance();
        if (lectureBlock.getStartDate() != null) {
            cal.setTime(lectureBlock.getStartDate());
            int hour = cal.get(Calendar.HOUR_OF_DAY);
            int minute = cal.get(Calendar.MINUTE);
            startHourEl.setValue(Integer.toString(hour));
            startMinuteEl.setValue(formatMinute(minute));
        }
        if (lectureBlock.getEndDate() != null) {
            cal.setTime(lectureBlock.getEndDate());
            int hour = cal.get(Calendar.HOUR_OF_DAY);
            int minute = cal.get(Calendar.MINUTE);
            endHourEl.setValue(Integer.toString(hour));
            endMinuteEl.setValue(formatMinute(minute));
        }
    }
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
    uifactory.addFormSubmitButton("save", buttonsCont);
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroup(org.olat.group.BusinessGroup) Calendar(java.util.Calendar) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Date(java.util.Date) Identity(org.olat.core.id.Identity)

Example 69 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class BusinessGroupServiceTest method testDeleteBusinessGroupWithWaitingGroup.

@Test
public void testDeleteBusinessGroupWithWaitingGroup() {
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup deleteTestGroup = businessGroupService.createBusinessGroup(id1, "deleteTestGroup-1", "deleteTestGroup-1", -1, -1, true, true, resource);
    dbInstance.commitAndCloseSession();
    businessGroupService.deleteBusinessGroup(deleteTestGroup);
    dbInstance.commitAndCloseSession();
    Group reloadedGroup = groupDao.loadGroup(deleteTestGroup.getBaseGroup().getKey());
    Assert.assertNull(reloadedGroup);
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 70 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class QTIResultManagerTest method selectResults_limitToSecurityGroup.

@Test
public void selectResults_limitToSecurityGroup() {
    RepositoryEntry re = createRepository();
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-result-mgr-16");
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.participant.name());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-result-mgr-17");
    dbInstance.commit();
    long assessmentId = 841l;
    String resSubPath = "qtiResult37";
    String itemIdent1 = "NES:PS4:849235797";
    String itemIdent2 = "NES:PS4:849235798";
    QTIResultSet set1_1 = createSet(1.0f, assessmentId, id1, re, resSubPath, modDate(3, 8, 5), modDate(3, 8, 20));
    QTIResult result1_1 = createResult(itemIdent1, "Hello world", set1_1);
    QTIResultSet set2_1 = createSet(3.0f, assessmentId, id2, re, resSubPath, modDate(3, 14, 8), modDate(3, 14, 32));
    QTIResult result2_1 = createResult(itemIdent1, "Bonjour madame", set2_1);
    QTIResultSet set1_1b = createSet(5.0f, assessmentId, id1, re, resSubPath, modDate(3, 10, 35), modDate(3, 10, 55));
    QTIResult result1_1b = createResult(itemIdent1, "Tschuss", set1_1b);
    QTIResult result1_1c = createResult(itemIdent2, "Tschuss", set1_1b);
    dbInstance.commitAndCloseSession();
    List<Group> secGroups = Collections.singletonList(repositoryEntryRelationDao.getDefaultGroup(re));
    List<QTIResult> resultsType1 = qtiResultManager.selectResults(re.getOlatResource().getResourceableId(), resSubPath, re.getKey(), secGroups, 1);
    Assert.assertNotNull(resultsType1);
    Assert.assertEquals(3, resultsType1.size());
    Assert.assertTrue(resultsType1.contains(result1_1));
    Assert.assertTrue(resultsType1.contains(result1_1b));
    Assert.assertTrue(resultsType1.contains(result1_1c));
    // not a participant in the security group
    Assert.assertFalse(resultsType1.contains(result2_1));
}
Also used : Group(org.olat.basesecurity.Group) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

Group (org.olat.basesecurity.Group)170 Test (org.junit.Test)92 Identity (org.olat.core.id.Identity)80 BusinessGroup (org.olat.group.BusinessGroup)72 RepositoryEntry (org.olat.repository.RepositoryEntry)46 ArrayList (java.util.ArrayList)28 GroupMembership (org.olat.basesecurity.GroupMembership)26 LectureBlock (org.olat.modules.lecture.LectureBlock)26 OLATResource (org.olat.resource.OLATResource)26 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)20 Date (java.util.Date)16 SecurityGroup (org.olat.basesecurity.SecurityGroup)16 EPStructureElementToGroupRelation (org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)14 HashSet (java.util.HashSet)12 RepositoryEntryToGroupRelation (org.olat.repository.model.RepositoryEntryToGroupRelation)11 HashMap (java.util.HashMap)8 Grant (org.olat.basesecurity.Grant)8 Calendar (java.util.Calendar)6 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)6 BGRights (org.olat.group.right.BGRights)5