Skip to content

Commit 35dbde0

Browse files
SK-1978 address the review comments
1 parent 3858863 commit 35dbde0

File tree

8 files changed

+59
-36
lines changed

8 files changed

+59
-36
lines changed

src/main/java/com/skyflow/Skyflow.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.skyflow;
22

3-
import java.util.LinkedHashMap;
4-
53
import com.skyflow.config.ConnectionConfig;
64
import com.skyflow.config.Credentials;
75
import com.skyflow.config.VaultConfig;
@@ -19,6 +17,8 @@
1917
import com.skyflow.vault.controller.DetectController;
2018
import com.skyflow.vault.controller.VaultController;
2119

20+
import java.util.LinkedHashMap;
21+
2222
public final class Skyflow {
2323
private final SkyflowClientBuilder builder;
2424

@@ -102,17 +102,43 @@ public VaultController vault(String vaultId) throws SkyflowException {
102102
return controller;
103103
}
104104

105-
public ConnectionController connection() {
106-
String connectionId = (String) this.builder.connectionsMap.keySet().toArray()[0];
105+
106+
public ConnectionController connection() throws SkyflowException {
107+
Object[] array = this.builder.connectionsMap.keySet().toArray();
108+
if (array.length < 1) {
109+
LogUtil.printErrorLog(ErrorLogs.CONNECTION_CONFIG_DOES_NOT_EXIST.getLog());
110+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.ConnectionIdNotInConfigList.getMessage());
111+
}
112+
String connectionId = (String) array[0];
107113
return this.connection(connectionId);
108114
}
109115

110-
public ConnectionController connection(String connectionId) {
111-
return this.builder.connectionsMap.get(connectionId);
116+
public ConnectionController connection(String connectionId) throws SkyflowException {
117+
ConnectionController controller = this.builder.connectionsMap.get(connectionId);
118+
if (controller == null) {
119+
LogUtil.printErrorLog(ErrorLogs.CONNECTION_CONFIG_DOES_NOT_EXIST.getLog());
120+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.ConnectionIdNotInConfigList.getMessage());
121+
}
122+
return controller;
123+
}
124+
125+
public DetectController detect() throws SkyflowException {
126+
Object[] array = this.builder.detectClientsMap.keySet().toArray();
127+
if (array.length < 1) {
128+
LogUtil.printErrorLog(ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST.getLog());
129+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage());
130+
}
131+
String detectId = (String) array[0];
132+
return this.detect(detectId);
112133
}
113134

114-
public DetectController detect(String vaultId) {
115-
return this.builder.detectClientsMap.get(vaultId);
135+
public DetectController detect(String vaultId) throws SkyflowException {
136+
DetectController controller = this.builder.detectClientsMap.get(vaultId);
137+
if (controller == null) {
138+
LogUtil.printErrorLog(ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST.getLog());
139+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage());
140+
}
141+
return controller;
116142
}
117143

