-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProbeInsertResponse.java
More file actions
58 lines (51 loc) · 1.84 KB
/
Copy pathProbeInsertResponse.java
File metadata and controls
58 lines (51 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.skyflow.utils.probe;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Response returned from an insert operation.
*/
public class ProbeInsertResponse {
private List<Map<String, Object>> insertedFields;
private List<String> errors;
public ProbeInsertResponse(List<Map<String, Object>> rawRecords) {
this.insertedFields = new ArrayList<>();
this.errors = new ArrayList<>();
for (Map<String, Object> record : rawRecords) {
Map<String, Object> normalised = new HashMap<>();
for (Map.Entry<String, Object> entry : record.entrySet()) {
if (entry.getKey().equals("skyflow_id")) {
normalised.put("skyflowId", entry.getValue());
} else {
normalised.put(entry.getKey(), entry.getValue());
}
}
insertedFields.add(normalised);
}
}
public List<Map<String, Object>> getInsertedFields() {
return insertedFields;
}
public List<String> getErrors() {
return errors;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("{\"records\":[");
for (int i = 0; i < insertedFields.size(); i++) {
Map<String, Object> record = insertedFields.get(i);
sb.append("{");
for (Map.Entry<String, Object> entry : record.entrySet()) {
String key = entry.getKey().equals("skyflow_id") ? "skyflowId" : entry.getKey();
sb.append("\"").append(key).append("\":\"").append(entry.getValue()).append("\",");
}
sb.append("}");
if (i < insertedFields.size() - 1) {
sb.append(",");
}
}
sb.append("]}");
return sb.toString();
}
}