diff --git a/src/main/java/de/bps/olat/util/notifications/SubscriptionProviderImpl.java b/src/main/java/de/bps/olat/util/notifications/SubscriptionProviderImpl.java deleted file mode 100644 index 9b5a930b6407c93427b94c1e744320e27be18446..0000000000000000000000000000000000000000 --- a/src/main/java/de/bps/olat/util/notifications/SubscriptionProviderImpl.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * <a href="http://www.openolat.org"> - * OpenOLAT - Online Learning and Training</a><br> - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); <br> - * you may not use this file except in compliance with the License.<br> - * You may obtain a copy of the License at the - * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> - * <p> - * Unless required by applicable law or agreed to in writing,<br> - * software distributed under the License is distributed on an "AS IS" BASIS, <br> - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> - * See the License for the specific language governing permissions and <br> - * limitations under the License. - * <p> - * Initial code contributed and copyrighted by<br> - * BPS Bildungsportal Sachsen GmbH, http://www.bps-system.de - * <p> - */ -package de.bps.olat.util.notifications; - -import org.olat.commons.calendar.CalendarManager; -import org.olat.commons.calendar.ui.CalendarController; -import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; -import org.olat.core.CoreSpringFactory; -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.control.WindowControl; -import org.olat.core.id.OLATResourceable; -import org.olat.core.util.notifications.ContextualSubscriptionController; -import org.olat.core.util.notifications.PublisherData; -import org.olat.core.util.notifications.SubscriptionContext; -import org.olat.core.util.resource.OresHelper; -import org.olat.course.CourseFactory; -import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupService; - -/** - * - * Description:<br> - * Managed different subscription sources. - * - * <P> - * Initial Date: 29.04.2009 <br> - * @author bja - */ -public class SubscriptionProviderImpl implements SubscriptionProvider { - - private String caller; - private KalendarRenderWrapper kalendarRenderWrapper; - private SubscriptionContext subscriptionContext; - private OLATResourceable course; - private BusinessGroup businessGroup; - - public SubscriptionProviderImpl(KalendarRenderWrapper kalendarRenderWrapper) { - this.kalendarRenderWrapper = kalendarRenderWrapper; - this.caller = kalendarRenderWrapper.getKalendar().getType(); - this.subscriptionContext = setSubscriptionContext(); - } - - public SubscriptionProviderImpl(String caller, KalendarRenderWrapper kalendarRenderWrapper) { - this.kalendarRenderWrapper = kalendarRenderWrapper; - this.caller = caller; - this.subscriptionContext = setSubscriptionContext(); - } - - public SubscriptionProviderImpl(KalendarRenderWrapper kalendarRenderWrapper, OLATResourceable course) { - this.kalendarRenderWrapper = kalendarRenderWrapper; - this.caller = kalendarRenderWrapper.getKalendar().getType(); - this.course = course; - this.subscriptionContext = setSubscriptionContext(); - } - - private SubscriptionContext setSubscriptionContext() { - SubscriptionContext subsContext = null; - if (this.caller.equals(CalendarController.CALLER_COURSE) || this.caller.equals(CalendarManager.TYPE_COURSE)) { - if (course != null) { - subsContext = new SubscriptionContext(OresHelper.calculateTypeName(CalendarManager.class) + "." + CalendarManager.TYPE_COURSE, course.getResourceableId(), CalendarController.ACTION_CALENDAR_COURSE); - } else { - Long courseId = this.kalendarRenderWrapper.getLinkProvider().getControler().getCourseID(); - if (courseId != null) { - this.course = CourseFactory.loadCourse(courseId); - subsContext = new SubscriptionContext(OresHelper.calculateTypeName(CalendarManager.class) + "." + CalendarManager.TYPE_COURSE, this.kalendarRenderWrapper.getLinkProvider().getControler().getCourseID(), CalendarController.ACTION_CALENDAR_COURSE); - } - } - } - if (caller.equals(CalendarController.CALLER_COLLAB) || this.caller.equals(CalendarManager.TYPE_GROUP)) { - Long resId = this.kalendarRenderWrapper.getKalendarConfig().getResId(); - if (resId == null) resId = Long.parseLong(this.kalendarRenderWrapper.getKalendar().getCalendarID()); - if (resId != null) { - this.businessGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(resId); - if (businessGroup != null) { - subsContext = new SubscriptionContext(OresHelper.calculateTypeName(CalendarManager.class) + "." + CalendarManager.TYPE_GROUP, businessGroup.getResourceableId(), CalendarController.ACTION_CALENDAR_GROUP); - } - } - } - return subsContext; - } - - public ContextualSubscriptionController getContextualSubscriptionController(UserRequest ureq, WindowControl wControl) { - ContextualSubscriptionController csc = null; - if (getSubscriptionContext() != null) { - if ((caller.equals(CalendarController.CALLER_COURSE) || caller.equals(CalendarManager.TYPE_COURSE)) && course != null) { - String businessPath = wControl.getBusinessControl().getAsString(); - PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(CalendarManager.class), String.valueOf(course.getResourceableId()), businessPath); - csc = new ContextualSubscriptionController(ureq, wControl, getSubscriptionContext(), pdata); - } - if ((caller.equals(CalendarController.CALLER_COLLAB) || caller.equals(CalendarManager.TYPE_GROUP)) && businessGroup != null) { - String businessPath = wControl.getBusinessControl().getAsString(); - PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(CalendarManager.class), String.valueOf(businessGroup.getResourceableId()), businessPath); - csc = new ContextualSubscriptionController(ureq, wControl, getSubscriptionContext(), pdata); - } - } - return csc; - } - - public SubscriptionContext getSubscriptionContext() { - return this.subscriptionContext; - } - -} diff --git a/src/main/java/org/olat/collaboration/CollaborationTools.java b/src/main/java/org/olat/collaboration/CollaborationTools.java index c3475abc9491738c8ec6ff729e976e5bee6c747e..1835eda4f2c830c1eb274a11f327dffca3b80ed1 100644 --- a/src/main/java/org/olat/collaboration/CollaborationTools.java +++ b/src/main/java/org/olat/collaboration/CollaborationTools.java @@ -129,7 +129,8 @@ import org.olat.testutils.codepoints.server.Codepoint; * @author guido */ public class CollaborationTools implements Serializable { - + + private static final long serialVersionUID = -155629068939748789L; boolean dirty = false; private final static String TRUE = "true"; private final static String FALSE = "false"; @@ -419,16 +420,18 @@ public class CollaborationTools implements Serializable { // add linking List<OLATResource> resources = CoreSpringFactory.getImpl(BusinessGroupService.class).findResources(Collections.singleton(businessGroup), 0, -1); + + List<ICourse> courses = new ArrayList<ICourse>(resources.size()); for (OLATResource resource:resources) { if (resource.getResourceableTypeName().equals(CourseModule.getCourseTypeName())) { ICourse course = CourseFactory.loadCourse(resource); - CourseLinkProviderController clp = new CourseLinkProviderController(course, ureq, wControl); - calRenderWrapper.setLinkProvider(clp); - // for the time being only internal learning groups are supported, therefore we only get - // the first course reference. - break; + courses.add(course); } } + if(!courses.isEmpty()) { + CourseLinkProviderController clp = new CourseLinkProviderController(null, courses, ureq, wControl); + calRenderWrapper.setLinkProvider(clp); + } List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>(); calendars.add(calRenderWrapper); diff --git a/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml b/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml index a38cbdce2ba1450e5d4cd44018c0c8227aa2ca3a..dc4e52bbe93c1a9a340248be8c96de97ed63b7f7 100644 --- a/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml +++ b/src/main/java/org/olat/commons/calendar/_spring/calendarContext.xml @@ -42,4 +42,7 @@ <bean id="calendarImportJob" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="org.olat.commons.calendar.ImportCalendarJob" /> </bean> + + <bean id="calendarNotificationManager" class="org.olat.commons.calendar.notification.CalendarNotificationManagerImpl"> + </bean> </beans> \ No newline at end of file diff --git a/src/main/java/org/olat/commons/calendar/model/KalendarComparator.java b/src/main/java/org/olat/commons/calendar/model/KalendarComparator.java index a32a1f4c08387d65db48653d19f83cd18b48bd94..9e0675b56417c09c084e30d06039bc42b6a90718 100644 --- a/src/main/java/org/olat/commons/calendar/model/KalendarComparator.java +++ b/src/main/java/org/olat/commons/calendar/model/KalendarComparator.java @@ -30,15 +30,13 @@ import java.util.Comparator; import org.olat.commons.calendar.CalendarManager; import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; -public class KalendarComparator implements Comparator { +public class KalendarComparator implements Comparator<KalendarRenderWrapper> { private static final KalendarComparator INSTANCE = new KalendarComparator(); public static final KalendarComparator getInstance() { return INSTANCE; } - public int compare(Object arg0, Object arg1) { - KalendarRenderWrapper calendar0 = (KalendarRenderWrapper)arg0; - KalendarRenderWrapper calendar1 = (KalendarRenderWrapper)arg1; + public int compare(KalendarRenderWrapper calendar0, KalendarRenderWrapper calendar1) { // if of the same type, order by display name if (calendar0.getKalendar().getType() == calendar1.getKalendar().getType()) return calendar0.getKalendarConfig().getDisplayName().compareTo( diff --git a/src/main/java/de/bps/olat/util/notifications/SubscriptionProvider.java b/src/main/java/org/olat/commons/calendar/notification/CalendarNotificationManager.java similarity index 57% rename from src/main/java/de/bps/olat/util/notifications/SubscriptionProvider.java rename to src/main/java/org/olat/commons/calendar/notification/CalendarNotificationManager.java index c12f5e4487479d160664d7c667cb74aa12968a05..983326012bafe1a3606135e399062de2b50acbb2 100644 --- a/src/main/java/de/bps/olat/util/notifications/SubscriptionProvider.java +++ b/src/main/java/org/olat/commons/calendar/notification/CalendarNotificationManager.java @@ -14,27 +14,28 @@ * limitations under the License. * <p> * Initial code contributed and copyrighted by<br> - * BPS Bildungsportal Sachsen GmbH, http://www.bps-system.de + * frentix GmbH, http://www.frentix.com * <p> */ -package de.bps.olat.util.notifications; +package org.olat.commons.calendar.notification; -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.control.WindowControl; -import org.olat.core.util.notifications.ContextualSubscriptionController; +import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; +import org.olat.core.id.OLATResourceable; import org.olat.core.util.notifications.SubscriptionContext; +import org.olat.group.BusinessGroup; /** * - * Description:<br> - * Managed different subscription sources. - * - * <P> - * Initial Date: 29.04.2009 <br> - * @author bja + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com */ -public interface SubscriptionProvider { - public SubscriptionContext getSubscriptionContext(); +public interface CalendarNotificationManager { + + + public SubscriptionContext getSubscriptionContext(KalendarRenderWrapper courseCalendar); - public ContextualSubscriptionController getContextualSubscriptionController(UserRequest ureq, WindowControl wControl); + public SubscriptionContext getSubscriptionContext(KalendarRenderWrapper courseCalendar, OLATResourceable res); + + + public BusinessGroup getBusinessGroup(KalendarRenderWrapper wrapper); + } diff --git a/src/main/java/org/olat/commons/calendar/notification/CalendarNotificationManagerImpl.java b/src/main/java/org/olat/commons/calendar/notification/CalendarNotificationManagerImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..101483e684cf0fc62dd6ef33eae09f7e557aab68 --- /dev/null +++ b/src/main/java/org/olat/commons/calendar/notification/CalendarNotificationManagerImpl.java @@ -0,0 +1,89 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.commons.calendar.notification; + +import org.olat.commons.calendar.CalendarManager; +import org.olat.commons.calendar.ui.CalendarController; +import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; +import org.olat.core.CoreSpringFactory; +import org.olat.core.id.OLATResourceable; +import org.olat.core.util.notifications.SubscriptionContext; +import org.olat.core.util.resource.OresHelper; +import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupService; + +/** + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class CalendarNotificationManagerImpl implements CalendarNotificationManager { + + @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; + } + + @Override + public SubscriptionContext getSubscriptionContext(KalendarRenderWrapper kalendarRenderWrapper, OLATResourceable course) { + String caller = kalendarRenderWrapper.getKalendar().getType(); + + SubscriptionContext subsContext = null; + if (caller.equals(CalendarController.CALLER_COURSE) || caller.equals(CalendarManager.TYPE_COURSE)) { + subsContext = new SubscriptionContext(OresHelper.calculateTypeName(CalendarManager.class) + "." + CalendarManager.TYPE_COURSE, course.getResourceableId(), CalendarController.ACTION_CALENDAR_COURSE); + } else 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; + } + + @Override + public BusinessGroup getBusinessGroup(KalendarRenderWrapper kalendarRenderWrapper) { + String caller = kalendarRenderWrapper.getKalendar().getType(); + if (caller.equals(CalendarController.CALLER_COLLAB) || caller.equals(CalendarManager.TYPE_GROUP)) { + Long resId = kalendarRenderWrapper.getKalendarConfig().getResId(); + if (resId == null) resId = Long.parseLong(kalendarRenderWrapper.getKalendar().getCalendarID()); + if (resId != null) { + BusinessGroup businessGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(resId); + if (businessGroup != null) { + return businessGroup; + } + } + } + return null; + + } + + +} diff --git a/src/main/java/org/olat/commons/calendar/ui/CalendarController.java b/src/main/java/org/olat/commons/calendar/ui/CalendarController.java index e014accd4782eec240c9c1a0f7aedc1f63f0d536..85d8322a96708c9c5db4800e8f74178413eb2a89 100644 --- a/src/main/java/org/olat/commons/calendar/ui/CalendarController.java +++ b/src/main/java/org/olat/commons/calendar/ui/CalendarController.java @@ -29,6 +29,7 @@ package org.olat.commons.calendar.ui; import java.util.Date; import java.util.List; +import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; import org.olat.core.gui.control.Controller; public interface CalendarController extends Controller { @@ -59,14 +60,14 @@ public interface CalendarController extends Controller { * * @param calendars */ - public void setCalendars(List calendars); + public void setCalendars(List<KalendarRenderWrapper> calendars); /** * Sets the list of KalendarRenderWrappers for this calendar controller. * * @param calendars */ - public void setCalendars(List calendars, List importedCalendars); + public void setCalendars(List<KalendarRenderWrapper> calendars, List<KalendarRenderWrapper> importedCalendars); /** * Sets the calendar dirty. The calendar controller should diff --git a/src/main/java/org/olat/commons/calendar/ui/WeeklyCalendarController.java b/src/main/java/org/olat/commons/calendar/ui/WeeklyCalendarController.java index faa461eb9ebdd0eee5e4b368d340ebc906e5b169..568ec9787bf7c4ca2f9221026b554f1487aad882 100644 --- a/src/main/java/org/olat/commons/calendar/ui/WeeklyCalendarController.java +++ b/src/main/java/org/olat/commons/calendar/ui/WeeklyCalendarController.java @@ -40,12 +40,14 @@ import org.olat.commons.calendar.ImportCalendarManager; import org.olat.commons.calendar.model.Kalendar; import org.olat.commons.calendar.model.KalendarComparator; import org.olat.commons.calendar.model.KalendarEvent; +import org.olat.commons.calendar.notification.CalendarNotificationManager; import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; import org.olat.commons.calendar.ui.components.WeeklyCalendarComponent; import org.olat.commons.calendar.ui.events.KalendarGUIAddEvent; import org.olat.commons.calendar.ui.events.KalendarGUIEditEvent; import org.olat.commons.calendar.ui.events.KalendarGUIImportEvent; import org.olat.commons.calendar.ui.events.KalendarModifiedEvent; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.link.Link; @@ -72,13 +74,12 @@ import org.olat.core.util.coordinate.CoordinatorManager; import org.olat.core.util.event.GenericEventListener; import org.olat.core.util.notifications.ContextualSubscriptionController; import org.olat.core.util.notifications.NotificationsManager; +import org.olat.core.util.notifications.PublisherData; import org.olat.core.util.notifications.SubscriptionContext; import org.olat.core.util.resource.OresHelper; +import org.olat.group.BusinessGroup; import org.olat.util.logging.activity.LoggingResourceable; -import de.bps.olat.util.notifications.SubscriptionProvider; -import de.bps.olat.util.notifications.SubscriptionProviderImpl; - public class WeeklyCalendarController extends BasicController implements Activateable2, CalendarController, GenericEventListener { private static final String CMD_PREVIOUS_WEEK = "pw"; @@ -127,6 +128,8 @@ public class WeeklyCalendarController extends BasicController implements Activat private boolean modifiedCalenderDirty = false; private ILoggingAction calLoggingAction; + + private final CalendarNotificationManager calendarNotificationsManager; /** * Display week view of calendar. Add the calendars to be displayed via @@ -183,6 +186,8 @@ public class WeeklyCalendarController extends BasicController implements Activat setBasePackage(CalendarManager.class); + calendarNotificationsManager = CoreSpringFactory.getImpl(CalendarNotificationManager.class); + this.calendarWrappers = calendarWrappers; this.importedCalendarWrappers = importedCalendarWrappers; this.calendarSubscription = calendarSubscription; @@ -224,11 +229,10 @@ public class WeeklyCalendarController extends BasicController implements Activat // subscription, see OLAT-3861 if (!isGuest && !calendarWrappers.isEmpty()) { - SubscriptionProvider provider = new SubscriptionProviderImpl(caller, calendarWrappers.get(0)); - subsContext = provider.getSubscriptionContext(); + subsContext = calendarNotificationsManager.getSubscriptionContext(calendarWrappers.get(0)); // if sc is null, then no subscription is desired if (subsContext != null) { - csc = provider.getContextualSubscriptionController(ureq, getWindowControl()); + csc = getContextualSubscriptionController(ureq, calendarWrappers.get(0), subsContext); vcMain.put("calsubscription", csc.getInitialComponent()); } } @@ -259,6 +263,24 @@ public class WeeklyCalendarController extends BasicController implements Activat CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), OresHelper.lookupType(CalendarManager.class)); } + + private ContextualSubscriptionController getContextualSubscriptionController(UserRequest ureq, KalendarRenderWrapper kalendarRenderWrapper, SubscriptionContext context) { + String businessPath = getWindowControl().getBusinessControl().getAsString(); + if ((caller.equals(CalendarController.CALLER_COURSE) || caller.equals(CalendarManager.TYPE_COURSE))) { + Long courseId = kalendarRenderWrapper.getLinkProvider().getControler().getCourseId(); + + PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(CalendarManager.class), String.valueOf(courseId), businessPath); + return new ContextualSubscriptionController(ureq, getWindowControl(), context, pdata); + } + if ((caller.equals(CalendarController.CALLER_COLLAB) || caller.equals(CalendarManager.TYPE_GROUP))) { + BusinessGroup businessGroup = calendarNotificationsManager.getBusinessGroup(kalendarRenderWrapper); + if(businessGroup != null) { + PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(CalendarManager.class), String.valueOf(businessGroup.getResourceableId()), businessPath); + return new ContextualSubscriptionController(ureq, getWindowControl(), context, pdata); + } + } + return null; + } public void setEnableRemoveFromPersonalCalendar(boolean enable) { calendarConfig.setEnableRemoveFromPersonalCalendar(enable); @@ -301,11 +323,11 @@ public class WeeklyCalendarController extends BasicController implements Activat } } - public void setCalendars(List calendars) { - setCalendars(calendars, new ArrayList()); + public void setCalendars(List<KalendarRenderWrapper> calendars) { + setCalendars(calendars, new ArrayList<KalendarRenderWrapper>()); } - public void setCalendars(List calendars, List importedCalendars) { + public void setCalendars(List<KalendarRenderWrapper> calendars, List<KalendarRenderWrapper> importedCalendars) { this.calendarWrappers = calendars; Collections.sort(calendarWrappers, KalendarComparator.getInstance()); weeklyCalendar.setKalendars(calendarWrappers); @@ -315,7 +337,7 @@ public class WeeklyCalendarController extends BasicController implements Activat Collections.sort(calendarWrappers, KalendarComparator.getInstance()); Collections.sort(importedCalendarWrappers, KalendarComparator.getInstance()); - ArrayList allCalendarWrappers = new ArrayList(calendarWrappers); + List<KalendarRenderWrapper> allCalendarWrappers = new ArrayList<KalendarRenderWrapper>(calendarWrappers); allCalendarWrappers.addAll(importedCalendarWrappers); weeklyCalendar.setKalendars(allCalendarWrappers); @@ -353,7 +375,7 @@ public class WeeklyCalendarController extends BasicController implements Activat weeklyCalendar.setFocus(cal.get(Calendar.YEAR), cal.get(Calendar.WEEK_OF_YEAR)); } else if (source == searchLink) { - ArrayList allCalendarWrappers = new ArrayList(calendarWrappers); + List<KalendarRenderWrapper> allCalendarWrappers = new ArrayList<KalendarRenderWrapper>(calendarWrappers); allCalendarWrappers.addAll(importedCalendarWrappers); removeAsListenerAndDispose(searchController); @@ -502,17 +524,13 @@ public class WeeklyCalendarController extends BasicController implements Activat if (subsContext != null) { // group or course calendar -> prepared subscription context is the right one NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity()); - } else if(this.caller.equals(CALLER_HOME) && affectedCal != null) { + } else if(caller.equals(CALLER_HOME) && affectedCal != null) { // one can add/edit/remove dates of group and course calendars from the home calendar view -> choose right subscription context - KalendarRenderWrapper calWrapper = null; - for( Object calWrapperObj : calendarWrappers) { - calWrapper = (KalendarRenderWrapper) calWrapperObj; - if(affectedCal == calWrapper.getKalendar()) break; - } - if(calWrapper != null) { - SubscriptionProvider provider = new SubscriptionProviderImpl(calWrapper); - SubscriptionContext tmpSubsContext = provider.getSubscriptionContext(); - NotificationsManager.getInstance().markPublisherNews(tmpSubsContext, ureq.getIdentity()); + for( KalendarRenderWrapper calWrapper : calendarWrappers) { + if(affectedCal == calWrapper.getKalendar()) { + SubscriptionContext tmpSubsContext = calendarNotificationsManager.getSubscriptionContext(calWrapper); + NotificationsManager.getInstance().markPublisherNews(tmpSubsContext, ureq.getIdentity()); + } } } } diff --git a/src/main/java/org/olat/core/gui/components/tree/TreeEvent.java b/src/main/java/org/olat/core/gui/components/tree/TreeEvent.java index 6d17578bb6275d24f33ff8cbb994931d86b2b918..e837262d502d95881bf47f25a1d42c59d84fae5d 100644 --- a/src/main/java/org/olat/core/gui/components/tree/TreeEvent.java +++ b/src/main/java/org/olat/core/gui/components/tree/TreeEvent.java @@ -35,6 +35,7 @@ import org.olat.core.gui.control.Event; * @author Felix Jost */ public class TreeEvent extends Event { + private static final long serialVersionUID = -1303677873858926922L; /** * Comment for <code>COMMAND_TREENODE_CLICKED</code> */ @@ -62,7 +63,7 @@ public class TreeEvent extends Event { public static final TreeEvent CANCELLED_TREEEVENT = new TreeEvent(COMMAND_CANCELLED, ""); private String nodeId; - private List nodeIds; + private List<String> nodeIds; private String subCommand; /** @@ -84,7 +85,7 @@ public class TreeEvent extends Event { * @param command * @param nodeIds */ - public TreeEvent(String command, List nodeIds) { + public TreeEvent(String command, List<String> nodeIds) { this(command, null, nodeIds); } @@ -92,7 +93,7 @@ public class TreeEvent extends Event { * @param command * @param nodeIds */ - public TreeEvent(String command, String subCommand, List nodeIds) { + public TreeEvent(String command, String subCommand, List<String> nodeIds) { super(command); this.subCommand = subCommand; this.nodeIds = nodeIds; @@ -108,7 +109,7 @@ public class TreeEvent extends Event { /** * @return */ - public List getNodeIds() { + public List<String> getNodeIds() { return nodeIds; } diff --git a/src/main/java/org/olat/course/CourseFactory.java b/src/main/java/org/olat/course/CourseFactory.java index 89dad79142ec704e4574afa790a7738502189d41..b29fc84851ad305a3f4b942ad4b892d637ca1eda 100644 --- a/src/main/java/org/olat/course/CourseFactory.java +++ b/src/main/java/org/olat/course/CourseFactory.java @@ -43,6 +43,7 @@ import org.olat.basesecurity.Constants; import org.olat.basesecurity.SecurityGroup; import org.olat.commons.calendar.CalendarManager; import org.olat.commons.calendar.CalendarManagerFactory; +import org.olat.commons.calendar.notification.CalendarNotificationManager; import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; @@ -108,7 +109,6 @@ import org.olat.course.nodes.STCourseNode; import org.olat.course.nodes.TACourseNode; import org.olat.course.properties.CoursePropertyManager; import org.olat.course.properties.PersistingCoursePropertyManager; -import org.olat.course.repository.ImportCourseController; import org.olat.course.repository.ImportGlossaryReferencesController; import org.olat.course.repository.ImportSharedfolderReferencesController; import org.olat.course.run.RunMainController; @@ -130,9 +130,6 @@ import org.olat.resource.references.ReferenceManager; import org.olat.testutils.codepoints.server.Codepoint; import org.olat.util.logging.activity.LoggingResourceable; -import de.bps.olat.util.notifications.SubscriptionProvider; -import de.bps.olat.util.notifications.SubscriptionProviderImpl; - /** * Description: <BR> @@ -421,14 +418,14 @@ public class CourseFactory extends BasicManager { private static void clearCalenderSubscriptions(OLATResourceable res) { //set Publisher state to 1 (= ressource is deleted) for all calendars of the course CalendarManager calMan = CalendarManagerFactory.getInstance().getCalendarManager(); + CalendarNotificationManager notificationManager = CoreSpringFactory.getImpl(CalendarNotificationManager.class); NotificationsManager nfm = NotificationsManager.getInstance(); CourseGroupManager courseGroupManager = PersistingCourseGroupManager.getInstance(res); List<BusinessGroup> learningGroups = courseGroupManager.getAllBusinessGroups(); //all learning and right group calendars for (BusinessGroup bg : learningGroups) { KalendarRenderWrapper calRenderWrapper = calMan.getGroupCalendar(bg); - SubscriptionProvider subProvider = new SubscriptionProviderImpl(calRenderWrapper); - SubscriptionContext subsContext = subProvider.getSubscriptionContext(); + SubscriptionContext subsContext = notificationManager.getSubscriptionContext(calRenderWrapper); Publisher pub = nfm.getPublisher(subsContext); if (pub != null) { pub.setState(1); //int 0 is OK -> all other is not OK @@ -443,8 +440,7 @@ public class CourseFactory extends BasicManager { */ KalendarRenderWrapper courseCalendar = calMan.getCalendarForDeletion(res); if(courseCalendar != null) { - SubscriptionProvider subProvider = new SubscriptionProviderImpl(courseCalendar, res); - SubscriptionContext subContext = subProvider.getSubscriptionContext(); + SubscriptionContext subContext = notificationManager.getSubscriptionContext(courseCalendar, res); OLATResourceable oresToDelete = OresHelper.createOLATResourceableInstance(subContext.getResName(), subContext.getResId()); nfm.deletePublishersOf(oresToDelete); } diff --git a/src/main/java/org/olat/course/nodes/cal/CourseCalendars.java b/src/main/java/org/olat/course/nodes/cal/CourseCalendars.java index 189a272d4db07f670d4c9479d37f46ba70013a12..9d6c4b9a3cdbeed92fc7ef4c43a5451ad6856609 100644 --- a/src/main/java/org/olat/course/nodes/cal/CourseCalendars.java +++ b/src/main/java/org/olat/course/nodes/cal/CourseCalendars.java @@ -20,6 +20,7 @@ package org.olat.course.nodes.cal; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.olat.collaboration.CollaborationTools; @@ -119,7 +120,7 @@ public class CourseCalendars { KalendarRenderWrapper courseKalendarWrapper = getCourseCalendarWrapper(ureq, ores, ne); // add link provider ICourse course = CourseFactory.loadCourse(ores); - CourseLinkProviderController clpc = new CourseLinkProviderController(course, ureq, wControl); + CourseLinkProviderController clpc = new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl); courseKalendarWrapper.setLinkProvider(clpc); calendars.add(courseKalendarWrapper); diff --git a/src/main/java/org/olat/course/run/calendar/CourseCalendarController.java b/src/main/java/org/olat/course/run/calendar/CourseCalendarController.java index d50320c635248ea16680bd5a9e93e3f73554aca9..893a7709052f70e103904bf3037e49f009f63f64 100644 --- a/src/main/java/org/olat/course/run/calendar/CourseCalendarController.java +++ b/src/main/java/org/olat/course/run/calendar/CourseCalendarController.java @@ -26,6 +26,7 @@ package org.olat.course.run.calendar; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -42,7 +43,6 @@ import org.olat.commons.calendar.ui.events.KalendarModifiedEvent; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.control.Controller; -import org.olat.core.gui.control.DefaultController; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; @@ -64,7 +64,7 @@ public class CourseCalendarController extends BasicController { public CourseCalendarController(UserRequest ureq, WindowControl wControl, OLATResourceable course) { super(ureq, wControl); this.ores = course; - List calendars = getListOfCalendarWrappers(ureq); + List<KalendarRenderWrapper> calendars = getListOfCalendarWrappers(ureq); CourseCalendarSubscription calendarSubscription = new CourseCalendarSubscription( courseKalendarWrapper.getKalendar(), ureq.getUserSession().getGuiPreferences()); calendarController = new WeeklyCalendarController( @@ -73,8 +73,8 @@ public class CourseCalendarController extends BasicController { putInitialPanel(calendarController.getInitialComponent()); } - private List getListOfCalendarWrappers(UserRequest ureq) { - List calendars = new ArrayList(); + private List<KalendarRenderWrapper> getListOfCalendarWrappers(UserRequest ureq) { + List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>(); CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager(); // add course calendar ICourse course = CourseFactory.loadCourse(ores); @@ -93,7 +93,7 @@ public class CourseCalendarController extends BasicController { courseKalendarWrapper.getKalendarConfig().setVis(config.isVis()); } // add link provider - CourseLinkProviderController clpc = new CourseLinkProviderController(course, ureq, getWindowControl()); + CourseLinkProviderController clpc = new CourseLinkProviderController(course, Collections.<ICourse>singletonList(course), ureq, getWindowControl()); courseKalendarWrapper.setLinkProvider(clpc); calendars.add(courseKalendarWrapper); @@ -113,11 +113,11 @@ public class CourseCalendarController extends BasicController { return calendars; } - private void addCalendars(UserRequest ureq, List groups, boolean isOwner, LinkProvider linkProvider, List calendars) { + private void addCalendars(UserRequest ureq, List<BusinessGroup> groups, boolean isOwner, LinkProvider linkProvider, + List<KalendarRenderWrapper> calendars) { CollaborationToolsFactory collabFactory = CollaborationToolsFactory.getInstance(); CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager(); - for (Iterator iter = groups.iterator(); iter.hasNext();) { - BusinessGroup bGroup = (BusinessGroup) iter.next(); + for (BusinessGroup bGroup:groups) { CollaborationTools collabTools = collabFactory.getOrCreateCollaborationTools(bGroup); if (!collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) continue; KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup); @@ -147,7 +147,7 @@ public class CourseCalendarController extends BasicController { public void event(UserRequest ureq, Controller source, Event event) { if (event instanceof KalendarModifiedEvent) { - List calendars = getListOfCalendarWrappers(ureq); + List<KalendarRenderWrapper> calendars = getListOfCalendarWrappers(ureq); calendarController.setCalendars(calendars); } } diff --git a/src/main/java/org/olat/course/run/calendar/CourseLinkProviderController.java b/src/main/java/org/olat/course/run/calendar/CourseLinkProviderController.java index ce6ad4cf368e91cc6d883b3d8706f253c6d2db3d..ed838168f14ca8c1cf323cf59700b75cea2e0b4e 100644 --- a/src/main/java/org/olat/course/run/calendar/CourseLinkProviderController.java +++ b/src/main/java/org/olat/course/run/calendar/CourseLinkProviderController.java @@ -46,11 +46,11 @@ import org.olat.core.gui.control.ControllerEventListener; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; -import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; import org.olat.core.util.Util; +import org.olat.core.util.nodes.INode; import org.olat.core.util.resource.OresHelper; import org.olat.course.ICourse; import org.olat.course.nodes.CourseNode; @@ -64,11 +64,15 @@ public class CourseLinkProviderController extends BasicController implements Lin private VelocityContainer clpVC; private KalendarEvent kalendarEvent; private SelectionTree selectionTree; - private OLATResourceable ores; + private final OLATResourceable ores; + private final List<ICourse> availableCourses; + + public CourseLinkProviderController(ICourse course, List<ICourse> courses, UserRequest ureq, WindowControl wControl) { + super(ureq, wControl, Util.createPackageTranslator(CalendarManager.class, ureq.getLocale())); - public CourseLinkProviderController(ICourse course, UserRequest ureq, WindowControl wControl) { - super(ureq, wControl, new PackageTranslator(Util.getPackageName(CalendarManager.class), ureq.getLocale())); this.ores = course; + this.availableCourses = new ArrayList<ICourse>(courses); + setVelocityRoot(Util.getPackageVelocityRoot(CalendarManager.class)); clpVC = createVelocityContainer("calCLP"); selectionTree = new SelectionTree("clpTree", getTranslator()); @@ -77,11 +81,15 @@ public class CourseLinkProviderController extends BasicController implements Lin selectionTree.setAllowEmptySelection(true); selectionTree.setShowCancelButton(true); selectionTree.setFormButtonKey(CAL_LINKS_SUBMIT); - selectionTree.setTreeModel(new CourseNodeSelectionTreeModel(course)); + selectionTree.setTreeModel(new CourseNodeSelectionTreeModel(courses)); clpVC.put("tree", selectionTree); putInitialPanel(clpVC); } + public Long getCourseId() { + return ores.getResourceableId(); + } + public void event(UserRequest ureq, Component source, Event event) { if (source == selectionTree) { TreeEvent te = (TreeEvent)event; @@ -114,44 +122,50 @@ public class CourseLinkProviderController extends BasicController implements Lin } } - private void rebuildKalendarEventLinks(TreeNode node, List selectedNodeIDs, List kalendarEventLinks) { - if (selectedNodeIDs.contains(node.getIdent())) { + private void rebuildKalendarEventLinks(INode node, List<String> selectedNodeIDs, List<KalendarEventLink> kalendarEventLinks) { + if (selectedNodeIDs.contains(node.getIdent()) && node instanceof LinkTreeNode) { // assemble link - RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(ores, true); - OLATResourceable oresNode = OresHelper.createOLATResourceableInstance("CourseNode", Long.valueOf(node.getIdent())); - List<ContextEntry> ces = new ArrayList<ContextEntry>(); - ces.add(BusinessControlFactory.getInstance().createContextEntry(re)); - ces.add(BusinessControlFactory.getInstance().createContextEntry(oresNode)); - String extLink = BusinessControlFactory.getInstance().getAsURIString(ces, false); - KalendarEventLink link = new KalendarEventLink(COURSE_LINK_PROVIDER, node.getIdent(), node.getTitle(), extLink, node.getIconCssClass()); - kalendarEventLinks.add(link); - node.setSelected(true); + LinkTreeNode treeNode = (LinkTreeNode)node; + OLATResourceable courseOres = treeNode.getCourse(); + if(courseOres != null) { + RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(courseOres, true); + List<ContextEntry> ces = new ArrayList<ContextEntry>(); + ces.add(BusinessControlFactory.getInstance().createContextEntry(re)); + if(treeNode.getCourseNode() != null) { + String courseNodeId = treeNode.getCourseNode().getIdent(); + OLATResourceable oresNode = OresHelper.createOLATResourceableInstance("CourseNode", Long.valueOf(courseNodeId)); + ces.add(BusinessControlFactory.getInstance().createContextEntry(oresNode)); + } + String extLink = BusinessControlFactory.getInstance().getAsURIString(ces, false); + KalendarEventLink link = new KalendarEventLink(COURSE_LINK_PROVIDER, node.getIdent(), treeNode.getTitle(), extLink, treeNode.getIconCssClass()); + kalendarEventLinks.add(link); + treeNode.setSelected(true); + } } for (int i = 0; i < node.getChildCount(); i++) { - rebuildKalendarEventLinks((TreeNode)node.getChildAt(i), selectedNodeIDs, kalendarEventLinks); + rebuildKalendarEventLinks(node.getChildAt(i), selectedNodeIDs, kalendarEventLinks); } } protected void doDispose() { - // TODO Auto-generated method stub + // } public CourseLinkProviderController getControler() { return this; } - public Long getCourseID() { - return ores.getResourceableId(); - } - public void setKalendarEvent(KalendarEvent kalendarEvent) { this.kalendarEvent = kalendarEvent; clearSelection(selectionTree.getTreeModel().getRootNode()); - for (Iterator iter = kalendarEvent.getKalendarEventLinks().iterator(); iter.hasNext();) { - KalendarEventLink link = (KalendarEventLink) iter.next(); + for (KalendarEventLink link: kalendarEvent.getKalendarEventLinks()) { if (!link.getProvider().equals(COURSE_LINK_PROVIDER)) continue; String nodeId = link.getId(); TreeNode node = selectionTree.getTreeModel().getNodeById(nodeId); + if(node == null) { + nodeId = availableCourses.get(0).getResourceableId() + "_" + nodeId; + node = selectionTree.getTreeModel().getNodeById(nodeId); + } if (node != null) { node.setSelected(true); } @@ -182,24 +196,61 @@ public class CourseLinkProviderController extends BasicController implements Lin super.addControllerListener(controller); } -} + private static class CourseNodeSelectionTreeModel extends GenericTreeModel { + private static final long serialVersionUID = -7863033366847344767L; -class CourseNodeSelectionTreeModel extends GenericTreeModel { - - public CourseNodeSelectionTreeModel(ICourse course) { - setRootNode(buildTree(course.getRunStructure().getRootNode())); - } + public CourseNodeSelectionTreeModel(List<ICourse> courses) { + if(courses.size() == 1) { + ICourse course = courses.get(0); + setRootNode(buildTree(course, course.getRunStructure().getRootNode())); + } else { + LinkTreeNode rootNode = new LinkTreeNode("", null, null); + for(ICourse course:courses) { + LinkTreeNode node = new LinkTreeNode(course.getCourseTitle(), course, null); + node.setAltText(course.getCourseTitle()); + node.setIdent(course.getResourceableId().toString()); + node.setIconCssClass("o_CourseModule_icon"); - private GenericTreeNode buildTree(CourseNode courseNode) { - GenericTreeNode node = new GenericTreeNode(courseNode.getShortTitle(), null); - node.setAltText(courseNode.getLongTitle()); - node.setIdent(courseNode.getIdent()); - node.setIconCssClass("o_" + courseNode.getType() + "_icon"); - for (int i = 0; i < courseNode.getChildCount(); i++) { - CourseNode childNode = (CourseNode)courseNode.getChildAt(i); - node.addChild(buildTree(childNode)); + LinkTreeNode childNode = buildTree(course, course.getRunStructure().getRootNode()); + node.addChild(childNode); + rootNode.addChild(node); + } + setRootNode(rootNode); + } + } + + private LinkTreeNode buildTree(ICourse course, CourseNode courseNode) { + LinkTreeNode node = new LinkTreeNode(courseNode.getShortTitle(), course, courseNode); + node.setAltText(courseNode.getLongTitle()); + node.setIdent(course.getResourceableId() + "_" + courseNode.getIdent()); + node.setIconCssClass("o_" + courseNode.getType() + "_icon"); + node.setUserObject(course); + for (int i = 0; i < courseNode.getChildCount(); i++) { + CourseNode childNode = (CourseNode)courseNode.getChildAt(i); + node.addChild(buildTree(course, childNode)); + } + return node; } - return node; } + private static class LinkTreeNode extends GenericTreeNode { + private static final long serialVersionUID = -6043669089871217496L; + private final ICourse course; + private final CourseNode courseNode; + + public LinkTreeNode(String title, ICourse course, CourseNode courseNode) { + super(title, null); + + this.course = course; + this.courseNode = courseNode; + } + + public ICourse getCourse() { + return course; + } + + public CourseNode getCourseNode() { + return courseNode; + } + } } \ No newline at end of file diff --git a/src/main/java/org/olat/home/HomeCalendarController.java b/src/main/java/org/olat/home/HomeCalendarController.java index c38b4893c4d823668c1e7c86395bc650020b5fe1..c6ef0dd6685e899249710754cc8abfedae3e4e84 100644 --- a/src/main/java/org/olat/home/HomeCalendarController.java +++ b/src/main/java/org/olat/home/HomeCalendarController.java @@ -26,6 +26,7 @@ package org.olat.home; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -172,7 +173,7 @@ public class HomeCalendarController extends BasicController implements Activatea courseCalendarWrapper.getKalendarConfig().setCss(courseKalendarConfig.getCss()); courseCalendarWrapper.getKalendarConfig().setVis(courseKalendarConfig.isVis()); } - courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, ureq, wControl)); + courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl)); calendars.add(courseCalendarWrapper); } catch (CorruptedCourseException e) { log.error("Corrupted course: " + courseResourceableID, null);