Search in sources :

Example 21 with EPStructureElementToGroupRelation

use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.

the class EPPolicyManager method createBaseRelation.

private EPStructureElementToGroupRelation createBaseRelation(PortfolioStructureMap map, Group group, String role, Date from, Date to) {
    // create security group
    EPStructureElementToGroupRelation relation = new EPStructureElementToGroupRelation();
    relation.setDefaultGroup(false);
    relation.setCreationDate(new Date());
    relation.setGroup(group);
    relation.setStructureElement((EPStructureElement) map);
    relation.setRole(role);
    relation.setValidFrom(from);
    relation.setValidTo(to);
    map.getGroups().add(relation);
    return relation;
}
Also used : EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) Date(java.util.Date)

Example 22 with EPStructureElementToGroupRelation

use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.

the class EPPolicyManager method applyPolicyToUsers.

private EPStructureElementToGroupRelation applyPolicyToUsers(EPMapPolicy policy, PortfolioStructureMap map) {
    List<EPStructureElementToGroupRelation> currentRelations = policy.getRelations();
    EPStructureElementToGroupRelation relation = (currentRelations == null || currentRelations.isEmpty()) ? null : currentRelations.get(0);
    if (relation == null) {
        Group secGroup = groupDao.createGroup();
        relation = createBaseRelation(map, secGroup, EPMapPolicy.Type.user.name(), policy.getFrom(), policy.getTo());
        for (Identity identity : policy.getIdentities()) {
            groupDao.addMembershipTwoWay(secGroup, identity, GroupRoles.participant.name());
        }
    } else {
        EPStructureElementToGroupRelation currentPolicy = reusePolicyInSession(relation, map);
        updatePolicy(currentPolicy, policy.getFrom(), policy.getTo());
        Group secGroup = relation.getGroup();
        List<Identity> currentMembers = groupDao.getMembers(secGroup, GroupRoles.participant.name());
        List<Identity> newMembers = new ArrayList<>(policy.getIdentities());
        for (Identity newMember : policy.getIdentities()) {
            if (currentMembers.contains(newMember)) {
                newMembers.remove(newMember);
                currentMembers.remove(newMember);
            }
        }
        // re-attach the session to lazy load the members
        secGroup = dbInstance.getCurrentEntityManager().merge(secGroup);
        for (Identity currentMember : currentMembers) {
            groupDao.removeMembership(secGroup, currentMember);
        }
        for (Identity newMember : newMembers) {
            groupDao.addMembershipTwoWay(secGroup, newMember, GroupRoles.participant.name());
        }
    }
    return relation;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) ArrayList(java.util.ArrayList) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) Identity(org.olat.core.id.Identity)

Example 23 with EPStructureElementToGroupRelation

use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.

the class EPPolicyManager method applyPolicy.

private List<EPStructureElementToGroupRelation> applyPolicy(EPMapPolicy policy, PortfolioStructureMap map) {
    List<EPStructureElementToGroupRelation> savedPolicies = new ArrayList<EPStructureElementToGroupRelation>();
    switch(policy.getType()) {
        case user:
            savedPolicies.add(applyPolicyToUsers(policy, map));
            break;
        case group:
            for (BusinessGroup group : policy.getGroups()) {
                savedPolicies.add(applyPolicyToGroup(group.getBaseGroup(), policy, map));
            }
            break;
        case invitation:
            Invitation invitation = policy.getInvitation();
            EPStructureElementToGroupRelation invitationPolicy = applyPolicyToInvitation(invitation, policy, map);
            savedPolicies.add(invitationPolicy);
            break;
        case allusers:
            EPStructureElementToGroupRelation allUsersPolicy = applyPolicyToAllUsers(policy, map);
            savedPolicies.add(allUsersPolicy);
            break;
    }
    return savedPolicies;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)

Example 24 with EPStructureElementToGroupRelation

use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project openolat by klemens.

the class EPPolicyManager method applyPolicyToUsers.

