use of io.gravitee.repository.management.api.search.ApiFieldExclusionFilter 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);
}
}
Aggregations