#862: CalendarLegacyFilter.kt

projectforge-business/src/main/kotlin/org/projectforge/business/calendar/CalendarLegacyFilter.kt Type: Kotlin class (migration utility)
Purpose: Migrates calendar preferences from ProjectForge v6 (Wicket) to the v7+ calendar system
Source path: projectforge-business/src/main/kotlin/org/projectforge/business/calendar/CalendarLegacyFilter.kt
File annotation: @file:Suppress("DEPRECATION") 97 lines · 47 code · 43 comments · 7 blank

CalendarLegacyFilter is a one-shot migration class that reads the old Wicket-based calendar filter preferences (stored as TeamCalCalendarFilter in t_user_xml_prefs under key "TeamCalendarPage.userPrefs") and converts them into the modern calendar data structures: CalendarFilterState, Favorites<CalendarFilter>, CalendarStyleMap, and a default CalendarFilter. This enables seamless upgrades from ProjectForge v6 to v7+ without users losing their calendar settings.

Constructor

The class holds all migrated data as constructor properties:

PropertyTypeDescription
stateCalendarFilterStateThe user's last view state (date range and view type).
listFavorites<CalendarFilter>The migrated list of named calendar filters (favorites).
currentCalendarFilterThe currently active filter after migration (derived from the old active template).
styleMapCalendarStyleMapColor/display styles for each calendar, inferred from the old template entries.

Companion Object — Migration Entry Point

migrate(userXmlPreferenceService: UserXmlPreferencesService): CalendarLegacyFilter?

The primary entry point. Steps:

  1. Retrieves the old TeamCalCalendarFilter from userXmlPreferenceService using key "TeamCalendarPage.userPrefs".
  2. If no old filter exists, returns null (no migration needed).
  3. Creates a fresh CalendarFilterState and sets startDate (converted from old Date via PFDateCompatibilityUtils) and view (converted from old ViewType).
  4. Creates a CalendarStyleMap, seeding it with background colors from the old CalendarProperty entries of each template.
  5. Creates the active filter by copying the old activeTemplateEntry via CalendarFilter.copyFrom().
  6. Iterates all old templateEntries, converting each to a CalendarFilter and adding them to the favorites list.
  7. Resolves the active filter's ID from the favorites list by matching on name.
  8. Returns a CalendarLegacyFilter containing all four migrated components.

convert(oldViewType: ViewType?): CalendarView?

Private mapping from the old ViewType enum to the modern CalendarView enum:

Old ViewTypeNew CalendarView
AGENDA_WEEKCalendarView.WEEK
BASIC_WEEKCalendarView.WEEK
AGENDA_DAYCalendarView.DAY
BASIC_DAYCalendarView.DAY
any otherCalendarView.MONTH

SQL Testing Hints

The class documentation includes SQL snippets for developers to manually inspect legacy preferences during testing:

select key, serializedSettings from t_user_xml_prefs
  where user_id=2 and key like 'calendar.%';

delete from t_user_pref where user_fk=2 and area='calendar';

Git History

Design Rationale

The migration logic is intentionally isolated in a separate class rather than embedded in CalendarFilter or the calendar service layer. This keeps the core data model clean of legacy dependencies and allows the migration class itself to be deleted in a future release once all users have been upgraded. The @file:Suppress("DEPRECATION") suppression is necessary because the code intentionally references deprecated types (TeamCalCalendarFilter, ViewType, TemplateEntry) — these are the exact types being migrated from. The class references both the old XStream-persistence key (OLD_USERPREF_KEY) and the legacy date utilities (PFDateCompatibilityUtils), encapsulating all legacy knowledge in one place.