@Test public void testDontAppendAsIs() throws Exception { CustomMapping customMapping = new CustomMapping(new JSONObject("{ \"id\":89, \"matches\":[{ \"message_type\":4, \"event_match_type\":\"\", \"event\":\"\" }], \"behavior\":{ \"append_unmapped_as_is\":false, \"is_default\":true }, \"action\":{ \"projected_event_name\":\"\", \"attribute_maps\":[ ] } }")); HashMap<String, String> info = new HashMap<String, String>(); info.put("some key", "some value"); info.put("another key", "another value"); MPEvent event = new MPEvent.Builder("whatever", MParticle.EventType.Other).customAttributes(info).build(); CustomMapping.ProjectionResult newEvent = customMapping.project(new EventWrapper.MPEventWrapper(event)).get(0); assertTrue(newEvent.getMPEvent().getCustomAttributes().size() == 0); customMapping = new CustomMapping(new JSONObject("{ \"id\":89, \"matches\":[{ \"message_type\":4, \"event_match_type\":\"\", \"event\":\"\" }], \"behavior\":{ \"append_unmapped_as_is\":true, \"is_default\":true }, \"action\":{ \"projected_event_name\":\"\", \"attribute_maps\":[ ] } }")); newEvent = customMapping.project(new EventWrapper.MPEventWrapper(event)).get(0); assertTrue(newEvent.getMPEvent().getCustomAttributes().size() == 2); }
public List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper) { List<ProjectionResult> projectionResults = new LinkedList<ProjectionResult>(); CommerceEvent commerceEvent = commerceEventWrapper.getEvent(); int eventType = CommerceEventUtils.getEventType(commerceEvent); if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_IMPRESSION) { return null; }else if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_CLICK || eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_VIEW) { List<Promotion> promotions = commerceEvent.getPromotions(); if (promotions == null || promotions.size() == 0){ ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ if (isSelectorLast) { Promotion promotion = promotions.get(promotions.size() - 1); ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotion); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ for (int i = 0; i < promotions.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotions.get(i)); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .promotions(null) .addPromotion(promotions.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } }else { List<Product> products = commerceEvent.getProducts(); if (isSelectorLast){ Product product = null; if (products != null && products.size() > 0){ product = products.get(products.size() - 1); } ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, product, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else { if (products != null) { for (int i = 0; i < products.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, products.get(i), null); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .products(null) .addProduct(products.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } } if (projectionResults.size() > 0) { return projectionResults; }else{ return null; } }
CustomMapping { public List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper) { List<ProjectionResult> projectionResults = new LinkedList<ProjectionResult>(); CommerceEvent commerceEvent = commerceEventWrapper.getEvent(); int eventType = CommerceEventUtils.getEventType(commerceEvent); if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_IMPRESSION) { return null; }else if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_CLICK || eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_VIEW) { List<Promotion> promotions = commerceEvent.getPromotions(); if (promotions == null || promotions.size() == 0){ ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ if (isSelectorLast) { Promotion promotion = promotions.get(promotions.size() - 1); ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotion); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ for (int i = 0; i < promotions.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotions.get(i)); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .promotions(null) .addPromotion(promotions.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } }else { List<Product> products = commerceEvent.getProducts(); if (isSelectorLast){ Product product = null; if (products != null && products.size() > 0){ product = products.get(products.size() - 1); } ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, product, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else { if (products != null) { for (int i = 0; i < products.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, products.get(i), null); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .products(null) .addProduct(products.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } } if (projectionResults.size() > 0) { return projectionResults; }else{ return null; } } }
CustomMapping { public List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper) { List<ProjectionResult> projectionResults = new LinkedList<ProjectionResult>(); CommerceEvent commerceEvent = commerceEventWrapper.getEvent(); int eventType = CommerceEventUtils.getEventType(commerceEvent); if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_IMPRESSION) { return null; }else if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_CLICK || eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_VIEW) { List<Promotion> promotions = commerceEvent.getPromotions(); if (promotions == null || promotions.size() == 0){ ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ if (isSelectorLast) { Promotion promotion = promotions.get(promotions.size() - 1); ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotion); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ for (int i = 0; i < promotions.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotions.get(i)); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .promotions(null) .addPromotion(promotions.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } }else { List<Product> products = commerceEvent.getProducts(); if (isSelectorLast){ Product product = null; if (products != null && products.size() > 0){ product = products.get(products.size() - 1); } ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, product, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else { if (products != null) { for (int i = 0; i < products.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, products.get(i), null); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .products(null) .addProduct(products.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } } if (projectionResults.size() > 0) { return projectionResults; }else{ return null; } } CustomMapping(JSONObject projectionJson); }
CustomMapping { public List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper) { List<ProjectionResult> projectionResults = new LinkedList<ProjectionResult>(); CommerceEvent commerceEvent = commerceEventWrapper.getEvent(); int eventType = CommerceEventUtils.getEventType(commerceEvent); if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_IMPRESSION) { return null; }else if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_CLICK || eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_VIEW) { List<Promotion> promotions = commerceEvent.getPromotions(); if (promotions == null || promotions.size() == 0){ ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ if (isSelectorLast) { Promotion promotion = promotions.get(promotions.size() - 1); ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotion); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ for (int i = 0; i < promotions.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotions.get(i)); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .promotions(null) .addPromotion(promotions.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } }else { List<Product> products = commerceEvent.getProducts(); if (isSelectorLast){ Product product = null; if (products != null && products.size() > 0){ product = products.get(products.size() - 1); } ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, product, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else { if (products != null) { for (int i = 0; i < products.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, products.get(i), null); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .products(null) .addProduct(products.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } } if (projectionResults.size() > 0) { return projectionResults; }else{ return null; } } 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 { public List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper) { List<ProjectionResult> projectionResults = new LinkedList<ProjectionResult>(); CommerceEvent commerceEvent = commerceEventWrapper.getEvent(); int eventType = CommerceEventUtils.getEventType(commerceEvent); if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_IMPRESSION) { return null; }else if (eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_CLICK || eventType == CommerceEventUtils.Constants.EVENT_TYPE_PROMOTION_VIEW) { List<Promotion> promotions = commerceEvent.getPromotions(); if (promotions == null || promotions.size() == 0){ ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ if (isSelectorLast) { Promotion promotion = promotions.get(promotions.size() - 1); ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotion); if (projectionResult != null) { projectionResults.add(projectionResult); } }else{ for (int i = 0; i < promotions.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, null, promotions.get(i)); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .promotions(null) .addPromotion(promotions.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } }else { List<Product> products = commerceEvent.getProducts(); if (isSelectorLast){ Product product = null; if (products != null && products.size() > 0){ product = products.get(products.size() - 1); } ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, product, null); if (projectionResult != null) { projectionResults.add(projectionResult); } }else { if (products != null) { for (int i = 0; i < products.size(); i++) { ProjectionResult projectionResult = projectCommerceEvent(commerceEventWrapper, products.get(i), null); if (projectionResult != null) { if (projectionResult.getCommerceEvent() != null) { CommerceEvent foreachCommerceEvent = new CommerceEvent.Builder(projectionResult.getCommerceEvent()) .products(null) .addProduct(products.get(i)) .build(); projectionResult.mCommerceEvent = foreachCommerceEvent; } projectionResults.add(projectionResult); } } } } } if (projectionResults.size() > 0) { return projectionResults; }else{ return null; } } 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; }