package eu.eudat.controllers; import eu.eudat.authorization.Permission; import eu.eudat.data.query.items.item.grant.GrantCriteriaRequest; import eu.eudat.data.query.items.table.grant.GrantTableRequest; import eu.eudat.logic.managers.GrantManager; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.grant.GrantListingModel; import eu.eudat.types.ApiMessageCode; import gr.cite.commons.web.authz.service.AuthorizationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import jakarta.validation.Valid; import javax.management.InvalidApplicationException; import java.util.List; @RestController @CrossOrigin @RequestMapping(value = {"/api/grants/"}) public class Grants extends BaseController { private GrantManager grantManager; private final AuthorizationService authorizationService; @Autowired public Grants(ApiContext apiContext, GrantManager grantManager, AuthorizationService authorizationService) { super(apiContext); this.grantManager = grantManager; this.authorizationService = authorizationService; } @RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody GrantTableRequest grantTableRequest, @RequestParam String fieldsGroup) throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); DataTableData dataTable = this.grantManager.getPaged(grantTableRequest, fieldsGroup); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.POST, value = {"public/paged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody GrantTableRequest grantTableRequest) throws Exception { DataTableData dataTable = this.grantManager.getPublicPaged(grantTableRequest); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.GET, value = {"{id}"}, produces = "application/json") public @ResponseBody ResponseEntity> getSingle(@PathVariable String id) throws IllegalAccessException, InstantiationException, InvalidApplicationException { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); eu.eudat.models.data.grant.Grant grant = this.grantManager.getSingle(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(grant).status(ApiMessageCode.NO_MESSAGE)); } /*@Transactional @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> addGrant(@Valid @RequestBody eu.eudat.models.data.grant.Grant grant) throws IOException, ParseException { this.grantManager.createOrUpdate(grant, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); }*/ /*@Transactional @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> inactivate(@PathVariable String id) throws IllegalAccessException, InstantiationException { this.grantManager.inactivate(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); }*/ @RequestMapping(method = RequestMethod.POST, value = {"/external"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getWithExternal(@RequestBody GrantCriteriaRequest grantCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); List dataTable = this.grantManager.getCriteriaWithExternal(grantCriteria); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.POST, value = {"get"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> get(@RequestBody GrantCriteriaRequest grantCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException { this.authorizationService.authorizeForce(Permission.AnonymousRole); List dataTable = this.grantManager.getCriteria(grantCriteria); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } }