From ba63dc49602e70a38cbe63fcfd71f0f0ec026e34 Mon Sep 17 00:00:00 2001 From: igorpojzl <59439434+igorpojzl@users.noreply.github.com> Date: Thu, 7 Jan 2021 11:27:41 +0100 Subject: [PATCH] IDEMPIERE-4622 Cross Tenant UserDefInfo, Role (#503) * IDEMPIERE-4622 Cross Tenant UserDefInfo, Role --- .../src/org/compiere/model/MUserDefInfo.java | 30 ++++++++++++++----- .../src/org/compiere/model/MUserDefProc.java | 30 ++++++++++++++----- .../src/org/compiere/model/MUserRoles.java | 5 ++-- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MUserDefInfo.java b/org.adempiere.base/src/org/compiere/model/MUserDefInfo.java index d916e046ca..a9ff3bac6f 100644 --- a/org.adempiere.base/src/org/compiere/model/MUserDefInfo.java +++ b/org.adempiere.base/src/org/compiere/model/MUserDefInfo.java @@ -26,7 +26,9 @@ package org.compiere.model; import java.sql.ResultSet; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.compiere.util.CCache; @@ -45,7 +47,7 @@ public class MUserDefInfo extends X_AD_UserDef_Info { */ private static final long serialVersionUID = 5611033457579880793L; - private volatile static List m_fullList = null; + private static final Map> m_fullMap = new HashMap>(); /** * Standard constructor. @@ -80,17 +82,25 @@ public class MUserDefInfo extends X_AD_UserDef_Info { */ private static MUserDefInfo[] getAll (Properties ctx, int infowindow_ID ) { - if (m_fullList == null) { - m_fullList = new Query(ctx, MUserDefInfo.Table_Name, "IsActive='Y'", null).list(); + List fullList = null; + synchronized (m_fullMap) { + fullList = m_fullMap.get(Env.getAD_Client_ID(ctx)); + if (fullList == null) { + fullList = new Query(ctx, MUserDefInfo.Table_Name, null, null) + .setOnlyActiveRecords(true) + .setClient_ID() + .list(); + m_fullMap.put(Env.getAD_Client_ID(ctx), fullList); + } } - - if (m_fullList.size() == 0) { + + if (fullList.size() == 0) { return null; } List list = new ArrayList(); - for (MUserDefInfo udw : m_fullList) { + for (MUserDefInfo udw : fullList) { if (udw.getAD_InfoWindow_ID() == infowindow_ID && udw.getAD_Client_ID() == Env.getAD_Client_ID(ctx) && (udw.getAD_Language() == null || udw.getAD_Language().equals(Env.getAD_Language(ctx))) @@ -209,13 +219,17 @@ public class MUserDefInfo extends X_AD_UserDef_Info { @Override protected boolean beforeSave(boolean newRecord) { - m_fullList = null; + synchronized (m_fullMap) { + m_fullMap.remove(getAD_Client_ID()); + } return true; } @Override protected boolean beforeDelete() { - m_fullList = null; + synchronized (m_fullMap) { + m_fullMap.remove(getAD_Client_ID()); + } return true; } diff --git a/org.adempiere.base/src/org/compiere/model/MUserDefProc.java b/org.adempiere.base/src/org/compiere/model/MUserDefProc.java index ae35e695e9..2840f136d6 100644 --- a/org.adempiere.base/src/org/compiere/model/MUserDefProc.java +++ b/org.adempiere.base/src/org/compiere/model/MUserDefProc.java @@ -14,13 +14,15 @@ package org.compiere.model; import java.sql.ResultSet; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.compiere.util.Env; -import org.idempiere.cache.ImmutablePOSupport; import org.idempiere.cache.ImmutablePOCache; +import org.idempiere.cache.ImmutablePOSupport; /** * Model class for Process Customizations @@ -34,7 +36,7 @@ public class MUserDefProc extends X_AD_UserDef_Proc implements ImmutablePOSuppor * */ private static final long serialVersionUID = 1599140293008534080L; - private volatile static List m_fullList = null; + private static final Map> m_fullMap = new HashMap>(); /** * @param ctx @@ -86,17 +88,25 @@ public class MUserDefProc extends X_AD_UserDef_Proc implements ImmutablePOSuppor private static MUserDefProc[] getAll (Properties ctx, int processID) { - if (m_fullList == null) { - m_fullList = new Query(ctx, MUserDefProc.Table_Name, "IsActive='Y'", null).list(); + List fullList = null; + synchronized (m_fullMap) { + fullList = m_fullMap.get(Env.getAD_Client_ID(ctx)); + if (fullList == null) { + fullList = new Query(ctx, MUserDefProc.Table_Name, null, null) + .setOnlyActiveRecords(true) + .setClient_ID() + .list(); + m_fullMap.put(Env.getAD_Client_ID(ctx), fullList); + } } - if (m_fullList.size() == 0) { + if (fullList.size() == 0) { return null; } List list = new ArrayList(); - for (MUserDefProc udp : m_fullList) { + for (MUserDefProc udp : fullList) { if (udp.getAD_Process_ID() == processID && udp.getAD_Client_ID() == Env.getAD_Client_ID(ctx) && (udp.getAD_Language() == null || udp.getAD_Language().equals(Env.getAD_Language(ctx))) @@ -225,13 +235,17 @@ public class MUserDefProc extends X_AD_UserDef_Proc implements ImmutablePOSuppor throw new AdempiereException("Esta personalização de processo já possui parametros configurados."); } - m_fullList = null; + synchronized (m_fullMap) { + m_fullMap.remove(getAD_Client_ID()); + } return true; } @Override protected boolean beforeDelete() { - m_fullList = null; + synchronized (m_fullMap) { + m_fullMap.remove(getAD_Client_ID()); + } return true; } diff --git a/org.adempiere.base/src/org/compiere/model/MUserRoles.java b/org.adempiere.base/src/org/compiere/model/MUserRoles.java index 68a30541dd..4097674384 100644 --- a/org.adempiere.base/src/org/compiere/model/MUserRoles.java +++ b/org.adempiere.base/src/org/compiere/model/MUserRoles.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Properties; import org.compiere.util.CLogger; +import org.compiere.util.Env; import org.compiere.util.Msg; /** @@ -61,9 +62,9 @@ public class MUserRoles extends X_AD_User_Roles */ public static MUserRoles[] getOfUser (Properties ctx, int AD_User_ID) { - final String whereClause = I_AD_User_Roles.COLUMNNAME_AD_User_ID+"=?"; + final String whereClause = I_AD_User_Roles.COLUMNNAME_AD_User_ID+"=? AND AD_Client_ID IN (0, ?)"; List list = new Query(ctx,I_AD_User_Roles.Table_Name,whereClause,null) - .setParameters(AD_User_ID) + .setParameters(new Object[]{AD_User_ID, Env.getAD_Client_ID(ctx)}) .list(); MUserRoles[] retValue = new MUserRoles[list.size ()]; list.toArray (retValue);