protected void putMap(Map map) throws Exception { validateMap(map); Set<Object> nonExisting = nonExistingKeys(map); if (!nonExisting.isEmpty()) { String msg = "Unknown rules: " + StringUtils.join(nonExisting.iterator(), ","); throw new RestException(msg, HttpStatus.CONFLICT); } for (Object entry : map.entrySet()) { Comparable rule = convertEntryToRule((Entry<String, String>) entry); // TODO, will not work for REST ruleDAO.removeRule(rule); ruleDAO.addRule(rule); } ruleDAO.storeRules(); }
@DeleteMapping(path = "/**") public void rulesDelete(HttpServletRequest request) throws UnsupportedEncodingException { checkUserIsAdmin(); String thePath = request.getPathInfo(); String ruleString = thePath.substring(getBasePath().length() + 1); ruleString = URLDecoder.decode(ruleString, "utf-8"); String msg = validateRuleKey(ruleString); if (msg != null) throw new RestException(msg, HttpStatus.UNPROCESSABLE_ENTITY); Comparable<?> rule = null; for (Comparable<?> ruleCandidate : ruleDAO.getRules()) { if (ruleString.equals(keyFor(ruleCandidate))) { rule = ruleCandidate; break; } } if (rule == null) { throw new ResourceNotFoundException("Rule not found: " + ruleString); } try { ruleDAO.removeRule(rule); ruleDAO.storeRules(); } catch (Exception e) { throw createRestException(e); } }