@Test public void testInsertDup() { RESTInputGroup group = new RESTInputGroup(); group.setName("g1"); Response res = restUserGroupService.insert(group); long gid1 = (Long)res.getEntity(); { RESTInputUser user = new RESTInputUser(); user.setName("user0"); user.setEnabled(Boolean.TRUE); user.setGroups(new ArrayList<IdName>()); user.getGroups().add(new IdName("g1")); Response userResp = restUserService.insert(user); Long id = (Long)userResp.getEntity(); } LOGGER.info("Inserting dup"); { RESTInputUser user = new RESTInputUser(); user.setName("user0"); user.setEnabled(Boolean.TRUE); user.setGroups(new ArrayList<IdName>()); user.getGroups().add(new IdName("g1")); try { Response userResp = restUserService.insert(user); Long id = (Long)userResp.getEntity(); fail("409 not trapped"); } catch(ConflictRestEx e) { LOGGER.info("Exception properly trapped"); } } }
@Override public Response insert(RESTInputUser user) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { boolean exists; try { userAdminService.get(user.getName()); exists = true; } catch (NotFoundServiceEx ex) { exists = false; } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if ( exists ) { throw new ConflictRestEx("User '" + user.getName() + "' already exists"); } try { Set<UserGroup> groups = new HashSet<UserGroup>(); List<IdName> inputGroups = user.getGroups(); if ( inputGroups == null || inputGroups.isEmpty() ) { LOGGER.warn("No groups defined for user " + user.getName()); } else { for (IdName identifier : inputGroups) { if ( identifier == null ) { throw new BadRequestRestEx("Bad group identifier"); } UserGroup group = getUserGroup(identifier); groups.add(group); } } GSUser u = new GSUser(); u.setGroups(groups); u.setExtId(user.getExtId()); u.setName(user.getName()); u.setPassword(user.getPassword()); u.setEnabled(user.isEnabled()); u.setAdmin(user.isAdmin()); u.setFullName(user.getFullName()); u.setEmailAddress(user.getEmailAddress()); Long ret = userAdminService.insert(u); return Response.status(Status.CREATED).tag(ret.toString()).entity(ret).build(); } catch (GeoFenceRestEx ex) { throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Problems inserting user: " + ex.getMessage(), ex); 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 InternalErrorRestEx(ex.getMessage()); } }
RESTUserServiceImpl extends BaseRESTServiceImpl implements RESTUserService { @Override public Response insert(RESTInputUser user) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { boolean exists; try { userAdminService.get(user.getName()); exists = true; } catch (NotFoundServiceEx ex) { exists = false; } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if ( exists ) { throw new ConflictRestEx("User '" + user.getName() + "' already exists"); } try { Set<UserGroup> groups = new HashSet<UserGroup>(); List<IdName> inputGroups = user.getGroups(); if ( inputGroups == null || inputGroups.isEmpty() ) { LOGGER.warn("No groups defined for user " + user.getName()); } else { for (IdName identifier : inputGroups) { if ( identifier == null ) { throw new BadRequestRestEx("Bad group identifier"); } UserGroup group = getUserGroup(identifier); groups.add(group); } } GSUser u = new GSUser(); u.setGroups(groups); u.setExtId(user.getExtId()); u.setName(user.getName()); u.setPassword(user.getPassword()); u.setEnabled(user.isEnabled()); u.setAdmin(user.isAdmin()); u.setFullName(user.getFullName()); u.setEmailAddress(user.getEmailAddress()); Long ret = userAdminService.insert(u); return Response.status(Status.CREATED).tag(ret.toString()).entity(ret).build(); } catch (GeoFenceRestEx ex) { throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Problems inserting user: " + ex.getMessage(), ex); 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 InternalErrorRestEx(ex.getMessage()); } } }
RESTUserServiceImpl extends BaseRESTServiceImpl implements RESTUserService { @Override public Response insert(RESTInputUser user) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { boolean exists; try { userAdminService.get(user.getName()); exists = true; } catch (NotFoundServiceEx ex) { exists = false; } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if ( exists ) { throw new ConflictRestEx("User '" + user.getName() + "' already exists"); } try { Set<UserGroup> groups = new HashSet<UserGroup>(); List<IdName> inputGroups = user.getGroups(); if ( inputGroups == null || inputGroups.isEmpty() ) { LOGGER.warn("No groups defined for user " + user.getName()); } else { for (IdName identifier : inputGroups) { if ( identifier == null ) { throw new BadRequestRestEx("Bad group identifier"); } UserGroup group = getUserGroup(identifier); groups.add(group); } } GSUser u = new GSUser(); u.setGroups(groups); u.setExtId(user.getExtId()); u.setName(user.getName()); u.setPassword(user.getPassword()); u.setEnabled(user.isEnabled()); u.setAdmin(user.isAdmin()); u.setFullName(user.getFullName()); u.setEmailAddress(user.getEmailAddress()); Long ret = userAdminService.insert(u); return Response.status(Status.CREATED).tag(ret.toString()).entity(ret).build(); } catch (GeoFenceRestEx ex) { throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Problems inserting user: " + ex.getMessage(), ex); 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 InternalErrorRestEx(ex.getMessage()); } }  }
RESTUserServiceImpl extends BaseRESTServiceImpl implements RESTUserService { @Override public Response insert(RESTInputUser user) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { boolean exists; try { userAdminService.get(user.getName()); exists = true; } catch (NotFoundServiceEx ex) { exists = false; } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if ( exists ) { throw new ConflictRestEx("User '" + user.getName() + "' already exists"); } try { Set<UserGroup> groups = new HashSet<UserGroup>(); List<IdName> inputGroups = user.getGroups(); if ( inputGroups == null || inputGroups.isEmpty() ) { LOGGER.warn("No groups defined for user " + user.getName()); } else { for (IdName identifier : inputGroups) { if ( identifier == null ) { throw new BadRequestRestEx("Bad group identifier"); } UserGroup group = getUserGroup(identifier); groups.add(group); } } GSUser u = new GSUser(); u.setGroups(groups); u.setExtId(user.getExtId()); u.setName(user.getName()); u.setPassword(user.getPassword()); u.setEnabled(user.isEnabled()); u.setAdmin(user.isAdmin()); u.setFullName(user.getFullName()); u.setEmailAddress(user.getEmailAddress()); Long ret = userAdminService.insert(u); return Response.status(Status.CREATED).tag(ret.toString()).entity(ret).build(); } catch (GeoFenceRestEx ex) { throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Problems inserting user: " + ex.getMessage(), ex); 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 InternalErrorRestEx(ex.getMessage()); } }  @Override Response delete(String username, boolean cascade); @Override RESTOutputUser get(String name); @Override Response insert(RESTInputUser user); @Override void update(String name, RESTInputUser user); @Override void update(Long id, RESTInputUser user); @Override RESTShortUserList getList(String nameLike, Integer page, Integer entries); @Override long count(String nameLike); static RESTShortUser toShortUser(GSUser user); static RESTOutputUser toOutputUser(GSUser user); @Override void addIntoGroup(String userName, String groupName); @Override void removeFromGroup(String userName, String groupName); }
RESTUserServiceImpl extends BaseRESTServiceImpl implements RESTUserService { @Override public Response insert(RESTInputUser user) throws BadRequestRestEx, NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { boolean exists; try { userAdminService.get(user.getName()); exists = true; } catch (NotFoundServiceEx ex) { exists = false; } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if ( exists ) { throw new ConflictRestEx("User '" + user.getName() + "' already exists"); } try { Set<UserGroup> groups = new HashSet<UserGroup>(); List<IdName> inputGroups = user.getGroups(); if ( inputGroups == null || inputGroups.isEmpty() ) { LOGGER.warn("No groups defined for user " + user.getName()); } else { for (IdName identifier : inputGroups) { if ( identifier == null ) { throw new BadRequestRestEx("Bad group identifier"); } UserGroup group = getUserGroup(identifier); groups.add(group); } } GSUser u = new GSUser(); u.setGroups(groups); u.setExtId(user.getExtId()); u.setName(user.getName()); u.setPassword(user.getPassword()); u.setEnabled(user.isEnabled()); u.setAdmin(user.isAdmin()); u.setFullName(user.getFullName()); u.setEmailAddress(user.getEmailAddress()); Long ret = userAdminService.insert(u); return Response.status(Status.CREATED).tag(ret.toString()).entity(ret).build(); } catch (GeoFenceRestEx ex) { throw ex; } catch (NotFoundServiceEx ex) { LOGGER.warn("Problems inserting user: " + ex.getMessage(), ex); 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 InternalErrorRestEx(ex.getMessage()); } }  @Override Response delete(String username, boolean cascade); @Override RESTOutputUser get(String name); @Override Response insert(RESTInputUser user); @Override void update(String name, RESTInputUser user); @Override void update(Long id, RESTInputUser user); @Override RESTShortUserList getList(String nameLike, Integer page, Integer entries); @Override long count(String nameLike); static RESTShortUser toShortUser(GSUser user); static RESTOutputUser toOutputUser(GSUser user); @Override void addIntoGroup(String userName, String groupName); @Override void removeFromGroup(String userName, String groupName);  }