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:
parent
6fb4ebbf2f
commit
22f47cd382
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue