use of org.olat.group.model.BusinessGroupRefImpl in project OpenOLAT by OpenOLAT.
the class BusinessGroupMembershipProcessor method processResourceRemoved.
private void processResourceRemoved(Long groupKey, Long repoKey) {
BusinessGroupRef groupRef = new BusinessGroupRefImpl(groupKey);
RepositoryEntryRef entryRef = new RepositoryEntryRefImpl(repoKey);
OLATResource resource = repositoryManager.lookupRepositoryEntryResource(entryRef.getKey());
List<Long> memberKeys = businessGroupRelationDao.getMemberKeys(Collections.singletonList(groupRef), GroupRoles.coach.name(), GroupRoles.participant.name());
for (Long memberKey : memberKeys) {
IdentityRef member = new IdentityRefImpl(memberKey);
List<String> remaingRoles = repositoryEntryRelationDao.getRoles(member, entryRef);
if (remaingRoles.isEmpty()) {
notificationsManager.unsubscribeAllForIdentityAndResId(member, resource.getResourceableId());
}
}
}
use of org.olat.group.model.BusinessGroupRefImpl in project openolat by klemens.
the class EnrollmentManager method getEnrollments.
protected List<EnrollmentRow> getEnrollments(IdentityRef identity, List<Long> groupKeys, List<Long> areaKeys, int descriptionMaxSize) {
List<Long> allGroupKeys = getBusinessGroupKeys(groupKeys, areaKeys);
if (allGroupKeys.isEmpty())
return Collections.emptyList();
// groupKey, name, description, maxParticipants, waitingListEnabled;
// numInWaitingList, numOfParticipants, participant, waiting;
StringBuilder sb = new StringBuilder();
sb.append("select grp.key, grp.name, grp.description, grp.maxParticipants, grp.waitingListEnabled, ").append(" (select count(participants.key) from bgroupmember participants ").append(" where participants.group=baseGroup and participants.role='").append(GroupRoles.participant.name()).append("'").append(" ) as numOfParticipants,").append(" (select count(reservations.key) from resourcereservation reservations ").append(" where reservations.resource.key=grp.resource.key").append(" ) as numOfReservationss,").append(" (select count(waiters.key) from bgroupmember waiters ").append(" where grp.waitingListEnabled=true and waiters.group=baseGroup and waiters.role='").append(GroupRoles.waiting.name()).append("'").append(" ) as numOfWaiters,").append(" (select count(meParticipant.key) from bgroupmember meParticipant ").append(" where meParticipant.group=baseGroup and meParticipant.role='").append(GroupRoles.participant.name()).append("'").append(" and meParticipant.identity.key=:identityKey").append(" ) as numOfMeParticipant,").append(" (select count(meWaiting.key) from bgroupmember meWaiting ").append(" where grp.waitingListEnabled=true and meWaiting.group=baseGroup and meWaiting.role='").append(GroupRoles.waiting.name()).append("'").append(" and meWaiting.identity.key=:identityKey").append(" ) as numOfMeWaiting").append(" from businessgroup grp ").append(" inner join grp.baseGroup as baseGroup ").append(" where grp.key in (:groupKeys)");
List<Object[]> rows = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("groupKeys", allGroupKeys).setParameter("identityKey", identity.getKey()).getResultList();
List<EnrollmentRow> enrollments = new ArrayList<>(rows.size());
for (Object[] row : rows) {
Long key = ((Number) row[0]).longValue();
String name = (String) row[1];
String desc = (String) row[2];
if (StringHelper.containsNonWhitespace(desc) && descriptionMaxSize > 0) {
desc = FilterFactory.getHtmlTagsFilter().filter(desc);
desc = Formatter.truncate(desc, 256);
}
int maxParticipants = row[3] == null ? -1 : ((Number) row[3]).intValue();
Object enabled = row[4];
boolean waitingListEnabled;
if (enabled == null) {
waitingListEnabled = false;
} else if (enabled instanceof Boolean) {
waitingListEnabled = ((Boolean) enabled).booleanValue();
} else if (enabled instanceof Number) {
int val = ((Number) enabled).intValue();
waitingListEnabled = val == 1;
} else {
waitingListEnabled = false;
}
int numOfParticipants = row[5] == null ? 0 : ((Number) row[5]).intValue();
int numOfReservations = row[6] == null ? 0 : ((Number) row[6]).intValue();
int numOfWaiters = row[7] == null ? 0 : ((Number) row[7]).intValue();
boolean participant = row[8] == null ? false : ((Number) row[8]).intValue() > 0;
boolean waiting = row[9] == null ? false : ((Number) row[9]).intValue() > 0;
EnrollmentRow enrollment = new EnrollmentRow(key, name, desc, maxParticipants, waitingListEnabled);
enrollment.setNumOfParticipants(numOfParticipants);
enrollment.setNumOfReservations(numOfReservations);
enrollment.setNumInWaitingList(numOfWaiters);
enrollment.setParticipant(participant);
enrollment.setWaiting(waiting);
if (waitingListEnabled && waiting) {
int pos = businessGroupService.getPositionInWaitingListFor(identity, new BusinessGroupRefImpl(key));
enrollment.setPositionInWaitingList(pos);
} else {
enrollment.setPositionInWaitingList(-1);
}
enrollments.add(enrollment);
}
return enrollments;
}
use of org.olat.group.model.BusinessGroupRefImpl in project openolat by klemens.
the class BusinessGroupMembershipProcessor method processIdentityRemoved.
private void processIdentityRemoved(Long groupKey, Long identityKey) {
IdentityRef identityRef = new IdentityRefImpl(identityKey);
BusinessGroupRef groupRef = new BusinessGroupRefImpl(groupKey);
if (!businessGroupRelationDao.hasAnyRole(identityRef, groupRef)) {
infoMessageManager.updateInfoMessagesOfIdentity(groupRef, identityRef);
notificationsManager.unsubscribeAllForIdentityAndResId(identityRef, groupRef.getKey());
List<BGRepositoryEntryRelation> relations = businessGroupRelationDao.findRelationToRepositoryEntries(Collections.singletonList(groupKey), 0, -1);
for (BGRepositoryEntryRelation relation : relations) {
Long repositoryEntryKey = relation.getRepositoryEntryKey();
RepositoryEntryRef entryRef = new RepositoryEntryRefImpl(repositoryEntryKey);
List<String> remaingRoles = repositoryEntryRelationDao.getRoles(identityRef, entryRef);
if (remaingRoles.isEmpty()) {
OLATResource resource = repositoryManager.lookupRepositoryEntryResource(entryRef.getKey());
notificationsManager.unsubscribeAllForIdentityAndResId(identityRef, resource.getResourceableId());
}
}
}
}
use of org.olat.group.model.BusinessGroupRefImpl in project OpenOLAT by OpenOLAT.
the class BusinessGroupRoleRuleSPI method evaluate.
@Override
public List<Identity> evaluate(RepositoryEntry entry, ReminderRule rule) {
List<Identity> identities = null;
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
String groupKey = r.getRightOperand();
if (StringHelper.isLong(groupKey)) {
Long key = Long.parseLong(groupKey);
BusinessGroupRef groupRef = new BusinessGroupRefImpl(key);
identities = businessGroupRelationDao.getMembers(groupRef, GroupRoles.coach.name(), GroupRoles.participant.name());
}
}
return identities == null ? Collections.<Identity>emptyList() : identities;
}
use of org.olat.group.model.BusinessGroupRefImpl in project OpenOLAT by OpenOLAT.
the class EnrollmentManager method getEnrollments.
protected List<EnrollmentRow> getEnrollments(IdentityRef identity, List<Long> groupKeys, List<Long> areaKeys, int descriptionMaxSize) {
List<Long> allGroupKeys = getBusinessGroupKeys(groupKeys, areaKeys);
if (allGroupKeys.isEmpty())
return Collections.emptyList();
// groupKey, name, description, maxParticipants, waitingListEnabled;
// numInWaitingList, numOfParticipants, participant, waiting;
StringBuilder sb = new StringBuilder();
sb.append("select grp.key, grp.name, grp.description, grp.maxParticipants, grp.waitingListEnabled, ").append(" (select count(participants.key) from bgroupmember participants ").append(" where participants.group=baseGroup and participants.role='").append(GroupRoles.participant.name()).append("'").append(" ) as numOfParticipants,").append(" (select count(reservations.key) from resourcereservation reservations ").append(" where reservations.resource.key=grp.resource.key").append(" ) as numOfReservationss,").append(" (select count(waiters.key) from bgroupmember waiters ").append(" where grp.waitingListEnabled=true and waiters.group=baseGroup and waiters.role='").append(GroupRoles.waiting.name()).append("'").append(" ) as numOfWaiters,").append(" (select count(meParticipant.key) from bgroupmember meParticipant ").append(" where meParticipant.group=baseGroup and meParticipant.role='").append(GroupRoles.participant.name()).append("'").append(" and meParticipant.identity.key=:identityKey").append(" ) as numOfMeParticipant,").append(" (select count(meWaiting.key) from bgroupmember meWaiting ").append(" where grp.waitingListEnabled=true and meWaiting.group=baseGroup and meWaiting.role='").append(GroupRoles.waiting.name()).append("'").append(" and meWaiting.identity.key=:identityKey").append(" ) as numOfMeWaiting").append(" from businessgroup grp ").append(" inner join grp.baseGroup as baseGroup ").append(" where grp.key in (:groupKeys)");
List<Object[]> rows = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("groupKeys", allGroupKeys).setParameter("identityKey", identity.getKey()).getResultList();
List<EnrollmentRow> enrollments = new ArrayList<>(rows.size());
for (Object[] row : rows) {
Long key = ((Number) row[0]).longValue();
String name = (String) row[1];
String desc = (String) row[2];
if (StringHelper.containsNonWhitespace(desc) && descriptionMaxSize > 0) {
desc = FilterFactory.getHtmlTagsFilter().filter(desc);
desc = Formatter.truncate(desc, 256);
}
int maxParticipants = row[3] == null ? -1 : ((Number) row[3]).intValue();
Object enabled = row[4];
boolean waitingListEnabled;
if (enabled == null) {
waitingListEnabled = false;
} else if (enabled instanceof Boolean) {
waitingListEnabled = ((Boolean) enabled).booleanValue();
} else if (enabled instanceof Number) {
int val = ((Number) enabled).intValue();
waitingListEnabled = val == 1;
} else {
waitingListEnabled = false;
}
int numOfParticipants = row[5] == null ? 0 : ((Number) row[5]).intValue();
int numOfReservations = row[6] == null ? 0 : ((Number) row[6]).intValue();
int numOfWaiters = row[7] == null ? 0 : ((Number) row[7]).intValue();
boolean participant = row[8] == null ? false : ((Number) row[8]).intValue() > 0;
boolean waiting = row[9] == null ? false : ((Number) row[9]).intValue() > 0;
EnrollmentRow enrollment = new EnrollmentRow(key, name, desc, maxParticipants, waitingListEnabled);
enrollment.setNumOfParticipants(numOfParticipants);
enrollment.setNumOfReservations(numOfReservations);
enrollment.setNumInWaitingList(numOfWaiters);
enrollment.setParticipant(participant);
enrollment.setWaiting(waiting);
if (waitingListEnabled && waiting) {
int pos = businessGroupService.getPositionInWaitingListFor(identity, new BusinessGroupRefImpl(key));
enrollment.setPositionInWaitingList(pos);
} else {
enrollment.setPositionInWaitingList(-1);
}
enrollments.add(enrollment);
}
return enrollments;
}
Aggregations