@Test public void testMatchCommerceEventProperty() throws Exception { JSONObject config = new JSONObject("{\"id\":99, \"pmid\":229, \"matches\":[{\"message_type\":16, \"event_match_type\":\"Hash\", \"event\":\"1569\", \"property\":\"EventField\", \"property_name\":\"-601244443\", \"property_values\":[\"5\"]}], \"behavior\":{\"max_custom_params\":0, \"selector\":\"last\"}, \"action\":{\"projected_event_name\":\"checkout - place order\", \"attribute_maps\":[{\"projected_attribute_name\":\"Last Place Order Category\", \"match_type\":\"Hash\", \"value\":\"-1167125985\", \"data_type\":\"String\", \"property\":\"ProductField\"} ], \"outbound_message_type\":16 } }"); CustomMapping customMapping = new CustomMapping(config); Product product = new Product.Builder("name", "sku", 0).build(); CommerceEvent commerceEvent = new CommerceEvent.Builder(Product.CHECKOUT, product).checkoutStep(4).build(); assertFalse(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(commerceEvent))); commerceEvent = new CommerceEvent.Builder(Product.CHECKOUT, product).checkoutStep(5).build(); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(commerceEvent))); config.getJSONArray("matches").getJSONObject(0).put("property", "EventAttribute"); customMapping = new CustomMapping(config); assertFalse(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(commerceEvent))); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("Checkout Step", "5"); commerceEvent = new CommerceEvent.Builder(Product.CHECKOUT, product).customAttributes(attributes).build(); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(commerceEvent))); config.getJSONArray("matches").getJSONObject(0).put("property", "ProductAttribute"); customMapping = new CustomMapping(config); assertFalse(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(commerceEvent))); commerceEvent = new CommerceEvent.Builder(Product.CHECKOUT, product).addProduct(new Product.Builder("name 2", "sku", 0).customAttributes(attributes).build()).build(); EventWrapper.CommerceEventWrapper wrapper = new EventWrapper.CommerceEventWrapper(commerceEvent); assertTrue(customMapping.isMatch(wrapper)); assertEquals(1, wrapper.getEvent().getProducts().size()); assertEquals("name 2", wrapper.getEvent().getProducts().get(0).getName()); config.getJSONArray("matches").getJSONObject(0).put("property", "ProductField"); config.getJSONArray("matches").getJSONObject(0).put("property_name", "-1167125985"); JSONArray values = new JSONArray(); values.put("some product cat"); config.getJSONArray("matches").getJSONObject(0).put("property_values",values); customMapping = new CustomMapping(config); assertFalse(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(commerceEvent))); commerceEvent = new CommerceEvent.Builder(Product.CHECKOUT, product).addProduct(new Product.Builder("name 2", "sku", 0).category("some product cat").build()).build(); wrapper = new EventWrapper.CommerceEventWrapper(commerceEvent); assertTrue(customMapping.isMatch(wrapper)); assertEquals(1, wrapper.getEvent().getProducts().size()); assertEquals("some product cat", wrapper.getEvent().getProducts().get(0).getCategory()); config.getJSONArray("matches").getJSONObject(0).put("property", "PromotionField"); config.getJSONArray("matches").getJSONObject(0).put("property_name", "835505623"); values = new JSONArray(); values.put("some promotion creative"); config.getJSONArray("matches").getJSONObject(0).put("property_values", values); customMapping = new CustomMapping(config); assertFalse(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(commerceEvent))); commerceEvent = new CommerceEvent.Builder(Promotion.CLICK, new Promotion().setCreative("some promotion creative")).addPromotion( new Promotion().setCreative("some other creative") ).build(); wrapper = new EventWrapper.CommerceEventWrapper(commerceEvent); assertTrue(customMapping.isMatch(wrapper)); assertEquals(1, wrapper.getEvent().getPromotions().size()); assertEquals("some promotion creative", wrapper.getEvent().getPromotions().get(0).getCreative()); }
boolean isMatch(EventWrapper wrapper) { if (mIsDefault) { return true; } for (CustomMappingMatch match : matchList) { if (!match.isMatch(wrapper)) { return false; } } return true; }
CustomMapping { boolean isMatch(EventWrapper wrapper) { if (mIsDefault) { return true; } for (CustomMappingMatch match : matchList) { if (!match.isMatch(wrapper)) { return false; } } return true; } }
CustomMapping { boolean isMatch(EventWrapper wrapper) { if (mIsDefault) { return true; } for (CustomMappingMatch match : matchList) { if (!match.isMatch(wrapper)) { return false; } } return true; } CustomMapping(JSONObject projectionJson); }
CustomMapping { boolean isMatch(EventWrapper wrapper) { if (mIsDefault) { return true; } for (CustomMappingMatch match : matchList) { if (!match.isMatch(wrapper)) { return false; } } return true; } CustomMapping(JSONObject projectionJson); List<CustomMappingMatch> getMatchList(); boolean isDefault(); List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper); List<ProjectionResult> project(EventWrapper.MPEventWrapper event); int getMessageType(); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(CommerceEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCommerceCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, boolean isScreenEvent, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping, CustomMapping defaultScreenCustomMapping); }
CustomMapping { boolean isMatch(EventWrapper wrapper) { if (mIsDefault) { return true; } for (CustomMappingMatch match : matchList) { if (!match.isMatch(wrapper)) { return false; } } return true; } CustomMapping(JSONObject projectionJson); List<CustomMappingMatch> getMatchList(); boolean isDefault(); List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper); List<ProjectionResult> project(EventWrapper.MPEventWrapper event); int getMessageType(); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(CommerceEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCommerceCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, boolean isScreenEvent, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping, CustomMapping defaultScreenCustomMapping); final static String PROPERTY_LOCATION_EVENT_FIELD; final static String PROPERTY_LOCATION_EVENT_ATTRIBUTE; final static String PROPERTY_LOCATION_PRODUCT_FIELD; final static String PROPERTY_LOCATION_PRODUCT_ATTRIBUTE; final static String PROPERTY_LOCATION_PROMOTION_FIELD; }