Add avatarUrl on UserListingModel

This commit is contained in:
George Kalampokis 2020-12-02 14:19:43 +02:00
parent fcd24fd907
commit d6970cc49a
2 changed files with 20 additions and 3 deletions

View File

@ -15,7 +15,7 @@ import java.util.*;
@NamedEntityGraphs({
@NamedEntityGraph(
name = "userInfo",
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")}),
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials"), @NamedAttributeNode("additionalinfo")}),
})
public class UserInfo implements DataEntity<UserInfo, UUID> {

View File

@ -1,14 +1,18 @@
package eu.eudat.models.data.userinfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.UserRole;
import eu.eudat.models.DataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class UserListingModel implements DataModel<eu.eudat.data.entities.UserInfo, UserListingModel> {
private static final Logger logger = LoggerFactory.getLogger(UserListingModel.class);
private UUID id;
private String email;
@ -19,6 +23,7 @@ public class UserListingModel implements DataModel<eu.eudat.data.entities.UserIn
private Date lastloggedin;
//private String additionalinfo;
private List<Integer> appRoles;
private String avatarUrl;
public UUID getId() {
return id;
@ -83,7 +88,13 @@ public class UserListingModel implements DataModel<eu.eudat.data.entities.UserIn
this.appRoles = appRoles;
}
@Override
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
@Override
public UserListingModel fromDataModel(UserInfo entity) {
this.id = entity.getId();
this.email = entity.getEmail();
@ -94,6 +105,12 @@ public class UserListingModel implements DataModel<eu.eudat.data.entities.UserIn
this.lastloggedin = entity.getLastloggedin();
// this.additionalinfo = entity.getAdditionalinfo();
this.appRoles = entity.getUserRoles().stream().map(item -> item.getRole()).collect(Collectors.toList());
try {
Map<String, Object> additionalInfo = new ObjectMapper().readValue(entity.getAdditionalinfo(), HashMap.class);
this.avatarUrl = (String) additionalInfo.get("avatarUrl");
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return this;
}