EN · DE · RU · FR · ES

#1086: HibernateSearchUsersGroupsBridge.kt

projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt Kotlin class, projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt 118 lines · 84 code · 22 comments · 12 blank
Purpose: Source file: teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt. HibernateSearchUsersGroupsBridge.kt is part of the ProjectForge open-source project management application.

Source (first 100 lines)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
// This community edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 3 of the License.
//
// This community edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////

package org.projectforge.business.teamcal.admin.model

import mu.KotlinLogging
import org.hibernate.search.engine.backend.document.DocumentElement
import org.hibernate.search.mapper.pojo.bridge.TypeBridge
import org.hibernate.search.mapper.pojo.bridge.runtime.TypeBridgeWriteContext
import org.projectforge.business.common.BaseUserGroupRightsDO
import org.projectforge.business.user.GroupsComparator
import org.projectforge.business.user.UserGroupCache
import org.projectforge.business.user.UsersComparator
import org.projectforge.common.DatabaseDialect
import org.projectforge.common.StringHelper
import org.projectforge.database.DatabaseSupport
import org.projectforge.framework.persistence.user.entities.GroupDO
import org.projectforge.framework.persistence.user.entities.PFUserDO
import java.util.*

private val log = KotlinLogging.logger {}

class HibernateSearchUsersGroupsBridge : TypeBridge<BaseUserGroupRightsDO> {

    private val groupsComparator = GroupsComparator()
    private val usersComparator = UsersComparator()

    override fun write(
        target: DocumentElement,
        bridgedElement: BaseUserGroupRightsDO,
        context: TypeBridgeWriteContext
    ) {
        val userGroupCache = UserGroupCache.getInstance()
        val sb = StringBuilder()

        if (DatabaseSupport.getInstance().getDialect() != DatabaseDialect.HSQL) {
            appendGroups(getSortedGroups(userGroupCache, bridgedElement.fullAccessGroupIds), sb)
            appendGroups(getSortedGroups(userGroupCache, bridgedElement.readonlyAccessGroupIds), sb)
            appendGroups(getSortedGroups(userGroupCache, bridgedElement.minimalAccessGroupIds), sb)
            appendUsers(getSortedUsers(userGroupCache, bridgedElement.fullAccessUserIds), sb)
            appendUsers(getSortedUsers(userGroupCache, bridgedElement.readonlyAccessUserIds), sb)
            appendUsers(getSortedUsers(userGroupCache, bridgedElement.minimalAccessUserIds), sb)
        }

        if (log.isDebugEnabled) {
            log.debug(sb.toString())
        }
        target.addValue("usersgroups", sb.toString())
    }

    private fun getSortedGroups(
        userGroupCache: UserGroupCache,
        groupIds: String?
    ): Collection<GroupDO>? {
        if (groupIds.isNullOrEmpty()) {
            return null
        }
        val sortedGroups: MutableCollection<GroupDO> = TreeSet(groupsComparator)
        val ids = StringHelper.splitToLongs(groupIds, ",", false)
        for (id in ids) {
            val group = userGroupCache.getGroup(id)
            if (group != null) {
                sortedGroups.add(group)
            } else {
                log.warn("Group with id '$id' not found in UserGroupCache. groupIds string was: $groupIds")
            }
        }
        return sortedGroups
    }

