use of org.olat.group.BusinessGroupOrder in project openolat by klemens.
the class BusinessGroupDAO method findBusinessGroup.
public List<BusinessGroup> findBusinessGroup(Identity identity, int maxResults, BusinessGroupOrder... ordering) {
StringBuilder sb = new StringBuilder();
sb.append("select bgi from businessgroup as bgi ").append(" inner join fetch bgi.resource as bgResource").append(" inner join fetch bgi.baseGroup as baseGroup").append(" where exists (select bmember from bgroupmember as bmember").append(" where bmember.identity.key=:identKey and bmember.group=baseGroup and bmember.role in ('").append(GroupRoles.coach.name()).append("','").append(GroupRoles.participant.name()).append("')").append(" )");
if (ordering != null && ordering.length > 0 && ordering[0] != null) {
sb.append(" order by ");
for (BusinessGroupOrder o : ordering) {
switch(o) {
case nameAsc:
sb.append("bgi.name");
break;
case nameDesc:
sb.append("bgi.name desc");
break;
case creationDateAsc:
sb.append("bgi.creationDate");
break;
case creationDateDesc:
sb.append("bgi.creationDate desc");
break;
}
}
// sb.append(" gp.key ");
}
TypedQuery<BusinessGroup> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BusinessGroup.class).setParameter("identKey", identity.getKey());
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
return query.getResultList();
}
use of org.olat.group.BusinessGroupOrder in project openolat by klemens.
the class GroupsPortletRunController method reloadModel.
@Override
protected void reloadModel(SortingCriteria sortCriteria) {
if (sortCriteria.getSortingType() == SortingCriteria.AUTO_SORTING) {
BusinessGroupOrder order = null;
if (sortCriteria.getSortingTerm() == SortingCriteria.ALPHABETICAL_SORTING) {
order = sortCriteria.isAscending() ? BusinessGroupOrder.nameAsc : BusinessGroupOrder.nameDesc;
} else if (sortCriteria.getSortingTerm() == SortingCriteria.DATE_SORTING) {
order = sortCriteria.isAscending() ? BusinessGroupOrder.creationDateAsc : BusinessGroupOrder.creationDateDesc;
}
int maxEntries = sortCriteria.getMaxEntries();
List<BusinessGroup> groupList = businessGroupService.findBusinessGroups(getIdentity(), maxEntries * 2, order);
Set<BusinessGroup> removeDuplicates = new HashSet<BusinessGroup>(maxEntries);
for (Iterator<BusinessGroup> it = groupList.iterator(); it.hasNext(); ) {
BusinessGroup group = it.next();
if (removeDuplicates.contains(group)) {
it.remove();
} else {
removeDuplicates.add(group);
}
}
List<BusinessGroup> uniqueList = groupList.subList(0, Math.min(maxEntries, groupList.size()));
List<PortletEntry<BusinessGroupEntry>> entries = convertShortBusinessGroupToPortletEntryList(uniqueList, false);
groupListModel.setObjects(entries);
tableCtr.modelChanged();
} else {
reloadModel(getPersistentManuallySortedItems());
}
}
use of org.olat.group.BusinessGroupOrder in project OpenOLAT by OpenOLAT.
the class GroupsPortletRunController method reloadModel.
@Override
protected void reloadModel(SortingCriteria sortCriteria) {
if (sortCriteria.getSortingType() == SortingCriteria.AUTO_SORTING) {
BusinessGroupOrder order = null;
if (sortCriteria.getSortingTerm() == SortingCriteria.ALPHABETICAL_SORTING) {
order = sortCriteria.isAscending() ? BusinessGroupOrder.nameAsc : BusinessGroupOrder.nameDesc;
} else if (sortCriteria.getSortingTerm() == SortingCriteria.DATE_SORTING) {
order = sortCriteria.isAscending() ? BusinessGroupOrder.creationDateAsc : BusinessGroupOrder.creationDateDesc;
}
int maxEntries = sortCriteria.getMaxEntries();
List<BusinessGroup> groupList = businessGroupService.findBusinessGroups(getIdentity(), maxEntries * 2, order);
Set<BusinessGroup> removeDuplicates = new HashSet<BusinessGroup>(maxEntries);
for (Iterator<BusinessGroup> it = groupList.iterator(); it.hasNext(); ) {
BusinessGroup group = it.next();
if (removeDuplicates.contains(group)) {
it.remove();
} else {
removeDuplicates.add(group);
}
}
List<BusinessGroup> uniqueList = groupList.subList(0, Math.min(maxEntries, groupList.size()));
List<PortletEntry<BusinessGroupEntry>> entries = convertShortBusinessGroupToPortletEntryList(uniqueList, false);
groupListModel.setObjects(entries);
tableCtr.modelChanged();
} else {
reloadModel(getPersistentManuallySortedItems());
}
}
use of org.olat.group.BusinessGroupOrder in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAO method findBusinessGroup.
public List<BusinessGroup> findBusinessGroup(Identity identity, int maxResults, BusinessGroupOrder... ordering) {
StringBuilder sb = new StringBuilder();
sb.append("select bgi from businessgroup as bgi ").append(" inner join fetch bgi.resource as bgResource").append(" inner join fetch bgi.baseGroup as baseGroup").append(" where exists (select bmember from bgroupmember as bmember").append(" where bmember.identity.key=:identKey and bmember.group=baseGroup and bmember.role in ('").append(GroupRoles.coach.name()).append("','").append(GroupRoles.participant.name()).append("')").append(" )");
if (ordering != null && ordering.length > 0 && ordering[0] != null) {
sb.append(" order by ");
for (BusinessGroupOrder o : ordering) {
switch(o) {
case nameAsc:
sb.append("bgi.name");
break;
case nameDesc:
sb.append("bgi.name desc");
break;
case creationDateAsc:
sb.append("bgi.creationDate");
break;
case creationDateDesc:
sb.append("bgi.creationDate desc");
break;
}
}
// sb.append(" gp.key ");
}
TypedQuery<BusinessGroup> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BusinessGroup.class).setParameter("identKey", identity.getKey());
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
return query.getResultList();
}
use of org.olat.group.BusinessGroupOrder in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAO method createFindDBQuery.
private <T> TypedQuery<T> createFindDBQuery(SearchBusinessGroupParams params, RepositoryEntryRef resource, Class<T> resultClass, BusinessGroupOrder... ordering) {
StringBuilder query = new StringBuilder();
if (BusinessGroup.class.equals(resultClass)) {
query.append("select distinct(bgi) from ");
} else {
query.append("select count(bgi.key) from ");
}
query.append("businessgroup as bgi ");
// inner joins
if (BusinessGroup.class.equals(resultClass)) {
query.append("inner join fetch bgi.resource bgResource ");
query.append("inner join fetch bgi.baseGroup as baseGroup ");
} else {
query.append("inner join bgi.resource bgResource ");
query.append("inner join bgi.baseGroup as baseGroup ");
}
boolean where = false;
if (StringHelper.containsNonWhitespace(params.getExternalId())) {
where = where(query, where);
query.append("bgi.externalId=:externalId");
}
Long id = null;
if (StringHelper.containsNonWhitespace(params.getIdRef())) {
if (StringHelper.isLong(params.getIdRef())) {
try {
id = new Long(params.getIdRef());
} catch (NumberFormatException e) {
// not a real number, can be a very long numerical external id
}
}
where = where(query, where);
query.append("(bgi.externalId=:idRefString");
if (id != null) {
query.append(" or bgi.key=:idRefLong");
}
query.append(")");
}
if (params.getManaged() != null) {
where = where(query, where);
if (params.getManaged().booleanValue()) {
query.append("bgi.managedFlagsString is not null");
} else {
query.append("bgi.managedFlagsString is null");
}
}
if (params.getGroupKeys() != null && !params.getGroupKeys().isEmpty()) {
where = where(query, where);
query.append("bgi.key in (:groupKeys)");
}
if (resource != null) {
where = where(query, where);
query.append(" bgi.baseGroup.key in (").append(" select relation.group.key from repoentrytogroup as relation where relation.entry.key=:resourceKey").append(" )");
}
if (StringHelper.containsNonWhitespace(params.getCourseTitle())) {
where = where(query, where);
query.append(" bgi.key in (").append(" select bgRel.relationId.groupKey from repoentryrelationview bgRel ").append(" where ");
searchLikeAttribute(query, "bgRel", "repositoryEntryDisplayName", "displayName");
query.append(" )");
}
List<String> roles = null;
if (params.isOwner() || params.isAttendee() || params.isWaiting()) {
where = where(query, where);
roles = new ArrayList<>();
query.append(" bgi.baseGroup.key in (select bmember.group.key from bgroupmember as bmember").append(" where bmember.identity.key=:identId and bmember.role in (:roles)").append(" )");
if (params.isOwner()) {
roles.add(GroupRoles.coach.name());
}
if (params.isAttendee()) {
roles.add(GroupRoles.participant.name());
}
if (params.isWaiting()) {
roles.add(GroupRoles.waiting.name());
}
}
if (StringHelper.containsNonWhitespace(params.getNameOrDesc())) {
where = where(query, where);
query.append("(");
searchLikeAttribute(query, "bgi", "name", "search");
query.append(" or ");
searchLikeAttribute(query, "bgi", "description", "search");
query.append(")");
} else {
if (StringHelper.containsNonWhitespace(params.getExactName())) {
where = where(query, where);
query.append("bgi.name=:exactName");
}
if (StringHelper.containsNonWhitespace(params.getName())) {
where = where(query, where);
searchLikeAttribute(query, "bgi", "name", "name");
}
if (StringHelper.containsNonWhitespace(params.getDescription())) {
where = where(query, where);
searchLikeAttribute(query, "bgi", "description", "description");
}
}
if (params.getTools() != null && !params.getTools().isEmpty()) {
where = where(query, where);
query.append("bgi.key in (select prop.resourceTypeId from ").append(Property.class.getName()).append(" prop").append(" where prop.category='").append(CollaborationTools.PROP_CAT_BG_COLLABTOOLS).append("'").append(" and prop.name in (:tools) and prop.stringValue='true' and prop.resourceTypeName='BusinessGroup')");
}
// order by (not for count)
if (BusinessGroup.class.equals(resultClass)) {
query.append(" order by ");
if (ordering != null && ordering.length > 0) {
for (BusinessGroupOrder o : ordering) {
switch(o) {
case nameAsc:
query.append("bgi.name,");
break;
case nameDesc:
query.append("bgi.name desc,");
break;
case creationDateAsc:
query.append("bgi.creationDate,");
break;
case creationDateDesc:
query.append("bgi.creationDate desc,");
break;
}
}
} else {
query.append("bgi.name,");
}
query.append("bgi.key");
}
TypedQuery<T> dbq = dbInstance.getCurrentEntityManager().createQuery(query.toString(), resultClass);
// add parameters
if (params.isOwner() || params.isAttendee() || params.isWaiting()) {
dbq.setParameter("identId", params.getIdentity().getKey());
}
if (params.getGroupKeys() != null && !params.getGroupKeys().isEmpty()) {
dbq.setParameter("groupKeys", params.getGroupKeys());
}
if (StringHelper.containsNonWhitespace(params.getExternalId())) {
dbq.setParameter("externalId", params.getExternalId());
}
if (StringHelper.containsNonWhitespace(params.getIdRef())) {
dbq.setParameter("idRefString", params.getIdRef());
if (id != null) {
dbq.setParameter("idRefLong", id);
}
}
if (resource != null) {
dbq.setParameter("resourceKey", resource.getKey());
}
if (params.getTools() != null && !params.getTools().isEmpty()) {
dbq.setParameter("tools", params.getTools());
}
if (roles != null) {
dbq.setParameter("roles", roles);
}
if (StringHelper.containsNonWhitespace(params.getNameOrDesc())) {
dbq.setParameter("search", PersistenceHelper.makeFuzzyQueryString(params.getNameOrDesc()));
} else {
if (StringHelper.containsNonWhitespace(params.getExactName())) {
dbq.setParameter("exactName", params.getExactName());
}
if (StringHelper.containsNonWhitespace(params.getName())) {
dbq.setParameter("name", PersistenceHelper.makeFuzzyQueryString(params.getName()));
}
if (StringHelper.containsNonWhitespace(params.getDescription())) {
dbq.setParameter("description", PersistenceHelper.makeFuzzyQueryString(params.getDescription()));
}
}
if (StringHelper.containsNonWhitespace(params.getCourseTitle())) {
dbq.setParameter("displayName", PersistenceHelper.makeFuzzyQueryString(params.getCourseTitle()));
}
return dbq;
}
Aggregations