Skip to content
Snippets Groups Projects
Commit 8398e8c0 authored by srosse's avatar srosse
Browse files

OO-399: fix a backwards compatibility check in the mail course building block,...

OO-399: fix a backwards compatibility check in the mail course building block, fix the query for the fallback based on group names
parent 687a46ec
No related branches found
No related tags found
No related merge requests found
...@@ -118,7 +118,7 @@ public class CORunController extends BasicController { ...@@ -118,7 +118,7 @@ public class CORunController extends BasicController {
String grpNames = (String)moduleConfiguration.get(COEditController.CONFIG_KEY_EMAILTOGROUPS); String grpNames = (String)moduleConfiguration.get(COEditController.CONFIG_KEY_EMAILTOGROUPS);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Long> groupKeys = (List<Long>) moduleConfiguration.get(COEditController.CONFIG_KEY_EMAILTOGROUP_IDS); List<Long> groupKeys = (List<Long>) moduleConfiguration.get(COEditController.CONFIG_KEY_EMAILTOGROUP_IDS);
if(groupKeys != null && StringHelper.containsNonWhitespace(grpNames)) { if(groupKeys == null && StringHelper.containsNonWhitespace(grpNames)) {
groupKeys = businessGroupService.toGroupKeys(grpNames, cgm.getCourseResource()); groupKeys = businessGroupService.toGroupKeys(grpNames, cgm.getCourseResource());
} }
if (coachesConfigured != null && coachesConfigured.booleanValue()) { if (coachesConfigured != null && coachesConfigured.booleanValue()) {
......
...@@ -390,29 +390,6 @@ public class BusinessGroupDAO { ...@@ -390,29 +390,6 @@ public class BusinessGroupDAO {
return groups; return groups;
} }
public List<Long> toGroupKeys(String groupNames, OLATResource resource) {
if(!StringHelper.containsNonWhitespace(groupNames)) return Collections.emptyList();
String[] groupNameArr = groupNames.split(",");
List<String> names = new ArrayList<String>();
for(String name:groupNameArr) {
names.add(name.trim());
}
if(names.isEmpty()) return Collections.emptyList();
StringBuilder sb = new StringBuilder();
sb.append("select bgs.key from ").append(BusinessGroupImpl.class.getName()).append(" as bgs ")
.append(" where bgs.resource.key =:resourceKey and bgs.name in (:names)");
List<Long> keys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class)
.setParameter("resourceKey", resource.getKey())
.setParameter("names", names)
.setHint("org.hibernate.cacheable", Boolean.TRUE)
.getResultList();
return keys;
}
public int countBusinessGroups(SearchBusinessGroupParams params, OLATResource resource) { public int countBusinessGroups(SearchBusinessGroupParams params, OLATResource resource) {
TypedQuery<Number> query = createFindDBQuery(params, resource, Number.class) TypedQuery<Number> query = createFindDBQuery(params, resource, Number.class)
.setHint("org.hibernate.cacheable", Boolean.TRUE); .setHint("org.hibernate.cacheable", Boolean.TRUE);
......
...@@ -31,6 +31,7 @@ import org.olat.basesecurity.SecurityGroupMembershipImpl; ...@@ -31,6 +31,7 @@ import org.olat.basesecurity.SecurityGroupMembershipImpl;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.PersistenceHelper; import org.olat.core.commons.persistence.PersistenceHelper;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.util.StringHelper;
import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroup;
import org.olat.group.BusinessGroupImpl; import org.olat.group.BusinessGroupImpl;
import org.olat.group.BusinessGroupShort; import org.olat.group.BusinessGroupShort;
...@@ -322,6 +323,30 @@ public class BusinessGroupRelationDAO { ...@@ -322,6 +323,30 @@ public class BusinessGroupRelationDAO {
return query.getResultList(); return query.getResultList();
} }
public List<Long> toGroupKeys(String groupNames, OLATResource resource) {
if(!StringHelper.containsNonWhitespace(groupNames)) return Collections.emptyList();
String[] groupNameArr = groupNames.split(",");
List<String> names = new ArrayList<String>();
for(String name:groupNameArr) {
names.add(name.trim());
}
if(names.isEmpty()) return Collections.emptyList();
StringBuilder sb = new StringBuilder();
sb.append("select rel.group.key from ").append(BGResourceRelation.class.getName()).append(" as rel ")
.append(" inner join rel.group bgs")
.append(" where rel.resource.key=:resourceKey and bgs.name in (:names)");
List<Long> keys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class)
.setParameter("resourceKey", resource.getKey())
.setParameter("names", names)
.setHint("org.hibernate.cacheable", Boolean.TRUE)
.getResultList();
return keys;
}
private boolean and(StringBuilder sb, boolean and) { private boolean and(StringBuilder sb, boolean and) {
if(and) sb.append(" and "); if(and) sb.append(" and ");
else sb.append(" where "); else sb.append(" where ");
......
...@@ -702,7 +702,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD ...@@ -702,7 +702,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD
@Override @Override
@Transactional(readOnly=true) @Transactional(readOnly=true)
public List<Long> toGroupKeys(String groupNames, OLATResource resource) { public List<Long> toGroupKeys(String groupNames, OLATResource resource) {
return businessGroupDAO.toGroupKeys(groupNames, resource); return businessGroupRelationDAO.toGroupKeys(groupNames, resource);
} }
@Override @Override
......
...@@ -602,6 +602,22 @@ public class BusinessGroupRelationDAOTest extends OlatTestCase { ...@@ -602,6 +602,22 @@ public class BusinessGroupRelationDAOTest extends OlatTestCase {
Assert.assertEquals(3, count); Assert.assertEquals(3, count);
} }
@Test
public void toGroupKeys() {
//create a resource with 2 groups
OLATResource resource = JunitTestHelper.createRandomResource();
BusinessGroup group1 = businessGroupDao.createAndPersist(null, "to-group-1", "to-group-1-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group1, resource);
BusinessGroup group2 = businessGroupDao.createAndPersist(null, "to-group-2", "to-group-2-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group2, resource);
dbInstance.commitAndCloseSession();
List<Long> groupKeys = businessGroupRelationDao.toGroupKeys("to-group-1", resource);
Assert.assertNotNull(groupKeys);
Assert.assertEquals(1, groupKeys.size());
Assert.assertTrue(groupKeys.contains(group1.getKey()));
}
@Test @Test
public void countResourcesOfBusinessGroups() { public void countResourcesOfBusinessGroups() {
//create 3 entries and 1 group //create 3 entries and 1 group
......
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