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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations