@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { int groupId = request.mandatoryParamAsInt(PARAM_GROUP_ID); GroupDto group = dbClient.groupDao().selectById(dbSession, groupId); checkFound(group, "Could not find a user group with id '%s'.", groupId); Optional<OrganizationDto> org = dbClient.organizationDao().selectByUuid(dbSession, group.getOrganizationUuid()); checkFoundWithOptional(org, "Could not find organization with id '%s'.", group.getOrganizationUuid()); userSession.checkPermission(ADMINISTER, org.get()); support.checkGroupIsNotDefault(dbSession, group); boolean changed = false; String newName = request.param(PARAM_GROUP_NAME); if (newName != null) { changed = true; UserGroupValidation.validateGroupName(newName); support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), newName); group.setName(newName); } String description = request.param(PARAM_GROUP_DESCRIPTION); if (description != null) { changed = true; group.setDescription(description); } if (changed) { dbClient.groupDao().update(dbSession, group); dbSession.commit(); } writeResponse(dbSession, request, response, org.get(), group); } }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { int groupId = request.mandatoryParamAsInt(PARAM_GROUP_ID); GroupDto group = dbClient.groupDao().selectById(dbSession, groupId); checkFound(group, "Could not find a user group with id '%s'.", groupId); Optional<OrganizationDto> org = dbClient.organizationDao().selectByUuid(dbSession, group.getOrganizationUuid()); checkFoundWithOptional(org, "Could not find organization with id '%s'.", group.getOrganizationUuid()); userSession.checkPermission(ADMINISTER, org.get()); support.checkGroupIsNotDefault(dbSession, group); boolean changed = false; String newName = request.param(PARAM_GROUP_NAME); if (newName != null) { changed = true; UserGroupValidation.validateGroupName(newName); support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), newName); group.setName(newName); } String description = request.param(PARAM_GROUP_DESCRIPTION); if (description != null) { changed = true; group.setDescription(description); } if (changed) { dbClient.groupDao().update(dbSession, group); dbSession.commit(); } writeResponse(dbSession, request, response, org.get(), group); } }