private List<ShortGroup> convertToShortList(List<UserGroup> list) { List<ShortGroup> swList = new ArrayList<>(list.size()); for (UserGroup group : list) { swList.add(new ShortGroup(group)); } return swList; }
@Override public long update(ShortGroup group) throws NotFoundServiceEx { UserGroup orig = userGroupDAO.find(group.getId()); if ( orig == null ) { throw new NotFoundServiceEx("UserGroup not found", group.getId()); } // orig.setName(group.getName()); if ( group.isEnabled() != null ) { orig.setEnabled(group.isEnabled()); } if ( group.getExtId() != null ) { orig.setExtId(group.getExtId()); } userGroupDAO.merge(orig); return orig.getId(); }
protected RESTBatch collectGroups(RESTBatch backup) { for (ShortGroup shortGroup : userGroupAdminService.getList(null, null, null)) { RESTBatchOperation op = RESTBatchOperationFactory.createGroupInputOp(shortGroup.getName()); RESTInputGroup input = (RESTInputGroup)op.getPayload(); input.setExtId(shortGroup.getExtId()); input.setEnabled(shortGroup.isEnabled()); backup.add(op); } return backup; }
ShortGroup short_profile = new ShortGroup(); short_profile.setId(remote_profile.getId()); short_profile.setName(profile.getName()); short_profile.setEnabled(profile.isEnabled()); geofenceRemoteService.getUserGroupAdminService().update(short_profile); ShortGroup short_profile = new ShortGroup(); short_profile.setName(profile.getName()); short_profile.setEnabled(profile.isEnabled()); geofenceRemoteService.getUserGroupAdminService().insert(short_profile);
@Override public Response insert(RESTInputGroup userGroup) throws NotFoundRestEx, InternalErrorRestEx, ConflictRestEx { // check that no group with same name exists boolean exists; try { userGroupAdminService.get(userGroup.getName()); exists = true; } catch (NotFoundServiceEx ex) { // well, ok, usergroup does not exist exists = false; } catch (Exception ex) { // something went wrong LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } if(exists) throw new ConflictRestEx("Role '"+userGroup.getName()+"' already exists"); // ok: insert it try { ShortGroup insert = new ShortGroup(); insert.setEnabled(userGroup.isEnabled()); insert.setExtId(userGroup.getExtId()); insert.setName(userGroup.getName()); Long id = userGroupAdminService.insert(insert); return Response.status(Status.CREATED).tag(id.toString()).entity(id).build(); } 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()); } }
public void removeAllProfiles() throws NotFoundServiceEx { List<ShortGroup> list = userGroupAdminService.getList(null, null, null); for (ShortGroup item : list) { LOGGER.warn("Removing " + item); boolean ret = userGroupAdminService.delete(item.getId()); if ( !ret ) { LOGGER.error("Could not remove " + item); } } long count = userGroupAdminService.getCount(null); if ( count > 0 ) { LOGGER.error("Items not removed"); } }
sortedNames.add(group.getName());
Long oldId = sp.getId(); long newId = userGroupAdminService.insert(sp); LOGGER.info("Remapping userGroup " + oldId + " -> " + newId);
@Override public ShortGroup get(String name) throws NotFoundRestEx, InternalErrorRestEx { try { UserGroup ret = userGroupAdminService.get(name); return new ShortGroup(ret); } catch (NotFoundServiceEx ex) { LOGGER.warn("Role not found: " + name); throw new NotFoundRestEx("Role not found: " + name); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); throw new InternalErrorRestEx(ex.getMessage()); } }