argos/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ExternalValidationControlle...

39 lines
1.7 KiB
Java
Raw Normal View History

2023-10-18 17:05:39 +02:00
package eu.eudat.controllers.v2;
import eu.eudat.authorization.Permission;
2024-01-03 17:22:24 +01:00
import eu.eudat.commons.exceptions.HugeResultSetException;
2023-10-20 16:44:41 +02:00
import eu.eudat.logic.services.ExternalValidationService;
2024-02-08 10:04:38 +01:00
import eu.eudat.models.old.helpers.responses.ResponseItem;
2023-10-18 17:05:39 +02:00
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
2024-01-03 17:22:24 +01:00
import gr.cite.tools.exception.MyNotFoundException;
2023-10-18 17:05:39 +02:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(path = {"api/validation"})
2024-02-08 10:04:38 +01:00
public class ExternalValidationController {
2023-10-18 17:05:39 +02:00
2023-10-20 16:44:41 +02:00
private ExternalValidationService externalValidationService;
private final AuthorizationService authorizationService;
2023-10-18 17:05:39 +02:00
@Autowired
2024-02-08 10:04:38 +01:00
public ExternalValidationController(ExternalValidationService externalValidationService, AuthorizationService authorizationService) {
2023-10-20 16:44:41 +02:00
this.externalValidationService = externalValidationService;
this.authorizationService = authorizationService;
2023-10-18 17:05:39 +02:00
}
@GetMapping(path = {""}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Boolean>> validate(
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
2024-01-03 17:22:24 +01:00
) throws HugeResultSetException, MyNotFoundException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
2023-10-20 16:44:41 +02:00
Boolean isValid = this.externalValidationService.validateIdentifier(query, type);
2023-10-18 17:05:39 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().payload(isValid).status(ApiMessageCode.NO_MESSAGE));
}
}