@Test public void testMissingLayerOnConstraints() { RESTInputRule rule = new RESTInputRule(); rule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop, 0)); rule.setGrant(GrantType.ALLOW); RESTLayerConstraints constraints = new RESTLayerConstraints(); rule.setConstraints(constraints); try { restRuleService.insert(rule).getEntity(); fail("Missing layer not trapped"); } catch (BadRequestRestEx e) { LOGGER.info("Exception properly trapped"); } rule.setLayer("l0"); Long rid = (Long)restRuleService.insert(rule).getEntity(); assertNotNull(rid); }
@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; 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()); } }
RESTRuleServiceImpl extends BaseRESTServiceImpl implements RESTRuleService { @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; 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()); } } }
RESTRuleServiceImpl extends BaseRESTServiceImpl implements RESTRuleService { @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; 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()); } }  }
RESTRuleServiceImpl extends BaseRESTServiceImpl implements RESTRuleService { @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; 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()); } }  @Override RESTOutputRule get(Long id); @Override @Transactional(propagation = Propagation.REQUIRED, value = "geofenceTransactionManager") Response insert(RESTInputRule inputRule); @Override void update(Long id, RESTInputRule rule); @Override Response delete(Long id); @Override RESTOutputRuleList get(Integer page, Integer entries,
            boolean full,
            String userName, Boolean userDefault,
            String roleName, Boolean roleDefault,
            Long instanceId, String instanceName, Boolean instanceDefault,
            String serviceName, Boolean serviceDefault,
            String requestName, Boolean requestDefault,
            String workspace, Boolean workspaceDefault,
            String layer, Boolean layerDefault); @Override long count(
            String userName, Boolean userDefault,
            String roleName, Boolean groupDefault,
            Long instanceId, String instanceName, Boolean instanceDefault,
            String serviceName, Boolean serviceDefault,
            String requestName, Boolean requestDefault,
            String workspace, Boolean workspaceDefault,
            String layer, Boolean layerDefault); @Override Response move(String rulesIds, Integer targetPriority); }
RESTRuleServiceImpl extends BaseRESTServiceImpl implements RESTRuleService { @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; 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()); } }  @Override RESTOutputRule get(Long id); @Override @Transactional(propagation = Propagation.REQUIRED, value = "geofenceTransactionManager") Response insert(RESTInputRule inputRule); @Override void update(Long id, RESTInputRule rule); @Override Response delete(Long id); @Override RESTOutputRuleList get(Integer page, Integer entries,
            boolean full,
            String userName, Boolean userDefault,
            String roleName, Boolean roleDefault,
            Long instanceId, String instanceName, Boolean instanceDefault,
            String serviceName, Boolean serviceDefault,
            String requestName, Boolean requestDefault,
            String workspace, Boolean workspaceDefault,
            String layer, Boolean layerDefault); @Override long count(
            String userName, Boolean userDefault,
            String roleName, Boolean groupDefault,
            Long instanceId, String instanceName, Boolean instanceDefault,
            String serviceName, Boolean serviceDefault,
            String requestName, Boolean requestDefault,
            String workspace, Boolean workspaceDefault,
            String layer, Boolean layerDefault); @Override Response move(String rulesIds, Integer targetPriority);  }