/
Installation.java
87 lines (69 loc) · 2.69 KB
/
Installation.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package de.thokari.epages.app.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.vertx.core.json.JsonArray;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;
import java.util.stream.Collectors;
public class Installation extends Model {
public static final String TABLE_NAME = "installations";
@JsonProperty("api_url")
public String apiUrl;
@JsonProperty("access_token")
public String accessToken;
@JsonProperty("shop_name")
public String shopName;
@JsonProperty("email")
@JsonInclude(JsonInclude.Include.NON_NULL)
public String email;
@JsonProperty("email_confirmed")
public Boolean emailConfirmed;
@JsonProperty("created")
public String created;
@JsonCreator
public Installation(@JsonProperty("api_url") String apiUrl, @JsonProperty("access_token") String accessToken,
@JsonProperty("shop_name") String shopName, @JsonProperty("email") String email,
@JsonProperty("email_confirmed") Boolean emailConfirmed,
@JsonProperty("created") String created) {
this.apiUrl = apiUrl;
this.accessToken = accessToken;
this.shopName = shopName;
this.email = email;
this.emailConfirmed = emailConfirmed;
if (created == null) {
this.created = new Timestamp(new Date().getTime()).toInstant().toString();
}
}
public Installation(String apiUrl, String accessToken, String shopName) {
this(apiUrl, accessToken, shopName, null, null, null);
}
@JsonIgnore
public String getInsertQuery() {
return String.format("INSERT INTO %s %s VALUES %s", TABLE_NAME, getColumnNames(), getParameterPart());
}
@JsonIgnore
public String getParameterPart() {
return this.toJsonObject().stream()
.filter(it -> it.getValue() != null)
.map(it -> "?")
.collect(Collectors.joining(", ", "(", ")"));
}
@JsonIgnore
public String getColumnNames() {
return this.toJsonObject().stream()
.filter(it -> it.getValue() != null)
.map(Map.Entry::getKey)
.collect(Collectors.joining(", ", "(", ")"));
}
@JsonIgnore
public JsonArray getInsertQueryParams() {
return new JsonArray(
this.toJsonObject().stream()
.filter(it -> it.getValue() != null)
.map(Map.Entry::getValue)
.collect(Collectors.toList()));
}
}