Revision 61374
Added by Konstantinos Triantafyllou almost 3 years ago
RegistryCalls.java | ||
---|---|---|
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
/** |
118 |
* 3. Get all OpenAIRE cous
|
|
118 |
* 3.1 Get OpenAIRE cous with a specific name(or substring)
|
|
119 | 119 |
*/ |
120 |
public JsonArray getCous() { |
|
120 |
public JsonArray getCous(String name) {
|
|
121 | 121 |
Map<String, String> params = new HashMap<>(); |
122 | 122 |
params.put("coid", coid); |
123 |
if(name != null) { |
|
124 |
params.put("name", name.toLowerCase()); |
|
125 |
} |
|
123 | 126 |
JsonElement response = httpUtils.get("cous.json", params); |
124 | 127 |
return (response != null) ? response.getAsJsonObject().get("Cous").getAsJsonArray() : new JsonArray(); |
125 | 128 |
} |
126 | 129 |
|
127 | 130 |
/** |
128 |
* 4. Get a couId by name |
|
131 |
* 3.2 Get all OpenAIRE cous |
|
132 |
*/ |
|
133 |
public JsonArray getCous() { |
|
134 |
return getCous(null); |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* 4.1 Get a couId by name |
|
129 | 139 |
* |
130 | 140 |
* @param name |
131 | 141 |
* @return |
132 | 142 |
*/ |
133 | 143 |
public Integer getCouId(String name) { |
134 |
JsonArray cous = getCous(); |
|
135 |
Integer couId = null; |
|
144 |
JsonArray cous = getCous(name); |
|
136 | 145 |
for (JsonElement cou : cous) { |
137 |
if (cou.getAsJsonObject().get("Name").getAsString().equals(name)) {
|
|
138 |
couId = cou.getAsJsonObject().get("Id").getAsInt();
|
|
146 |
if (cou.getAsJsonObject().get("Name").getAsString().toLowerCase().equals(name.toLowerCase())) {
|
|
147 |
return cou.getAsJsonObject().get("Id").getAsInt();
|
|
139 | 148 |
} |
140 | 149 |
} |
141 |
return couId;
|
|
150 |
return null;
|
|
142 | 151 |
} |
143 | 152 |
|
144 | 153 |
/** |
145 |
* 4. Get a couId by type.id
|
|
154 |
* 4.2 Get a couId by type.id with/without mapping type
|
|
146 | 155 |
* |
147 | 156 |
* @param type |
148 | 157 |
* @param id |
149 | 158 |
* @return |
150 | 159 |
*/ |
151 |
public Integer getCouId(String type, String id) { |
|
152 |
return getCouId(type, id, true);
|
|
160 |
public Integer getCouId(String type, String id, boolean communityMap) {
|
|
161 |
return getCouId(mapType(type, communityMap) + "." + id);
|
|
153 | 162 |
} |
154 | 163 |
|
155 |
|
|
156 | 164 |
/** |
157 |
* 4. Get a couId by type.id without mapping type
|
|
165 |
* 4.3 Get a couId by type.id with mapping type
|
|
158 | 166 |
* |
159 | 167 |
* @param type |
160 | 168 |
* @param id |
161 | 169 |
* @return |
162 | 170 |
*/ |
163 |
public Integer getCouId(String type, String id, boolean communityMap) { |
|
164 |
JsonArray cous = getCous(); |
|
165 |
Integer couId = null; |
|
166 |
for (JsonElement cou : cous) { |
|
167 |
if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type, communityMap) + "." + id)) { |
|
168 |
couId = cou.getAsJsonObject().get("Id").getAsInt(); |
|
169 |
} |
|
170 |
} |
|
171 |
return couId; |
|
171 |
public Integer getCouId(String type, String id) { |
|
172 |
return getCouId(type, id, true); |
|
172 | 173 |
} |
173 | 174 |
|
174 | 175 |
/** |
... | ... | |
354 | 355 |
/** |
355 | 356 |
* 17. Create a new role |
356 | 357 |
*/ |
357 |
public void createRole(Role role) { |
|
358 |
httpUtils.post("cous.json", jsonUtils.createNewCou(role)); |
|
358 |
public Integer createRole(Role role) { |
|
359 |
JsonElement element = httpUtils.post("cous.json", jsonUtils.createNewCou(role)); |
|
360 |
return element.getAsJsonObject().get("Id").getAsInt(); |
|
359 | 361 |
} |
360 | 362 |
|
361 | 363 |
/** |
Also available in: Unified diff
Update dnet-login-core to 1.0.2. Create role returns id of created role