Skip to content
Snippets Groups Projects
Commit 6d97bfb2 authored by srosse's avatar srosse
Browse files

OO-3286: fix some issues with members count in courses linked to

curriculum elements
parent 25ae7dae
No related branches found
No related tags found
No related merge requests found
Showing with 64 additions and 70 deletions
...@@ -54,8 +54,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -54,8 +54,7 @@ import org.springframework.beans.factory.annotation.Autowired;
*/ */
public class MembersCourseNodeRunController extends BasicController { public class MembersCourseNodeRunController extends BasicController {
private List<Identity> owners, coaches, participants;
private MembersDisplayRunController membersDisplayRunController; private MembersDisplayRunController membersDisplayRunController;
@Autowired @Autowired
...@@ -69,9 +68,10 @@ public class MembersCourseNodeRunController extends BasicController { ...@@ -69,9 +68,10 @@ public class MembersCourseNodeRunController extends BasicController {
super(ureq, wControl); super(ureq, wControl);
CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment(); CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment();
this.coaches = new ArrayList<>(); List<Identity> owners;
this.participants = new ArrayList<>(); List<Identity> coaches = new ArrayList<>();
List<Identity> participants = new ArrayList<>();
boolean showOwners = config.getBooleanSafe(MembersCourseNode.CONFIG_KEY_SHOWOWNER); boolean showOwners = config.getBooleanSafe(MembersCourseNode.CONFIG_KEY_SHOWOWNER);
......
...@@ -72,8 +72,7 @@ public class MembersHelpers { ...@@ -72,8 +72,7 @@ public class MembersHelpers {
list.addAll(retrieveCoachesFromAreas(coachAreaKeys, cgm)); list.addAll(retrieveCoachesFromAreas(coachAreaKeys, cgm));
} }
if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_COURSE if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_COURSE, MembersCourseNode.CONFIG_KEY_COACHES_ALL)) {
, MembersCourseNode.CONFIG_KEY_COACHES_ALL)) {
list.addAll(retrieveCoachesFromCourse(cgm)); list.addAll(retrieveCoachesFromCourse(cgm));
} }
if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_ALL)) { if(moduleConfiguration.anyTrue(MembersCourseNode.CONFIG_KEY_COACHES_ALL)) {
...@@ -83,32 +82,22 @@ public class MembersHelpers { ...@@ -83,32 +82,22 @@ public class MembersHelpers {
public static List<Identity> retrieveCoachesFromAreas(List<Long> areaKeys, CourseGroupManager cgm) { public static List<Identity> retrieveCoachesFromAreas(List<Long> areaKeys, CourseGroupManager cgm) {
List<Identity> coaches = cgm.getCoachesFromAreas(areaKeys); List<Identity> coaches = cgm.getCoachesFromAreas(areaKeys);
Set<Identity> coachesWithoutDuplicates = new HashSet<Identity>(coaches); return new ArrayList<>(new HashSet<>(coaches));
coaches = new ArrayList<Identity>(coachesWithoutDuplicates);
return coaches;
} }
public static List<Identity> retrieveCoachesFromGroups(List<Long> groupKeys, CourseGroupManager cgm) { public static List<Identity> retrieveCoachesFromGroups(List<Long> groupKeys, CourseGroupManager cgm) {
List<Identity> coaches = new ArrayList<Identity>(new HashSet<Identity>(cgm.getCoachesFromBusinessGroups(groupKeys))); return new ArrayList<>(new HashSet<>(cgm.getCoachesFromBusinessGroups(groupKeys)));
return coaches;
} }
public static List<Identity> retrieveCoachesFromCourse(CourseGroupManager cgm) { public static List<Identity> retrieveCoachesFromCourse(CourseGroupManager cgm) {
List<Identity> coaches = cgm.getCoaches(); return cgm.getCoaches();
return coaches;
} }
public static List<Identity> retrieveCoachesFromCourseGroups(CourseGroupManager cgm) { public static List<Identity> retrieveCoachesFromCourseGroups(CourseGroupManager cgm) {
Set<Identity> uniq = new HashSet<Identity>(); Set<Identity> uniq = new HashSet<>();
{ uniq.addAll(cgm.getCoachesFromAreas());
List<Identity> coaches = cgm.getCoachesFromAreas(); uniq.addAll(cgm.getCoachesFromBusinessGroups());
uniq.addAll(coaches); return new ArrayList<>(uniq);
}
{
List<Identity> coaches = cgm.getCoachesFromBusinessGroups();
uniq.addAll(coaches);
}
return new ArrayList<Identity>(uniq);
} }
// ----------------------------------------------------- // -----------------------------------------------------
...@@ -143,31 +132,21 @@ public class MembersHelpers { ...@@ -143,31 +132,21 @@ public class MembersHelpers {
} }
public static List<Identity> retrieveParticipantsFromAreas(List<Long> areaKeys, CourseGroupManager cgm) { public static List<Identity> retrieveParticipantsFromAreas(List<Long> areaKeys, CourseGroupManager cgm) {
List<Identity> participiants = cgm.getParticipantsFromAreas(areaKeys); return cgm.getParticipantsFromAreas(areaKeys);
return participiants;
} }
public static List<Identity> retrieveParticipantsFromGroups(List<Long> groupKeys, CourseGroupManager cgm) { public static List<Identity> retrieveParticipantsFromGroups(List<Long> groupKeys, CourseGroupManager cgm) {
List<Identity> participiants = cgm.getParticipantsFromBusinessGroups(groupKeys); return cgm.getParticipantsFromBusinessGroups(groupKeys);
return participiants;
} }
public static List<Identity> retrieveParticipantsFromCourse(CourseGroupManager cgm) { public static List<Identity> retrieveParticipantsFromCourse(CourseGroupManager cgm) {
List<Identity> participiants = cgm.getParticipants(); return cgm.getParticipants();
return participiants;
} }
public static List<Identity> retrieveParticipantsFromCourseGroups(CourseGroupManager cgm) { public static List<Identity> retrieveParticipantsFromCourseGroups(CourseGroupManager cgm) {
Set<Identity> uniq = new HashSet<Identity>(); Set<Identity> uniq = new HashSet<>();
{ uniq.addAll(cgm.getParticipantsFromAreas());
List<Identity> participiants = cgm.getParticipantsFromAreas(); uniq.addAll(cgm.getParticipantsFromBusinessGroups());
uniq.addAll(participiants); return new ArrayList<>(uniq);
}
{
List<Identity> participiants = cgm.getParticipantsFromBusinessGroups();
uniq.addAll(participiants);
}
return new ArrayList<Identity>(uniq);
} }
} }
...@@ -162,7 +162,7 @@ import.member=Mitglieder hinzuf\u00FCgen ...@@ -162,7 +162,7 @@ import.member=Mitglieder hinzuf\u00FCgen
role.curriculum.participant=Curriculumteilnehmer role.curriculum.participant=Curriculumteilnehmer
role.curriculum.coach=Curriculumbetreuers role.curriculum.coach=Curriculumbetreuer
role.curriculum.owner=Curriculumkursbesitzer role.curriculum.owner=Curriculumkursbesitzer
role.group.tutor=Gruppenbetreuer role.group.tutor=Gruppenbetreuer
role.group.participant=Gruppenteilnehmer role.group.participant=Gruppenteilnehmer
......
...@@ -346,6 +346,13 @@ public interface CurriculumService { ...@@ -346,6 +346,13 @@ public interface CurriculumService {
public void removeRepositoryEntry(CurriculumElement element, RepositoryEntryRef entry); public void removeRepositoryEntry(CurriculumElement element, RepositoryEntryRef entry);
/**
* Remove the repository entry from all the curriculum elements.
*
* @param entry
*/
public void removeRepositoryEntry(RepositoryEntry entry);
/** /**
* The list of taxonomy levels of the curriculum element. * The list of taxonomy levels of the curriculum element.
* *
......
...@@ -379,6 +379,14 @@ public class CurriculumServiceImpl implements CurriculumService { ...@@ -379,6 +379,14 @@ public class CurriculumServiceImpl implements CurriculumService {
return repositoryEntryRelationDao.hasRelation(element.getGroup(), entry); return repositoryEntryRelationDao.hasRelation(element.getGroup(), entry);
} }
@Override
public void removeRepositoryEntry(RepositoryEntry entry) {
List<CurriculumElement> elements = curriculumRepositoryEntryRelationDao.getCurriculumElements(entry);
for(CurriculumElement element:elements) {
repositoryEntryRelationDao.removeRelation(element.getGroup(), entry);
}
}
@Override @Override
public void removeRepositoryEntry(CurriculumElement element, RepositoryEntryRef entry) { public void removeRepositoryEntry(CurriculumElement element, RepositoryEntryRef entry) {
repositoryEntryRelationDao.removeRelation(element.getGroup(), entry); repositoryEntryRelationDao.removeRelation(element.getGroup(), entry);
......
...@@ -183,7 +183,14 @@ public interface RepositoryService { ...@@ -183,7 +183,14 @@ public interface RepositoryService {
public void filterMembership(IdentityRef identity, Collection<Long> entries); public void filterMembership(IdentityRef identity, Collection<Long> entries);
public int countMembers(RepositoryEntryRef re, String... roles); /**
* Count the number of member with the specified role.
*
* @param re The repository entry
* @param role The role (mandatory)
* @return
*/
public int countMembers(RepositoryEntryRef re, String role);
/** /**
* Count all members (following up to business groups waiting list) with the following * Count all members (following up to business groups waiting list) with the following
......
...@@ -274,31 +274,22 @@ public class RepositoryEntryRelationDAO { ...@@ -274,31 +274,22 @@ public class RepositoryEntryRelationDAO {
* the organizations. * the organizations.
* *
* @param re The repository entry * @param re The repository entry
* @param roles The roles (optional) * @param roles The role (mandatory)
* @return * @return
*/ */
public int countMembers(RepositoryEntryRef re, String... roles) { public int countMembers(RepositoryEntryRef re, String role) {
List<String> roleList = GroupRoles.toList(roles); StringBuilder sb = new StringBuilder(256);
StringBuilder sb = new StringBuilder();
sb.append("select count(members) from ").append(RepositoryEntry.class.getName()).append(" as v") sb.append("select count(members) from ").append(RepositoryEntry.class.getName()).append(" as v")
.append(" inner join v.groups as relGroup") .append(" inner join v.groups as relGroup")
.append(" inner join relGroup.group as baseGroup") .append(" inner join relGroup.group as baseGroup")
.append(" inner join baseGroup.members as members") .append(" inner join baseGroup.members as members")
.append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") .append(" where v.key=:repoKey and members.role=:role");
.append(" where v.key=:repoKey and (relGroup.defaultGroup=true or businessGroup.key is not null)");
if(!roleList.isEmpty()) { Number count = dbInstance.getCurrentEntityManager()
sb.append(" and members.role in (:roles)");
}
TypedQuery<Number> query = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Number.class) .createQuery(sb.toString(), Number.class)
.setParameter("repoKey", re.getKey()); .setParameter("repoKey", re.getKey())
if(!roleList.isEmpty()) { .setParameter("role", role)
query.setParameter("roles", roleList); .getSingleResult();
}
Number count = query.getSingleResult();
return count == null ? 0 : count.intValue(); return count == null ? 0 : count.intValue();
} }
......
...@@ -63,6 +63,7 @@ import org.olat.course.assessment.manager.UserCourseInformationsManager; ...@@ -63,6 +63,7 @@ import org.olat.course.assessment.manager.UserCourseInformationsManager;
import org.olat.course.certificate.CertificatesManager; import org.olat.course.certificate.CertificatesManager;
import org.olat.ims.qti21.manager.AssessmentTestSessionDAO; import org.olat.ims.qti21.manager.AssessmentTestSessionDAO;
import org.olat.modules.assessment.manager.AssessmentEntryDAO; import org.olat.modules.assessment.manager.AssessmentEntryDAO;
import org.olat.modules.curriculum.CurriculumService;
import org.olat.modules.lecture.LectureService; import org.olat.modules.lecture.LectureService;
import org.olat.modules.portfolio.PortfolioService; import org.olat.modules.portfolio.PortfolioService;
import org.olat.modules.reminder.manager.ReminderDAO; import org.olat.modules.reminder.manager.ReminderDAO;
...@@ -451,6 +452,9 @@ public class RepositoryServiceImpl implements RepositoryService { ...@@ -451,6 +452,9 @@ public class RepositoryServiceImpl implements RepositoryService {
//detach portfolio if there are some lost //detach portfolio if there are some lost
CoreSpringFactory.getImpl(PortfolioService.class).detachCourseFromBinders(entry); CoreSpringFactory.getImpl(PortfolioService.class).detachCourseFromBinders(entry);
dbInstance.commit(); dbInstance.commit();
//detach from curriculum
CoreSpringFactory.getImpl(CurriculumService.class).removeRepositoryEntry(entry);
dbInstance.commit();
// inform handler to do any cleanup work... handler must delete the // inform handler to do any cleanup work... handler must delete the
// referenced resourceable a swell. // referenced resourceable a swell.
...@@ -616,11 +620,10 @@ public class RepositoryServiceImpl implements RepositoryService { ...@@ -616,11 +620,10 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override @Override
public int countMembers(RepositoryEntryRef re, String... roles) { public int countMembers(RepositoryEntryRef re, String role) {
return reToGroupDao.countMembers(re, roles); return reToGroupDao.countMembers(re, role);
} }
@Override @Override
public int countMembers(List<? extends RepositoryEntryRef> res, Identity excludeMe) { public int countMembers(List<? extends RepositoryEntryRef> res, Identity excludeMe) {
return reToGroupDao.countMembers(res, excludeMe); return reToGroupDao.countMembers(res, excludeMe);
...@@ -653,10 +656,7 @@ public class RepositoryServiceImpl implements RepositoryService { ...@@ -653,10 +656,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override @Override
public List<Identity> getIdentitiesWithRole(String role) { public List<Identity> getIdentitiesWithRole(String role) {
long start = System.nanoTime(); return reToGroupDao.getIdentitiesWithRole(role);
List<Identity> ids = reToGroupDao.getIdentitiesWithRole(role);
CodeHelper.printNanoTime(start, "Repository ids with role");
return ids;
} }
@Override @Override
......
...@@ -154,13 +154,15 @@ public class RepositoryEntryRelationDAOTest extends OlatTestCase { ...@@ -154,13 +154,15 @@ public class RepositoryEntryRelationDAOTest extends OlatTestCase {
//all members //all members
List<Identity> members = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.defaultGroup); List<Identity> members = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.defaultGroup);
int numOfMembers = repositoryEntryRelationDao.countMembers(re);
Assert.assertNotNull(members); Assert.assertNotNull(members);
Assert.assertEquals(2, members.size()); Assert.assertEquals(2, members.size());
Assert.assertEquals(2, numOfMembers);
Assert.assertTrue(members.contains(id1)); Assert.assertTrue(members.contains(id1));
Assert.assertTrue(members.contains(id2)); Assert.assertTrue(members.contains(id2));
// owner
int numOfOwners = repositoryEntryRelationDao.countMembers(re, GroupRoles.owner.name());
Assert.assertEquals(1, numOfOwners);
//participant //participant
List<Identity> participants = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.defaultGroup, GroupRoles.participant.name()); List<Identity> participants = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.defaultGroup, GroupRoles.participant.name());
int numOfParticipants = repositoryEntryRelationDao.countMembers(re, GroupRoles.participant.name()); int numOfParticipants = repositoryEntryRelationDao.countMembers(re, GroupRoles.participant.name());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment