@RequestMapping( value = "/rules", method = RequestMethod.POST, consumes = { MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE } ) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Long> insert(@RequestBody(required = true) JaxbRule rule) { long priority = rule.getPriority() == null ? 0 : rule.getPriority().longValue(); if (adminService.getRuleByPriority(priority) != null) { adminService.shift(priority, 1); } Long id = adminService.insert(rule.toRule()); if (rule.getLimits() != null && rule.getAccess().equals("LIMIT")) { adminService.setLimits(id, rule.getLimits().toRuleLimits(null)); } if (rule.getLayerDetails() != null && !rule.getAccess().equals("LIMIT")) { adminService.setDetails(id, rule.getLayerDetails().toLayerDetails(null)); } return new ResponseEntity<Long>(id, HttpStatus.CREATED); }
@Override @Transactional(propagation = Propagation.REQUIRED, value = "geofenceTransactionManager") public Response insert(RESTInputRule inputRule) throws NotFoundRestEx, BadRequestRestEx, InternalErrorRestEx { if (inputRule.getPosition() == null || inputRule.getPosition().getPosition() == null) { throw new BadRequestRestEx("Bad position: " + inputRule.getPosition()); } if (inputRule.getGrant() == null) { throw new BadRequestRestEx("Missing grant type"); } Rule rule = fromInput(inputRule); InsertPosition position = inputRule.getPosition().getPosition() == RulePosition.fixedPriority ? InsertPosition.FIXED : inputRule.getPosition().getPosition() == RulePosition.offsetFromBottom ? InsertPosition.FROM_END : inputRule.getPosition().getPosition() == RulePosition.offsetFromTop ? InsertPosition.FROM_START : null; // ok: insert it try { Long id = ruleAdminService.insert(rule, position); LayerDetails details = detailsFromInput(inputRule); if (details != null) { ruleAdminService.setDetails(id, details); } return Response.status(Status.CREATED).tag(id.toString()).entity(id).build(); } catch (BadRequestServiceEx ex) { LOGGER.error(ex.getMessage()); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }
out.setLayer(in.getLayer()); long ruleid = ruleAdminService.insert(out); okCnt++;
public void saveAllRules(List<RuleModel> rules) throws ApplicationException { for (ShortRule rule : geofenceRemoteService.getRuleAdminService() .getAll()) { try { geofenceRemoteService.getRuleAdminService() .delete(rule.getId()); } catch (NotFoundServiceEx e) { logger.error(e.getMessage(), e); throw new ApplicationException(e.getMessage(), e); } } for (RuleModel localRule : rules) { IPAddressRange addressRange = validateSourceRange(localRule.getSourceIPRange()); Rule rule = new Rule( localRule.getPriority(), "*".equals(localRule.getUsername()) ? null : localRule.getUsername(), "*".equals(localRule.getRolename()) ? null : localRule.getRolename(), getInstance(localRule.getInstance()), addressRange, "*".equals(localRule.getService()) ? null : localRule.getService(), "*".equals(localRule.getRequest()) ? null : localRule.getRequest(), "*".equals(localRule.getWorkspace()) ? null : localRule.getWorkspace(), "*".equals(localRule.getLayer()) ? null : localRule.getLayer(), getAccessType(localRule.getGrant())); geofenceRemoteService.getRuleAdminService().insert(rule); } }
public void save(ShortRule rule) { if (rule.getId() == null) { shiftIfNecessary(rule.getPriority(), rule); // local int i = 0; while (i < rules.size() && rules.get(i).getPriority() < rule.getPriority()) { i++; } rules.add(i, rule); // db Rule bigRule = new Rule(); syncRule(rule, bigRule); rule.setId(adminService().insert(bigRule)); } else { // db Rule bigRule = adminService().get(rule.getId()); if (bigRule.getPriority() != rule.getPriority()) { shiftIfNecessary(rule.getPriority(), rule); } syncRule(rule, bigRule); adminService().update(bigRule); } }
if (ruleModel.getId() == -1) { // REQUEST FOR INSERT rule.setId(null); geofenceRemoteService.getRuleAdminService().insert(rule); } else { // REQUEST FOR UPDATE long ruleId = ruleModel.getId();
@Before public void initGeoFenceControllers() { controller = (RulesRestController) applicationContext.getBean("rulesRestController"); adminService = (RuleAdminService) applicationContext.getBean("ruleAdminService"); if (adminService.getCountAll() > 0) { for (ShortRule r : adminService.getAll()) { adminService.delete(r.getId()); } } Rule citeRule = new Rule(0, "cite", null, null, null, "wms", null, "cite", null, GrantType.ALLOW); Rule sfRule = new Rule(1, "cite", null, null, null, "wms", null, "sf", null, GrantType.ALLOW); adminService.insert(citeRule); adminService.insert(sfRule); }
rule.setLayerDetails(null); long newId = ruleAdminService.insert(rule); LOGGER.info("Remapping rule " + oldId + " -> " + newId); remap.getRules().put(oldId, newId);