in custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/mapper/UserProfileMapper.java [49:123]
public static UserProfile createUserProfileEntityFromUserProfile(org.apache.custos.user.profile.service.UserProfile userProfile) {
UserProfile entity = new UserProfile();
entity.setUsername(userProfile.getUsername());
if (userProfile.getEmail() != null && !userProfile.getEmail().trim().equals("")) {
entity.setEmailAddress(userProfile.getEmail());
}
if (userProfile.getFirstName() != null && !userProfile.getFirstName().trim().equals("")) {
entity.setFirstName(userProfile.getFirstName());
}
if (userProfile.getLastName() != null && !userProfile.getLastName().trim().equals("")) {
entity.setLastName(userProfile.getLastName());
}
if (userProfile.getType() != null) {
entity.setType(userProfile.getType().name());
} else {
entity.setType(UserTypes.END_USER.name());
}
entity.setStatus(userProfile.getStatus().name());
Set<UserAttribute> attributeSet = new HashSet<>();
if (userProfile.getAttributesList() != null && !userProfile.getAttributesList().isEmpty()) {
userProfile.getAttributesList().forEach(atr -> {
if (atr.getValuesList() != null && !atr.getValuesList().isEmpty()) {
for (String value : atr.getValuesList()) {
UserAttribute userAttribute = new UserAttribute();
userAttribute.setKey(atr.getKey());
userAttribute.setValue(value);
userAttribute.setUserProfile(entity);
attributeSet.add(userAttribute);
}
}
});
}
entity.setUserAttribute(attributeSet);
Set<UserRole> userRoleSet = new HashSet<>();
if (userProfile.getRealmRolesList() != null && !userProfile.getRealmRolesList().isEmpty()) {
userProfile.getRealmRolesList().forEach(role -> {
UserRole userRole = new UserRole();
userRole.setValue(role);
userRole.setType(Constants.ROLE_TYPE_REALM);
userRole.setUserProfile(entity);
userRoleSet.add(userRole);
});
}
if (userProfile.getClientRolesList() != null && !userProfile.getClientRolesList().isEmpty()) {
userProfile.getClientRolesList().forEach(role -> {
UserRole userRole = new UserRole();
userRole.setValue(role);
userRole.setType(Constants.ROLE_TYPE_CLIENT);
userRole.setUserProfile(entity);
userRoleSet.add(userRole);
});
}
entity.setUserRole(userRoleSet);
return entity;
}