From ad12ada4a029329124802404510a0331f9c953b4 Mon Sep 17 00:00:00 2001 From: "Benito J. Gonzalez" Date: Tue, 13 Jul 2021 09:27:24 -0700 Subject: [PATCH 1/3] fix: add cache to portlet window state collection --- .../org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java b/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java index 054411cb8b2..95ff312b0f2 100644 --- a/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java +++ b/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java @@ -105,8 +105,9 @@ class PortletEntityImpl implements IPortletEntity { @MapKeyJoinColumn(name = "STYLESHEET_DESCRIPTOR_ID") @Column(name = "WINDOW_STATE") @Type(type = "windowState") + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) private final Map windowStates = - new HashMap(0); + new HashMap<>(0); @OneToOne( cascade = {CascadeType.ALL}, From 89f824eb0071f46fa0dbf23f1df45ab09ce5c1e1 Mon Sep 17 00:00:00 2001 From: "Benito J. Gonzalez" Date: Tue, 13 Jul 2021 09:35:10 -0700 Subject: [PATCH 2/3] fix: code formatted correctly --- .../org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java b/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java index 95ff312b0f2..b24cbc5c235 100644 --- a/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java +++ b/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java @@ -106,8 +106,7 @@ class PortletEntityImpl implements IPortletEntity { @Column(name = "WINDOW_STATE") @Type(type = "windowState") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) - private final Map windowStates = - new HashMap<>(0); + private final Map windowStates = new HashMap<>(0); @OneToOne( cascade = {CascadeType.ALL}, From da2640e4842b01b98c2d42da41a4708244c95930 Mon Sep 17 00:00:00 2001 From: "Benito J. Gonzalez" Date: Wed, 14 Jul 2021 17:22:58 -0700 Subject: [PATCH 3/3] fix: avoid using WindowState which is not Serializable --- .../portlet/dao/jpa/PortletEntityImpl.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java b/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java index b24cbc5c235..04cece6d173 100644 --- a/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java +++ b/uPortal-content/uPortal-content-portlet/src/main/java/org/apereo/portal/portlet/dao/jpa/PortletEntityImpl.java @@ -56,7 +56,6 @@ import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.Index; import org.hibernate.annotations.NaturalId; -import org.hibernate.annotations.Type; /** */ @Entity @@ -104,9 +103,8 @@ class PortletEntityImpl implements IPortletEntity { joinColumns = @JoinColumn(name = "PORTLET_ENT_ID")) @MapKeyJoinColumn(name = "STYLESHEET_DESCRIPTOR_ID") @Column(name = "WINDOW_STATE") - @Type(type = "windowState") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) - private final Map windowStates = new HashMap<>(0); + private final Map windowStates = new HashMap<>(0); @OneToOne( cascade = {CascadeType.ALL}, @@ -187,14 +185,16 @@ public int getUserId() { @Override public Map getWindowStates() { - final Map simpleWindowStates = new LinkedHashMap(); + final Map simpleWindowStates = new LinkedHashMap<>(); synchronized (this.windowStates) { - for (Map.Entry windowStateEntry : + for (Map.Entry windowStateEntry : windowStates.entrySet()) { final StylesheetDescriptorImpl stylesheetDescriptor = windowStateEntry.getKey(); final long stylesheetDescriptorId = stylesheetDescriptor.getId(); - final WindowState windowState = windowStateEntry.getValue(); - simpleWindowStates.put(stylesheetDescriptorId, windowState); + if (windowStateEntry.getValue() != null) { + final WindowState windowState = new WindowState(windowStateEntry.getValue()); + simpleWindowStates.put(stylesheetDescriptorId, windowState); + } } } return Collections.unmodifiableMap(simpleWindowStates); @@ -202,18 +202,27 @@ public Map getWindowStates() { @Override public WindowState getWindowState(IStylesheetDescriptor stylesheetDescriptor) { + StylesheetDescriptorImpl stylesheetDescriptorImpl = + (StylesheetDescriptorImpl) stylesheetDescriptor; synchronized (this.windowStates) { - return this.windowStates.get(stylesheetDescriptor); + String state = this.windowStates.get(stylesheetDescriptorImpl); + if (state == null) { + return null; + } else { + return new WindowState(state); + } } } @Override public void setWindowState(IStylesheetDescriptor stylesheetDescriptor, WindowState state) { + StylesheetDescriptorImpl stylesheetDescriptorImpl = + (StylesheetDescriptorImpl) stylesheetDescriptor; synchronized (this.windowStates) { if (state == null) { - this.windowStates.remove(stylesheetDescriptor); + this.windowStates.remove(stylesheetDescriptorImpl); } else { - this.windowStates.put((StylesheetDescriptorImpl) stylesheetDescriptor, state); + this.windowStates.put(stylesheetDescriptorImpl, state.toString()); } } }