use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class LDAPLoginManagerImpl method getManagerBusinessGroup.
private BusinessGroup getManagerBusinessGroup(String externalId) {
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
params.setExternalId(externalId);
List<BusinessGroup> businessGroups = businessGroupService.findBusinessGroups(params, null, 0, -1);
BusinessGroup managedBusinessGroup;
if (businessGroups.size() == 0) {
String managedFlags = BusinessGroupManagedFlag.membersmanagement.name() + "," + BusinessGroupManagedFlag.delete.name();
managedBusinessGroup = businessGroupService.createBusinessGroup(null, externalId, externalId, externalId, managedFlags, null, null, false, false, null);
} else if (businessGroups.size() == 1) {
managedBusinessGroup = businessGroups.get(0);
} else {
log.error(businessGroups.size() + " managed groups found with the following external id: " + externalId);
managedBusinessGroup = null;
}
return managedBusinessGroup;
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class AssessedIdentityListController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
layoutCont.contextPut("title", testEntry.getDisplayname());
RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(testEntry);
layoutCont.contextPut("cssClass", RepositoyUIFactory.getIconCssClass(handler.getSupportedType()));
}
// add the table
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
if (isAdministrativeUser) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.username, "select"));
}
int colIndex = AssessmentToolConstants.USER_PROPS_OFFSET;
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = UserManager.getInstance().isMandatoryUserProperty(AssessmentToolConstants.usageIdentifyer, userPropertyHandler);
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, "select", true, "userProp-" + colIndex));
colIndex++;
}
if (element.hasAttemptsConfigured()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.attempts, "select"));
}
if (element.hasScoreConfigured()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.min, "select", new ScoreCellRenderer()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.max, "select", new ScoreCellRenderer()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.score, "select", new ScoreCellRenderer()));
}
if (element.hasPassedConfigured()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.passed, new PassedCellRenderer()));
}
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.assessmentStatus, new AssessmentStatusCellRenderer(getLocale())));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.initialLaunchDate, "select"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, IdentityCourseElementCols.lastModified, "select"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.lastUserModified, "select"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, IdentityCourseElementCols.lastCoachModified, "select"));
usersTableModel = new AssessedIdentityListTableModel(columnsModel, element);
usersTableModel.setCertificateMap(new ConcurrentHashMap<>());
tableEl = uifactory.addTableElement(getWindowControl(), "table", usersTableModel, 20, false, getTranslator(), formLayout);
tableEl.setExportEnabled(true);
tableEl.setSearchEnabled(new AssessedIdentityListProvider(getIdentity(), testEntry, testEntry, null, assessmentCallback), ureq.getUserSession());
List<FlexiTableFilter> filters = new ArrayList<>();
filters.add(new FlexiTableFilter(translate("filter.passed"), "passed"));
filters.add(new FlexiTableFilter(translate("filter.failed"), "failed"));
filters.add(new FlexiTableFilter(translate("filter.inProgress"), "inProgress"));
filters.add(new FlexiTableFilter(translate("filter.inReview"), "inReview"));
filters.add(new FlexiTableFilter(translate("filter.done"), "done"));
tableEl.setFilters("", filters, false);
if (assessmentCallback.canAssessBusinessGoupMembers()) {
List<BusinessGroup> coachedGroups;
if (assessmentCallback.isAdmin()) {
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
coachedGroups = businessGroupService.findBusinessGroups(params, testEntry, 0, -1);
} else {
coachedGroups = assessmentCallback.getCoachedGroups();
}
if (coachedGroups.size() > 0) {
List<FlexiTableFilter> groupFilters = new ArrayList<>();
for (BusinessGroup coachedGroup : coachedGroups) {
String groupName = StringHelper.escapeHtml(coachedGroup.getName());
groupFilters.add(new FlexiTableFilter(groupName, coachedGroup.getKey().toString(), "o_icon o_icon_group"));
}
tableEl.setExtendedFilterButton(translate("filter.groups"), groupFilters);
}
}
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class MyForumsWebService method getForums.
/**
* Retrieves a list of forums on a user base. All forums of groups
* where the user is participant/tutor + all forums in course where
* the user is a participant (owner, tutor or participant)
* @response.representation.200.qname {http://www.example.com}forumVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The forums
* @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param identityKey The key of the user (IdentityImpl)
* @param httpRequest The HTTP request
* @return The forums
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getForums(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
Roles roles;
Identity retrievedUser = getIdentity(httpRequest);
if (retrievedUser == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identityKey.equals(retrievedUser.getKey())) {
if (isAdmin(httpRequest)) {
retrievedUser = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
roles = BaseSecurityManager.getInstance().getRoles(retrievedUser);
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
} else {
roles = getRoles(httpRequest);
}
Map<Long, Long> groupNotified = new HashMap<Long, Long>();
Map<Long, Collection<Long>> courseNotified = new HashMap<Long, Collection<Long>>();
final Set<Long> subscriptions = new HashSet<Long>();
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = Collections.singletonList("Forum");
List<Subscriber> subs = man.getSubscribers(retrievedUser, notiTypes);
for (Subscriber sub : subs) {
String resName = sub.getPublisher().getResName();
Long forumKey = Long.parseLong(sub.getPublisher().getData());
subscriptions.add(forumKey);
if ("BusinessGroup".equals(resName)) {
Long groupKey = sub.getPublisher().getResId();
groupNotified.put(groupKey, forumKey);
} else if ("CourseModule".equals(resName)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new ArrayList<Long>());
}
courseNotified.get(courseKey).add(forumKey);
}
}
}
final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
for (Map.Entry<Long, Collection<Long>> e : courseNotified.entrySet()) {
final Long courseKey = e.getKey();
final Collection<Long> forumKeys = e.getValue();
final ICourse course = CourseFactory.loadCourse(courseKey);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
if (forumKeys.contains(forumVo.getForumKey())) {
forumVOs.add(forumVo);
}
}
}
}, new VisibleTreeFilter());
}
/*
RepositoryManager rm = RepositoryManager.getInstance();
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
repoParams.setOnlyExplicitMember(true);
List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
for(RepositoryEntry entry:entries) {
AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
if(result.isAccessible()) {
try {
final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if(node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode)node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
forumVOs.add(forumVo);
}
}
});
} catch (Exception e) {
log.error("", e);
}
}
}*/
// start found forums in groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
params.addTools(CollaborationTools.TOOL_FORUM);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
// list forum keys
List<Long> groupIds = new ArrayList<Long>();
Map<Long, BusinessGroup> groupsMap = new HashMap<Long, BusinessGroup>();
for (BusinessGroup group : groups) {
if (groupNotified.containsKey(group.getKey())) {
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(groupNotified.get(group.getKey()));
forumVo.setSubscribed(true);
forumVOs.add(forumVo);
groupIds.remove(group.getKey());
} else {
groupIds.add(group.getKey());
groupsMap.put(group.getKey(), group);
}
}
PropertyManager pm = PropertyManager.getInstance();
List<Property> forumProperties = pm.findProperties(OresHelper.calculateTypeName(BusinessGroup.class), groupIds, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
for (Property prop : forumProperties) {
Long forumKey = prop.getLongValue();
if (forumKey != null && groupsMap.containsKey(prop.getResourceTypeId())) {
BusinessGroup group = groupsMap.get(prop.getResourceTypeId());
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(prop.getLongValue());
forumVo.setSubscribed(false);
forumVOs.add(forumVo);
}
}
ForumVOes voes = new ForumVOes();
voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
voes.setTotalCount(forumVOs.size());
return Response.ok(voes).build();
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class PersistingCourseGroupManager method getOwnedBusinessGroups.
/**
* @see org.olat.course.groupsandrights.CourseGroupManager#getOwnedBusinessGroups(org.olat.core.id.Identity)
*/
@Override
public List<BusinessGroup> getOwnedBusinessGroups(Identity identity) {
if (identity == null)
return new ArrayList<>();
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
List<BusinessGroup> allGroups = businessGroupService.findBusinessGroups(params, getCourseEntry(), 0, -1);
return allGroups;
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class GroupOverviewController method updateModel.
/**
* @param ureq
* @param control
* @param identity
* @return
*/
private void updateModel() {
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
params.setIdentity(identity);
params.setOwner(true);
params.setAttendee(true);
params.setWaiting(true);
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
List<Long> groupKeysWithMembers;
if (groups.size() > 50) {
groupKeysWithMembers = null;
} else {
groupKeysWithMembers = new ArrayList<Long>(groups.size());
for (BusinessGroup view : groups) {
groupKeysWithMembers.add(view.getKey());
}
}
// retrieve all user's membership if there are more than 50 groups
List<BusinessGroupMembership> groupsAsOwner = businessGroupService.getBusinessGroupMembership(groupKeysWithMembers, identity);
Map<Long, BusinessGroupMembership> memberships = new HashMap<Long, BusinessGroupMembership>();
for (BusinessGroupMembership membership : groupsAsOwner) {
memberships.put(membership.getGroupKey(), membership);
}
List<GroupOverviewRow> items = new ArrayList<GroupOverviewRow>();
for (BusinessGroup group : groups) {
BusinessGroupMembership membership = memberships.get(group.getKey());
GroupOverviewRow tableItem = new GroupOverviewRow(group, membership, Boolean.TRUE);
items.add(tableItem);
}
tableDataModel.setEntries(items);
groupListCtr.modelChanged();
}
Aggregations