|
1 | 1 | package com.skyflow; |
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
3 | 6 | import com.skyflow.config.Credentials; |
4 | 7 | import com.skyflow.config.VaultConfig; |
5 | 8 | import com.skyflow.enums.UpdateType; |
|
20 | 23 | import com.skyflow.utils.logger.LogUtil; |
21 | 24 | import com.skyflow.utils.validations.Validations; |
22 | 25 | import com.skyflow.vault.data.DetokenizeRequest; |
| 26 | +import com.skyflow.vault.data.InsertRecord; |
| 27 | + |
23 | 28 | import io.github.cdimascio.dotenv.Dotenv; |
24 | 29 | import io.github.cdimascio.dotenv.DotenvException; |
25 | 30 | import okhttp3.OkHttpClient; |
26 | 31 | import okhttp3.Request; |
27 | 32 |
|
28 | | -import java.util.ArrayList; |
29 | | -import java.util.HashMap; |
30 | | -import java.util.List; |
31 | | - |
32 | 33 |
|
33 | 34 | public class VaultClient { |
34 | 35 | private final VaultConfig vaultConfig; |
@@ -132,17 +133,41 @@ protected void updateExecutorInHTTP() { |
132 | 133 | apiClientBuilder.httpClient(httpClient); |
133 | 134 | } |
134 | 135 |
|
135 | | - protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRequest request, VaultConfig config) throws SkyflowException { |
136 | | - List<HashMap<String, Object>> values = request.getValues(); |
| 136 | + protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRequest request, VaultConfig config) { |
| 137 | + ArrayList<InsertRecord> records = request.getRecords(); |
137 | 138 | List<InsertRecordData> insertRecordDataList = new ArrayList<>(); |
138 | | - for (HashMap<String, Object> value : values) { |
139 | | - InsertRecordData data = InsertRecordData.builder().data(value).build(); |
140 | | - insertRecordDataList.add(data); |
| 139 | + for (InsertRecord record : records) { |
| 140 | + InsertRecordData.Builder data = InsertRecordData.builder(); |
| 141 | + data.data(record.getData()); |
| 142 | + if (record.getTable() != null && !record.getTable().isEmpty()){ |
| 143 | + data.tableName(record.getTable()); |
| 144 | + } |
| 145 | + if (record.getUpsert() != null && !record.getUpsert().isEmpty()){ |
| 146 | + if (record.getUpsertType() != null) { |
| 147 | + EnumUpdateType updateType = null; |
| 148 | + if (record.getUpsertType() == UpdateType.REPLACE) { |
| 149 | + updateType = EnumUpdateType.REPLACE; |
| 150 | + } else if (record.getUpsertType() == UpdateType.UPDATE) { |
| 151 | + updateType = EnumUpdateType.UPDATE; |
| 152 | + } |
| 153 | + Upsert upsert = Upsert.builder().uniqueColumns(record.getUpsert()).updateType(updateType).build(); |
| 154 | + data.upsert(upsert); |
| 155 | + } else { |
| 156 | + Upsert upsert = Upsert.builder().uniqueColumns(record.getUpsert()).build(); |
| 157 | + data.upsert(upsert); |
| 158 | + } |
| 159 | + } |
| 160 | + insertRecordDataList.add(data.build()); |
141 | 161 | } |
| 162 | + |
142 | 163 | InsertRequest.Builder builder = InsertRequest.builder() |
143 | 164 | .vaultId(config.getVaultId()) |
144 | | - .records(insertRecordDataList) |
145 | | - .tableName(request.getTable()); |
| 165 | + .records(insertRecordDataList); |
| 166 | + |
| 167 | + if (request.getTable() != null && !request.getTable().isEmpty()){ |
| 168 | + builder.tableName(request.getTable()); |
| 169 | + } |
| 170 | + |
146 | 171 | if (request.getUpsert() != null && !request.getUpsert().isEmpty()) { |
147 | 172 | if (request.getUpsertType() != null) { |
148 | 173 | EnumUpdateType updateType = null; |
|
0 commit comments