From 1d5befaf6abd97699ae0215445aa1a8e330d9ea1 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Mon, 10 May 2021 13:40:08 +0300 Subject: [PATCH] Add new endpoint in order to validate datasets --- .../src/main/java/eu/eudat/controllers/Datasets.java | 12 ++++++++++++ .../java/eu/eudat/logic/managers/DatasetManager.java | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java index 908f3476f..d79ec0a64 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java @@ -280,6 +280,18 @@ public class Datasets extends BaseController { } } + @RequestMapping(method = RequestMethod.GET, value = {"/{id}/validate"}, produces = "application/json") + public @ResponseBody + ResponseEntity> validate(@PathVariable(value = "id") UUID id, Principal principal) throws Exception { + try { + Dataset dataset = datasetManager.getEntitySingle(id); + datasetManager.checkDatasetValidation(dataset); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Valid")); + } catch (Exception datasetWizardCannotUnlockException) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage())); + } + } + /* * Data Import * */ diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 867f688f1..e164b9092 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -351,6 +351,10 @@ public class DatasetManager { return dataset; } + public Dataset getEntitySingle(UUID id) { + return databaseRepository.getDatasetDao().find(id); + } + public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) { eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile()); datasetprofile.setStatus(dataset.getStatus()); @@ -653,7 +657,7 @@ public class DatasetManager { } - private void checkDatasetValidation(Dataset dataset) throws Exception { + public void checkDatasetValidation(Dataset dataset) throws Exception { List datasetProfileValidators = new LinkedList<>(); DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId()); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();