Revision 60924
Added by Konstantinos Triantafyllou about 3 years ago
RegistryCalls.java | ||
---|---|---|
8 | 8 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
9 | 9 |
import org.springframework.beans.factory.annotation.Autowired; |
10 | 10 |
import org.springframework.beans.factory.annotation.Value; |
11 |
import org.springframework.security.access.method.P; |
|
11 | 12 |
import org.springframework.security.core.context.SecurityContextHolder; |
12 | 13 |
import org.springframework.stereotype.Service; |
13 | 14 |
|
15 |
import java.util.ArrayList; |
|
14 | 16 |
import java.util.HashMap; |
17 |
import java.util.List; |
|
15 | 18 |
import java.util.Map; |
16 | 19 |
|
17 | 20 |
@Service |
... | ... | |
70 | 73 |
return null; |
71 | 74 |
} |
72 | 75 |
|
76 |
public List<Integer> getCoPersonIdsByEmail(String email) { |
|
77 |
List<Integer> coPersonIds = new ArrayList<>(); |
|
78 |
Map<String, String> params = new HashMap<>(); |
|
79 |
params.put("coid", coid); |
|
80 |
params.put("mail", email); |
|
81 |
JsonElement response = httpUtils.get("co_people.json", params); |
|
82 |
if(response != null) { |
|
83 |
JsonArray coPeople = response.getAsJsonObject().get("CoPeople").getAsJsonArray(); |
|
84 |
for(int i = 0; i < coPeople.size(); i++) { |
|
85 |
coPersonIds.add(coPeople.get(i).getAsJsonObject().get("Id").getAsInt()); |
|
86 |
} |
|
87 |
} |
|
88 |
return coPersonIds; |
|
89 |
} |
|
90 |
|
|
73 | 91 |
/** |
74 | 92 |
* 2. Get CoPersonId by AAI identifier |
75 | 93 |
*/ |
... | ... | |
255 | 273 |
JsonArray emails = new JsonArray(); |
256 | 274 |
infos.forEach(info -> { |
257 | 275 |
JsonObject user = new JsonObject(); |
258 |
user.addProperty("email", info.getAsJsonObject().get("Mail").getAsString()); |
|
259 |
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString()); |
|
260 |
emails.add(user); |
|
276 |
boolean add = true; |
|
277 |
String email = info.getAsJsonObject().get("Mail").getAsString(); |
|
278 |
for(JsonElement element : emails) { |
|
279 |
if(element.getAsJsonObject().get("email").getAsString().equals(email)) { |
|
280 |
add = false; |
|
281 |
} |
|
282 |
} |
|
283 |
if(add) { |
|
284 |
user.addProperty("email", email); |
|
285 |
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString()); |
|
286 |
emails.add(user); |
|
287 |
} |
|
261 | 288 |
}); |
262 | 289 |
return emails; |
263 | 290 |
} |
... | ... | |
284 | 311 |
} |
285 | 312 |
|
286 | 313 |
/** |
287 |
* 14. Assign a member role to a User
|
|
314 |
* 14. Get Users' identifiers of a Cou
|
|
288 | 315 |
*/ |
316 |
public JsonArray getUserIdByCouId(Integer couId, boolean admin) { |
|
317 |
Map<String, String> params = new HashMap<>(); |
|
318 |
params.put("couid", couId.toString()); |
|
319 |
if (admin) { |
|
320 |
params.put("admin", "true"); |
|
321 |
} |
|
322 |
JsonElement response = httpUtils.get("identifiers.json", params); |
|
323 |
JsonArray infos = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray() : new JsonArray(); |
|
324 |
JsonArray emails = new JsonArray(); |
|
325 |
infos.forEach(info -> { |
|
326 |
JsonObject user = new JsonObject(); |
|
327 |
user.addProperty("id", info.getAsJsonObject().get("Identifier").getAsString()); |
|
328 |
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString()); |
|
329 |
emails.add(user); |
|
330 |
}); |
|
331 |
return emails; |
|
332 |
} |
|
333 |
|
|
334 |
/** |
|
335 |
* 15. Assign a member role to a User |
|
336 |
*/ |
|
289 | 337 |
public void assignMemberRole(Integer coPersonId, Integer couId, Integer id) { |
290 | 338 |
if (id != null) { |
291 | 339 |
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Active")); |
... | ... | |
295 | 343 |
} |
296 | 344 |
|
297 | 345 |
/** |
298 |
* 15. Remove a member role from a User
|
|
346 |
* 16. Remove a member role from a User
|
|
299 | 347 |
*/ |
300 | 348 |
public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) { |
301 |
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted")); |
|
349 |
if(id != null) { |
|
350 |
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted")); |
|
351 |
} |
|
302 | 352 |
} |
303 | 353 |
|
304 | 354 |
/** |
305 |
* 16. Create a new role
|
|
355 |
* 17. Create a new role
|
|
306 | 356 |
*/ |
307 | 357 |
public void createRole(Role role) { |
308 | 358 |
httpUtils.post("cous.json", jsonUtils.createNewCou(role)); |
309 | 359 |
} |
310 | 360 |
|
311 | 361 |
/** |
312 |
* 17. Get User's email
|
|
362 |
* 18. Get User's email
|
|
313 | 363 |
*/ |
314 | 364 |
public String getUserEmail(Integer coPersonId) { |
315 | 365 |
Map<String, String> params = new HashMap<>(); |
... | ... | |
320 | 370 |
} |
321 | 371 |
|
322 | 372 |
/** |
323 |
* 18. Get User's names
|
|
373 |
* 19. Get User's names
|
|
324 | 374 |
*/ |
325 | 375 |
public String getUserNames(Integer coPersonId) { |
326 | 376 |
Map<String, String> params = new HashMap<>(); |
... | ... | |
331 | 381 |
} |
332 | 382 |
|
333 | 383 |
/** |
334 |
* 14. Assign an admin role to a User
|
|
384 |
* 20. Get User's identifier
|
|
335 | 385 |
*/ |
386 |
public String getUserId(Integer coPersonId) { |
|
387 |
Map<String, String> params = new HashMap<>(); |
|
388 |
params.put("copersonid", coPersonId.toString()); |
|
389 |
JsonElement response = httpUtils.get("identifiers.json", params); |
|
390 |
JsonObject info = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray().get(0).getAsJsonObject() : null; |
|
391 |
return (info != null) ? info.getAsJsonObject().get("Identifier").getAsString() : null; |
|
392 |
} |
|
393 |
|
|
394 |
/** |
|
395 |
* 21. Assign an admin role to a User |
|
396 |
*/ |
|
336 | 397 |
public void assignAdminRole(Integer coPersonId, Integer couId) { |
337 | 398 |
JsonObject group = getCouAdminGroup(couId); |
338 | 399 |
if (group != null) { |
... | ... | |
341 | 402 |
} |
342 | 403 |
|
343 | 404 |
/** |
344 |
* 15. Remove an admin role from a User
|
|
405 |
* 22. Remove an admin role from a User
|
|
345 | 406 |
*/ |
346 | 407 |
public void removeAdminRole(Integer coPersonId, Integer couId) { |
347 | 408 |
JsonObject adminGroup = this.getCouAdminGroup(couId); |
Also available in: Unified diff
Merge last changes from trunk