Search in sources :

Example 31 with Group

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

the class OLATUpgrade_10_0_0 method processInvitation.

private void processInvitation(InvitationUpgrade invitation) {
    if (invitation.getBaseGroup() == null) {
        Group invitationGroup = groupDao.createGroup();
        invitation.setBaseGroup(invitationGroup);
        dbInstance.getCurrentEntityManager().merge(invitation);
    }
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Example 32 with Group

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

the class BGRightManagerImpl method findBGRights.

@Override
public List<BGRights> findBGRights(List<Group> baseGroups, OLATResource resource) {
    List<Grant> grants = groupDao.getGrants(baseGroups, resource);
    List<BGRights> rights = new ArrayList<>();
    Map<BGRights, BGRights> rightsMap = new HashMap<>();
    for (Grant grant : grants) {
        String right = grant.getPermission();
        if (right.indexOf(BG_RIGHT_PREFIX) == 0 && grant.getResource().equals(resource)) {
            BGRightsRole role = null;
            if (GroupRoles.participant.name().equals(grant.getRole())) {
                role = BGRightsRole.participant;
            } else if (GroupRoles.coach.name().equals(grant.getRole())) {
                role = BGRightsRole.tutor;
            }
            BGRights wrapper = new BGRightsImpl(grant.getGroup(), role);
            wrapper = rightsMap.computeIfAbsent(wrapper, w -> w);
            wrapper.getRights().add(right);
            rights.add(wrapper);
        }
    }
    return rights;
}
Also used : Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) IdentityRef(org.olat.basesecurity.IdentityRef) OLATResource(org.olat.resource.OLATResource) ArrayList(java.util.ArrayList) List(java.util.List) DB(org.olat.core.commons.persistence.DB) GroupRoles(org.olat.basesecurity.GroupRoles) GroupDAO(org.olat.basesecurity.manager.GroupDAO) Service(org.springframework.stereotype.Service) Map(java.util.Map) BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) Collections(java.util.Collections) Grant(org.olat.basesecurity.Grant) Grant(org.olat.basesecurity.Grant) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 33 with Group

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

the class BusinessGroupRelationDAO method addRole.

public void addRole(Identity identity, BusinessGroup businessGroup, String role) {
    Group group = null;
    try {
        group = businessGroup.getBaseGroup();
        if (group == null) {
            group = getGroup(businessGroup);
        }
    } catch (Exception e) {
        log.warn("", e);
        group = getGroup(businessGroup);
    }
    groupDao.addMembershipOneWay(group, identity, role);
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup)

Example 34 with Group

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

the class CheckboxManagerImpl method getAssessmentDatas.

@Override
public List<AssessmentData> getAssessmentDatas(OLATResourceable ores, String resSubPath, RepositoryEntry re, List<BusinessGroup> businessGroups) {
    StringBuilder sb = new StringBuilder();
    sb.append("select check from clcheck check").append(" inner join fetch check.checkbox box").append(" inner join fetch check.identity ident").append(" inner join fetch ident.user identUser").append(" where box.resName=:resName and box.resId=:resId");
    if (StringHelper.containsNonWhitespace(resSubPath)) {
        sb.append(" and box.resSubPath=:resSubPath");
    }
    boolean hasBusinessGroups = businessGroups != null && businessGroups.size() > 0;
    if (hasBusinessGroups) {
        sb.append(" and ");
        if (re != null) {
            sb.append(" ( ");
        }
        sb.append(" check.identity.key in ( select membership.identity.key from bgroupmember membership ").append("   where membership.group in (:baseGroups) and membership.role='").append(GroupRole.participant).append("'").append(" )");
    }
    if (re != null) {
        if (hasBusinessGroups) {
            sb.append(" or ");
        } else {
            sb.append(" and ");
        }
        sb.append(" check.identity.key in ( select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ").append("   where rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'").append(" )");
        if (hasBusinessGroups) {
            sb.append(" ) ");
        }
    }
    TypedQuery<DBCheck> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), DBCheck.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId());
    if (StringHelper.containsNonWhitespace(resSubPath)) {
        query.setParameter("resSubPath", resSubPath);
    }
    if (hasBusinessGroups) {
        List<Group> groups = new ArrayList<>(businessGroups.size());
        for (BusinessGroup businessGroup : businessGroups) {
            groups.add(businessGroup.getBaseGroup());
        }
        query.setParameter("baseGroups", groups);
    }
    if (re != null) {
        query.setParameter("repoKey", re.getKey());
    }
    List<DBCheck> checks = query.getResultList();
    Map<Long, AssessmentData> identToBox = new HashMap<Long, AssessmentData>();
    for (DBCheck check : checks) {
        AssessmentData data = identToBox.get(check.getIdentity().getKey());
        if (data == null) {
            data = new AssessmentData(check.getIdentity());
            identToBox.put(check.getIdentity().getKey(), data);
        }
        data.getChecks().add(check);
    }
    return new ArrayList<AssessmentData>(identToBox.values());
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) DBCheck(org.olat.course.nodes.cl.model.DBCheck) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData)

Example 35 with Group

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

the class BinderDAO method deleteBinder.

public int deleteBinder(BinderRef binderRef) {
    int rows = userInformationsDAO.deleteBinderUserInfos(binderRef);
    BinderImpl binder = (BinderImpl) loadByKey(binderRef.getKey());
    List<Section> sections = new ArrayList<>(binder.getSections());
    for (Section section : sections) {
        List<Page> pages = new ArrayList<>(section.getPages());
        section.getPages().clear();
        section = dbInstance.getCurrentEntityManager().merge(section);
        for (Page page : pages) {
            if (page != null) {
                rows += pageDao.deletePage(page);
                rows += pageUserInfosDao.delete(page);
            }
        }
        rows += assessmentSectionDao.deleteAssessmentSections(section);
        Group baseGroup = section.getBaseGroup();
        rows += groupDao.removeMemberships(baseGroup);
        dbInstance.getCurrentEntityManager().remove(section);
        dbInstance.getCurrentEntityManager().remove(baseGroup);
        rows += 2;
    }
    binder.getSections().clear();
    Group baseGroup = binder.getBaseGroup();
    rows += groupDao.removeMemberships(baseGroup);
    dbInstance.getCurrentEntityManager().remove(binder);
    dbInstance.getCurrentEntityManager().remove(baseGroup);
    return rows + 2;
}
Also used : Group(org.olat.basesecurity.Group) ArrayList(java.util.ArrayList) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section)

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