Search in sources :

Example 11 with EPStructureElementToGroupRelation

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

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 12 with EPStructureElementToGroupRelation

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

the class EPPolicyManager method applyPolicyToAllUsers.

private EPStructureElementToGroupRelation applyPolicyToAllUsers(EPMapPolicy wrapper, PortfolioStructureMap map) {
    List<EPStructureElementToGroupRelation> currentRelations = wrapper.getRelations();
    if (!currentRelations.isEmpty()) {
        EPStructureElementToGroupRelation currentRelation = currentRelations.get(0);
        updatePolicy(currentRelation, wrapper.getFrom(), wrapper.getTo());
        return currentRelation;
    }
    return createBaseRelation(map, null, EPMapPolicy.Type.allusers.name(), wrapper.getFrom(), wrapper.getTo());
}
Also used : EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)

Example 13 with EPStructureElementToGroupRelation

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

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 EPStructureElementToGroupRelation

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

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 15 with EPStructureElementToGroupRelation

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

the class EPStructureManager method importPortfolioMapTemplate.

/**
 * Import the structure.
 * @param root
 * @param identity
 * @return
 */
public PortfolioStructureMap importPortfolioMapTemplate(PortfolioStructure root, OLATResource resource) {
    EPStructuredMapTemplate el = new EPStructuredMapTemplate();
    fillStructureElement(el, root.getTitle(), root.getDescription(), resource);
    EPStructuredMapTemplate rootTemp = (EPStructuredMapTemplate) root;
    rootTemp.setStructureElSource(null);
    el.setStyle(((EPStructureElement) root).getStyle());
    importEPStructureElementRecursively((EPStructureElement) root, el);
    // create an empty group
    Group ownerGroup = groupDao.createGroup();
    EPStructureElementToGroupRelation relation = createBaseRelation(el, ownerGroup);
    Set<EPStructureElementToGroupRelation> relations = new HashSet<>();
    relations.add(relation);
    el.setGroups(relations);
    return el;
}
Also used : Group(org.olat.basesecurity.Group) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) HashSet(java.util.HashSet)

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