1
|
package eu.dnetlib.repo.manager.utils;
|
2
|
|
3
|
import com.google.gson.JsonArray;
|
4
|
import com.google.gson.JsonElement;
|
5
|
import com.google.gson.JsonObject;
|
6
|
import eu.dnetlib.repo.manager.domain.dto.Role;
|
7
|
import org.springframework.beans.factory.annotation.Value;
|
8
|
import org.springframework.stereotype.Component;
|
9
|
|
10
|
@Component
|
11
|
public class JsonUtils {
|
12
|
|
13
|
@Value("1.0")
|
14
|
private String version;
|
15
|
|
16
|
@Value("2")
|
17
|
private String coid;
|
18
|
|
19
|
public JsonObject coPersonRoles(Integer coPersonId, Integer couId, String status) {
|
20
|
JsonObject role = new JsonObject();
|
21
|
JsonArray coPersonRoles = new JsonArray();
|
22
|
JsonObject coPersonRole = new JsonObject();
|
23
|
JsonObject person = new JsonObject();
|
24
|
person.addProperty("Type", "CO");
|
25
|
person.addProperty("Id", coPersonId.toString());
|
26
|
coPersonRole.addProperty("Version", version);
|
27
|
coPersonRole.add("Person", person);
|
28
|
coPersonRole.addProperty("CouId", couId.toString());
|
29
|
coPersonRole.addProperty("Affiliation", "member");
|
30
|
coPersonRole.addProperty("Title", "");
|
31
|
coPersonRole.addProperty("O", "Openaire");
|
32
|
coPersonRole.addProperty("Status", status);
|
33
|
coPersonRole.addProperty("ValidFrom", "");
|
34
|
coPersonRole.addProperty("ValidThrough", "");
|
35
|
coPersonRoles.add(coPersonRole);
|
36
|
role.addProperty("RequestType", "CoPersonRoles");
|
37
|
role.addProperty("Version", version);
|
38
|
role.add("CoPersonRoles", coPersonRoles);
|
39
|
return role;
|
40
|
}
|
41
|
|
42
|
public JsonObject createNewCou(Role role) {
|
43
|
JsonObject cou = new JsonObject();
|
44
|
JsonArray cous = new JsonArray();
|
45
|
JsonObject newCou = new JsonObject();
|
46
|
newCou.addProperty("Version", version);
|
47
|
newCou.addProperty("CoId", coid);
|
48
|
newCou.addProperty("Name", role.getName());
|
49
|
newCou.addProperty("Description", role.getDescription());
|
50
|
cous.add(newCou);
|
51
|
cou.addProperty("RequestType", "Cous");
|
52
|
cou.addProperty("Version", version);
|
53
|
cou.add("Cous", cous);
|
54
|
return cou;
|
55
|
}
|
56
|
|
57
|
public JsonObject createResponse(JsonElement response) {
|
58
|
JsonObject json = new JsonObject();
|
59
|
json.add("response", response);
|
60
|
return json;
|
61
|
}
|
62
|
|
63
|
public JsonObject createResponse(String response) {
|
64
|
JsonObject json = new JsonObject();
|
65
|
json.addProperty("response", response);
|
66
|
return json;
|
67
|
}
|
68
|
|
69
|
public JsonObject createResponse(Number response) {
|
70
|
JsonObject json = new JsonObject();
|
71
|
json.addProperty("response", response);
|
72
|
return json;
|
73
|
}
|
74
|
|
75
|
public JsonObject createResponse(Boolean response) {
|
76
|
JsonObject json = new JsonObject();
|
77
|
json.addProperty("response", response);
|
78
|
return json;
|
79
|
}
|
80
|
|
81
|
public JsonObject createResponse(Character response) {
|
82
|
JsonObject json = new JsonObject();
|
83
|
json.addProperty("response", response);
|
84
|
return json;
|
85
|
}
|
86
|
}
|