Search in sources :

Example 1 with EPMapUpgradeToGroupRelation

use of org.olat.upgrade.model.EPMapUpgradeToGroupRelation in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_0_0 method createDefaultGroup.

private EPMapUpgradeToGroupRelation createDefaultGroup(EPMapUpgrade element, Group group) {
    EPMapUpgradeToGroupRelation relation = new EPMapUpgradeToGroupRelation();
    relation.setDefaultGroup(true);
    relation.setCreationDate(new Date());
    relation.setGroup(group);
    relation.setEntry(element);
    return relation;
}
Also used : EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) Date(java.util.Date)

Example 2 with EPMapUpgradeToGroupRelation

use of org.olat.upgrade.model.EPMapUpgradeToGroupRelation in project openolat by klemens.

the class OLATUpgrade_10_0_0 method createDefaultGroup.

private EPMapUpgradeToGroupRelation createDefaultGroup(EPMapUpgrade element, Group group) {
    EPMapUpgradeToGroupRelation relation = new EPMapUpgradeToGroupRelation();
    relation.setDefaultGroup(true);
    relation.setCreationDate(new Date());
    relation.setGroup(group);
    relation.setEntry(element);
    return relation;
}
Also used : EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) Date(java.util.Date)

Example 3 with EPMapUpgradeToGroupRelation

use of org.olat.upgrade.model.EPMapUpgradeToGroupRelation in project openolat by klemens.

the class OLATUpgrade_10_0_0 method processMapPolicy.

private EPMapUpgradeToGroupRelation processMapPolicy(Policy policy, EPMapUpgrade element) {
    String permission = policy.getPermission();
    SecurityGroup secGroup = policy.getSecurityGroup();
    Group group;
    String role;
    if (permission.startsWith(EPMapPolicy.Type.user.name())) {
        group = groupDao.createGroup();
        processSecurityGroup(group, GroupRoles.participant.name(), secGroup);
        role = EPMapPolicy.Type.user.name();
    } else if (permission.startsWith(EPMapPolicy.Type.group.name())) {
        group = findGroupOfBusinessGroup(secGroup);
        role = EPMapPolicy.Type.group.name();
    } else if (permission.startsWith(EPMapPolicy.Type.invitation.name())) {
        InvitationUpgrade invitation = findInvitation(policy.getSecurityGroup());
        if (invitation == null) {
            return null;
        }
        group = invitation.getBaseGroup();
        role = EPMapPolicy.Type.invitation.name();
    } else if (permission.startsWith(EPMapPolicy.Type.allusers.name())) {
        group = groupDao.createGroup(EPMapPolicy.Type.allusers.name());
        role = EPMapPolicy.Type.allusers.name();
    } else {
        return null;
    }
    if (group == null) {
        log.error("Group not resolve for policy of map: " + element.getKey() + " and policy: " + policy.getKey());
        return null;
    }
    EPMapUpgradeToGroupRelation relation = new EPMapUpgradeToGroupRelation();
    relation.setDefaultGroup(false);
    relation.setCreationDate(new Date());
    relation.setEntry(element);
    relation.setValidTo(policy.getTo());
    relation.setValidFrom(policy.getFrom());
    relation.setGroup(group);
    relation.setRole(role);
    return relation;
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) InvitationUpgrade(org.olat.upgrade.model.InvitationUpgrade) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date)

Example 4 with EPMapUpgradeToGroupRelation

use of org.olat.upgrade.model.EPMapUpgradeToGroupRelation in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_0_0 method processMapPolicy.

