@ExceptionHandler(BadRequestServiceEx.class) public void badRequest( BadRequestServiceEx exception, HttpServletRequest request, HttpServletResponse response) throws IOException { response.sendError(400, exception.getMessage()); }
@Override public RESTShortUserList getList(String nameLike, Integer page, Integer entries) throws BadRequestRestEx, InternalErrorRestEx { try { List<GSUser> list = userAdminService.getFullList(nameLike, page, entries); RESTShortUserList ret = new RESTShortUserList(list.size()); for (GSUser user : list) { ret.add(toShortUser(user)); } return ret; } catch (BadRequestServiceEx ex) { LOGGER.warn(ex.getMessage()); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.warn("Unexpected exception", ex); throw new InternalErrorRestEx(ex.getMessage()); } }
@Override @Transactional(propagation = Propagation.REQUIRED, value = "geofenceTransactionManager") public Response insert(RESTInputAdminRule inputAdminRule) throws NotFoundRestEx, BadRequestRestEx, InternalErrorRestEx { if (inputAdminRule.getPosition() == null || inputAdminRule.getPosition().getPosition() == null) { throw new BadRequestRestEx("Bad position: " + inputAdminRule.getPosition()); } if (inputAdminRule.getGrant() == null) { throw new BadRequestRestEx("Missing grant type"); } AdminRule rule = fromInput(inputAdminRule); InsertPosition position = inputAdminRule.getPosition().getPosition() == RulePosition.fixedPriority ? InsertPosition.FIXED : inputAdminRule.getPosition().getPosition() == RulePosition.offsetFromBottom ? InsertPosition.FROM_END : inputAdminRule.getPosition().getPosition() == RulePosition.offsetFromTop ? InsertPosition.FROM_START : null; // ok: insert it try { Long id = adminRuleAdminService.insert(rule, position); 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 @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()); } }
@Override public void update(String name, RESTInputGroup group) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx { try { UserGroup old = userGroupAdminService.get(name); ShortGroup newGroup = new ShortGroup(); newGroup.setId(old.getId()); if ( (group.getExtId() != null) ) { throw new BadRequestRestEx("ExtId can't be updated"); } if ( (group.getName() != null) ) { throw new BadRequestRestEx("Name can't be updated"); } if ( group.isEnabled() != null ) { newGroup.setEnabled(group.isEnabled()); } userGroupAdminService.update(newGroup); } catch (GeoFenceRestEx ex) { // already handled throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Role not found: " + name + ": " + ex.getMessage(), ex); throw new NotFoundRestEx(ex.getMessage()); } catch (BadRequestServiceEx ex) { LOGGER.warn("Problems updating role:" + name + ": " + ex.getMessage(), ex); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error(ex); throw new InternalErrorRestEx(ex.getMessage()); } }
throw new NotFoundRestEx(ex.getMessage()); } catch (BadRequestServiceEx ex) { LOGGER.warn("Problems inserting user: " + ex.getMessage(), ex); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex);
throw new NotFoundRestEx(ex.getMessage()); } catch (BadRequestServiceEx ex) { LOGGER.warn("Problems updating AdminRule id:" + id + ": " + ex.getMessage(), ex); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error("Unexpected exception: " + ex.getMessage(), ex);
throw new NotFoundRestEx(ex.getMessage()); } catch (BadRequestServiceEx ex) { LOGGER.warn("Problems updating GSInstance id:" + id + ": " + ex.getMessage(), ex); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error(ex);
throw new NotFoundRestEx(ex.getMessage()); } catch (BadRequestServiceEx ex) { LOGGER.warn("Problems updating user " + id + ": " + ex.getMessage(), ex); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error(ex);
throw new NotFoundRestEx(ex.getMessage()); } catch (BadRequestServiceEx ex) { LOGGER.warn("Problems updating rule id:" + id + ": " + ex.getMessage(), ex); throw new BadRequestRestEx(ex.getMessage()); } catch (Exception ex) { LOGGER.error("Unexpected exception: " + ex.getMessage(), ex);