118144
public static final class SkyflowClientBuilder {
@@ -236,6 +262,9 @@ public SkyflowClientBuilder addSkyflowCredentials(Credentials credentials) throw
236262
for (VaultController vault : this.vaultClientsMap.values()) {
237263
vault.setCommonCredentials(this.skyflowCredentials);
238264
}
265+
for (DetectController detect : this.detectClientsMap.values()) {
266+
detect.setCommonCredentials(this.skyflowCredentials);
267+
}
239268
for (ConnectionController connection : this.connectionsMap.values()) {
240269
connection.setCommonCredentials(this.skyflowCredentials);
241270
}

src/main/java/com/skyflow/logs/InfoLogs.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ public enum InfoLogs {
7676
INVOKE_CONNECTION_REQUEST_RESOLVED("Invoke connection request resolved."),
7777

7878
// detect
79+
VALIDATE_DEIDENTIFY_TEXT_REQUEST("Validating deidentify text request."),
80+
DEIDENTIFY_TEXT_SUCCESS("Text data de-identified."),
7981
DEIDENTIFY_TEXT_TRIGGERED("DeIdentify text method triggered."),
8082
DEIDENTIFY_TEXT_REQUEST_RESOLVED("DeIdentify text request resolved."),
83+
VALIDATE_REIDENTIFY_TEXT_REQUEST("Validating reidentify text request."),
8184
REIDENTIFY_TEXT_TRIGGERED("ReIdentify text method triggered."),
8285
REIDENTIFY_TEXT_REQUEST_RESOLVED("ReIdentify text request resolved."),
86+
REIDENTIFY_TEXT_SUCCESS("Text data re-identified."),
8387
;
8488

8589

src/main/java/com/skyflow/vault/controller/DetectController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public DeidentifyTextResponse deidentifyText(DeidentifyTextRequest deidentifyTex
3131
DeidentifyTextResponse deidentifyTextResponse = null;
3232
try {
3333
// Validate the request
34+
LogUtil.printInfoLog(InfoLogs.VALIDATE_DEIDENTIFY_TEXT_REQUEST.getLog());
3435
Validations.validateDeidentifyTextRequest(deidentifyTextRequest);
3536
setBearerToken();
3637

@@ -48,8 +49,10 @@ public DeidentifyTextResponse deidentifyText(DeidentifyTextRequest deidentifyTex
4849
LogUtil.printErrorLog(ErrorLogs.DEIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
4950
throw new SkyflowException(ex.statusCode(), ex, ex.headers(), ex.body().toString());
5051
} catch (Exception e) {
52+
LogUtil.printErrorLog(ErrorLogs.DEIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
5153
throw new SkyflowException(e.getMessage(), e);
5254
}
55+
LogUtil.printInfoLog(InfoLogs.DEIDENTIFY_TEXT_SUCCESS.getLog());
5356
return deidentifyTextResponse;
5457
}
5558

@@ -58,6 +61,7 @@ public ReidentifyTextResponse reidentifyText(ReidentifyTextRequest reidentifyTex
5861
ReidentifyTextResponse reidentifyTextResponse = null;
5962
try {
6063
// Validate the request
64+
LogUtil.printInfoLog(InfoLogs.VALIDATE_REIDENTIFY_TEXT_REQUEST.getLog());
6165
Validations.validateReidentifyTextRequest(reidentifyTextRequest);
6266
setBearerToken();
6367
// Parse the request to ReidentifyTextRequest
@@ -74,8 +78,10 @@ public ReidentifyTextResponse reidentifyText(ReidentifyTextRequest reidentifyTex
7478
LogUtil.printErrorLog(ErrorLogs.REIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
7579
throw new SkyflowException(ex.statusCode(), ex, ex.headers(), ex.body().toString());
7680
} catch (Exception e) {
81+
LogUtil.printErrorLog(ErrorLogs.REIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
7782
throw new SkyflowException(e.getMessage(), e);
7883
}
84+
LogUtil.printInfoLog(InfoLogs.REIDENTIFY_TEXT_SUCCESS.getLog());
7985
return reidentifyTextResponse;
8086
}
8187
}

src/main/java/com/skyflow/vault/detect/DeIdentifyRequest.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/java/com/skyflow/vault/detect/DeIdentifyResponse.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/java/com/skyflow/vault/detect/DeidentifyTextResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
56

67
import java.util.List;
78

@@ -36,7 +37,7 @@ public int getCharCount() {
3637

3738
@Override
3839
public String toString() {
39-
Gson gson = new Gson();
40+
Gson gson = new GsonBuilder().serializeNulls().create();
4041
return gson.toJson(this);
4142
}
4243

src/main/java/com/skyflow/vault/detect/ReidentifyTextResponse.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.skyflow.vault.detect;
22

33

4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
6+
47
public class ReidentifyTextResponse {
58
private final String processedText;
69

@@ -14,8 +17,7 @@ public String getProcessedText() {
1417

1518
@Override
1619
public String toString() {
17-
return "ReidentifyTextResponse{" +
18-
"processedText='" + processedText + '\'' +
19-
'}';
20+
Gson gson = new GsonBuilder().serializeNulls().create();
21+
return gson.toJson(this);
2022
}
2123
}

src/main/java/com/skyflow/vault/detect/TextIndex.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.skyflow.vault.detect;
22

33

4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
6+
47
public class TextIndex {
58
private final int start;
69
private final int end;
@@ -20,9 +23,7 @@ public int getEnd() {
2023

2124
@Override
2225
public String toString() {
23-
return "TextIndex{" +
24-
"start=" + start +
25-
", end=" + end +
26-
'}';
26+
Gson gson = new GsonBuilder().serializeNulls().create();
27+
return gson.toJson(this);
2728
}
2829
}

0 commit comments

Comments
 (0)