PropertyConditionEvaluator implements ConditionEvaluator { protected Object getHardcodedPropertyValue(Item item, String expression) { if (item instanceof Event) { Event event = (Event) item; if (expression.startsWith("properties.")) { return getNestedPropertyValue(expression.substring("properties.".length()), event.getProperties()); } if ("target.itemId".equals(expression)) { return event.getTarget().getItemId(); } if (expression.startsWith("target.properties.")) { String expressionPart = expression.substring("target.properties.".length()); Item targetItem = event.getTarget(); if (targetItem instanceof CustomItem) { return getNestedPropertyValue(expressionPart, ((CustomItem) targetItem).getProperties()); } else if (targetItem instanceof Session) { return getNestedPropertyValue(expressionPart, ((Session) targetItem).getProperties()); } else if (targetItem instanceof Rule) { return null; } else if (targetItem instanceof Profile) { return getNestedPropertyValue(expressionPart, ((Profile) targetItem).getProperties()); } } if ("target.scope".equals(expression)) { return event.getTarget().getScope(); } if ("scope".equals(expression)) { return event.getScope(); } if ("eventType".equals(expression)) { return event.getEventType(); } if ("profile".equals(expression)) { return event.getProfile(); } if ("profileId".equals(expression)) { return event.getProfileId(); } if ("session".equals(expression)) { return event.getSession(); } if ("sessionId".equals(expression)) { return event.getSessionId(); } if ("source".equals(expression)) { return event.getSource(); } if ("target".equals(expression)) { return event.getTarget(); } if ("timeStamp".equals(expression)) { return event.getTimeStamp(); } if ("itemId".equals(expression)) { return event.getItemId(); } if ("itemType".equals(expression)) { return event.getItemType(); } } else if (item instanceof Session) { Session session = (Session) item; if ("scope".equals(expression)) { return session.getScope(); } if ("timeStamp".equals(expression)) { return session.getTimeStamp(); } if ("duration".equals(expression)) { return session.getDuration(); } if ("size".equals(expression)) { return session.getSize(); } if ("lastEventDate".equals(expression)) { return session.getLastEventDate(); } if (expression.startsWith("properties.")) { return getNestedPropertyValue(expression.substring("properties.".length()), session.getProperties()); } if (expression.startsWith("systemProperties.")) { return getNestedPropertyValue(expression.substring("systemProperties.".length()), session.getSystemProperties()); } if ("itemId".equals(expression)) { return session.getItemId(); } if ("itemType".equals(expression)) { return session.getItemType(); } if ("profile".equals(expression)) { return session.getProfile(); } if ("profileId".equals(expression)) { return session.getProfileId(); } } else if (item instanceof Profile) { Profile profile = (Profile) item; if ("segments".equals(expression)) { return profile.getSegments(); } if ("consents".equals(expression)) { return profile.getConsents(); } if (expression.startsWith("scores.")) { return profile.getScores().get(expression.substring("scores.".length())); } if (expression.startsWith("properties.")) { return getNestedPropertyValue(expression.substring("properties.".length()), profile.getProperties()); } if (expression.startsWith("systemProperties.")) { return getNestedPropertyValue(expression.substring("systemProperties.".length()), profile.getSystemProperties()); } if ("itemId".equals(expression)) { return profile.getItemId(); } if ("itemType".equals(expression)) { return profile.getItemType(); } if ("mergedWith".equals(expression)) { return profile.getMergedWith(); } } else if (item instanceof CustomItem) { CustomItem customItem = (CustomItem) item; if (expression.startsWith("properties.")) { return getNestedPropertyValue(expression.substring("properties.".length()), customItem.getProperties()); } if ("itemId".equals(expression)) { return customItem.getItemId(); } if ("itemType".equals(expression)) { return customItem.getItemType(); } if ("scope".equals(expression)) { return customItem.getScope(); } } return NOT_OPTIMIZED_MARKER; }  void setUsePropertyConditionOptimizations(boolean usePropertyConditionOptimizations); void setExpressionFilterFactory(ExpressionFilterFactory expressionFilterFactory); @Override boolean eval(Condition condition, Item item, Map<String, Object> context, ConditionEvaluatorDispatcher dispatcher); static final String NOT_OPTIMIZED_MARKER; }
@Test public void testHardcodedEvaluator() { Event mockEvent = generateMockEvent(); assertEquals("Target itemId value is not correct", MOCK_ITEM_ID, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.itemId")); assertEquals("Target scope is not correct", DIGITALL_SCOPE, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.scope")); assertEquals("Target page path value is not correct", PAGE_PATH_VALUE, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.properties.pageInfo.pagePath")); assertEquals("Target page url value is not correct", PAGE_URL_VALUE, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.properties.pageInfo.pageURL")); assertEquals("Session size should be 10", 10, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "size")); assertNull("Unexisting property should be null", propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "systemProperties.goals._csk6r4cgeStartReached")); assertNull("Unexisting property should be null", propertyConditionEvaluator.getHardcodedPropertyValue(mockProfile, "properties.email")); assertEquals("Should have received the non-optimized marker string", NOT_OPTIMIZED_MARKER, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "profile.itemId")); }