#872: BaseUserGroupRightService.kt

projectforge-business/src/main/kotlin/org/projectforge/business/common/BaseUserGroupRightService.kt Type: Spring @Service · Purpose: User/group rights CRUD helper · Source: projectforge-business/src/main/kotlin/org/projectforge/business/common/BaseUserGroupRightService.kt 230 lines · 91 code · 112 comments · 27 blank
Spring service providing getter/setter methods for the access rights CSV fields on BaseUserGroupRightsDO objects. Resolves raw ID strings to sorted GroupDO and PFUserDO collections via GroupService and UserService. Maintains a singleton instance via @PostConstruct for static access.

Dependencies

DependencyTypePurpose
GroupService@AutowiredResolves group IDs to GroupDO entities
UserService@AutowiredResolves user IDs to PFUserDO entities

Getter Methods (6 total)

Each access tier (full, readonly, minimal) x entity type (groups, users) has a corresponding getter:

MethodReturns
getSortedFullAccessGroups(rights)Collection<GroupDO>
getSortedFullAccessUsers(rights)Collection<PFUserDO>
getSortedReadonlyAccessGroups(rights)Collection<GroupDO>
getSortedReadonlyAccessUsers(rights)Collection<PFUserDO>
getSortedMinimalAccessGroups(rights)Collection<GroupDO>
getSortedMinimalAccessUsers(rights)Collection<PFUserDO>

Setter Methods (12 total)

Each access tier x entity type has two overloads—one accepting a Collection<IdObject<Long>?>? and one accepting a raw String? of comma-separated IDs:

MethodInput
setFullAccessGroupsCollection<IdObject<Long>?>? or String?
setFullAccessUsersCollection<IdObject<Long>?>? or String?
setReadonlyAccessGroupsCollection<IdObject<Long>?>? or String?
setReadonlyAccessUsersCollection<IdObject<Long>?>? or String?
setMinimalAccessGroupsCollection<IdObject<Long>?>? or String?
setMinimalAccessUsersCollection<IdObject<Long>?>? or String?
All setter methods only modify the DO's field in memory. None trigger a database save—the caller is responsible for persisting the entity.

Companion Object

asSortedIdStrings(collection)

@JvmStatic. Converts a collection of IdObject<Long> to a sorted, comma-separated string of IDs. Filters nulls, sorts numerically, joins with ",". Returns null if the collection is null or empty.

// Example: [Group(3), Group(1), Group(2)] → "1,2,3"

asSortedIdStrings(idString)

@JvmStatic. Parses a CSV string, extracts valid Long values, sorts them, and returns the normalized CSV string. Filters blank/invalid entries. Returns null for null input.

instance

@JvmStatic lateinit var with private setter. Initialized in @PostConstruct. Provides global static access to the Spring-managed singleton for utility contexts where dependency injection is unavailable.

Design Rationale

The getter/setter pattern ensures that the raw CSV strings are always kept sorted and normalized. The two overloads per setter (collection vs. string) support both UI-driven editing (where a multi-select produces a collection of entities) and programmatic/API-driven editing (where raw ID strings are provided).

The singleton instance pattern is a pragmatic bridge between Spring DI and older static-utility code. Newer code should prefer constructor injection of BaseUserGroupRightService.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
a33f8f203 Migration stuff in progress... (all tests of all packages: OK).