use of io.gravitee.rest.api.model.providers.User in project gravitee-management-rest-api by gravitee-io.
the class MembershipServiceImpl method findUserMembershipMetadata.
@Override
public Metadata findUserMembershipMetadata(List<UserMembership> memberships, MembershipReferenceType type) {
if (memberships == null || memberships.isEmpty() || type == null || (!type.equals(MembershipReferenceType.API) && !type.equals(MembershipReferenceType.APPLICATION) && !type.equals(MembershipReferenceType.GROUP))) {
return new Metadata();
}
try {
Metadata metadata = new Metadata();
if (type.equals(MembershipReferenceType.API)) {
ApiCriteria.Builder criteria = new ApiCriteria.Builder();
ApiFieldExclusionFilter filter = (new ApiFieldExclusionFilter.Builder()).excludeDefinition().excludePicture().build();
criteria.ids(memberships.stream().map(UserMembership::getReference).toArray(String[]::new));
apiRepository.search(criteria.build(), filter).forEach(api -> {
metadata.put(api.getId(), "name", api.getName());
metadata.put(api.getId(), "version", api.getVersion());
metadata.put(api.getId(), "visibility", api.getVisibility());
});
} else if (type.equals(MembershipReferenceType.APPLICATION)) {
applicationRepository.findByIds(memberships.stream().map(UserMembership::getReference).collect(Collectors.toList())).forEach(application -> {
metadata.put(application.getId(), "name", application.getName());
});
}
return metadata;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to get user membership metadata", ex);
throw new TechnicalManagementException("An error occurs while trying to get user membership metadata", ex);
}
}
use of io.gravitee.rest.api.model.providers.User in project gravitee-management-rest-api by gravitee-io.
the class MembershipServiceImpl method findUserFromMembershipMember.
private UserEntity findUserFromMembershipMember(MembershipMember member) {
UserEntity userEntity;
if (member.getMemberId() != null) {
userEntity = userService.findById(member.getMemberId());
} else {
// We have a user reference, meaning that the user is coming from an external system
// User does not exist so we are looking into defined providers
Optional<io.gravitee.rest.api.model.providers.User> providerUser = identityService.findByReference(member.getReference());
if (providerUser.isPresent()) {
User identityUser = providerUser.get();
userEntity = findOrCreateUser(identityUser);
} else {
throw new UserNotFoundException(member.getReference());
}
}
return userEntity;
}
use of io.gravitee.rest.api.model.providers.User in project gravitee-management-rest-api by gravitee-io.
the class IdentityServiceImpl method convert.
private User convert(io.gravitee.rest.api.idp.api.identity.User identity) {
User user = new User();
user.setId(identity.getId());
user.setSourceId(identity.getReference());
user.setSource(identity.getSource());
user.setEmail(identity.getEmail());
user.setFirstname(identity.getFirstname());
user.setLastname(identity.getLastname());
user.setDisplayName(identity.getDisplayName());
user.setPicture(identity.getPicture());
user.setRoles(identity.getRoles());
return user;
}
Aggregations