wikumW

Untitled

Nov 23rd, 2023
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. @Override
  2. public boolean checkRequireExpression(Requireable candidate, AppContextModel contextModel) {
  3. try {
  4. String requireExpression = candidate.getRequire();
  5. if (StringUtils.isBlank(requireExpression)) {
  6. return true;
  7. }
  8. ObjectMapper j = new ObjectMapper();
  9. for (Map.Entry<String, Object> e : contextModel.entrySet()) {
  10. if (!(e.getValue() instanceof Map) && !"util".equals(e.getKey())) {
  11. javascriptEngine.eval("var " + e.getKey() + " = " + j.writeValueAsString(e.getValue()) + ";");
  12. }
  13. }
  14. return javascriptEngine.eval("(" + requireExpression + ") == true").equals(Boolean.TRUE);
  15. }
  16. catch (Exception e) {
  17. log.error("Failed to evaluate 'require' check for extension " + candidate.getId(), e);
  18. return false;
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment