mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-26 17:37:33 +00:00
DSS-3968, sample data show guid, headerId as hex string
This commit is contained in:
parent
c763f45878
commit
416691ff40
@ -15,12 +15,64 @@ package utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.TextNode;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SampleData
|
||||
{
|
||||
private final static String MEMBER_ID = "memberId";
|
||||
private final static String TREE_ID = "treeId";
|
||||
private final static String TRACKING_ID = "trackingId";
|
||||
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;
|
||||
}
|
||||
|
||||
public static JsonNode secureSampleData(JsonNode sample) {
|
||||
|
||||
String[] nameArray = new String[]{"member_sk", "membersk", "member_id", "memberid", "mem_sk", "mem_id"};
|
||||
@ -42,6 +94,114 @@ public class SampleData
|
||||
}
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sample;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user