Skip to content

Commit

Permalink
Merge pull request #264 from buehner/precheck-wpsprocess-deletion
Browse files Browse the repository at this point in the history
Precheck deletion of WpsProcessExecute
  • Loading branch information
buehner authored Jul 21, 2017
2 parents cdfde3c + b5e4eea commit 86e18b7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.terrestris.shogun2.service;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Restrictions;
Expand Down Expand Up @@ -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<String> preCheckDelete(Integer wpsId) {
List<String> result = new ArrayList<>();

E wpsProcessExecute = this.dao.findById(wpsId);

if (wpsProcessExecute != null) {

List<WpsPlugin> pluginsWithWps = wpsPluginService.findAllWhereFieldEquals("process", wpsProcessExecute);

for (WpsPlugin plugin : pluginsWithWps) {
result.add(plugin.getName());
}

}

return result;
}

/**
* @return the wpsPluginService
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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<String> 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);
}

}

0 comments on commit 86e18b7

Please sign in to comment.