use of eu.openminted.registry.core.exception.ResourceNotFoundException in project resource-catalogue by madgeek-arc.
the class ServiceController method getInactiveServices.
// Filter a list of inactive Services based on a set of filters or get a list of all inactive Services in the Catalogue.
@ApiImplicitParams({ @ApiImplicitParam(name = "query", value = "Keyword to refine the search", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "from", value = "Starting index in the result set", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "quantity", value = "Quantity to be fetched", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "order", value = "asc / desc", dataType = "string", paramType = "query"), @ApiImplicitParam(name = "orderField", value = "Order field", dataType = "string", paramType = "query") })
@GetMapping(path = "inactive/all", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Paging<Service>> getInactiveServices(@ApiIgnore @RequestParam MultiValueMap<String, Object> allRequestParams, @ApiIgnore Authentication auth) throws ResourceNotFoundException {
FacetFilter ff = FacetFilterUtils.createMultiFacetFilter(allRequestParams);
ff.addFilter("active", false);
Paging<InfraService> infraServices = infraService.getAll(ff, auth);
// Paging<InfraService> infraServices = infraService.getInactiveServices();
List<Service> services = infraServices.getResults().stream().map(InfraService::getService).collect(Collectors.toList());
if (services.isEmpty()) {
throw new ResourceNotFoundException();
}
return ResponseEntity.ok(new Paging<>(infraServices.getTotal(), infraServices.getFrom(), infraServices.getTo(), services, infraServices.getFacets()));
}
use of eu.openminted.registry.core.exception.ResourceNotFoundException in project resource-catalogue by madgeek-arc.
the class EventManager method setScheduledRating.
@CacheEvict(value = { CACHE_EVENTS, CACHE_SERVICE_EVENTS }, allEntries = true)
public Event setScheduledRating(String serviceId, Float value) throws ResourceNotFoundException {
if (!infraServiceService.exists(new SearchService.KeyValue("infra_service_id", serviceId))) {
throw new ResourceNotFoundException("infra_service", serviceId);
}
Event event;
event = new Event();
event.setService(serviceId);
event.setType(Event.UserActionType.RATING.getKey());
event.setValue(value);
// remove auth
event = add(event, null);
logger.debug("Adding a new RATING Event: {}", event);
return event;
}
use of eu.openminted.registry.core.exception.ResourceNotFoundException in project resource-catalogue by madgeek-arc.
the class EventManager method setVisit.
@CacheEvict(value = { CACHE_EVENTS, CACHE_SERVICE_EVENTS }, allEntries = true)
public Event setVisit(String serviceId, Float value) throws ResourceNotFoundException {
if (!infraServiceService.exists(new SearchService.KeyValue("infra_service_id", serviceId))) {
throw new ResourceNotFoundException("infra_service", serviceId);
}
Event event;
event = new Event();
event.setService(serviceId);
event.setType(Event.UserActionType.VISIT.getKey());
event.setValue(value);
// remove auth
event = add(event, null);
logger.debug("Adding a new VISIT Event: {}", event);
return event;
}
use of eu.openminted.registry.core.exception.ResourceNotFoundException in project resource-catalogue by madgeek-arc.
the class EventManager method setFavourite.
@Override
@CacheEvict(value = { CACHE_EVENTS, CACHE_SERVICE_EVENTS }, allEntries = true)
public Event setFavourite(String serviceId, Float value, Authentication authentication) throws ResourceNotFoundException {
if (!infraServiceService.exists(new SearchService.KeyValue("infra_service_id", serviceId))) {
throw new ResourceNotFoundException("infra_service", serviceId);
}
if (value != 1 && value != 0) {
throw new ValidationException("Values of Favoring range between 0 - Unfavorite and 1 - Favorite");
}
List<Event> events = getEvents(Event.UserActionType.FAVOURITE.getKey(), serviceId, authentication);
Event event;
if (!events.isEmpty() && sameDay(events.get(0).getInstant())) {
event = events.get(0);
delete(event);
logger.debug("Deleting previous FAVORITE Event '{}' because it happened more than once in the same day.", event);
}
event = new Event();
event.setService(serviceId);
event.setUser(AuthenticationInfo.getSub(authentication));
event.setType(Event.UserActionType.FAVOURITE.getKey());
event.setValue(value);
// remove auth
event = add(event, authentication);
logger.debug("Adding a new FAVORITE Event: {}", event);
return event;
}
use of eu.openminted.registry.core.exception.ResourceNotFoundException in project resource-catalogue by madgeek-arc.
the class EventManager method setRating.
@Override
@CacheEvict(value = { CACHE_EVENTS, CACHE_SERVICE_EVENTS }, allEntries = true)
public Event setRating(String serviceId, Float value, Authentication authentication) throws ResourceNotFoundException, NumberParseException {
if (!infraServiceService.exists(new SearchService.KeyValue("infra_service_id", serviceId))) {
throw new ResourceNotFoundException("infra_service", serviceId);
}
if (value <= 0 || value > 5) {
throw new ValidationException("Values of Rating range between 0 and 5");
}
List<Event> events = getEvents(Event.UserActionType.RATING.getKey(), serviceId, authentication);
Event event;
if (!events.isEmpty() && sameDay(events.get(0).getInstant())) {
event = events.get(0);
event.setValue(value);
event = update(event, authentication);
logger.debug("Updating RATING Event: {}", event);
//
} else {
event = new Event();
event.setService(serviceId);
event.setUser(AuthenticationInfo.getSub(authentication));
event.setType(Event.UserActionType.RATING.getKey());
event.setValue(value);
// remove auth
event = add(event, authentication);
logger.debug("Adding a new RATING Event: {}", event);
}
return event;
}
Aggregations