use of org.olat.group.model.BusinessGroupRow in project openolat by klemens.
the class BusinessGroupDAOTest method findBusinessGroupsWithResources.
@Test
public void findBusinessGroupsWithResources() {
// create a group attach to a resource
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-10");
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("marker-");
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group1 = businessGroupDao.createAndPersist(owner, "rsrc-grp-1", "rsrc-grp-1-desc", 0, 5, true, false, true, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(owner, "rsrc-grp-2", "rsrc-grp-2-desc", 0, 5, true, false, true, false, false);
businessGroupRelationDao.addRelationToResource(group1, re);
dbInstance.commitAndCloseSession();
// check the same with the views
// check the search function with resources
BusinessGroupQueryParams queryWithParams = new BusinessGroupQueryParams();
queryWithParams.setResources(Boolean.TRUE);
List<BusinessGroupRow> groupViewWith = businessGroupDao.searchBusinessGroupsWithMemberships(queryWithParams, id);
Assert.assertNotNull(groupViewWith);
Assert.assertFalse(groupViewWith.isEmpty());
Assert.assertTrue(contains(groupViewWith, group1));
// check the search function without resources
BusinessGroupQueryParams queryWithoutParams = new BusinessGroupQueryParams();
queryWithoutParams.setResources(Boolean.FALSE);
List<BusinessGroupRow> groupViewWithout = businessGroupDao.searchBusinessGroupsWithMemberships(queryWithoutParams, id);
Assert.assertNotNull(groupViewWithout);
Assert.assertFalse(groupViewWithout.isEmpty());
Assert.assertTrue(contains(groupViewWithout, group2));
}
use of org.olat.group.model.BusinessGroupRow in project openolat by klemens.
the class BusinessGroupDAOTest method findMarkedBusinessGroup.
@Test
public void findMarkedBusinessGroup() {
Identity marker = JunitTestHelper.createAndPersistIdentityAsUser("marker-" + UUID.randomUUID().toString());
// create a group with a mark and an other without as control
BusinessGroup group1 = businessGroupDao.createAndPersist(marker, "marked-grp-1", "marked-grp-1-desc", 0, 5, true, false, true, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(marker, "marked-grp-2", "marked-grp-2-desc", 0, 5, true, false, true, false, false);
markManager.setMark(group1.getResource(), marker, null, "[BusinessGroup:" + group1.getKey() + "]");
dbInstance.commitAndCloseSession();
// check the search with the views
// check marked
BusinessGroupQueryParams queryMarkedParams = new BusinessGroupQueryParams();
queryMarkedParams.setOwner(true);
queryMarkedParams.setMarked(true);
List<BusinessGroupRow> markedGroupViews = businessGroupDao.searchBusinessGroupsWithMemberships(queryMarkedParams, marker);
Assert.assertNotNull(markedGroupViews);
Assert.assertEquals(1, markedGroupViews.size());
Assert.assertTrue(contains(markedGroupViews, group1));
Assert.assertFalse(contains(markedGroupViews, group2));
}
use of org.olat.group.model.BusinessGroupRow in project openolat by klemens.
the class CourseBusinessGroupListController method doConfirmRemove.
private void doConfirmRemove(UserRequest ureq, List<BusinessGroupRow> selectedItems) {
StringBuilder sb = new StringBuilder();
StringBuilder managedSb = new StringBuilder();
for (BusinessGroupRow item : selectedItems) {
String gname = item.getName() == null ? "???" : StringHelper.escapeHtml(item.getName());
if (BusinessGroupManagedFlag.isManaged(item.getManagedFlags(), BusinessGroupManagedFlag.resources)) {
if (managedSb.length() > 0)
managedSb.append(", ");
managedSb.append(gname);
} else {
if (sb.length() > 0)
sb.append(", ");
sb.append(gname);
}
}
if (managedSb.length() > 0) {
showWarning("error.managed.group", managedSb.toString());
} else {
String text = getTranslator().translate("group.remove", new String[] { sb.toString(), StringHelper.escapeHtml(re.getDisplayname()) });
confirmRemoveMultiResource = activateYesNoDialog(ureq, null, text, confirmRemoveResource);
confirmRemoveMultiResource.setUserObject(selectedItems);
}
}
use of org.olat.group.model.BusinessGroupRow in project openolat by klemens.
the class CourseBusinessGroupListController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (event instanceof BusinessGroupSelectionEvent) {
BusinessGroupSelectionEvent selectionEvent = (BusinessGroupSelectionEvent) event;
List<BusinessGroup> selectedGroups = selectionEvent.getGroups();
cmc.deactivate();
cleanUpPopups();
addGroupsToCourse(selectedGroups);
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (source == confirmRemoveResource) {
if (DialogBoxUIFactory.isYesEvent(event)) {
// yes case
BusinessGroup group = (BusinessGroup) confirmRemoveResource.getUserObject();
doRemoveBusinessGroups(Collections.singletonList(group));
fireEvent(ureq, Event.CHANGED_EVENT);
}
} else if (source == confirmRemoveMultiResource) {
if (DialogBoxUIFactory.isYesEvent(event)) {
// yes case
@SuppressWarnings("unchecked") List<BusinessGroupRow> selectedItems = (List<BusinessGroupRow>) confirmRemoveMultiResource.getUserObject();
List<BusinessGroup> groups = toBusinessGroups(ureq, selectedItems, false);
doRemoveBusinessGroups(groups);
}
}
super.event(ureq, source, event);
}
use of org.olat.group.model.BusinessGroupRow in project openolat by klemens.
the class BusinessGroupDAO method loadRelations.
private void loadRelations(Map<Long, ? extends BusinessGroupRow> keyToGroup, BusinessGroupQueryParams params, IdentityRef identity) {
if (keyToGroup.isEmpty())
return;
// no resources, no relations
if (params.getResources() != null && !params.getResources().booleanValue())
return;
// headless don't have relations
if (params.isHeadless())
return;
final int RELATIONS_IN_LIMIT = 64;
final boolean restrictToMembership = params != null && identity != null && (params.isAttendee() || params.isOwner() || params.isWaiting() || params.isMarked());
// resources
StringBuilder sr = new StringBuilder();
sr.append("select entry.key, entry.displayname, bgi.key from repoentrytobusinessgroup as v").append(" inner join v.entry entry").append(" inner join v.businessGroup relationToGroup").append(" inner join relationToGroup.businessGroups bgi");
if (restrictToMembership) {
sr.append(" inner join bgi.baseGroup as bGroup ").append(" inner join bGroup.members as membership on membership.identity.key=:identityKey");
} else if (keyToGroup.size() < RELATIONS_IN_LIMIT) {
sr.append(" where bgi.key in (:businessGroupKeys)");
} else if (params.getPublicGroups() != null && params.getPublicGroups().booleanValue()) {
sr.append(" inner join acoffer as offer on (bgi.resource.key = offer.resource.key)");
} else if (params.getRepositoryEntry() != null) {
sr.append(" inner join repoentrytobusinessgroup as refBgiToGroup").append(" on (refBgiToGroup.entry.key=:repositoryEntryKey and bgi.baseGroup.key=refBgiToGroup.businessGroup.key)");
} else {
sr.append(" inner join bgi.resource as bgResource ").append(" inner join bgi.baseGroup as bGroup ");
filterBusinessGroupToSearch(sr, params, false);
}
TypedQuery<Object[]> resourcesQuery = dbInstance.getCurrentEntityManager().createQuery(sr.toString(), Object[].class);
if (restrictToMembership) {
resourcesQuery.setParameter("identityKey", identity.getKey());
} else if (keyToGroup.size() < RELATIONS_IN_LIMIT) {
List<Long> businessGroupKeys = new ArrayList<>(keyToGroup.size());
for (Long businessGroupKey : keyToGroup.keySet()) {
businessGroupKeys.add(businessGroupKey);
}
resourcesQuery.setParameter("businessGroupKeys", businessGroupKeys);
} else if (params.getPublicGroups() != null && params.getPublicGroups().booleanValue()) {
// no parameters to add
} else if (params.getRepositoryEntry() != null) {
resourcesQuery.setParameter("repositoryEntryKey", params.getRepositoryEntry().getKey());
} else {
filterBusinessGroupToSearchParameters(resourcesQuery, params, identity, false);
}
List<Object[]> resources = resourcesQuery.getResultList();
for (Object[] resource : resources) {
Long groupKey = (Long) resource[2];
BusinessGroupRow row = keyToGroup.get(groupKey);
if (row != null) {
Long entryKey = (Long) resource[0];
String displayName = (String) resource[1];
REShort entry = new REShort(entryKey, displayName);
if (row.getResources() == null) {
row.setResources(new ArrayList<>(4));
}
row.getResources().add(entry);
}
}
}
Aggregations