    private fun getSortedUsers(
        userGroupCache: UserGroupCache,
        userIds: String?
    ): Collection<PFUserDO>? {
        if (userIds.isNullOrEmpty()) {
            return null
        }
        val sortedUsers: MutableCollection<PFUserDO> = TreeSet(usersComparator)
        val ids = StringHelper.splitToLongs(userIds, ",", false)
        for (id in ids) {

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
8c0b82f21 Unused imports removed.
4c04cfd65 MAJOR-CHANGE! Migration of integer id's to Long id's (including fk's etc.)
c04fb0d51 Migration stuff in progress...

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
index 7678f8448..375d6969e 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

63081666f

Source file headers: 2024-> 2025.
63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
index 47c6e2d70..7678f8448 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

8c0b82f21

Unused imports removed.
8c0b82f212543f1da4a56ab523e8e599850e8338
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
index c48290704..47c6e2d70 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
@@ -25,9 +25,7 @@ package org.projectforge.business.teamcal.admin.model
 
 import mu.KotlinLogging
 import org.hibernate.search.engine.backend.document.DocumentElement
-import org.hibernate.search.engine.backend.document.IndexFieldReference
 import org.hibernate.search.mapper.pojo.bridge.TypeBridge
-import org.hibernate.search.mapper.pojo.bridge.binding.TypeBindingContext
 import org.hibernate.search.mapper.pojo.bridge.runtime.TypeBridgeWriteContext
 import org.projectforge.business.common.BaseUserGroupRightsDO
 import org.projectforge.business.user.GroupsComparator
@@ -38,7 +36,6 @@ import org.projectforge.common.StringHelper
 import org.projectforge.database.DatabaseSupport
 import org.projectforge.framework.persistence.user.entities.GroupDO
 import org.projectforge.framework.persistence.user.entities.PFUserDO
-import org.slf4j.LoggerFactory
 import java.util.*
 
 private val log = KotlinLogging.logger {}

4c04cfd65

MAJOR-CHANGE! Migration of integer id's to Long id's (including fk's etc.)
4c04cfd652210afe373d55f53a5300c85997b109
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
index a1884451f..c48290704 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
@@ -79,7 +79,7 @@ class HibernateSearchUsersGroupsBridge : TypeBridge<BaseUserGroupRightsDO> {
             return null
         }
         val sortedGroups: MutableCollection<GroupDO> = TreeSet(groupsComparator)
-        val ids = StringHelper.splitToInts(groupIds, ",", false)
+        val ids = StringHelper.splitToLongs(groupIds, ",", false)
         for (id in ids) {
             val group = userGroupCache.getGroup(id)
             if (group != null) {
@@ -99,7 +99,7 @@ class HibernateSearchUsersGroupsBridge : TypeBridge<BaseUserGroupRightsDO> {
             return null
         }
         val sortedUsers: MutableCollection<PFUserDO> = TreeSet(usersComparator)
-        val ids = StringHelper.splitToInts(userIds, ",", false)
+        val ids = StringHelper.splitToLongs(userIds, ",", false)
         for (id in ids) {
             val user = userGroupCache.getUser(id)
             if (user != null) {

c04fb0d51

Migration stuff in progress...
c04fb0d51cdba72e1bf43720ea1982dc166bb145
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
index 89a315f55..a1884451f 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/admin/model/HibernateSearchUsersGroupsBridge.kt
@@ -20,63 +20,68 @@
 // with this program; if not, see http://www.gnu.org/licenses/.
 //
 /////////////////////////////////////////////////////////////////////////////
+
 package org.projectforge.business.teamcal.admin.model
 
-import org.apache.commons.lang3.StringUtils
-import org.hibernate.search.bridge.TwoWayStringBridge
+import mu.KotlinLogging
+import org.hibernate.search.engine.backend.document.DocumentElement
+import org.hibernate.search.engine.backend.document.IndexFieldReference
+import org.hibernate.search.mapper.pojo.bridge.TypeBridge
+import org.hibernate.search.mapper.pojo.bridge.binding.TypeBindingContext
+import org.hibernate.search.mapper.pojo.bridge.runtime.TypeBridgeWriteContext
+import org.projectforge.business.common.BaseUserGroupRightsDO
+import org.projectforge.business.user.GroupsComparator
+import org.projectforge.business.user.UserGroupCache
+import org.projectforge.business.user.UsersComparator
+import org.projectforge.common.DatabaseDialect
 import org.projectforge.common.StringHelper
 import org.projectforge.database.DatabaseSupport
-import org.slf4j.Logger
+import org.projectforge.framework.persistence.user.entities.GroupDO
+import org.projectforge.framework.persistence.user.entities.PFUserDO
 import org.slf4j.LoggerFactory
 import java.util.*
 
-/**
- * Users and groups bridge for hibernate search.
- *
- * @author Kai Reinhard (k.reinhard@micromata.de)
- */
-class HibernateSearchUsersGroupsBridge : TwoWayStringBridge {
-    private val groupsComparator: GroupsComparator = GroupsComparator()
+private val log = KotlinLogging.logger {}
+
+class HibernateSearchUsersGroupsBridge : TypeBridge<BaseUserGroupRightsDO> {
 
-    private val usersComparator: UsersComparator = UsersComparator()
+    private val groupsComparator = GroupsComparator()
+    private val usersComparator = UsersComparator()
 
-    /**
-     * Get all names of groups and users and creates an index containing all user and group names separated by '|'. <br></br>
-     */
-    override fun objectToString(`object`: Any): String {
-        if (`object` is String) return `object`
-        val userGroupCache: UserGroupCache = UserGroupCache.getInstance()
-        val doObject: BaseUserGroupRightsDO = `object` as BaseUserGroupRightsDO
+    override fun write(
+        target: DocumentElement,
+        bridgedElement: BaseUserGroupRightsDO,
+        context: TypeBridgeWriteContext
+    ) {