use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.
the class GoToMeetingCourseNode method isCoach.
private final boolean isCoach(RepositoryEntry re, Identity identity) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
int count = bgs.countBusinessGroups(params, re);
return count > 0;
}
use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.
the class HomeCalendarManager method appendGroupCalendars.
private void appendGroupCalendars(Identity identity, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
// get group calendars
if (calendarModule.isEnableGroupCalendar()) {
SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(identity, true, false);
groupParams.addTools(CollaborationTools.TOOL_CALENDAR);
List<BusinessGroup> ownerGroups = businessGroupService.findBusinessGroups(groupParams, null, 0, -1);
addCalendars(ownerGroups, true, false, calendars, configMap);
SearchBusinessGroupParams groupParams2 = new SearchBusinessGroupParams(identity, false, true);
groupParams2.addTools(CollaborationTools.TOOL_CALENDAR);
List<BusinessGroup> attendedGroups = businessGroupService.findBusinessGroups(groupParams2, null, 0, -1);
attendedGroups.removeAll(ownerGroups);
addCalendars(attendedGroups, false, true, calendars, configMap);
}
}
use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.
the class EditLectureBlockController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_repo_edit_lecture_form");
if (lectureBlock != null && StringHelper.containsNonWhitespace(lectureBlock.getManagedFlagsString())) {
setFormWarning("form.managedflags.intro.short", null);
}
String title = lectureBlock == null ? null : lectureBlock.getTitle();
titleEl = uifactory.addTextElement("title", "lecture.title", 128, title, formLayout);
titleEl.setElementCssClass("o_sel_repo_lecture_title");
titleEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.title));
titleEl.setMandatory(true);
plannedLecturesEl = uifactory.addDropdownSingleselect("planned.lectures", "planned.lectures", formLayout, plannedLecturesKeys, plannedLecturesKeys, null);
plannedLecturesEl.setMandatory(true);
String plannedlectures = lectureBlock == null ? "4" : Integer.toString(lectureBlock.getPlannedLecturesNumber());
for (String plannedLecturesKey : plannedLecturesKeys) {
if (plannedlectures.equals(plannedLecturesKey)) {
plannedLecturesEl.select(plannedLecturesKey, true);
break;
}
}
// freeze it after roll call done
boolean plannedLecturesEditable = (lectureBlock == null || (lectureBlock.getStatus() != LectureBlockStatus.done && lectureBlock.getRollCallStatus() != LectureRollCallStatus.closed && lectureBlock.getRollCallStatus() != LectureRollCallStatus.autoclosed)) && !lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.plannedLectures);
plannedLecturesEl.setEnabled(plannedLecturesEditable);
String[] onValues = new String[] { "" };
boolean compulsory = lectureBlock == null ? true : lectureBlock.isCompulsory();
compulsoryEl = uifactory.addCheckboxesVertical("compulsory", "lecture.compulsory", formLayout, onKeys, onValues, 1);
compulsoryEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.compulsory));
compulsoryEl.addActionListener(FormEvent.ONCHANGE);
if (compulsory) {
compulsoryEl.select(onKeys[0], true);
}
List<Identity> coaches = repositoryService.getMembers(entry, GroupRoles.coach.name());
teacherKeys = new String[coaches.size() + 1];
teacherValues = new String[coaches.size() + 1];
for (int i = coaches.size() + 1; i-- > 1; ) {
Identity coach = coaches.get(i - 1);
teacherKeys[i] = coach.getKey().toString();
teacherValues[i] = userManager.getUserDisplayName(coach);
}
teacherKeys[0] = "-";
teacherValues[0] = translate("no.teachers");
teacherEl = uifactory.addCheckboxesVertical("teacher", "lecture.teacher", formLayout, teacherKeys, teacherValues, 2);
teacherEl.setElementCssClass("o_sel_repo_lecture_teachers");
teacherEl.setMandatory(true);
teacherEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.teachers));
boolean found = false;
if (teachers != null && teachers.size() > 0) {
for (Identity teacher : teachers) {
String currentTeacherKey = teacher.getKey().toString();
for (String teacherKey : teacherKeys) {
if (currentTeacherKey.equals(teacherKey)) {
teacherEl.select(currentTeacherKey, true);
found = true;
}
}
}
}
if (!found) {
teacherEl.select(teacherKeys[0], true);
}
Group entryBaseGroup = repositoryService.getDefaultGroup(entry);
groupBox = new ArrayList<>();
groupBox.add(new GroupBox(entry, entryBaseGroup));
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
List<BusinessGroup> businessGroups = businessGroupService.findBusinessGroups(params, entry, 0, -1, BusinessGroupOrder.nameAsc);
for (BusinessGroup businessGroup : businessGroups) {
groupBox.add(new GroupBox(businessGroup));
}
String[] groupKeys = new String[groupBox.size()];
String[] groupValues = new String[groupBox.size()];
for (int i = groupBox.size(); i-- > 0; ) {
groupKeys[i] = Integer.toString(i);
groupValues[i] = groupBox.get(i).getName();
}
groupsEl = uifactory.addCheckboxesVertical("lecture.groups", "lecture.groups", formLayout, groupKeys, groupValues, 2);
groupsEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.groups));
groupsEl.setMandatory(true);
if (lectureBlock != null) {
List<Group> selectedGroups = lectureService.getLectureBlockToGroups(lectureBlock);
for (int i = 0; i < groupBox.size(); i++) {
if (selectedGroups.contains(groupBox.get(i).getBaseGroup())) {
groupsEl.select(Integer.toString(i), true);
}
}
} else if (groupKeys.length == 1) {
groupsEl.select(groupKeys[0], true);
}
String description = lectureBlock == null ? "" : lectureBlock.getDescription();
descriptionEl = uifactory.addTextAreaElement("lecture.descr", 4, 72, description, formLayout);
descriptionEl.setElementCssClass("o_sel_repo_lecture_description");
descriptionEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.description));
String preparation = lectureBlock == null ? "" : lectureBlock.getPreparation();
preparationEl = uifactory.addTextAreaElement("lecture.preparation", 4, 72, preparation, formLayout);
preparationEl.setElementCssClass("o_sel_repo_lecture_preparation");
preparationEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.preparation));
String location = lectureBlock == null ? "" : lectureBlock.getLocation();
locationEl = uifactory.addTextElementWithAutoCompleter("location", "lecture.location", 128, location, formLayout);
locationEl.setElementCssClass("o_sel_repo_lecture_location");
locationEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.location));
locationEl.setListProvider(new LocationListProvider(), ureq.getUserSession());
locationEl.setMinLength(1);
Date startDate = lectureBlock == null ? null : lectureBlock.getStartDate();
dateEl = uifactory.addDateChooser("lecture.date", startDate, formLayout);
dateEl.setElementCssClass("o_sel_repo_lecture_date");
dateEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
dateEl.setDomReplacementWrapperRequired(false);
dateEl.setMandatory(true);
String datePage = velocity_root + "/date_start_end.html";
FormLayoutContainer dateCont = FormLayoutContainer.createCustomFormLayout("start_end", getTranslator(), datePage);
dateCont.setLabel("lecture.time", null);
formLayout.add(dateCont);
startHourEl = uifactory.addTextElement("lecture.start.hour", null, 2, "", dateCont);
startHourEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
startHourEl.setDomReplacementWrapperRequired(false);
startHourEl.setDisplaySize(2);
startHourEl.setMandatory(true);
startMinuteEl = uifactory.addTextElement("lecture.start.minute", null, 2, "", dateCont);
startMinuteEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
startMinuteEl.setDomReplacementWrapperRequired(false);
startMinuteEl.setDisplaySize(2);
endHourEl = uifactory.addTextElement("lecture.end.hour", null, 2, "", dateCont);
endHourEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
endHourEl.setDomReplacementWrapperRequired(false);
endHourEl.setDisplaySize(2);
endHourEl.setMandatory(true);
endMinuteEl = uifactory.addTextElement("lecture.end.minute", null, 2, "", dateCont);
endMinuteEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
endMinuteEl.setDomReplacementWrapperRequired(false);
endMinuteEl.setDisplaySize(2);
if (lectureBlock != null) {
Calendar cal = Calendar.getInstance();
if (lectureBlock.getStartDate() != null) {
cal.setTime(lectureBlock.getStartDate());
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
startHourEl.setValue(Integer.toString(hour));
startMinuteEl.setValue(formatMinute(minute));
}
if (lectureBlock.getEndDate() != null) {
cal.setTime(lectureBlock.getEndDate());
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
endHourEl.setValue(Integer.toString(hour));
endMinuteEl.setValue(formatMinute(minute));
}
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
uifactory.addFormSubmitButton("save", buttonsCont);
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class UserFoldersWebService method getFolders.
/**
* Retrieves a list of folders on a user base. All folders of groups
* where the user is participant/tutor + all folders in course where
* the user is a participant (owner, tutor or participant)
* @response.representation.200.qname {http://www.example.com}folderVOes
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The folders
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
* @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 folders
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFolders(@Context HttpServletRequest httpRequest) {
Roles roles;
Identity ureqIdentity = getIdentity(httpRequest);
if (ureqIdentity == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identity.getKey().equals(ureqIdentity.getKey())) {
if (isAdmin(httpRequest)) {
ureqIdentity = identity;
roles = BaseSecurityManager.getInstance().getRoles(identity);
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
} else {
roles = getRoles(httpRequest);
}
final Map<Long, Long> groupNotified = new HashMap<Long, Long>();
final Map<Long, Collection<String>> courseNotified = new HashMap<Long, Collection<String>>();
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = Collections.singletonList("FolderModule");
List<Subscriber> subs = man.getSubscribers(ureqIdentity, notiTypes);
for (Subscriber sub : subs) {
String resName = sub.getPublisher().getResName();
if ("BusinessGroup".equals(resName)) {
Long groupKey = sub.getPublisher().getResId();
groupNotified.put(groupKey, sub.getPublisher().getResId());
} else if ("CourseModule".equals(resName)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new ArrayList<String>());
}
courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
}
}
}
final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(ureqIdentity, roles);
for (Map.Entry<Long, Collection<String>> e : courseNotified.entrySet()) {
final Long courseKey = e.getKey();
final Collection<String> nodeKeys = e.getValue();
final ICourse course = CourseFactory.loadCourse(courseKey);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) node;
if (nodeKeys.contains(bcNode.getIdent())) {
FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
folderVOs.add(folder);
}
}
}
}, 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 BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode)node;
FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
folderVOs.add(folder);
}
}
});
} catch (Exception e) {
log.error("", e);
}
}
}*/
// start found forums in groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(ureqIdentity, true, true);
params.addTools(CollaborationTools.TOOL_FOLDER);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
for (BusinessGroup group : groups) {
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
VFSContainer container = tools.getSecuredFolder(group, null, ureqIdentity, false);
FolderVO folderVo = new FolderVO();
folderVo.setName(group.getName());
folderVo.setGroupKey(group.getKey());
folderVo.setSubscribed(groupNotified.containsKey(group.getKey()));
folderVo.setRead(container.getLocalSecurityCallback().canRead());
folderVo.setList(container.getLocalSecurityCallback().canList());
folderVo.setWrite(container.getLocalSecurityCallback().canWrite());
folderVo.setDelete(container.getLocalSecurityCallback().canDelete());
folderVOs.add(folderVo);
}
FolderVOes voes = new FolderVOes();
voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
voes.setTotalCount(folderVOs.size());
return Response.ok(voes).build();
}
use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.
the class RepositoryServiceImplTest method deleteCourseSoftly.
@Test
public void deleteCourseSoftly() {
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
Identity coachGroup = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-del-1");
RepositoryEntry re = JunitTestHelper.deployDemoCourse(initialAuthor);
dbInstance.commitAndCloseSession();
// add business group
BusinessGroup group = businessGroupService.createBusinessGroup(coachGroup, "Relation 1", "tg", null, null, false, false, re);
businessGroupService.addResourceTo(group, re);
dbInstance.commit();
// catalog
List<CatalogEntry> rootEntries = catalogManager.getRootCatalogEntries();
CatalogEntry catEntry = catalogManager.createCatalogEntry();
catEntry.setName("Soft");
catEntry.setRepositoryEntry(re);
catEntry.setParent(rootEntries.get(0));
catEntry.setOwnerGroup(securityManager.createAndPersistSecurityGroup());
catalogManager.saveCatalogEntry(catEntry);
dbInstance.commit();
// check the catalog
List<CatalogEntry> catEntries = catalogManager.getCatalogCategoriesFor(re);
Assert.assertNotNull(catEntries);
Assert.assertEquals(1, catEntries.size());
// add owner, coach...
repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
dbInstance.commit();
// kill it softly like A. Keys
repositoryService.deleteSoftly(re, initialAuthor, false);
dbInstance.commit();
// check that the members are removed
List<Identity> coachAndParticipants = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.both, GroupRoles.coach.name(), GroupRoles.participant.name());
Assert.assertNotNull(coachAndParticipants);
Assert.assertEquals(0, coachAndParticipants.size());
// check the relations between course and business groups
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, re, 0, -1);
Assert.assertNotNull(groups);
Assert.assertEquals(0, groups.size());
// check the catalog
List<CatalogEntry> removedCatEntries = catalogManager.getCatalogCategoriesFor(re);
Assert.assertNotNull(removedCatEntries);
Assert.assertEquals(0, removedCatEntries.size());
RepositoryEntry reloadEntry = repositoryService.loadByKey(re.getKey());
Assert.assertNotNull(reloadEntry);
Assert.assertEquals(0, reloadEntry.getAccess());
Assert.assertNotNull(reloadEntry.getDeletionDate());
Assert.assertEquals(initialAuthor, reloadEntry.getDeletedBy());
}
Aggregations