| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Copyright 2015 LinkedIn Corp. All rights reserved.
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  |  * You may obtain a copy of the License at
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  |  */
 | 
					
						
							|  |  |  | package utils;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import com.fasterxml.jackson.databind.JsonNode;
 | 
					
						
							|  |  |  | import com.fasterxml.jackson.databind.node.ArrayNode;
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  | import com.fasterxml.jackson.databind.node.ObjectNode;
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | import com.fasterxml.jackson.databind.node.TextNode;
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  | import org.apache.commons.lang3.StringUtils;
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import java.util.Arrays;
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  | import java.util.Iterator;
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public class SampleData
 | 
					
						
							|  |  |  | {
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  |     private final static String MEMBER_ID = "memberId";
 | 
					
						
							|  |  |  |     private final static String TREE_ID = "treeId";
 | 
					
						
							|  |  |  |     private final static String TRACKING_ID = "trackingId";
 | 
					
						
							| 
									
										
										
										
											2016-03-16 18:35:46 -07:00
										 |  |  |     private final static String IP_AS_BYTES_1 = "ipAsBytes";
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  |     private final static String IP_AS_BYTES = "ip_as_bytes";
 | 
					
						
							|  |  |  |     private final static String ATTACHMENTS = "attachments";
 | 
					
						
							|  |  |  |     private final static String PAYLOAD = "payload";
 | 
					
						
							|  |  |  |     private final static String MEDIA = "MEDIA";
 | 
					
						
							|  |  |  |     private final static String HEADER = "header";
 | 
					
						
							|  |  |  |     private final static String GUID = "guid";
 | 
					
						
							|  |  |  |     private final static String AUDITHEADER = "auditHeader";
 | 
					
						
							|  |  |  |     private final static String MESSAGE_ID = "messageId";
 | 
					
						
							|  |  |  |     private final static String REQUEST = "request";
 | 
					
						
							|  |  |  |     private final static String REQUEST_HEADER = "requestHeader";
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static String convertToHexString(JsonNode node)
 | 
					
						
							|  |  |  |     {
 | 
					
						
							|  |  |  |         String result = null;
 | 
					
						
							|  |  |  |         if (node != null)
 | 
					
						
							|  |  |  |         {
 | 
					
						
							|  |  |  |             if (node.isArray())
 | 
					
						
							|  |  |  |             {
 | 
					
						
							|  |  |  |                 Iterator<JsonNode> arrayIterator = node.elements();
 | 
					
						
							|  |  |  |                 StringBuilder sb = new StringBuilder();
 | 
					
						
							|  |  |  |                 while (arrayIterator.hasNext()) {
 | 
					
						
							|  |  |  |                     JsonNode elementNode = arrayIterator.next();
 | 
					
						
							|  |  |  |                     if (elementNode != null)
 | 
					
						
							|  |  |  |                     {
 | 
					
						
							|  |  |  |                         String text = elementNode.asText();
 | 
					
						
							|  |  |  |                         if (StringUtils.isNotBlank(text))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             byte[] bytes = text.getBytes();
 | 
					
						
							|  |  |  |                             if (bytes != null && bytes.length > 0)
 | 
					
						
							|  |  |  |                             {
 | 
					
						
							|  |  |  |                                 sb.append(String.format("%02x", text.getBytes()[0]));
 | 
					
						
							|  |  |  |                             }
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |                 result = sb.toString();
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |             else
 | 
					
						
							|  |  |  |             {
 | 
					
						
							|  |  |  |                 result = node.asText();
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return result;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  |     public static JsonNode secureSampleData(JsonNode sample) {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         String[] nameArray = new String[]{"member_sk", "membersk", "member_id", "memberid", "mem_sk", "mem_id"};
 | 
					
						
							|  |  |  |         if (sample != null && sample.has("sample")) {
 | 
					
						
							|  |  |  |             JsonNode sampleNode = sample.get("sample");
 | 
					
						
							|  |  |  |             if (sampleNode != null && sampleNode.has("columnNames") && sampleNode.has("data")) {
 | 
					
						
							|  |  |  |                 JsonNode namesNode = sampleNode.get("columnNames");
 | 
					
						
							|  |  |  |                 JsonNode dataNode = sampleNode.get("data");
 | 
					
						
							|  |  |  |                 if (namesNode != null && namesNode.isArray()) {
 | 
					
						
							|  |  |  |                     for (int i = 0; i < namesNode.size(); i++) {
 | 
					
						
							|  |  |  |                         if (Arrays.asList(nameArray).contains(namesNode.get(i).asText().toLowerCase())) {
 | 
					
						
							|  |  |  |                             if (dataNode != null && dataNode.isArray()) {
 | 
					
						
							|  |  |  |                                 for (JsonNode node : dataNode) {
 | 
					
						
							|  |  |  |                                     JsonNode valueNode = node.get(i);
 | 
					
						
							|  |  |  |                                     ((ArrayNode)node).set(i, new TextNode("********"));
 | 
					
						
							|  |  |  |                                 }
 | 
					
						
							|  |  |  |                             }
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  |             else
 | 
					
						
							|  |  |  |             {
 | 
					
						
							|  |  |  |                 int index = 0;
 | 
					
						
							|  |  |  |                 Iterator<JsonNode> arrayIterator = sampleNode.elements();
 | 
					
						
							|  |  |  |                 while (arrayIterator.hasNext()) {
 | 
					
						
							|  |  |  |                     JsonNode sampleRowNode = arrayIterator.next();
 | 
					
						
							|  |  |  |                     if (sampleRowNode != null)
 | 
					
						
							|  |  |  |                     {
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(MEMBER_ID))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             ((ObjectNode)sampleRowNode).put(MEMBER_ID, new TextNode("********"));
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(TREE_ID))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode treeIdNode = sampleRowNode.get(TREE_ID);
 | 
					
						
							|  |  |  |                             String convertedValue = convertToHexString(treeIdNode);
 | 
					
						
							|  |  |  |                             ((ObjectNode) sampleRowNode).put(TREE_ID, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(TRACKING_ID))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode trackingIdNode = sampleRowNode.get(TRACKING_ID);
 | 
					
						
							|  |  |  |                             String convertedValue = convertToHexString(trackingIdNode);
 | 
					
						
							|  |  |  |                             ((ObjectNode) sampleRowNode).put(TRACKING_ID, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(IP_AS_BYTES))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode ipNode = sampleRowNode.get(IP_AS_BYTES);
 | 
					
						
							|  |  |  |                             String convertedValue = convertToHexString(ipNode);
 | 
					
						
							|  |  |  |                             ((ObjectNode) sampleRowNode).put(IP_AS_BYTES, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							| 
									
										
										
										
											2016-03-16 18:35:46 -07:00
										 |  |  |                         if (sampleRowNode.has(IP_AS_BYTES_1))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode ipNode = sampleRowNode.get(IP_AS_BYTES_1);
 | 
					
						
							|  |  |  |                             String convertedValue = convertToHexString(ipNode);
 | 
					
						
							|  |  |  |                             ((ObjectNode) sampleRowNode).put(IP_AS_BYTES_1, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  |                         if (sampleRowNode.has(ATTACHMENTS))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode attachmentNode = sampleRowNode.get(ATTACHMENTS);
 | 
					
						
							|  |  |  |                             if (attachmentNode.has(PAYLOAD))
 | 
					
						
							|  |  |  |                             {
 | 
					
						
							|  |  |  |                                 JsonNode payloadNode = attachmentNode.get(PAYLOAD);
 | 
					
						
							|  |  |  |                                 String value = "** " + Integer.toString(payloadNode.size()) + " bytes binary data **";
 | 
					
						
							|  |  |  |                                 ((ObjectNode) attachmentNode).put(PAYLOAD, new TextNode(value));
 | 
					
						
							|  |  |  |                             }
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(MEDIA))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode mediaNode = sampleRowNode.get(MEDIA);
 | 
					
						
							|  |  |  |                             String convertedValue = convertToHexString(mediaNode);
 | 
					
						
							|  |  |  |                             ((ObjectNode) sampleRowNode).put(MEDIA, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(HEADER))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode headerNode = sampleRowNode.get(HEADER);
 | 
					
						
							|  |  |  |                             if (headerNode != null)
 | 
					
						
							|  |  |  |                             {
 | 
					
						
							|  |  |  |                                 if (headerNode.has(MEMBER_ID))
 | 
					
						
							|  |  |  |                                 {
 | 
					
						
							|  |  |  |                                     ((ObjectNode)headerNode).put(MEMBER_ID, new TextNode("********"));
 | 
					
						
							|  |  |  |                                 }
 | 
					
						
							|  |  |  |                                 if (headerNode.has(GUID))
 | 
					
						
							|  |  |  |                                 {
 | 
					
						
							|  |  |  |                                     JsonNode guidNode = headerNode.get(GUID);
 | 
					
						
							|  |  |  |                                     String convertedValue = convertToHexString(guidNode);
 | 
					
						
							|  |  |  |                                     ((ObjectNode) headerNode).put(GUID, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                                 }
 | 
					
						
							|  |  |  |                                 if (headerNode.has(TREE_ID))
 | 
					
						
							|  |  |  |                                 {
 | 
					
						
							|  |  |  |                                     JsonNode headerTreeIdNode = headerNode.get(TREE_ID);
 | 
					
						
							|  |  |  |                                     String convertedValue = convertToHexString(headerTreeIdNode);
 | 
					
						
							|  |  |  |                                     ((ObjectNode) headerNode).put(TREE_ID, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                                 }
 | 
					
						
							|  |  |  |                                 if (headerNode.has(AUDITHEADER))
 | 
					
						
							|  |  |  |                                 {
 | 
					
						
							|  |  |  |                                     JsonNode auditHeaderNode = headerNode.get(AUDITHEADER);
 | 
					
						
							|  |  |  |                                     if (auditHeaderNode != null && auditHeaderNode.has(MESSAGE_ID))
 | 
					
						
							|  |  |  |                                     {
 | 
					
						
							|  |  |  |                                         JsonNode messageIdNode = auditHeaderNode.get(MESSAGE_ID);
 | 
					
						
							|  |  |  |                                         String convertedValue = convertToHexString(messageIdNode);
 | 
					
						
							|  |  |  |                                         ((ObjectNode) auditHeaderNode).put(MESSAGE_ID, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                                     }
 | 
					
						
							|  |  |  |                                 }
 | 
					
						
							|  |  |  |                             }
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(REQUEST))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode requestNode = sampleRowNode.get(REQUEST);
 | 
					
						
							|  |  |  |                             if (requestNode != null && requestNode.has(ATTACHMENTS))
 | 
					
						
							|  |  |  |                             {
 | 
					
						
							|  |  |  |                                 JsonNode attachmentsNode = requestNode.get(ATTACHMENTS);
 | 
					
						
							|  |  |  |                                 if (attachmentsNode != null && attachmentsNode.has(PAYLOAD))
 | 
					
						
							|  |  |  |                                 {
 | 
					
						
							|  |  |  |                                     JsonNode payloadNode = attachmentsNode.get(PAYLOAD);
 | 
					
						
							|  |  |  |                                     String value = "** " +
 | 
					
						
							|  |  |  |                                             Integer.toString(payloadNode.size()) +
 | 
					
						
							|  |  |  |                                             " bytes binary data **";
 | 
					
						
							|  |  |  |                                     ((ObjectNode) attachmentsNode).put(PAYLOAD, new TextNode(value));
 | 
					
						
							|  |  |  |                                 }
 | 
					
						
							|  |  |  |                             }
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         if (sampleRowNode.has(REQUEST_HEADER))
 | 
					
						
							|  |  |  |                         {
 | 
					
						
							|  |  |  |                             JsonNode requestHeaderNode = sampleRowNode.get(REQUEST_HEADER);
 | 
					
						
							|  |  |  |                             if (requestHeaderNode != null && requestHeaderNode.has(IP_AS_BYTES))
 | 
					
						
							|  |  |  |                             {
 | 
					
						
							|  |  |  |                                 JsonNode ipNode = requestHeaderNode.get(IP_AS_BYTES);
 | 
					
						
							|  |  |  |                                 String convertedValue = convertToHexString(ipNode);
 | 
					
						
							|  |  |  |                                 ((ObjectNode) requestHeaderNode).put(IP_AS_BYTES, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                             }
 | 
					
						
							| 
									
										
										
										
											2016-03-16 18:35:46 -07:00
										 |  |  |                             if (requestHeaderNode != null && requestHeaderNode.has(IP_AS_BYTES_1))
 | 
					
						
							|  |  |  |                             {
 | 
					
						
							|  |  |  |                                 JsonNode ipNode = requestHeaderNode.get(IP_AS_BYTES_1);
 | 
					
						
							|  |  |  |                                 String convertedValue = convertToHexString(ipNode);
 | 
					
						
							|  |  |  |                                 ((ObjectNode) requestHeaderNode).put(IP_AS_BYTES_1, new TextNode(convertedValue));
 | 
					
						
							|  |  |  |                             }
 | 
					
						
							| 
									
										
										
										
											2016-02-25 17:10:09 -08:00
										 |  |  |                         }
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:39:21 -08:00
										 |  |  |         }
 | 
					
						
							|  |  |  |         return sample;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | }
 |