Search in sources :

Example 1 with InfraService

use of eu.einfracentral.domain.InfraService in project resource-catalogue by madgeek-arc.

the class PendingServiceController method updateService.

@PostMapping(path = "/updateResource", produces = { MediaType.APPLICATION_JSON_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EPOT') or @securityService.isServiceProviderAdmin(#auth, #service)")
public ResponseEntity<Service> updateService(@RequestBody Service service, @ApiIgnore Authentication auth) {
    InfraService infraService = pendingServiceManager.get(service.getId());
    infraService.setService(service);
    return new ResponseEntity<>(pendingServiceManager.update(infraService, auth).getService(), HttpStatus.OK);
}
Also used : InfraService(eu.einfracentral.domain.InfraService) ResponseEntity(org.springframework.http.ResponseEntity) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with InfraService

use of eu.einfracentral.domain.InfraService 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);
}
Also used : HashMap(java.util.HashMap) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) ArrayList(java.util.ArrayList) InfraService(eu.einfracentral.domain.InfraService) ResponseEntity(org.springframework.http.ResponseEntity) RichService(eu.einfracentral.domain.RichService) Event(eu.einfracentral.domain.Event) HashMap(java.util.HashMap) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with InfraService

use of eu.einfracentral.domain.InfraService in project resource-catalogue by madgeek-arc.

the class CSVController method servicesToCSV.

// Downloads a csv file with Service entries
@GetMapping(path = "services", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EPOT')")
public ResponseEntity<String> servicesToCSV(@ApiIgnore Authentication auth, HttpServletResponse response) {
    FacetFilter ff = new FacetFilter();
    ff.setQuantity(maxQuantity);
    ff.addFilter("latest", true);
    Paging<InfraService> infraServices = infraService.getAll(ff, auth);
    String csvData = listServicesToCSV(infraServices.getResults());
    response.setHeader("Content-disposition", "attachment; filename=" + "services.csv");
    return ResponseEntity.ok(csvData);
}
Also used : InfraService(eu.einfracentral.domain.InfraService) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with InfraService

use of eu.einfracentral.domain.InfraService in project resource-catalogue by madgeek-arc.

the class InfraServiceController method setActive.

@PatchMapping(path = "publish/{id}/{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<InfraService> setActive(@PathVariable String id, @PathVariable String version, @RequestParam boolean active, @RequestParam Boolean latest, @ApiIgnore Authentication auth) throws ResourceNotFoundException {
    InfraService service = infraService.get(id, version);
    service.setActive(active);
    service.setLatest(latest);
    Metadata metadata = service.getMetadata();
    metadata.setModifiedBy("system");
    metadata.setModifiedAt(String.valueOf(System.currentTimeMillis()));
    service.setMetadata(metadata);
    if (active) {
        logger.info("User '{}' set InfraService '{}' with id: {} as active", auth.getName(), service.getService().getName(), service.getService().getId());
    } else {
        logger.info("User '{}' set InfraService '{}' with id: {} as inactive", auth.getName(), service.getService().getName(), service.getService().getId());
    }
    return ResponseEntity.ok(infraService.update(service, auth));
}
Also used : InfraService(eu.einfracentral.domain.InfraService) Metadata(eu.einfracentral.domain.Metadata) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with InfraService

use of eu.einfracentral.domain.InfraService in project resource-catalogue by madgeek-arc.

the class InfraServiceController method deleteAll.

@DeleteMapping(path = "delete/all", produces = { MediaType.APPLICATION_JSON_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<InfraService> deleteAll(@ApiIgnore Authentication authentication) throws ResourceNotFoundException {
    FacetFilter ff = new FacetFilter();
    ff.setQuantity(10000);
    List<InfraService> services = infraService.getAll(ff, null).getResults();
    for (InfraService service : services) {
        logger.info("Deleting service with name: {}", service.getService().getName());
        infraService.delete(service);
    }
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Also used : InfraService(eu.einfracentral.domain.InfraService) ResponseEntity(org.springframework.http.ResponseEntity) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

InfraService (eu.einfracentral.domain.InfraService)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 ResponseEntity (org.springframework.http.ResponseEntity)8 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)5 ResourceException (eu.einfracentral.exception.ResourceException)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 ProviderBundle (eu.einfracentral.domain.ProviderBundle)2 HashMap (java.util.HashMap)2 Event (eu.einfracentral.domain.Event)1 Metadata (eu.einfracentral.domain.Metadata)1 ProviderRequest (eu.einfracentral.domain.ProviderRequest)1 RichService (eu.einfracentral.domain.RichService)1 Value (eu.einfracentral.dto.Value)1 ResourceNotFoundException (eu.einfracentral.exception.ResourceNotFoundException)1 ValidationException (eu.einfracentral.exception.ValidationException)1 Facet (eu.openminted.registry.core.domain.Facet)1 ResourceNotFoundException (eu.openminted.registry.core.exception.ResourceNotFoundException)1 ServiceException (eu.openminted.registry.core.service.ServiceException)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1