private EPStructureElementToGroupRelation applyPolicyToUsers(EPMapPolicy policy, PortfolioStructureMap map) {
    List<EPStructureElementToGroupRelation> currentRelations = policy.getRelations();
    EPStructureElementToGroupRelation relation = (currentRelations == null || currentRelations.isEmpty()) ? null : currentRelations.get(0);
    if (relation == null) {
        Group secGroup = groupDao.createGroup();
        relation = createBaseRelation(map, secGroup, EPMapPolicy.Type.user.name(), policy.getFrom(), policy.getTo());
        for (Identity identity : policy.getIdentities()) {
            groupDao.addMembershipTwoWay(secGroup, identity, GroupRoles.participant.name());
        }
    } else {
        EPStructureElementToGroupRelation currentPolicy = reusePolicyInSession(relation, map);
        updatePolicy(currentPolicy, policy.getFrom(), policy.getTo());
        Group secGroup = relation.getGroup();
        List<Identity> currentMembers = groupDao.getMembers(secGroup, GroupRoles.participant.name());
        List<Identity> newMembers = new ArrayList<>(policy.getIdentities());
        for (Identity newMember : policy.getIdentities()) {
            if (currentMembers.contains(newMember)) {
                newMembers.remove(newMember);
                currentMembers.remove(newMember);
            }
        }
        // re-attach the session to lazy load the members
        secGroup = dbInstance.getCurrentEntityManager().merge(secGroup);
        for (Identity currentMember : currentMembers) {
            groupDao.removeMembership(secGroup, currentMember);
        }
        for (Identity newMember : newMembers) {
            groupDao.addMembershipTwoWay(secGroup, newMember, GroupRoles.participant.name());
        }
    }
    return relation;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) ArrayList(java.util.ArrayList) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) Identity(org.olat.core.id.Identity)

Example 25 with EPStructureElementToGroupRelation

use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project openolat by klemens.

the class EPPolicyManager method getMapPolicies.

/**
 * Return a list of wrapper containing the read policies of the map
 * @param map
 */
public List<EPMapPolicy> getMapPolicies(PortfolioStructureMapRef mapRef) {
    EPMapShort map = dbInstance.getCurrentEntityManager().find(EPMapShort.class, mapRef.getKey());
    List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    Set<EPStructureElementToGroupRelation> relations = map.getGroups();
    for (EPStructureElementToGroupRelation relation : relations) {
        if (relation.isDefaultGroup()) {
            continue;
        }
        EPMapPolicy policy = getEquivalentWrapper(relation, policies);
        if (policy == null) {
            policy = new EPMapPolicy();
            policy.setTo(relation.getValidTo());
            policy.setFrom(relation.getValidFrom());
            policies.add(policy);
        }
        String role = relation.getRole();
        if (role.startsWith(EPMapPolicy.Type.user.name())) {
            List<Identity> identities = groupDao.getMembers(relation.getGroup(), GroupRoles.participant.name());
            policy.addRelation(relation);
            policy.setType(EPMapPolicy.Type.user);
            policy.addIdentities(identities);
        } else if (role.startsWith(EPMapPolicy.Type.group.name())) {
            policy.addRelation(relation);
            BusinessGroup group = businessGroupDao.findBusinessGroup(relation.getGroup());
            policy.addGroup(group);
            policy.setType(EPMapPolicy.Type.group);
        } else if (role.startsWith(EPMapPolicy.Type.invitation.name())) {
            policy.addRelation(relation);
            Invitation invitation = invitationDao.findInvitation(relation.getGroup());
            policy.setInvitation(invitation);
            policy.setType(EPMapPolicy.Type.invitation);
        } else if (role.startsWith(EPMapPolicy.Type.allusers.name())) {
            policy.addRelation(relation);
            policy.setType(EPMapPolicy.Type.allusers);
        }
    }
    return policies;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Invitation(org.olat.basesecurity.Invitation) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) Identity(org.olat.core.id.Identity) EPMapShort(org.olat.portfolio.model.structel.EPMapShort)

Aggregations

EPStructureElementToGroupRelation (org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)32 Group (org.olat.basesecurity.Group)14 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 BusinessGroup (org.olat.group.BusinessGroup)8 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)6 Invitation (org.olat.basesecurity.Invitation)4 Identity (org.olat.core.id.Identity)4 EPDefaultMap (org.olat.portfolio.model.structel.EPDefaultMap)2 EPMapShort (org.olat.portfolio.model.structel.EPMapShort)2 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)2 EPTargetResource (org.olat.portfolio.model.structel.EPTargetResource)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2