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;
}
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();
}
}
}
}
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();
}
}
}
}
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;
}
Aggregations