private EPMapUpgradeToGroupRelation processMapPolicy(Policy policy, EPMapUpgrade element) {
    String permission = policy.getPermission();
    SecurityGroup secGroup = policy.getSecurityGroup();
    Group group;
    String role;
    if (permission.startsWith(EPMapPolicy.Type.user.name())) {
        group = groupDao.createGroup();
        processSecurityGroup(group, GroupRoles.participant.name(), secGroup);
        role = EPMapPolicy.Type.user.name();
    } else if (permission.startsWith(EPMapPolicy.Type.group.name())) {
        group = findGroupOfBusinessGroup(secGroup);
        role = EPMapPolicy.Type.group.name();
    } else if (permission.startsWith(EPMapPolicy.Type.invitation.name())) {
        InvitationUpgrade invitation = findInvitation(policy.getSecurityGroup());
        if (invitation == null) {
            return null;
        }
        group = invitation.getBaseGroup();
        role = EPMapPolicy.Type.invitation.name();
    } else if (permission.startsWith(EPMapPolicy.Type.allusers.name())) {
        group = groupDao.createGroup(EPMapPolicy.Type.allusers.name());
        role = EPMapPolicy.Type.allusers.name();
    } else {
        return null;
    }
    if (group == null) {
        log.error("Group not resolve for policy of map: " + element.getKey() + " and policy: " + policy.getKey());
        return null;
    }
    EPMapUpgradeToGroupRelation relation = new EPMapUpgradeToGroupRelation();
    relation.setDefaultGroup(false);
    relation.setCreationDate(new Date());
    relation.setEntry(element);
    relation.setValidTo(policy.getTo());
    relation.setValidFrom(policy.getFrom());
    relation.setGroup(group);
    relation.setRole(role);
    return relation;
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) InvitationUpgrade(org.olat.upgrade.model.InvitationUpgrade) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date)

Example 5 with EPMapUpgradeToGroupRelation

use of org.olat.upgrade.model.EPMapUpgradeToGroupRelation in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_0_0 method processMap.

private void processMap(EPMapUpgrade map) {
    if (hasGroupsRelations(map)) {
        return;
    }
    Set<EPMapUpgradeToGroupRelation> relations = new HashSet<>();
    SecurityGroup ownerGroup = map.getOwnerGroup();
    if (ownerGroup != null) {
        // create default group
        RepositoryEntryUpgrade re = findMapRepoEntry(ownerGroup);
        if (re != null) {
            Group reGroup = repositoryEntryToGroupDAO.getDefaultGroup(re);
            if (reGroup != null) {
                relations.add(createDefaultGroup(map, reGroup));
            }
        }
        if (relations.isEmpty()) {
            Group group = groupDao.createGroup();
            relations.add(createDefaultGroup(map, group));
            processSecurityGroup(group, GroupRoles.owner.name(), ownerGroup);
        }
        // create policy -> relation
        List<Policy> policies = securityManager.getPoliciesOfResource(map.getOlatResource(), null);
        for (Policy policy : policies) {
            if (policy.getPermission().contains(Constants.PERMISSION_READ)) {
                EPMapUpgradeToGroupRelation policyRelation = processMapPolicy(policy, map);
                if (policyRelation != null) {
                    relations.add(policyRelation);
                }
            }
        }
        for (EPMapUpgradeToGroupRelation relation : relations) {
            dbInstance.getCurrentEntityManager().persist(relation);
        }
    }
}
Also used : Policy(org.olat.basesecurity.Policy) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) RepositoryEntryUpgrade(org.olat.upgrade.model.RepositoryEntryUpgrade) Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) SecurityGroup(org.olat.basesecurity.SecurityGroup) HashSet(java.util.HashSet)

Aggregations

EPMapUpgradeToGroupRelation (org.olat.upgrade.model.EPMapUpgradeToGroupRelation)6 Date (java.util.Date)4 Group (org.olat.basesecurity.Group)4 SecurityGroup (org.olat.basesecurity.SecurityGroup)4 HashSet (java.util.HashSet)2 Policy (org.olat.basesecurity.Policy)2 EPMapPolicy (org.olat.portfolio.manager.EPMapPolicy)2 InvitationUpgrade (org.olat.upgrade.model.InvitationUpgrade)2 RepositoryEntryUpgrade (org.olat.upgrade.model.RepositoryEntryUpgrade)2