use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class CourseLeaveDialogBoxController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
StringBuilder groupToLeaveNames = new StringBuilder();
for (BusinessGroup group : groupsToLeave) {
if (groupToLeaveNames.length() > 0)
groupToLeaveNames.append(", ");
groupToLeaveNames.append(group.getName());
}
StringBuilder repoEntryToLeaveNames = new StringBuilder();
for (RepositoryEntry entry : repoEntriesToLeave) {
if (repoEntryToLeaveNames.length() > 0)
repoEntryToLeaveNames.append(", ");
repoEntryToLeaveNames.append(entry.getDisplayname());
}
String identityName = UserManager.getInstance().getUserDisplayName(leavingIdentity);
String leaveText;
if (groupsToLeave.isEmpty()) {
leaveText = translate("unsubscribe.text", new String[] { identityName, repoEntryToLeaveNames.toString() });
} else {
leaveText = translate("unsubscribe.withgroups.text", new String[] { identityName, repoEntryToLeaveNames.toString(), groupToLeaveNames.toString() });
}
uifactory.addStaticTextElement("leaving.desc", null, leaveText, formLayout);
String[] values = new String[] { translate("dialog.modal.bg.mail.text") };
sendMail = uifactory.addCheckboxesHorizontal("send.mail", null, formLayout, keys, values);
if (!groupsToDelete.isEmpty()) {
String deletMsg = translate("unsubscribe.group.del");
uifactory.addStaticTextElement("delete.desc", null, deletMsg, formLayout);
String[] delValues = new String[] { translate("group.delete.confirmation") };
groupDeleteEl = uifactory.addCheckboxesHorizontal("group.del", null, formLayout, keys, delValues);
groupDeleteEl.select(keys[0], true);
}
FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsContainer.setRootForm(mainForm);
formLayout.add(buttonsContainer);
uifactory.addFormSubmitButton("deleteButton", "ok", buttonsContainer);
uifactory.addFormCancelButton("cancel", buttonsContainer, ureq, getWindowControl());
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class CalendarNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
// can't be loaded when already deleted
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
Long id = p.getResId();
String type = p.getSubidentifier();
try {
Translator translator = Util.createPackageTranslator(CalendarModule.class, locale);
String calType = null;
String title = null;
if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
calType = CalendarManager.TYPE_COURSE;
title = translator.translate("cal.notifications.header.course", new String[] { displayName });
} else if (type.equals(CalendarController.ACTION_CALENDAR_GROUP)) {
BusinessGroup group = businessGroupDao.load(id);
calType = CalendarManager.TYPE_GROUP;
if (group == null) {
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate("cal.notifications.header.group", new String[] { group.getName() });
}
if (calType != null) {
Formatter form = Formatter.getInstance(locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_CALENDAR_ICON), null);
String bPath;
if (StringHelper.containsNonWhitespace(p.getBusinessPath())) {
bPath = p.getBusinessPath();
} else if ("CalendarManager.course".equals(p.getResName())) {
try {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.getCourseTypeName(), p.getResId());
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(ores, true);
// Fallback
bPath = "[RepositoryEntry:" + re.getKey() + "]";
} catch (Exception e) {
log.error("Error processing calendar notifications of publisher:" + p.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
} else {
// cannot make link without business path
return notificationsManager.getNoSubscriptionInfo();
}
Kalendar cal = calendarManager.getCalendar(calType, id.toString());
Collection<KalendarEvent> calEvents = cal.getEvents();
for (KalendarEvent kalendarEvent : calEvents) {
if (showEvent(compareDate, kalendarEvent)) {
log.debug("found a KalendarEvent: " + kalendarEvent.getSubject() + " with time: " + kalendarEvent.getBegin() + " modified before: " + compareDate.toString(), null);
// found a modified event in this calendar
Date modDate = null;
if (kalendarEvent.getLastModified() > 0) {
modDate = new Date(kalendarEvent.getLastModified());
} else if (kalendarEvent.getCreated() > 0) {
modDate = new Date(kalendarEvent.getCreated());
} else if (kalendarEvent.getBegin() != null) {
modDate = kalendarEvent.getBegin();
}
String subject = kalendarEvent.getSubject();
String author = kalendarEvent.getCreatedBy();
if (author == null)
author = "";
String location = "";
if (StringHelper.containsNonWhitespace(kalendarEvent.getLocation())) {
location = kalendarEvent.getLocation() == null ? "" : translator.translate("cal.notifications.location", new String[] { kalendarEvent.getLocation() });
}
String dateStr;
if (kalendarEvent.isAllDayEvent()) {
dateStr = form.formatDate(kalendarEvent.getBegin());
} else {
dateStr = form.formatDate(kalendarEvent.getBegin()) + " - " + form.formatDate(kalendarEvent.getEnd());
}
String desc = translator.translate("cal.notifications.entry", new String[] { subject, dateStr, location, author });
String businessPath = bPath + "[path=" + kalendarEvent.getID() + ":0]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_CALENDAR_ICON);
si.addSubscriptionListItem(subListItem);
}
}
}
} catch (Exception e) {
log.error("Unexpected exception", e);
checkPublisher(p);
si = notificationsManager.getNoSubscriptionInfo();
}
} else {
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class CalendarNotificationHandler method checkPublisher.
private void checkPublisher(Publisher p) {
try {
if (CalendarController.ACTION_CALENDAR_GROUP.equals(p.getSubidentifier())) {
BusinessGroup bg = businessGroupDao.load(p.getResId());
if (bg == null) {
log.info("deactivating publisher with key; " + p.getKey(), null);
notificationsManager.deactivate(p);
}
} else if (CalendarController.ACTION_CALENDAR_COURSE.equals(p.getSubidentifier())) {
if (!NotificationsUpgradeHelper.checkCourse(p)) {
log.info("deactivating publisher with key; " + p.getKey(), null);
notificationsManager.deactivate(p);
}
}
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class CalendarNotificationManagerImpl method getSubscriptionContext.
@Override
public SubscriptionContext getSubscriptionContext(KalendarRenderWrapper kalendarRenderWrapper) {
String caller = kalendarRenderWrapper.getKalendar().getType();
SubscriptionContext subsContext = null;
if (caller.equals(CalendarController.CALLER_COURSE) || caller.equals(CalendarManager.TYPE_COURSE)) {
Long courseId = kalendarRenderWrapper.getLinkProvider().getControler().getCourseId();
subsContext = new SubscriptionContext(OresHelper.calculateTypeName(CalendarManager.class) + "." + CalendarManager.TYPE_COURSE, courseId, CalendarController.ACTION_CALENDAR_COURSE);
}
if (caller.equals(CalendarController.CALLER_COLLAB) || caller.equals(CalendarManager.TYPE_GROUP)) {
BusinessGroup businessGroup = getBusinessGroup(kalendarRenderWrapper);
if (businessGroup != null) {
subsContext = new SubscriptionContext(OresHelper.calculateTypeName(CalendarManager.class) + "." + CalendarManager.TYPE_GROUP, businessGroup.getResourceableId(), CalendarController.ACTION_CALENDAR_GROUP);
}
}
return subsContext;
}
use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.
the class ImportToCalendarManager method check.
private boolean check(ImportedToCalendar importedToCalendar) {
String id = importedToCalendar.getToCalendarId();
String type = importedToCalendar.getToType();
if (CalendarManager.TYPE_USER.equals(type)) {
Identity identity = securityManager.findIdentityByNameCaseInsensitive(id);
return identity != null && identity.getStatus() != null && identity.getStatus().intValue() < Identity.STATUS_DELETED;
}
if (CalendarManager.TYPE_COURSE.equals(type)) {
Long resourceId = new Long(id);
RepositoryEntry entry = repositoryEntryDao.loadByResourceId("CourseModule", resourceId);
return entry != null;
}
if (CalendarManager.TYPE_GROUP.equals(type)) {
Long resourceId = new Long(id);
BusinessGroup group = businessGroupDao.loadByResourceId(resourceId);
return group != null;
}
return true;
}
Aggregations