Search in sources :

Example 1 with BGContextImpl

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

the class OLATUpgrade_7_1_1 method findBGContextsForResource.

private List<BGContextImpl> findBGContextsForResource(OLATResource resource, boolean defaultContexts, boolean nonDefaultContexts) {
    DB db = DBFactory.getInstance();
    StringBuilder q = new StringBuilder();
    q.append(" select context from org.olat.group.context.BGContextImpl as context,");
    q.append(" org.olat.group.context.BGContext2Resource as bgcr");
    q.append(" where bgcr.resource = :resource");
    q.append(" and bgcr.groupContext = context");
    boolean checkDefault = defaultContexts != nonDefaultContexts;
    if (checkDefault) {
        q.append(" and context.defaultContext = :isDefault");
    }
    DBQuery query = db.createQuery(q.toString());
    query.setEntity("resource", resource);
    if (checkDefault) {
        query.setBoolean("isDefault", defaultContexts ? true : false);
    }
    @SuppressWarnings("unchecked") List<BGContextImpl> contexts = query.list();
    return contexts;
}
Also used : BGContextImpl(org.olat.upgrade.model.BGContextImpl) DBQuery(org.olat.core.commons.persistence.DBQuery) DB(org.olat.core.commons.persistence.DB)

Example 2 with BGContextImpl

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

the class OLATUpgrade_7_1_1 method migrateRepoEntrySecurityGroups.

private void migrateRepoEntrySecurityGroups(RepositoryEntryUpgrade entry) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    List<BGContextImpl> contexts = findBGContextsForResource(entry.getOlatResource(), true, true);
    for (BGContextImpl context : contexts) {
        List<BusinessGroupUpgrade> groups = getGroupsOfBGContext(context);
        for (BusinessGroupUpgrade group : groups) {
            // migrate tutors
            if (group.getOwnerGroup() != null) {
                int count = 0;
                List<Identity> owners = securityManager.getIdentitiesOfSecurityGroup(group.getOwnerGroup());
                SecurityGroup tutorGroup = entry.getTutorGroup();
                for (Identity owner : owners) {
                    if (securityManager.isIdentityInSecurityGroup(owner, tutorGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(owner, tutorGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
            // migrate participants
            if (group.getPartipiciantGroup() != null) {
                int count = 0;
                List<Identity> participants = securityManager.getIdentitiesOfSecurityGroup(group.getPartipiciantGroup());
                SecurityGroup participantGroup = entry.getParticipantGroup();
                for (Identity participant : participants) {
                    if (securityManager.isIdentityInSecurityGroup(participant, participantGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(participant, participantGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
        }
    }
}
Also used : BGContextImpl(org.olat.upgrade.model.BGContextImpl) BusinessGroupUpgrade(org.olat.upgrade.model.BusinessGroupUpgrade) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 3 with BGContextImpl

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

the class OLATUpgrade_7_1_1 method migrateRepoEntrySecurityGroups.

private void migrateRepoEntrySecurityGroups(RepositoryEntryUpgrade entry) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    List<BGContextImpl> contexts = findBGContextsForResource(entry.getOlatResource(), true, true);
    for (BGContextImpl context : contexts) {
        List<BusinessGroupUpgrade> groups = getGroupsOfBGContext(context);
        for (BusinessGroupUpgrade group : groups) {
            // migrate tutors
            if (group.getOwnerGroup() != null) {
                int count = 0;
                List<Identity> owners = securityManager.getIdentitiesOfSecurityGroup(group.getOwnerGroup());
                SecurityGroup tutorGroup = entry.getTutorGroup();
                for (Identity owner : owners) {
                    if (securityManager.isIdentityInSecurityGroup(owner, tutorGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(owner, tutorGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
            // migrate participants
            if (group.getPartipiciantGroup() != null) {
                int count = 0;
                List<Identity> participants = securityManager.getIdentitiesOfSecurityGroup(group.getPartipiciantGroup());
                SecurityGroup participantGroup = entry.getParticipantGroup();
                for (Identity participant : participants) {
                    if (securityManager.isIdentityInSecurityGroup(participant, participantGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(participant, participantGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
        }
    }
}
Also used : BGContextImpl(org.olat.upgrade.model.BGContextImpl) BusinessGroupUpgrade(org.olat.upgrade.model.BusinessGroupUpgrade) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 4 with BGContextImpl

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

the class OLATUpgrade_7_1_1 method findBGContextsForResource.

private List<BGContextImpl> findBGContextsForResource(OLATResource resource, boolean defaultContexts, boolean nonDefaultContexts) {
    DB db = DBFactory.getInstance();
    StringBuilder q = new StringBuilder();
    q.append(" select context from org.olat.group.context.BGContextImpl as context,");
    q.append(" org.olat.group.context.BGContext2Resource as bgcr");
    q.append(" where bgcr.resource = :resource");
    q.append(" and bgcr.groupContext = context");
    boolean checkDefault = defaultContexts != nonDefaultContexts;
    if (checkDefault) {
        q.append(" and context.defaultContext = :isDefault");
    }
    DBQuery query = db.createQuery(q.toString());
    query.setEntity("resource", resource);
    if (checkDefault) {
        query.setBoolean("isDefault", defaultContexts ? true : false);
    }
    @SuppressWarnings("unchecked") List<BGContextImpl> contexts = query.list();
    return contexts;
}
Also used : BGContextImpl(org.olat.upgrade.model.BGContextImpl) DBQuery(org.olat.core.commons.persistence.DBQuery) DB(org.olat.core.commons.persistence.DB)

Aggregations

BGContextImpl (org.olat.upgrade.model.BGContextImpl)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 DB (org.olat.core.commons.persistence.DB)2 DBQuery (org.olat.core.commons.persistence.DBQuery)2 Identity (org.olat.core.id.Identity)2 BusinessGroupUpgrade (org.olat.upgrade.model.BusinessGroupUpgrade)2