/** * Move the provided rules to the target priority. Rules will be sorted by their priority, first * rule will be updated with a priority equal to the target priority and the next ones will get * an incremented priority value. */ @RequestMapping( value = "/adminrules/move", method = RequestMethod.GET, produces = {"application/xml", "application/json"} ) public @ResponseBody ResponseEntity<JaxbAdminRuleList> move( @RequestParam(value = "targetPriority", required = true) int targetPriority, @RequestParam(value = "rulesIds", required = true) String rulesIds) { // let's find the rules that need to be moved List<AdminRule> rules = findRules(rulesIds); if (rules.isEmpty()) { return ResponseEntity.ok(null); } // shift priorities of rules with a priority equal or lower than the target priority adminService.shift(targetPriority, rules.size()); // update moved rules priority long priority = targetPriority; for (AdminRule rule : rules) { rule.setPriority(priority); adminService.update(rule); priority++; } // return moved rules with their priority updated return ResponseEntity.ok(new JaxbAdminRuleList(rules)); }
@RequestMapping(value = "/adminrules/id/{id}", method = RequestMethod.POST) public @ResponseStatus(HttpStatus.OK) void update( @PathVariable("id") Long id, @RequestBody JaxbAdminRule rule) { if (rule.getPriority() != null) { ShortAdminRule priorityRule = adminService.getRuleByPriority(rule.getPriority()); if (priorityRule != null && priorityRule.getId().longValue() != id) { adminService.shift(rule.getPriority(), 1); } } adminService.update(rule.toRule(adminService.get(id))); }
if(LOGGER.isDebugEnabled()) LOGGER.debug("Updating rule " + rule); adminRuleAdminService.update(old); } else { if(LOGGER.isDebugEnabled())
public void save(ShortAdminRule rule) { if (rule.getId() == null) { shiftIfNecessary(rule.getPriority(), rule); int i = 0; while (i < rules.size() && rules.get(i).getPriority() < rule.getPriority()) { i++; } rules.add(i, rule); AdminRule bigRule = new AdminRule(); syncRule(rule, bigRule); rule.setId(adminService().insert(bigRule)); } else { AdminRule bigRule = adminService().get(rule.getId()); if (bigRule.getPriority() != rule.getPriority()) { shiftIfNecessary(rule.getPriority(), rule); } syncRule(rule, bigRule); adminService().update(bigRule); } }