Project

General

Profile

« Previous | Next » 

Revision 60486

latest and gratest from trunk

View differences:

RegistryCalls.java
29 29
    public JsonUtils jsonUtils;
30 30

  
31 31

  
32
    private String mapType(String type) {
32
    private String mapType(String type, boolean communityMap) {
33 33
        if(type.equals("organization")) {
34 34
            type = "institution";
35
        }
36
        if(type.equals("ri")) {
35
        } else if(type.equals("ri") && communityMap) {
37 36
            type = "community";
38 37
        }
39 38
        return type;
......
62 61
        params.put("coid", coid);
63 62
        params.put("mail", email);
64 63
        JsonElement response = httpUtils.get("co_people.json", params);
65
        return (response != null) ? response.getAsJsonObject().get("CoPeople").getAsJsonArray().get(0).getAsJsonObject().get("Id").getAsInt() : null;
64
        if(response != null) {
65
            JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray();
66
            if(coPeople.size() > 0) {
67
                return coPeople.get(0).getAsJsonObject().get("Id").getAsInt();
68
            }
69
        }
70
        return null;
66 71
    }
67 72

  
68 73
    /**
......
102 107
    }
103 108

  
104 109
    /**
110
     * 4. Get a couId by name
111
     *
112
     * @param name
113
     * @return
114
     */
115
    public Integer getCouId(String name) {
116
        JsonArray cous = getCous();
117
        Integer couId = null;
118
        for (JsonElement cou : cous) {
119
            if (cou.getAsJsonObject().get("Name").getAsString().equals(name)) {
120
                couId = cou.getAsJsonObject().get("Id").getAsInt();
121
            }
122
        }
123
        return couId;
124
    }
125

  
126
    /**
105 127
     * 4. Get a couId by type.id
106 128
     *
107 129
     * @param type
......
109 131
     * @return
110 132
     */
111 133
    public Integer getCouId(String type, String id) {
134
        return getCouId(type, id, true);
135
    }
136

  
137

  
138
    /**
139
     * 4. Get a couId by type.id without mapping type
140
     *
141
     * @param type
142
     * @param id
143
     * @return
144
     */
145
    public Integer getCouId(String type, String id, boolean communityMap) {
112 146
        JsonArray cous = getCous();
113 147
        Integer couId = null;
114 148
        for (JsonElement cou : cous) {
115
            if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type) + "." + id)) {
149
            if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type, communityMap) + "." + id)) {
116 150
                couId = cou.getAsJsonObject().get("Id").getAsInt();
117 151
            }
118 152
        }

Also available in: Unified diff