Skip to content

Commit e7809d8

Browse files
committed
SK-2243 Refactor v2 and v3 wrapper code
1 parent 19dbe0c commit e7809d8

33 files changed

+1089
-193
lines changed

common/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
<parent>
77
<groupId>com.skyflow</groupId>
88
<artifactId>skyflow-java</artifactId>
9-
<version>2.0.0-beta.2</version>
9+
<version>1.0.0</version>
1010
</parent>
1111

1212
<artifactId>common</artifactId>
1313
<version>1.0.0</version>
14-
<groupId>com.skyflow</groupId>
1514

1615
<properties>
1716
<maven.compiler.source>8</maven.compiler.source>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.skyflow;
2+
3+
import com.skyflow.config.Credentials;
4+
import com.skyflow.config.VaultConfig;
5+
import com.skyflow.enums.LogLevel;
6+
import com.skyflow.logs.InfoLogs;
7+
import com.skyflow.utils.BaseUtils;
8+
import com.skyflow.utils.logger.LogUtil;
9+
10+
import java.util.LinkedHashMap;
11+
12+
class BaseSkyflow {
13+
private final BaseSkyflowClientBuilder builder;
14+
15+
protected BaseSkyflow(BaseSkyflowClientBuilder builder) {
16+
this.builder = builder;
17+
}
18+
19+
public LogLevel getLogLevel() {
20+
return this.builder.logLevel;
21+
}
22+
23+
public VaultConfig getVaultConfig() {
24+
Object[] array = this.builder.vaultConfigMap.values().toArray();
25+
return (VaultConfig) array[0];
26+
}
27+
28+
static class BaseSkyflowClientBuilder {
29+
protected final LinkedHashMap<String, VaultConfig> vaultConfigMap;
30+
protected Credentials skyflowCredentials;
31+
protected LogLevel logLevel;
32+
33+
protected BaseSkyflowClientBuilder() {
34+
this.vaultConfigMap = new LinkedHashMap<>();
35+
this.skyflowCredentials = null;
36+
this.logLevel = LogLevel.ERROR;
37+
}
38+
39+
public BaseSkyflowClientBuilder setLogLevel(LogLevel logLevel) {
40+
this.logLevel = logLevel == null ? LogLevel.ERROR : logLevel;
41+
LogUtil.setupLogger(this.logLevel);
42+
LogUtil.printInfoLog(BaseUtils.parameterizedString(
43+
InfoLogs.CURRENT_LOG_LEVEL.getLog(), String.valueOf(logLevel)
44+
));
45+
return this;
46+
}
47+
}
48+
}

common/src/main/java/com/skyflow/config/VaultConfig.java

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

33
import com.skyflow.enums.Env;
44

