Add email name and isManager(only for members) in getAll methods to handle different specs
This commit is contained in:
parent
0bf6ba9fa6
commit
7ede4c62c2
|
@ -39,12 +39,14 @@ public class AdminController {
|
|||
* Get the user info of the managers of a type(Community, etc.) with id(ee, egi, etc.)
|
||||
*/
|
||||
@RequestMapping(value = "/{type}/{id}", method = RequestMethod.GET)
|
||||
public ResponseEntity<User[]> getAll(@PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
public ResponseEntity<User[]> getAll(@PathVariable("type") String type, @PathVariable("id") String id,
|
||||
@RequestParam(value = "email", required = false, defaultValue = "true") boolean email,
|
||||
@RequestParam(value = "name", required = false, defaultValue = "true") boolean name) {
|
||||
Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id));
|
||||
if (couId != null) {
|
||||
JsonArray users = registryService.getUserIdByCouId(couId, true);
|
||||
JsonArray emails = registryService.getUserEmailByCouId(couId, true);
|
||||
JsonArray names = registryService.getUserNamesByCouId(couId, true);
|
||||
JsonArray emails = (email)?registryService.getUserEmailByCouId(couId, true):new JsonArray();
|
||||
JsonArray names = (name)?registryService.getUserNamesByCouId(couId, true):new JsonArray();
|
||||
return ResponseEntity.ok(JsonUtils.mergeUserInfo(users, emails, names, gson));
|
||||
}
|
||||
throw new ResourceNotFoundException("Role has not been found");
|
||||
|
|
|
@ -58,12 +58,21 @@ public class MemberController {
|
|||
* Get the user info of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
||||
*/
|
||||
@RequestMapping(value = "/{type}/{id}", method = RequestMethod.GET)
|
||||
public ResponseEntity<User[]> getAll(@PathVariable("type") String type, @PathVariable("id") String id) {
|
||||
public ResponseEntity<User[]> getAll(@PathVariable("type") String type, @PathVariable("id") String id,
|
||||
@RequestParam(value = "isManager", required = false, defaultValue = "true") boolean isManager,
|
||||
@RequestParam(value = "email", required = false, defaultValue = "true") boolean email,
|
||||
@RequestParam(value = "name", required = false, defaultValue = "true") boolean name) {
|
||||
Integer couId = registryService.getCouId(AuthoritiesUtils.memberRole(type, id));
|
||||
if (couId != null) {
|
||||
JsonArray users = registryService.getUserIdByCouId(couId, false);
|
||||
JsonArray emails = registryService.getUserEmailByCouId(couId, false);
|
||||
JsonArray names = registryService.getUserNamesByCouId(couId, false);
|
||||
JsonArray emails = (email)?registryService.getUserEmailByCouId(couId, false):new JsonArray();
|
||||
JsonArray names = (name)?registryService.getUserNamesByCouId(couId, false):new JsonArray();
|
||||
if(isManager) {
|
||||
JsonArray managers = registryService.getUserIdByCouId(couId, true);
|
||||
users.getAsJsonArray().forEach(element -> {
|
||||
element.getAsJsonObject().addProperty("isManager", managers.contains(element));
|
||||
});
|
||||
}
|
||||
return ResponseEntity.ok(JsonUtils.mergeUserInfo(users, emails, names, gson));
|
||||
}
|
||||
throw new ResourceNotFoundException("Role has not been found");
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
package eu.dnetlib.dnetrolemanagement.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
public class User {
|
||||
|
||||
@JsonIgnore
|
||||
private String coPersonId;
|
||||
private String id;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private String email;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private String name;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Boolean isManager;
|
||||
private String memberSince;
|
||||
|
||||
public User() {
|
||||
|
@ -46,6 +51,14 @@ public class User {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public Boolean isIsManager() {
|
||||
return isManager;
|
||||
}
|
||||
|
||||
public void setIsManager(Boolean isManager) {
|
||||
this.isManager = isManager;
|
||||
}
|
||||
|
||||
public String getMemberSince() {
|
||||
return memberSince;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue