From b5e4eea825d7edbf4e3bb56349caebd5b3738322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20B=C3=BChner?= Date: Thu, 20 Jul 2017 16:26:02 +0200 Subject: [PATCH] Introduce precheck of deletion of WpsProcessExecute --- .../service/WpsProcessExecuteService.java | 25 ++++++++++++++++ .../web/WpsProcessExecuteController.java | 30 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/shogun2-core/src/main/java/de/terrestris/shogun2/service/WpsProcessExecuteService.java b/src/shogun2-core/src/main/java/de/terrestris/shogun2/service/WpsProcessExecuteService.java index 1c81fc82c..5be9e2d9d 100644 --- a/src/shogun2-core/src/main/java/de/terrestris/shogun2/service/WpsProcessExecuteService.java +++ b/src/shogun2-core/src/main/java/de/terrestris/shogun2/service/WpsProcessExecuteService.java @@ -1,5 +1,6 @@ package de.terrestris.shogun2.service; +import java.util.ArrayList; import java.util.List; import org.hibernate.criterion.Restrictions; @@ -99,6 +100,30 @@ public void setDao(D dao) { this.dao = dao; } + /** + * + * @param wpsId + * @return List of {@link WpsPlugin}s that are connected to the given {@link WpsProcessExecute} + */ + @PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#wpsId, 'de.terrestris.shogun2.model.wps.WpsProcessExecute', 'DELETE')") + public List preCheckDelete(Integer wpsId) { + List result = new ArrayList<>(); + + E wpsProcessExecute = this.dao.findById(wpsId); + + if (wpsProcessExecute != null) { + + List pluginsWithWps = wpsPluginService.findAllWhereFieldEquals("process", wpsProcessExecute); + + for (WpsPlugin plugin : pluginsWithWps) { + result.add(plugin.getName()); + } + + } + + return result; + } + /** * @return the wpsPluginService */ diff --git a/src/shogun2-core/src/main/java/de/terrestris/shogun2/web/WpsProcessExecuteController.java b/src/shogun2-core/src/main/java/de/terrestris/shogun2/web/WpsProcessExecuteController.java index 04f6ad9f2..239bb3a9a 100644 --- a/src/shogun2-core/src/main/java/de/terrestris/shogun2/web/WpsProcessExecuteController.java +++ b/src/shogun2-core/src/main/java/de/terrestris/shogun2/web/WpsProcessExecuteController.java @@ -3,14 +3,22 @@ */ package de.terrestris.shogun2.web; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import de.terrestris.shogun2.dao.WpsProcessExecuteDao; +import de.terrestris.shogun2.model.wps.WpsPlugin; import de.terrestris.shogun2.model.wps.WpsProcessExecute; import de.terrestris.shogun2.service.WpsProcessExecuteService; +import de.terrestris.shogun2.util.data.ResultSet; /** * @@ -50,4 +58,26 @@ public void setService(S service) { this.service = service; } + /** + * Checks in which {@link WpsPlugin}s the given {@link WpsProcessExecute} is + * contained (and from which it would be "disconnected" in case of + * deletion). + * + * @param wpsProcessId + * ID of the {@link WpsProcessExecute} + * @return + */ + @RequestMapping(value="preCheckDelete.action", method = RequestMethod.POST) + public ResponseEntity preCheckDelete(@RequestParam("wpsProcessId") Integer wpsProcessId) { + List result = null; + try { + result = service.preCheckDelete(wpsProcessId); + } catch (Exception e) { + final String msg = e.getMessage(); + LOG.error("Could not pre-check WpsProcessExecute deletion: " + msg); + return new ResponseEntity<>(ResultSet.error(msg), HttpStatus.INTERNAL_SERVER_ERROR); + } + return new ResponseEntity<>(ResultSet.success(result), HttpStatus.OK); + } + }