Search in sources :

Example 1 with ResourceNotFoundException

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()));
}
Also used : FacetFilter(eu.openminted.registry.core.domain.FacetFilter) InfraServiceService(eu.einfracentral.registry.service.InfraServiceService) ProviderService(eu.einfracentral.registry.service.ProviderService) ResourceNotFoundException(eu.openminted.registry.core.exception.ResourceNotFoundException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams)

Example 2 with ResourceNotFoundException

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;
}
Also used : Event(eu.einfracentral.domain.Event) ResourceNotFoundException(eu.openminted.registry.core.exception.ResourceNotFoundException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 3 with ResourceNotFoundException

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;
}
Also used : Event(eu.einfracentral.domain.Event) ResourceNotFoundException(eu.openminted.registry.core.exception.ResourceNotFoundException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 4 with ResourceNotFoundException

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;
}
Also used : ValidationException(eu.einfracentral.exception.ValidationException) Event(eu.einfracentral.domain.Event) ResourceNotFoundException(eu.openminted.registry.core.exception.ResourceNotFoundException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 5 with ResourceNotFoundException

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;
}
Also used : ValidationException(eu.einfracentral.exception.ValidationException) Event(eu.einfracentral.domain.Event) ResourceNotFoundException(eu.openminted.registry.core.exception.ResourceNotFoundException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Aggregations

ResourceNotFoundException (eu.openminted.registry.core.exception.ResourceNotFoundException)15 CacheEvict (org.springframework.cache.annotation.CacheEvict)11 Event (eu.einfracentral.domain.Event)7 Resource (eu.openminted.registry.core.domain.Resource)4 ResourceType (eu.openminted.registry.core.domain.ResourceType)4 ArrayList (java.util.ArrayList)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Scheduled (org.springframework.scheduling.annotation.Scheduled)3 ResourceException (eu.einfracentral.exception.ResourceException)2 ValidationException (eu.einfracentral.exception.ValidationException)2 InfraServiceService (eu.einfracentral.registry.service.InfraServiceService)1 ProviderService (eu.einfracentral.registry.service.ProviderService)1 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1