Skip to content
Snippets Groups Projects
Commit 0db472e1 authored by srosse's avatar srosse
Browse files

OO-1207: fetch the base group and resource with the load of the business group

parent 95c19122
No related branches found
No related tags found
No related merge requests found
......@@ -90,7 +90,6 @@ public class CourseBusinessGroupListController extends AbstractBusinessGroupList
tableEl.setMultiSelect(true);
RepositoryEntry re = (RepositoryEntry)getUserObject();
boolean managed = RepositoryEntryManagedFlag.isManaged(re, RepositoryEntryManagedFlag.groups);
if(!managed) {
duplicateButton = uifactory.addFormLink("table.duplicate", TABLE_ACTION_DUPLICATE, "table.duplicate", null, formLayout, Link.BUTTON);
......@@ -114,7 +113,6 @@ public class CourseBusinessGroupListController extends AbstractBusinessGroupList
@Override
protected FlexiTableColumnModel initColumnModel() {
RepositoryEntry re = (RepositoryEntry)getUserObject();
boolean managed = RepositoryEntryManagedFlag.isManaged(re, RepositoryEntryManagedFlag.groups);
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
......
......@@ -140,10 +140,17 @@ public class BusinessGroupDAO {
return businessgroup;
}
public BusinessGroup load(Long id) {
EntityManager em = dbInstance.getCurrentEntityManager();
BusinessGroup group = em.find(BusinessGroupImpl.class, id);
return group;
public BusinessGroup load(Long key) {
StringBuilder sb = new StringBuilder();
sb.append("select bgi from ").append(BusinessGroupImpl.class.getName()).append(" bgi ")
.append(" left join fetch bgi.baseGroup baseGroup")
.append(" left join fetch bgi.resource resource")
.append(" where bgi.key=:key");
List<BusinessGroup> groups = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), BusinessGroup.class)
.setParameter("key", key)
.getResultList();
return groups == null || groups.isEmpty() ? null : groups.get(0);
}
public List<BusinessGroupShort> loadShort(Collection<Long> ids) {
......
......@@ -34,6 +34,7 @@ import junit.framework.Assert;
import org.junit.Test;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.Group;
import org.olat.basesecurity.GroupRoles;
import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.PersistenceHelper;
......@@ -51,6 +52,7 @@ import org.olat.group.model.BusinessGroupMembershipViewImpl;
import org.olat.group.model.SearchBusinessGroupParams;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.manager.RepositoryEntryRelationDAO;
import org.olat.resource.OLATResource;
import org.olat.resource.accesscontrol.ACService;
import org.olat.resource.accesscontrol.model.Offer;
import org.olat.test.JunitTestHelper;
......@@ -143,6 +145,25 @@ public class BusinessGroupDAOTest extends OlatTestCase {
Assert.assertTrue(reloadedGroup.getAutoCloseRanksEnabled());
}
@Test
public void loadBusinessGroup_fetch() {
//create business group
BusinessGroup group = businessGroupDao.createAndPersist(null, "gd-fetch", "gd-fetch-desc", 0, 10, true, true, false, false, false);
dbInstance.commitAndCloseSession();
BusinessGroup reloadedGroup = businessGroupDao.load(group.getKey());
Assert.assertNotNull(reloadedGroup);
dbInstance.commitAndCloseSession();
//check lazy
Group baseGroup = reloadedGroup.getBaseGroup();
Assert.assertNotNull(baseGroup);
Assert.assertNotNull(baseGroup.getKey());
OLATResource resource = reloadedGroup.getResource();
Assert.assertNotNull(resource);
Assert.assertNotNull(resource.getKey());
}
@Test
public void loadBusinessGroup_forUpdate() {
//create a 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