IDEMPIERE-4939 Implement ability to discover operating system environment variables when parsing context (FHCA-3026) (#853)

* IDEMPIERE-4939 Implement ability to discover operating system environment variables when parsing context (FHCA-3026)

* IDEMPIERE-4939 Add unit test
This commit is contained in:
Carlos Ruiz 2021-08-31 14:24:19 +02:00 committed by GitHub
parent 6fb4ebbf2f
commit 22f47cd382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -130,6 +130,8 @@ public final class Env
public static final String UI_CLIENT = "#UIClient";
public static final String USER_LEVEL = "#User_Level";
private static final String PREFIX_SYSTEM_VARIABLE = "$env.";
private final static ContextProvider clientContextProvider = new DefaultContextProvider();
@ -568,6 +570,12 @@ public final class Env
{
if (ctx == null || context == null)
throw new IllegalArgumentException ("Require Context");
if (context.startsWith(PREFIX_SYSTEM_VARIABLE)) {
String retValue = System.getenv(context.substring(PREFIX_SYSTEM_VARIABLE.length()));
if (retValue == null)
retValue = "";
return retValue;
}
return ctx.getProperty(context, "");
} // getContext

View File

@ -565,6 +565,15 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
@Test
public void testOSEnvVariable() {
String username = System.getenv("USER");
if (username == null)
username = "";
String expr = "@$env.USER@='" + username + "'";
assertTrue(LegacyLogicEvaluator.evaluateLogic(evaluatee, expr));
}
private static class ContextEvaluatee implements Evaluatee {
@Override