5-
public class VaultConfig {
5+
import java.io.Serializable;
6+
7+
public class VaultConfig implements Serializable {
68
private String vaultId;
79
private String clusterId;
810
private Env env;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.skyflow.logs;
2+
3+
public enum WarningLogs {
4+
OVERRIDING_EXISTING_VAULT_CONFIG("New vault config identified. Overriding existing vault config");
5+
6+
private final String log;
7+
8+
WarningLogs(String log) {
9+
this.log = log;
10+
}
11+
12+
public final String getLog() {
13+
return log;
14+
}
15+
}

common/src/main/java/com/skyflow/utils/BaseUtils.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.skyflow.utils.logger.LogUtil;
1111
import org.apache.commons.codec.binary.Base64;
1212

13-
import java.io.File;
13+
import java.io.*;
1414
import java.net.MalformedURLException;
1515
import java.net.URL;
1616
import java.security.KeyFactory;
@@ -111,4 +111,27 @@ private static PrivateKey parsePkcs8PrivateKey(byte[] pkcs8Bytes) throws Skyflow
111111
}
112112
return privateKey;
113113
}
114+
115+
public static <T extends Serializable> T deepCopy(T obj) {
116+
try {
117+
// Serialize the object to a byte array
118+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
119+
ObjectOutputStream oos = new ObjectOutputStream(bos);
120+
oos.writeObject(obj);
121+
oos.close();
122+
bos.close();
123+
124+
// Deserialize the byte array back to a new object
125+
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
126+
ObjectInputStream ois = new ObjectInputStream(bis);
127+
T copiedObj = (T) ois.readObject();
128+
ois.close();
129+
bis.close();
130+
131+
return copiedObj;
132+
} catch (IOException | ClassNotFoundException e) {
133+
e.printStackTrace();
134+
return null;
135+
}
136+
}
114137
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.skyflow.vault;
2+
3+
public class RequestOptions {
4+
public RequestOptionsBuilder builder;
5+
6+
public static RequestOptionsBuilder builder() {
7+
return new RequestOptionsBuilder();
8+
}
9+
10+
public int getBatchSize() {
11+
return this.builder.batchSize;
12+
}
13+
14+
public int getConcurrencyLimit() {
15+
return this.builder.concurrencyLimit;
16+
}
17+
18+
public static class RequestOptionsBuilder {
19+
private int batchSize;
20+
private int concurrencyLimit;
21+
22+
private RequestOptionsBuilder() {
23+
this.batchSize = 100;
24+
this.concurrencyLimit = 1;
25+
}
26+
27+
public RequestOptionsBuilder batchSize(int batchSize) {
28+
this.batchSize = batchSize;
29+
return this;
30+
}
31+
32+
public RequestOptionsBuilder concurrencyLimit(int concurrencyLimit) {
33+
this.concurrencyLimit = concurrencyLimit;
34+
return this;
35+
}
36+
}
37+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package com.skyflow.vault.data;
2+
3+
import com.skyflow.utils.BaseConstants;
4+
5+
import java.util.ArrayList;
6+
7+
class BaseGetRequest {
8+
private final BaseGetRequestBuilder builder;
9+
10+
protected BaseGetRequest(BaseGetRequestBuilder builder) {
11+
this.builder = builder;
12+
}
13+
14+
public String getTable() {
15+
return this.builder.table;
16+
}
17+
18+
public ArrayList<String> getIds() {
19+
return this.builder.ids;
20+
}
21+
22+
public Boolean getReturnTokens() {
23+
return this.builder.returnTokens;
24+
}
25+
26+
public ArrayList<String> getFields() {
27+
return this.builder.fields;
28+
}
29+
30+
public String getOffset() {
31+
return this.builder.offset;
32+
}
33+
34+
public String getLimit() {
35+
return this.builder.limit;
36+
}
37+
38+
public Boolean getDownloadURL() {
39+
return this.builder.downloadURL;
40+
}
41+
42+
public String getColumnName() {
43+
return this.builder.columnName;
44+
}
45+
46+
public ArrayList<String> getColumnValues() {
47+
return this.builder.columnValues;
48+
}
49+
50+
public String getOrderBy() {
51+
return this.builder.orderBy;
52+
}
53+
54+
static class BaseGetRequestBuilder {
55+
protected String table;
56+
protected ArrayList<String> ids;
57+
protected Boolean returnTokens;
58+
protected ArrayList<String> fields;
59+
protected String offset;
60+
protected String limit;
61+
protected Boolean downloadURL;
62+
protected String columnName;
63+
protected ArrayList<String> columnValues;
64+
protected String orderBy;
65+
66+
protected BaseGetRequestBuilder() {
67+
this.downloadURL = true;
68+
this.orderBy = BaseConstants.ORDER_ASCENDING;
69+
}
70+
71+
public BaseGetRequestBuilder table(String table) {
72+
this.table = table;
73+
return this;
74+
}
75+
76+
public BaseGetRequestBuilder ids(ArrayList<String> ids) {
77+
this.ids = ids;
78+
return this;
79+
}
80+
81+
public BaseGetRequestBuilder returnTokens(Boolean returnTokens) {
82+
this.returnTokens = returnTokens;
83+
return this;
84+
}
85+
86+
public BaseGetRequestBuilder fields(ArrayList<String> fields) {
87+
this.fields = fields;
88+
return this;
89+
}
90+
91+
public BaseGetRequestBuilder offset(String offset) {
92+
this.offset = offset;
93+
return this;
94+
}
95+
96+
public BaseGetRequestBuilder limit(String limit) {
97+
this.limit = limit;
98+
return this;
99+
}
100+
101+
public BaseGetRequestBuilder downloadURL(Boolean downloadURL) {
102+
this.downloadURL = downloadURL == null || downloadURL;
103+
return this;
104+
}
105+
106+
public BaseGetRequestBuilder columnName(String columnName) {
107+
this.columnName = columnName;
108+
return this;
109+
}
110+
111+
public BaseGetRequestBuilder columnValues(ArrayList<String> columnValues) {
112+
this.columnValues = columnValues;
113+
return this;
114+
}
115+
116+
public BaseGetRequestBuilder orderBy(String orderBy) {
117+
this.orderBy = orderBy == null ? BaseConstants.ORDER_ASCENDING : orderBy;
118+
return this;
119+
}
120+
121+
}
122+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.skyflow.vault.data;
2+
3+
import com.google.gson.Gson;
4+
5+
import java.util.ArrayList;
6+
import java.util.HashMap;
7+
8+
public class BaseGetResponse {
9+
private final ArrayList<HashMap<String, Object>> data;
10+
private final ArrayList<HashMap<String, Object>> errors;
11+
12+
public BaseGetResponse(ArrayList<HashMap<String, Object>> data, ArrayList<HashMap<String, Object>> errors) {
13+
this.data = data;
14+
this.errors = errors;
15+
}
16+
17+
public ArrayList<HashMap<String, Object>> getData() {
18+
return data;
19+
}
20+
21+
public ArrayList<HashMap<String, Object>> getErrors() {
22+
return errors;
23+
}
24+
25+
@Override
26+
public String toString() {
27+
Gson gson = new Gson();
28+
return gson.toJson(this);
29+
}
30+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.skyflow.vault.data;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
6+
class BaseInsertRequest {
7+
private final BaseInsertRequestBuilder builder;
8+
9+
protected BaseInsertRequest(BaseInsertRequestBuilder builder) {
10+
this.builder = builder;
11+
}
12+
13+
public String getTable() {
14+
return this.builder.table;
15+
}
16+
17+
public ArrayList<HashMap<String, Object>> getValues() {
18+
return this.builder.values;
19+
}
20+
21+
public ArrayList<HashMap<String, Object>> getTokens() {
22+
return this.builder.tokens;
23+
}
24+
25+
public Boolean getReturnTokens() {
26+
return this.builder.returnTokens;
27+
}
28+
29+
public String getUpsert() {
30+
return this.builder.upsert;
31+
}
32+
33+
static class BaseInsertRequestBuilder {
34+
protected String table;
35+
protected ArrayList<HashMap<String, Object>> values;
36+
protected ArrayList<HashMap<String, Object>> tokens;
37+
protected Boolean returnTokens;
38+
protected String upsert;
39+
40+
protected BaseInsertRequestBuilder() {
41+
this.returnTokens = false;
42+
}
43+
44+
public BaseInsertRequestBuilder table(String table) {
45+
this.table = table;
46+
return this;
47+
}
48+
49+
public BaseInsertRequestBuilder values(ArrayList<HashMap<String, Object>> values) {
50+
this.values = values;
51+
return this;
52+
}
53+
54+
public BaseInsertRequestBuilder tokens(ArrayList<HashMap<String, Object>> tokens) {
55+
this.tokens = tokens;
56+
return this;
57+
}
58+
59+
public BaseInsertRequestBuilder returnTokens(Boolean returnTokens) {
60+
this.returnTokens = returnTokens != null && returnTokens;
61+
return this;
62+
}
63+
64+
public BaseInsertRequestBuilder upsert(String upsert) {
65+
this.upsert = upsert;
66+
return this;
67+
}
68+
}
69+
}
70+

0 commit comments

Comments
 (0)