@Test public void testMatchCommerceEventType() throws Exception { Product product = new Product.Builder("name", "sku", 0).build(); JSONObject config = new JSONObject("{\"id\":99, \"pmid\":229, \"matches\":[{\"message_type\":16, \"event_match_type\":\"Hash\", \"event\":\"1569\", }], \"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 } }"); CommerceEvent event = new CommerceEvent.Builder(Product.DETAIL, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); CustomMapping customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.ADD_TO_CART, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.PURCHASE, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.ADD_TO_WISHLIST, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.CHECKOUT, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.CHECKOUT_OPTION, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.CLICK, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.REFUND, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.REMOVE_FROM_CART, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Product.REMOVE_FROM_WISHLIST, product).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(new Impression("list name", product)).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Promotion.VIEW, new Promotion().setId("id")).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); event = new CommerceEvent.Builder(Promotion.CLICK, new Promotion().setId("id")).transactionAttributes(new TransactionAttributes().setId("id")).build(); config.getJSONArray("matches").getJSONObject(0).put("event",""+KitUtils.hashForFiltering(""+ CommerceEventUtils.getEventType(event))); customMapping = new CustomMapping(config); assertTrue(customMapping.isMatch(new EventWrapper.CommerceEventWrapper(event))); }
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; }