@RequestMapping( value = "/adminrules/id/{id}", method = RequestMethod.GET, produces = {"application/xml", "application/json"} ) public @ResponseBody JaxbAdminRule get(@PathVariable("id") Long id) { return new JaxbAdminRule(adminService.get(id)); }
@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))); }
@Override public RESTOutputAdminRule get(Long id) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { try { AdminRule ret = adminRuleAdminService.get(id); return toOutput(ret); } catch (NotFoundServiceEx ex) { LOGGER.warn("AdminRule not found: " + id); throw new NotFoundRestEx("AdminRule not found: " + id); } catch (Exception ex) { LOGGER.error(ex); throw new InternalErrorRestEx(ex.getMessage()); } }
/** Helper method that will parse and retrieve the provided rules sorted by their priority. */ private List<AdminRule> findRules(String rulesIds) { return Arrays.stream(rulesIds.split(",")) .map( ruleId -> { try { // parsing the rule id return Long.parseLong(ruleId); } catch (NumberFormatException exception) { // error parsing the rule id throw new InvalidRulesIds(); } }) .map( ruleId -> { // search the rule by id return adminService.get(ruleId); }) .filter(rule -> rule != null) .sorted((ruleA, ruleB) -> Long.compare(ruleA.getPriority(), ruleB.getPriority())) .collect(Collectors.toList()); }
AdminRule old = adminRuleAdminService.get(id); boolean isRuleUpdated = false;
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); } }
AdminRule realRule = adminService.get(id); realRule = adminService.get(id); long id2 = controller.insert(rule2).getBody(); realRule = adminService.get(id); assertEquals(6L, realRule.getPriority()); controller.update(id2, rule2Mods); realRule = adminService.get(id2); assertEquals(3L, realRule.getPriority()); controller.update(id2, rule2Mods); realRule = adminService.get(id2); assertEquals(6L, realRule.getPriority()); realRule = adminService.get(id); assertEquals(7L, realRule.getPriority()); boolean notfound = false; try { adminService.get(id); } catch (NotFoundServiceEx e) { notfound = true;