@Test public void testCollection() throws Exception { FieldGroup source = populateCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo"); String expression = String.format( "IF(ISEMPTY(${%s:/testPathfoo<0>}), null, ${%s:/testPathfoo<>})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID); recreateSession(); FieldGroup wrapper = new FieldGroup(); wrapper.getField().add(source); wrapper.getField().add(source.getField().get(0)); session.head().setSourceField(wrapper); DefaultAtlasExpressionProcessor.processExpression(session, expression); assertFalse(printAudit(session), session.hasErrors()); assertEquals(FieldGroup.class, session.head().getSourceField().getClass()); FieldGroup fieldGroup = (FieldGroup) session.head().getSourceField(); assertEquals("/testPathfoo<>", fieldGroup.getPath()); assertEquals(10, fieldGroup.getField().size()); assertEquals("foo0", fieldGroup.getField().get(0).getValue()); }
public static void processExpression(DefaultAtlasSession session, String expression) { if (expression == null || expression.trim().isEmpty()) { return; } try { Map<String, Field> sourceFieldMap = new HashMap<>(); Field parent = session.head().getSourceField(); if (parent != null && !AtlasUtil.isEmpty(parent.getDocId()) && !AtlasUtil.isEmpty(parent.getPath())) { sourceFieldMap.put(parent.getDocId() + ":" + parent.getPath(), parent); } if (parent instanceof FieldGroup && AtlasUtil.isEmpty(parent.getPath())) { FieldGroup parentGroup = FieldGroup.class.cast(parent); for (Field child : parentGroup.getField()) { if (!(AtlasUtil.isEmpty(child.getDocId()) && AtlasUtil.isEmpty(child.getPath()))) { sourceFieldMap.put(child.getDocId() + ":" + child.getPath(), child); } } } Expression parsedExpression = Expression.parse(expression, DefaultAtlasFunctionResolver.getInstance()); Object answer = parsedExpression.evaluate((path) -> { if (path == null || path.isEmpty()) { return null; } try { String[] splitted = path.split(":", 2); AtlasFieldReader reader = session.getFieldReader(splitted[0]); Field f = sourceFieldMap.get(path); if (f == null) { return null; } session.head().setSourceField(f); return reader.read(session); } catch (Exception e) { throw new ExpressionException(e); } }); if (answer instanceof Field) { session.head().setSourceField((Field)answer); } else { Field from = session.head().getSourceField(); SimpleField to = new SimpleField(); AtlasModelFactory.copyField(from, to, false); to.setValue(answer); session.head().setSourceField(to); } } catch (Exception e) { AtlasUtil.addAudit(session, null, String.format("Expression processing error: %s", e.getMessage()), expression, AuditStatus.ERROR, null); if (LOG.isDebugEnabled()) { LOG.debug("", e); } } }
DefaultAtlasExpressionProcessor { public static void processExpression(DefaultAtlasSession session, String expression) { if (expression == null || expression.trim().isEmpty()) { return; } try { Map<String, Field> sourceFieldMap = new HashMap<>(); Field parent = session.head().getSourceField(); if (parent != null && !AtlasUtil.isEmpty(parent.getDocId()) && !AtlasUtil.isEmpty(parent.getPath())) { sourceFieldMap.put(parent.getDocId() + ":" + parent.getPath(), parent); } if (parent instanceof FieldGroup && AtlasUtil.isEmpty(parent.getPath())) { FieldGroup parentGroup = FieldGroup.class.cast(parent); for (Field child : parentGroup.getField()) { if (!(AtlasUtil.isEmpty(child.getDocId()) && AtlasUtil.isEmpty(child.getPath()))) { sourceFieldMap.put(child.getDocId() + ":" + child.getPath(), child); } } } Expression parsedExpression = Expression.parse(expression, DefaultAtlasFunctionResolver.getInstance()); Object answer = parsedExpression.evaluate((path) -> { if (path == null || path.isEmpty()) { return null; } try { String[] splitted = path.split(":", 2); AtlasFieldReader reader = session.getFieldReader(splitted[0]); Field f = sourceFieldMap.get(path); if (f == null) { return null; } session.head().setSourceField(f); return reader.read(session); } catch (Exception e) { throw new ExpressionException(e); } }); if (answer instanceof Field) { session.head().setSourceField((Field)answer); } else { Field from = session.head().getSourceField(); SimpleField to = new SimpleField(); AtlasModelFactory.copyField(from, to, false); to.setValue(answer); session.head().setSourceField(to); } } catch (Exception e) { AtlasUtil.addAudit(session, null, String.format("Expression processing error: %s", e.getMessage()), expression, AuditStatus.ERROR, null); if (LOG.isDebugEnabled()) { LOG.debug("", e); } } } }
DefaultAtlasExpressionProcessor { public static void processExpression(DefaultAtlasSession session, String expression) { if (expression == null || expression.trim().isEmpty()) { return; } try { Map<String, Field> sourceFieldMap = new HashMap<>(); Field parent = session.head().getSourceField(); if (parent != null && !AtlasUtil.isEmpty(parent.getDocId()) && !AtlasUtil.isEmpty(parent.getPath())) { sourceFieldMap.put(parent.getDocId() + ":" + parent.getPath(), parent); } if (parent instanceof FieldGroup && AtlasUtil.isEmpty(parent.getPath())) { FieldGroup parentGroup = FieldGroup.class.cast(parent); for (Field child : parentGroup.getField()) { if (!(AtlasUtil.isEmpty(child.getDocId()) && AtlasUtil.isEmpty(child.getPath()))) { sourceFieldMap.put(child.getDocId() + ":" + child.getPath(), child); } } } Expression parsedExpression = Expression.parse(expression, DefaultAtlasFunctionResolver.getInstance()); Object answer = parsedExpression.evaluate((path) -> { if (path == null || path.isEmpty()) { return null; } try { String[] splitted = path.split(":", 2); AtlasFieldReader reader = session.getFieldReader(splitted[0]); Field f = sourceFieldMap.get(path); if (f == null) { return null; } session.head().setSourceField(f); return reader.read(session); } catch (Exception e) { throw new ExpressionException(e); } }); if (answer instanceof Field) { session.head().setSourceField((Field)answer); } else { Field from = session.head().getSourceField(); SimpleField to = new SimpleField(); AtlasModelFactory.copyField(from, to, false); to.setValue(answer); session.head().setSourceField(to); } } catch (Exception e) { AtlasUtil.addAudit(session, null, String.format("Expression processing error: %s", e.getMessage()), expression, AuditStatus.ERROR, null); if (LOG.isDebugEnabled()) { LOG.debug("", e); } } }  }
DefaultAtlasExpressionProcessor { public static void processExpression(DefaultAtlasSession session, String expression) { if (expression == null || expression.trim().isEmpty()) { return; } try { Map<String, Field> sourceFieldMap = new HashMap<>(); Field parent = session.head().getSourceField(); if (parent != null && !AtlasUtil.isEmpty(parent.getDocId()) && !AtlasUtil.isEmpty(parent.getPath())) { sourceFieldMap.put(parent.getDocId() + ":" + parent.getPath(), parent); } if (parent instanceof FieldGroup && AtlasUtil.isEmpty(parent.getPath())) { FieldGroup parentGroup = FieldGroup.class.cast(parent); for (Field child : parentGroup.getField()) { if (!(AtlasUtil.isEmpty(child.getDocId()) && AtlasUtil.isEmpty(child.getPath()))) { sourceFieldMap.put(child.getDocId() + ":" + child.getPath(), child); } } } Expression parsedExpression = Expression.parse(expression, DefaultAtlasFunctionResolver.getInstance()); Object answer = parsedExpression.evaluate((path) -> { if (path == null || path.isEmpty()) { return null; } try { String[] splitted = path.split(":", 2); AtlasFieldReader reader = session.getFieldReader(splitted[0]); Field f = sourceFieldMap.get(path); if (f == null) { return null; } session.head().setSourceField(f); return reader.read(session); } catch (Exception e) { throw new ExpressionException(e); } }); if (answer instanceof Field) { session.head().setSourceField((Field)answer); } else { Field from = session.head().getSourceField(); SimpleField to = new SimpleField(); AtlasModelFactory.copyField(from, to, false); to.setValue(answer); session.head().setSourceField(to); } } catch (Exception e) { AtlasUtil.addAudit(session, null, String.format("Expression processing error: %s", e.getMessage()), expression, AuditStatus.ERROR, null); if (LOG.isDebugEnabled()) { LOG.debug("", e); } } }  static void processExpression(DefaultAtlasSession session, String expression); }
DefaultAtlasExpressionProcessor { public static void processExpression(DefaultAtlasSession session, String expression) { if (expression == null || expression.trim().isEmpty()) { return; } try { Map<String, Field> sourceFieldMap = new HashMap<>(); Field parent = session.head().getSourceField(); if (parent != null && !AtlasUtil.isEmpty(parent.getDocId()) && !AtlasUtil.isEmpty(parent.getPath())) { sourceFieldMap.put(parent.getDocId() + ":" + parent.getPath(), parent); } if (parent instanceof FieldGroup && AtlasUtil.isEmpty(parent.getPath())) { FieldGroup parentGroup = FieldGroup.class.cast(parent); for (Field child : parentGroup.getField()) { if (!(AtlasUtil.isEmpty(child.getDocId()) && AtlasUtil.isEmpty(child.getPath()))) { sourceFieldMap.put(child.getDocId() + ":" + child.getPath(), child); } } } Expression parsedExpression = Expression.parse(expression, DefaultAtlasFunctionResolver.getInstance()); Object answer = parsedExpression.evaluate((path) -> { if (path == null || path.isEmpty()) { return null; } try { String[] splitted = path.split(":", 2); AtlasFieldReader reader = session.getFieldReader(splitted[0]); Field f = sourceFieldMap.get(path); if (f == null) { return null; } session.head().setSourceField(f); return reader.read(session); } catch (Exception e) { throw new ExpressionException(e); } }); if (answer instanceof Field) { session.head().setSourceField((Field)answer); } else { Field from = session.head().getSourceField(); SimpleField to = new SimpleField(); AtlasModelFactory.copyField(from, to, false); to.setValue(answer); session.head().setSourceField(to); } } catch (Exception e) { AtlasUtil.addAudit(session, null, String.format("Expression processing error: %s", e.getMessage()), expression, AuditStatus.ERROR, null); if (LOG.isDebugEnabled()) { LOG.debug("", e); } } }  static void processExpression(DefaultAtlasSession session, String expression);  }