Project

General

Profile

« Previous | Next » 

Revision 61318

1. fixed authorization in RepositoryController
2. created new methods and classes
3. made authorities mapping the same as with other openaire projects
4. refactoring

View differences:

JsonUtils.java
1 1
package eu.dnetlib.repo.manager.utils;
2 2

  
3
import com.google.gson.JsonArray;
4 3
import com.google.gson.JsonElement;
5 4
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 5

  
10
@Component
11 6
public class JsonUtils {
12 7

  
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;
8
    private JsonUtils() {
40 9
    }
41 10

  
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 11
    public JsonObject createResponse(JsonElement response) {
58 12
        JsonObject json = new JsonObject();
59 13
        json.add("response", response);
60 14
        return json;
61 15
    }
62 16

  
63
    public JsonObject createResponse(String response) {
17
    public static JsonObject createResponse(String response) {
64 18
        JsonObject json = new JsonObject();
65 19
        json.addProperty("response", response);
66 20
        return json;
......
72 26
        return json;
73 27
    }
74 28

  
75
    public JsonObject createResponse(Boolean response) {
29
    public static JsonObject createResponse(Boolean response) {
76 30
        JsonObject json = new JsonObject();
77 31
        json.addProperty("response", response);
78 32
        return json;
79 33
    }
80 34

  
81
    public JsonObject createResponse(Character response) {
35
    public static JsonObject createResponse(Character response) {
82 36
        JsonObject json = new JsonObject();
83 37
        json.addProperty("response", response);
84 38
        return json;

Also available in: Unified diff