Search in sources :

Example 11 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class LecturesBlocksTest method removeRepositoryEntryDefaultGroupToLectureBlock.

@Test
public void removeRepositoryEntryDefaultGroupToLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    Group defGroup = repositoryService.getDefaultGroup(entry);
    lectureService.save(block, Collections.singletonList(defGroup));
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path(block.getKey().toString()).path("participants").path("repositoryentry").build();
    HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    // check the response
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the database
    List<Group> groups = lectureService.getLectureBlockToGroups(block);
    Assert.assertNotNull(groups);
    Assert.assertEquals(0, groups.size());
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) Group(org.olat.basesecurity.Group) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 12 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class LecturesBlocksTest method addRepositoryEntryDefaultGroupToLectureBlock.

@Test
public void addRepositoryEntryDefaultGroupToLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path(block.getKey().toString()).path("participants").path("repositoryentry").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    // check the response
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the database
    List<Group> groups = lectureService.getLectureBlockToGroups(block);
    Assert.assertNotNull(groups);
    Assert.assertEquals(1, groups.size());
    Group defGroup = repositoryService.getDefaultGroup(entry);
    Assert.assertEquals(defGroup, groups.get(0));
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) Group(org.olat.basesecurity.Group) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 13 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class EPPolicyManager method applyPolicyToInvitation.

private EPStructureElementToGroupRelation applyPolicyToInvitation(Invitation invitation, EPMapPolicy policy, PortfolioStructureMap map) {
    invitation = dbInstance.getCurrentEntityManager().merge(invitation);
    Group secGroup = invitation.getBaseGroup();
    Collection<EPStructureElementToGroupRelation> currentRelations = map.getGroups();
    for (EPStructureElementToGroupRelation currentRelation : currentRelations) {
        if (secGroup.equals(currentRelation.getGroup())) {
            updatePolicy(currentRelation, policy.getFrom(), policy.getTo());
            return currentRelation;
        }
    }
    return createBaseRelation(map, secGroup, EPMapPolicy.Type.invitation.name(), policy.getFrom(), policy.getTo());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)

Example 14 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class EPStructureManager method removeBaseGroup.

private void removeBaseGroup(EPAbstractMap map) {
    Set<EPStructureElementToGroupRelation> relations = map.getGroups();
    if (relations != null) {
        for (EPStructureElementToGroupRelation relation : relations) {
            Group group = relation.getGroup();
            if (relation.isDefaultGroup()) {
                groupDao.removeMemberships(group);
                groupDao.removeGroup(group);
            }
        }
    }
}
Also used : Group(org.olat.basesecurity.Group) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)

Example 15 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class EPStructureManager method createBaseGroup.

private EPStructureElementToGroupRelation createBaseGroup(EPStructureElement element, Identity author) {
    // create security group
    Group ownerGroup = groupDao.createGroup();
    EPStructureElementToGroupRelation relation = new EPStructureElementToGroupRelation();
    relation.setDefaultGroup(true);
    relation.setCreationDate(new Date());
    relation.setGroup(ownerGroup);
    relation.setStructureElement(element);
    groupDao.addMembershipTwoWay(ownerGroup, author, GroupRoles.owner.name());
    return relation;
}
Also used : Group(org.olat.basesecurity.Group) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) Date(java.util.Date)

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