Search in sources :

Example 1 with EPStructureElementToGroupRelation

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

the class EPPolicyManager method updateMapPolicies.

/**
 * Update the map policies of a map. The missing policies are deleted!
 * @param map
 * @param policies
 */
public PortfolioStructureMap updateMapPolicies(PortfolioStructureMap map, List<EPMapPolicy> policies) {
    map = dbInstance.getCurrentEntityManager().merge(map);
    List<EPStructureElementToGroupRelation> savedPolicies = new ArrayList<EPStructureElementToGroupRelation>();
    for (EPMapPolicy wrapper : policies) {
        savedPolicies.addAll(applyPolicy(wrapper, map));
    }
    Collection<EPStructureElementToGroupRelation> currentRelations = new ArrayList<>(map.getGroups());
    for (EPStructureElementToGroupRelation currentRelation : currentRelations) {
        if (currentRelation.isDefaultGroup()) {
            continue;
        }
        boolean inUse = savedPolicies.contains(currentRelation);
        if (!inUse) {
            map.getGroups().remove(currentRelation);
        }
    }
    return dbInstance.getCurrentEntityManager().merge(map);
}
Also used : ArrayList(java.util.ArrayList) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)

Example 2 with EPStructureElementToGroupRelation

use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation 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 3 with EPStructureElementToGroupRelation

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

the class EPPolicyManager method getEquivalentWrapper.

private EPMapPolicy getEquivalentWrapper(EPStructureElementToGroupRelation relation, List<EPMapPolicy> policies) {
    Date to = relation.getValidTo();
    Date from = relation.getValidFrom();
    String role = relation.getRole();
    a_a: for (EPMapPolicy policy : policies) {
        for (EPStructureElementToGroupRelation p : policy.getRelations()) {
            if (!role.equals(p.getRole())) {
                continue a_a;
            }
            if (from == null && p.getValidFrom() == null || (from != null && p.getValidFrom() != null && from.equals(p.getValidFrom()))) {
                if (to == null && p.getValidTo() == null || (to != null && p.getValidTo() != null && to.equals(p.getValidTo()))) {
                    return policy;
                }
            }
        }
    }
    return null;
}
Also used : EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) Date(java.util.Date)

Example 4 with EPStructureElementToGroupRelation

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

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)

Example 5 with EPStructureElementToGroupRelation

use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation 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)

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