IDEMPIERE-5647 Allow definition of context variables by Role - fix issue not being used in Logic (#2452)
This commit is contained in:
parent
90c4b7a64a
commit
3de220daec
|
|
@ -1845,7 +1845,7 @@ class QueryEvaluatee implements Evaluatee {
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = null;
|
String value = null;
|
||||||
if (variableName.startsWith("#") || variableName.startsWith("$")) {
|
if (Env.isGlobalVariable(variableName)) {
|
||||||
value = Env.getContext(ctx, variableName);
|
value = Env.getContext(ctx, variableName);
|
||||||
} else {
|
} else {
|
||||||
value = parameterMap.get(variableName);
|
value = parameterMap.get(variableName);
|
||||||
|
|
@ -1857,7 +1857,7 @@ class QueryEvaluatee implements Evaluatee {
|
||||||
id = Integer.parseInt(value);
|
id = Integer.parseInt(value);
|
||||||
} catch (Exception e){}
|
} catch (Exception e){}
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
if (variableName.startsWith("#") || variableName.startsWith("$")) {
|
if (Env.isGlobalVariable(variableName)) {
|
||||||
variableName = variableName.substring(1);
|
variableName = variableName.substring(1);
|
||||||
} else if (variableName.indexOf("|") > 0) {
|
} else if (variableName.indexOf("|") > 0) {
|
||||||
variableName = variableName.substring(variableName.lastIndexOf("|")+1);
|
variableName = variableName.substring(variableName.lastIndexOf("|")+1);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public class PrintDataEvaluatee implements Evaluatee {
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = null;
|
String value = null;
|
||||||
if (variableName.startsWith("#") || variableName.startsWith("$")) {
|
if (Env.isGlobalVariable(variableName)) {
|
||||||
value = Env.getContext(Env.getCtx(), variableName);
|
value = Env.getContext(Env.getCtx(), variableName);
|
||||||
} else {
|
} else {
|
||||||
Object obj = m_data.getNode(variableName);
|
Object obj = m_data.getNode(variableName);
|
||||||
|
|
@ -89,7 +89,7 @@ public class PrintDataEvaluatee implements Evaluatee {
|
||||||
"SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE "
|
"SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE "
|
||||||
+ foreignTable + "_ID = ?", id);
|
+ foreignTable + "_ID = ?", id);
|
||||||
} else {
|
} else {
|
||||||
if (variableName.startsWith("#") || variableName.startsWith("$")) {
|
if (Env.isGlobalVariable(variableName)) {
|
||||||
variableName = variableName.substring(1);
|
variableName = variableName.substring(1);
|
||||||
} else if (variableName.indexOf("|") > 0) {
|
} else if (variableName.indexOf("|") > 0) {
|
||||||
variableName = variableName.substring(variableName.lastIndexOf("|")+1);
|
variableName = variableName.substring(variableName.lastIndexOf("|")+1);
|
||||||
|
|
|
||||||
|
|
@ -629,7 +629,7 @@ public final class Env
|
||||||
if (s == null)
|
if (s == null)
|
||||||
{
|
{
|
||||||
// Explicit Base Values
|
// Explicit Base Values
|
||||||
if (context.startsWith("#") || context.startsWith("$") || context.startsWith("P|"))
|
if (Env.isGlobalVariable(context) || Env.isPreference(context))
|
||||||
return getContext(ctx, context);
|
return getContext(ctx, context);
|
||||||
if (onlyWindow) // no Default values
|
if (onlyWindow) // no Default values
|
||||||
return "";
|
return "";
|
||||||
|
|
@ -1039,6 +1039,8 @@ public final class Env
|
||||||
retValue = ctx.getProperty("#"+context); // Login setting
|
retValue = ctx.getProperty("#"+context); // Login setting
|
||||||
if (retValue == null)
|
if (retValue == null)
|
||||||
retValue = ctx.getProperty("$"+context); // Accounting setting
|
retValue = ctx.getProperty("$"+context); // Accounting setting
|
||||||
|
if (retValue == null)
|
||||||
|
retValue = ctx.getProperty("+"+context); // Injected Role Variable
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
return (retValue == null ? "" : retValue);
|
return (retValue == null ? "" : retValue);
|
||||||
|
|
@ -1527,7 +1529,7 @@ public final class Env
|
||||||
}
|
}
|
||||||
|
|
||||||
String ctxInfo = getContext(ctx, WindowNo, token, onlyWindow); // get context
|
String ctxInfo = getContext(ctx, WindowNo, token, onlyWindow); // get context
|
||||||
if (ctxInfo.length() == 0 && (token.startsWith("#") || token.startsWith("$")) )
|
if (ctxInfo.length() == 0 && Env.isGlobalVariable(token))
|
||||||
ctxInfo = getContext(ctx, token); // get global context
|
ctxInfo = getContext(ctx, token); // get global context
|
||||||
|
|
||||||
if (ctxInfo.length() == 0 && defaultV != null)
|
if (ctxInfo.length() == 0 && defaultV != null)
|
||||||
|
|
@ -1613,7 +1615,7 @@ public final class Env
|
||||||
ctxInfo = getContext(ctx, WindowNo, tabNo, token, onlyTab); // get context
|
ctxInfo = getContext(ctx, WindowNo, tabNo, token, onlyTab); // get context
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctxInfo.length() == 0 && (token.startsWith("#") || token.startsWith("$")) )
|
if (ctxInfo.length() == 0 && Env.isGlobalVariable(token))
|
||||||
ctxInfo = getContext(ctx, token); // get global context
|
ctxInfo = getContext(ctx, token); // get global context
|
||||||
|
|
||||||
if (ctxInfo.length() == 0 && defaultV != null)
|
if (ctxInfo.length() == 0 && defaultV != null)
|
||||||
|
|
@ -1729,7 +1731,7 @@ public final class Env
|
||||||
}
|
}
|
||||||
|
|
||||||
Properties ctx = po != null ? po.getCtx() : Env.getCtx();
|
Properties ctx = po != null ? po.getCtx() : Env.getCtx();
|
||||||
if (token.startsWith("#") || token.startsWith("$")) {
|
if (Env.isGlobalVariable(token)) {
|
||||||
//take from context
|
//take from context
|
||||||
String v = Env.getContext(ctx, token);
|
String v = Env.getContext(ctx, token);
|
||||||
if (v != null && v.length() > 0) {
|
if (v != null && v.length() > 0) {
|
||||||
|
|
@ -1818,7 +1820,7 @@ public final class Env
|
||||||
String token, String format, MColumn colToken, Object value, StringBuilder outStr) {
|
String token, String format, MColumn colToken, Object value, StringBuilder outStr) {
|
||||||
if (format != null && format.length() > 0) {
|
if (format != null && format.length() > 0) {
|
||||||
String foreignTable = colToken != null ? colToken.getReferenceTableName() : null;
|
String foreignTable = colToken != null ? colToken.getReferenceTableName() : null;
|
||||||
if (value instanceof String && token.endsWith("_ID") && (token.startsWith("#") || token.startsWith("$"))) {
|
if (value instanceof String && token.endsWith("_ID") && Env.isGlobalVariable(token)) {
|
||||||
try {
|
try {
|
||||||
int id = Integer.parseInt((String)value);
|
int id = Integer.parseInt((String)value);
|
||||||
value = id;
|
value = id;
|
||||||
|
|
@ -2343,4 +2345,28 @@ public final class Env
|
||||||
return "Y".equals(Env.getContext(Env.getCtx(), "IsReadOnlySession"));
|
return "Y".equals(Env.getContext(Env.getCtx(), "IsReadOnlySession"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies if a context variable name is global, this is, starting with:
|
||||||
|
* # Login
|
||||||
|
* $ Accounting
|
||||||
|
* + Role Injected
|
||||||
|
* @param variable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isGlobalVariable(String variable) {
|
||||||
|
return variable.startsWith("#")
|
||||||
|
|| variable.startsWith("$")
|
||||||
|
|| variable.startsWith("+");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies if a context variable name is a preference, this is, starting with:
|
||||||
|
* P| Preference
|
||||||
|
* @param variable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isPreference(String variable) {
|
||||||
|
return variable.startsWith("P|");
|
||||||
|
}
|
||||||
|
|
||||||
} // Env
|
} // Env
|
||||||
Loading…
Reference in New Issue