Search in sources :

Example 56 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class GroupBulkDownloadResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    String label = StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeWithMinutes(new Date()) + ".zip";
    String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
    hres.setHeader("Content-Description", urlEncodedLabel);
    try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
        zout.setLevel(9);
        ICourse course = CourseFactory.loadCourse(courseOres);
        GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        if (courseNode.getModuleConfiguration().getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
            List<Identity> assessableIdentities = CoreSpringFactory.getImpl(BusinessGroupService.class).getMembers(groups, GroupRoles.participant.name());
            String courseTitle = course.getCourseTitle();
            String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
            List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(courseNode);
            try (OutputStream out = new ShieldOutputStream(zout)) {
                zout.putNextEntry(new ZipEntry(fileName));
                ScoreAccountingHelper.createCourseResultsOverviewXMLTable(assessableIdentities, nodes, course, locale, out);
                zout.closeEntry();
            } catch (Exception e) {
                log.error("", e);
            }
        }
        TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), courseNode);
        for (BusinessGroup businessGroup : groups) {
            courseNode.archiveNodeData(course, businessGroup, taskList, "", zout);
        }
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipEntry(java.util.zip.ZipEntry) TaskList(org.olat.course.nodes.gta.TaskList) ICourse(org.olat.course.ICourse) Date(java.util.Date) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) BusinessGroupService(org.olat.group.BusinessGroupService) ZipOutputStream(java.util.zip.ZipOutputStream) GTAManager(org.olat.course.nodes.gta.GTAManager) Identity(org.olat.core.id.Identity)

Example 57 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class GTAManagerImpl method filterBusinessGroups.

@Override
public List<BusinessGroup> filterBusinessGroups(List<BusinessGroup> groups, GTACourseNode cNode) {
    if (groups == null || groups.isEmpty())
        return new ArrayList<>(1);
    List<BusinessGroup> filteredGroups = new ArrayList<>();
    ModuleConfiguration config = cNode.getModuleConfiguration();
    List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
    for (BusinessGroup group : groups) {
        if (groupKeys.contains(group.getKey())) {
            filteredGroups.add(group);
        }
    }
    if (filteredGroups.size() < groups.size()) {
        List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
        List<Long> groupKeysOfAreas = areaManager.findBusinessGroupKeysOfAreaKeys(areaKeys);
        for (BusinessGroup group : groups) {
            // don't add 2x
            if (!groupKeys.contains(group.getKey()) && groupKeysOfAreas.contains(group.getKey())) {
                filteredGroups.add(group);
            }
        }
    }
    return filteredGroups;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList)

Example 58 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class ACFrontendManager method reserveAccessToResource.

@Override
public boolean reserveAccessToResource(final Identity identity, final OfferAccess offer) {
    final OLATResource resource = offer.getOffer().getResource();
    String resourceType = resource.getResourceableTypeName();
    if ("BusinessGroup".equals(resourceType)) {
        boolean reserved = false;
        final BusinessGroup group = businessGroupDao.loadForUpdate(resource.getResourceableId());
        if (group.getMaxParticipants() == null && group.getMaxParticipants() <= 0) {
            // don't need reservation
            reserved = true;
        } else {
            BusinessGroup reloadedGroup = businessGroupService.loadBusinessGroup(resource);
            ResourceReservation reservation = reservationDao.loadReservation(identity, resource);
            if (reservation != null) {
                reserved = true;
            }
            int currentCount = businessGroupService.countMembers(reloadedGroup, GroupRoles.participant.name());
            int reservations = reservationDao.countReservations(resource);
            if (currentCount + reservations < reloadedGroup.getMaxParticipants().intValue()) {
                reservationDao.createReservation(identity, offer.getMethod().getType(), null, resource);
                reserved = true;
            }
        }
        return reserved;
    }
    return true;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) OLATResource(org.olat.resource.OLATResource)

Example 59 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method getParticipantRepositoryEntryWithGroups.

@Test
public void getParticipantRepositoryEntryWithGroups() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-stud-ld-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "studh", "th", null, null, false, false, re);
    businessGroupRelationDao.addRole(id, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    List<RepositoryEntryLight> entries = repositoryManager.getParticipantRepositoryEntry(id, -1);
    Assert.assertNotNull(entries);
    Assert.assertFalse(entries.isEmpty());
    boolean found = false;
    Set<Long> duplicates = new HashSet<Long>();
    for (RepositoryEntryLight entry : entries) {
        Assert.assertTrue(duplicates.add(entry.getKey()));
        if (entry.getKey().equals(re.getKey())) {
            found = true;
        }
    }
    Assert.assertTrue(found);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 60 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method getTutorRepositoryEntryWithGroups.

@Test
public void getTutorRepositoryEntryWithGroups() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-stud-lf-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "studi", "ti", null, null, false, false, re);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    List<RepositoryEntryLight> entries = repositoryManager.getTutorRepositoryEntry(id, -1);
    Assert.assertNotNull(entries);
    Assert.assertFalse(entries.isEmpty());
    boolean found = false;
    Set<Long> duplicates = new HashSet<Long>();
    for (RepositoryEntryLight entry : entries) {
        Assert.assertTrue(duplicates.add(entry.getKey()));
        if (entry.getKey().equals(re.getKey())) {
            found = true;
        }
    }
    Assert.assertTrue(found);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BusinessGroup (org.olat.group.BusinessGroup)1034 Test (org.junit.Test)536 Identity (org.olat.core.id.Identity)536 RepositoryEntry (org.olat.repository.RepositoryEntry)324 ArrayList (java.util.ArrayList)224 BusinessGroupService (org.olat.group.BusinessGroupService)116 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)84 BGArea (org.olat.group.area.BGArea)70 CollaborationTools (org.olat.collaboration.CollaborationTools)58 OLATResource (org.olat.resource.OLATResource)56 Date (java.util.Date)54 HashSet (java.util.HashSet)50 File (java.io.File)46 Path (javax.ws.rs.Path)42 Group (org.olat.basesecurity.Group)42 HashMap (java.util.HashMap)38 Roles (org.olat.core.id.Roles)38 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)38 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38