EN · DE · RU · FR · ES

#551: TeamCalCache.java

projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java Java class, projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java 180 lines · 113 code · 50 comments · 17 blank
Purpose: Source file: business/teamcal/admin/TeamCalCache.java. TeamCalCache.java 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;

import org.hibernate.Hibernate;
import org.projectforge.business.teamcal.admin.model.TeamCalDO;
import org.projectforge.business.teamcal.admin.right.TeamCalRight;
import org.projectforge.business.user.UserRightId;
import org.projectforge.framework.cache.AbstractCache;
import org.projectforge.framework.configuration.ApplicationContextProvider;
import org.projectforge.framework.persistence.api.UserRightService;
import org.projectforge.framework.persistence.jpa.PfPersistenceService;
import org.projectforge.framework.persistence.user.api.ThreadLocalUserContext;
import org.projectforge.framework.persistence.user.entities.PFUserDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * Caches all calendars.
 *
 * @author Kai Reinhard (k.reinhard@micromata.de)
 */
@Component
public class TeamCalCache extends AbstractCache {
    private static final long serialVersionUID = 1742102774636598280L;

    private static Logger log = LoggerFactory.getLogger(TeamCalCache.class);

    @Autowired
    PfPersistenceService persistenceService;

    @Autowired
    UserRightService userRights;

    private transient TeamCalRight teamCalRight;

    private Map<Long, TeamCalDO> calendarMap;

    public TeamCalRight getTeamCalRight() {
        return teamCalRight;
    }

    public TeamCalDO getCalendar(final Long calendarId) {
        checkRefresh();
        return calendarMap.get(calendarId);
    }

    /**
     * Returns the TeamCalDO if it is initialized (Hibernate). Otherwise, it will be loaded from the database.
     * Prevents lazy loadings.
     */
    public TeamCalDO getCalendarIfNotInitialized(TeamCalDO teamCalDO) {
        if (teamCalDO == null) {
            return teamCalDO;
        }
        if (Hibernate.isInitialized(teamCalDO)) {
            return teamCalDO;
        }
        return getCalendar(teamCalDO.getId());
    }

    /**
     * Get ordered calendars (by title and id).
     *
     * @return All accessible calendars of the context user (as owner or with full, read-only or minimal access).
     */
    public Collection<TeamCalDO> getAllAccessibleCalendars() {
        checkRefresh();
        final Set<TeamCalDO> set = new TreeSet<>(new TeamCalsComparator());
        final PFUserDO loggedInUser = ThreadLocalUserContext.getLoggedInUser();
        for (final TeamCalDO cal : calendarMap.values()) {
            if (teamCalRight.hasSelectAccess(loggedInUser, cal) && !cal.getDeleted()) {
                set.add(cal);
            }
        }

Git History

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

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
index e58f25362..972188fc0 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
@@ -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/java/org/projectforge/business/teamcal/admin/TeamCalCache.java b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
index cbae8b998..e58f25362 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
@@ -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.
 //

50c3b7b46

Migration stuff in progress... (all tests of all packages: OK).
50c3b7b46e5038432710f94a4f403dea31786a27
diff --git a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
index 63e7da77c..cbae8b998 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
@@ -75,14 +75,13 @@ public class TeamCalCache extends AbstractCache {
      * Prevents lazy loadings.
      */
     public TeamCalDO getCalendarIfNotInitialized(TeamCalDO teamCalDO) {
-        Long id = teamCalDO.getId();
-        if (id == null) {
+        if (teamCalDO == null) {
             return teamCalDO;
         }
         if (Hibernate.isInitialized(teamCalDO)) {
             return teamCalDO;
         }
-        return getCalendar(id);
+        return getCalendar(teamCalDO.getId());
     }
 
     /**

4942c854d

Migration stuff in progress...
4942c854d9c05928c5d2712e58b309ad12da14f0
diff --git a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
index 08ba0d1fa..63e7da77c 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
@@ -23,6 +23,7 @@
 
 package org.projectforge.business.teamcal.admin;
 
+import org.hibernate.Hibernate;
 import org.projectforge.business.teamcal.admin.model.TeamCalDO;
 import org.projectforge.business.teamcal.admin.right.TeamCalRight;
 import org.projectforge.business.user.UserRightId;
@@ -69,6 +70,21 @@ public class TeamCalCache extends AbstractCache {
         return calendarMap.get(calendarId);
     }
 
+    /**
+     * Returns the TeamCalDO if it is initialized (Hibernate). Otherwise, it will be loaded from the database.
+     * Prevents lazy loadings.
+     */
+    public TeamCalDO getCalendarIfNotInitialized(TeamCalDO teamCalDO) {
+        Long id = teamCalDO.getId();
+        if (id == null) {
+            return teamCalDO;
+        }
+        if (Hibernate.isInitialized(teamCalDO)) {
+            return teamCalDO;
+        }
+        return getCalendar(id);
+    }
+
     /**
      * Get ordered calendars (by title and id).
      *

d394f410f

Migration stuff in progress... (all tests of all packages: OK).
d394f410fc43d3e8ed04035f50382bffd8958a1d
diff --git a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
index d05791377..08ba0d1fa 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/teamcal/admin/TeamCalCache.java
@@ -143,7 +143,7 @@ public class TeamCalCache extends AbstractCache {
     @Override
     protected void refresh() {
         log.info("Initializing TeamCalCache ...");
-        persistenceService.runIsolatedReadOnly(context -> {
+        persistenceService.runIsolatedReadOnly(true, context -> {
             TeamCalDao dao = ApplicationContextProvider.getApplicationContext().getBean(TeamCalDao.class);
             if (dao == null || teamCalRight == null) {
                 teamCalRight = (TeamCalRight) userRights.getRight(UserRightId.PLUGIN_CALENDAR);
@@ -158,8 +158,8 @@ public class TeamCalCache extends AbstractCache {
                 }
             }
             this.calendarMap = map;
+            log.info("Initializing of TeamCalCache done: " + context.formatStats(true));
             return null;
         });
-        log.info("Initializing of TeamCalCache done.");
     }
 }