1
|
package eu.dnetlib.openaire.usermanagement.utils;
|
2
|
|
3
|
import com.google.gson.JsonArray;
|
4
|
import com.google.gson.JsonElement;
|
5
|
import com.google.gson.JsonObject;
|
6
|
import eu.dnetlib.openaire.user.pojos.RoleVerification;
|
7
|
import eu.dnetlib.openaire.usermanagement.dto.Role;
|
8
|
import org.springframework.beans.factory.annotation.Value;
|
9
|
import org.springframework.stereotype.Component;
|
10
|
|
11
|
@Component
|
12
|
public class JsonUtils {
|
13
|
|
14
|
@Value("${registry.version}")
|
15
|
private String version;
|
16
|
|
17
|
@Value("${registry.coid}")
|
18
|
private String coid;
|
19
|
|
20
|
public JsonObject coPersonRoles(Integer coPersonId, Integer couId, String status) {
|
21
|
JsonObject role = new JsonObject();
|
22
|
JsonArray coPersonRoles = new JsonArray();
|
23
|
JsonObject coPersonRole = new JsonObject();
|
24
|
JsonObject person = new JsonObject();
|
25
|
person.addProperty("Type", "CO");
|
26
|
person.addProperty("Id", coPersonId.toString());
|
27
|
coPersonRole.addProperty("Version", version);
|
28
|
coPersonRole.add("Person", person);
|
29
|
coPersonRole.addProperty("CouId", couId.toString());
|
30
|
coPersonRole.addProperty("Affiliation", "member");
|
31
|
coPersonRole.addProperty("Title", "");
|
32
|
coPersonRole.addProperty("O", "Openaire");
|
33
|
coPersonRole.addProperty("Status", status);
|
34
|
coPersonRole.addProperty("ValidFrom", "");
|
35
|
coPersonRole.addProperty("ValidThrough", "");
|
36
|
coPersonRoles.add(coPersonRole);
|
37
|
role.addProperty("RequestType", "CoPersonRoles");
|
38
|
role.addProperty("Version", version);
|
39
|
role.add("CoPersonRoles", coPersonRoles);
|
40
|
return role;
|
41
|
}
|
42
|
|
43
|
public JsonObject coGroupMembers(Integer coGroupId, Integer coPersonId, boolean member) {
|
44
|
JsonObject coGroup = new JsonObject();
|
45
|
JsonArray coGroupMembers = new JsonArray();
|
46
|
JsonObject coGroupMember = new JsonObject();
|
47
|
JsonObject person = new JsonObject();
|
48
|
person.addProperty("Type", "CO");
|
49
|
person.addProperty("Id", coPersonId.toString());
|
50
|
coGroupMember.addProperty("Version", version);
|
51
|
coGroupMember.add("Person", person);
|
52
|
coGroupMember.addProperty("CoGroupId", coGroupId.toString());
|
53
|
coGroupMember.addProperty("Member", member);
|
54
|
coGroupMember.addProperty("Owner", false);
|
55
|
coGroupMember.addProperty("ValidFrom", "");
|
56
|
coGroupMember.addProperty("ValidThrough", "");
|
57
|
coGroupMembers.add(coGroupMember);
|
58
|
coGroup.addProperty("RequestType", "CoGroupMembers");
|
59
|
coGroup.addProperty("Version", version);
|
60
|
coGroup.add("CoGroupMembers", coGroupMembers);
|
61
|
return coGroup;
|
62
|
}
|
63
|
|
64
|
public JsonObject createNewCou(Role role) {
|
65
|
JsonObject cou = new JsonObject();
|
66
|
JsonArray cous = new JsonArray();
|
67
|
JsonObject newCou = new JsonObject();
|
68
|
newCou.addProperty("Version", version);
|
69
|
newCou.addProperty("CoId", coid);
|
70
|
newCou.addProperty("Name", role.getName());
|
71
|
newCou.addProperty("Description", role.getDescription());
|
72
|
cous.add(newCou);
|
73
|
cou.addProperty("RequestType", "Cous");
|
74
|
cou.addProperty("Version", version);
|
75
|
cou.add("Cous", cous);
|
76
|
return cou;
|
77
|
}
|
78
|
|
79
|
public JsonObject createVerification(RoleVerification roleVerification) {
|
80
|
JsonObject verification = new JsonObject();
|
81
|
verification.addProperty("id", roleVerification.getId());
|
82
|
verification.addProperty("email", roleVerification.getEmail());
|
83
|
verification.addProperty("type", roleVerification.getType());
|
84
|
verification.addProperty("entity", roleVerification.getEntity());
|
85
|
verification.addProperty("verificationType", roleVerification.getVerificationType());
|
86
|
verification.addProperty("date", roleVerification.getDate().getTime());
|
87
|
return verification;
|
88
|
}
|
89
|
|
90
|
public JsonObject createResponse(JsonElement response) {
|
91
|
JsonObject json = new JsonObject();
|
92
|
json.add("response", response);
|
93
|
return json;
|
94
|
}
|
95
|
|
96
|
public JsonObject createResponse(String response) {
|
97
|
JsonObject json = new JsonObject();
|
98
|
json.addProperty("response", response);
|
99
|
return json;
|
100
|
}
|
101
|
|
102
|
public JsonObject createResponse(Number response) {
|
103
|
JsonObject json = new JsonObject();
|
104
|
json.addProperty("response", response);
|
105
|
return json;
|
106
|
}
|
107
|
|
108
|
public JsonObject createResponse(Boolean response) {
|
109
|
JsonObject json = new JsonObject();
|
110
|
json.addProperty("response", response);
|
111
|
return json;
|
112
|
}
|
113
|
|
114
|
public JsonObject createResponse(Character response) {
|
115
|
JsonObject json = new JsonObject();
|
116
|
json.addProperty("response", response);
|
117
|
return json;
|
118
|
}
|
119
|
}
|