use of eu.einfracentral.domain.RichService in project resource-catalogue by madgeek-arc.
the class UserEventsController method favourites.
/**
* Retrieve all the favourite Services of the authenticated user.
*
* @param auth
* @return
*/
@GetMapping(path = "favourites", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<List<RichService>> favourites(Authentication auth) {
Map<String, Float> favouriteServices = new HashMap<>();
List<Event> userEvents = eventService.getUserEvents(Event.UserActionType.FAVOURITE.getKey(), auth);
List<RichService> services = new ArrayList<>();
// Check if the serviceId exists and add it on the list, so to avoid errors
FacetFilter ff = new FacetFilter();
ff.setQuantity(10000);
List<String> serviceIds = new ArrayList<>();
for (InfraService infraService : infraServiceService.getAll(ff, auth).getResults()) {
serviceIds.add(infraService.getService().getId());
}
for (Event userEvent : userEvents) {
if (serviceIds.contains(userEvent.getService())) {
favouriteServices.putIfAbsent(userEvent.getService(), userEvent.getValue());
}
}
for (Map.Entry<String, Float> favouriteService : favouriteServices.entrySet()) {
if (favouriteService.getValue() == 1) {
// "1" is true
services.add(infraServiceService.getRichService(favouriteService.getKey(), "latest", auth));
}
}
return new ResponseEntity<>(services, HttpStatus.OK);
}
use of eu.einfracentral.domain.RichService in project resource-catalogue by madgeek-arc.
the class RecommendationManager method getRecommendedResources.
public ResponseEntity<List<RichService>> getRecommendedResources(int limit, Authentication authentication) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(recdbDataSource);
List<RichService> services = new ArrayList<>();
/* Get user id */
int user_id = -1;
String query = "SELECT user_pk FROM users WHERE user_email = ?;";
try {
if (authentication != null) {
user_id = jdbcTemplate.queryForObject(query, new Object[] { ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() }, int.class);
}
// TODO: get recommendations for non authenticated users
query = "SELECT service_name " + "FROM services " + "WHERE service_pk IN " + "(SELECT service_id FROM view_count R RECOMMEND R.service_id TO R.user_id ON R.visits USING ItemCosCF WHERE R.user_id = ? ORDER BY R.visits LIMIT ? )";
List<String> serviceIds = jdbcTemplate.queryForList(query, new Object[] { user_id, limit }, java.lang.String.class);
String[] ids = serviceIds.toArray(new String[0]);
services = infraService.getByIds(authentication, ids);
} catch (DataAccessException e) {
logger.warn("Could not find user {} in recommendation database.", ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail());
} catch (Exception e) {
logger.error(e);
}
return ResponseEntity.ok(services);
}
use of eu.einfracentral.domain.RichService in project resource-catalogue by madgeek-arc.
the class UserEventsController method ratings.
/**
* Retrieve all the rated Services of the authenticated user.
*
* @param auth
* @return
*/
@GetMapping(path = "ratings", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<List<RichService>> ratings(Authentication auth) {
Map<String, Float> serviceRatings = new HashMap<>();
List<Event> userEvents = eventService.getUserEvents(Event.UserActionType.RATING.getKey(), auth);
List<RichService> services = new ArrayList<>();
for (Event userEvent : userEvents) {
serviceRatings.putIfAbsent(userEvent.getService(), userEvent.getValue());
}
for (Map.Entry<String, Float> serviceRating : serviceRatings.entrySet()) {
services.add(infraServiceService.getRichService(serviceRating.getKey(), "latest", auth));
}
return new ResponseEntity<>(services, HttpStatus.OK);
}
Aggregations