use of io.gravitee.repository.management.model.Rating in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method convert.
private RatingEntity convert(final Rating rating) {
final RatingEntity ratingEntity = new RatingEntity();
final UserEntity user = userService.findById(rating.getUser());
ratingEntity.setUser(user.getId());
if (user.getFirstname() != null && user.getLastname() != null) {
ratingEntity.setUserDisplayName(user.getFirstname() + ' ' + user.getLastname());
} else {
ratingEntity.setUserDisplayName(user.getUsername());
}
ratingEntity.setId(rating.getId());
ratingEntity.setApi(rating.getApi());
ratingEntity.setTitle(rating.getTitle());
ratingEntity.setComment(rating.getComment());
ratingEntity.setRate(rating.getRate());
ratingEntity.setCreatedAt(rating.getCreatedAt());
ratingEntity.setUpdatedAt(rating.getUpdatedAt());
try {
final List<RatingAnswer> ratingAnswers = ratingAnswerRepository.findByRating(rating.getId());
if (ratingAnswers != null) {
ratingEntity.setAnswers(ratingAnswers.stream().map(ratingAnswer -> {
final RatingAnswerEntity ratingAnswerEntity = new RatingAnswerEntity();
ratingAnswerEntity.setId(ratingAnswer.getId());
final UserEntity userAnswer = userService.findById(ratingAnswer.getUser());
ratingAnswerEntity.setUser(userAnswer.getId());
if (userAnswer.getFirstname() != null && userAnswer.getLastname() != null) {
ratingAnswerEntity.setUserDisplayName(userAnswer.getFirstname() + ' ' + userAnswer.getLastname());
} else {
ratingAnswerEntity.setUserDisplayName(userAnswer.getUsername());
}
ratingAnswerEntity.setComment(ratingAnswer.getComment());
ratingAnswerEntity.setCreatedAt(ratingAnswer.getCreatedAt());
return ratingAnswerEntity;
}).sorted(comparing(RatingAnswerEntity::getCreatedAt, reverseOrder())).collect(toList()));
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find rating answers by rating id {}", rating.getId(), ex);
throw new TechnicalManagementException("An error occurred while trying to find rating answers by rating id " + rating.getId(), ex);
}
return ratingEntity;
}
use of io.gravitee.repository.management.model.Rating in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method convert.
private Rating convert(final NewRatingEntity ratingEntity) {
final Rating rating = new Rating();
rating.setId(UUID.toString(UUID.random()));
rating.setApi(ratingEntity.getApi());
rating.setRate(ratingEntity.getRate());
rating.setTitle(ratingEntity.getTitle());
rating.setComment(ratingEntity.getComment());
rating.setUser(getAuthenticatedUsername());
final Date now = new Date();
rating.setCreatedAt(now);
rating.setUpdatedAt(now);
return rating;
}
Aggregations