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

42 lines
1.9 KiB
Java

package eu.eudat.controllers.v2;
import eu.eudat.authorization.Permission;
import eu.eudat.controllers.BaseController;
import eu.eudat.commons.exceptions.HugeResultSetException;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.ExternalValidationService;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.exception.MyNotFoundException;
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"})
public class ExternalValidationController extends BaseController {
private ExternalValidationService externalValidationService;
private final AuthorizationService authorizationService;
@Autowired
public ExternalValidationController(ApiContext apiContext, ExternalValidationService externalValidationService, AuthorizationService authorizationService) {
super(apiContext);
this.externalValidationService = externalValidationService;
this.authorizationService = authorizationService;
}
@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
) throws HugeResultSetException, MyNotFoundException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
Boolean isValid = this.externalValidationService.validateIdentifier(query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().payload(isValid).status(ApiMessageCode.NO_MESSAGE));
}
}