@Override public void handle(Request request, Response response) throws Exception { if (settings.getBoolean(CorePropertyDefinitions.ORGANIZATIONS_ANYONE_CAN_CREATE)) { userSession.checkLoggedIn(); } else { userSession.checkIsRoot(); } String name = wsSupport.getAndCheckMandatoryName(request); String requestKey = getAndCheckKey(request); String key = useOrGenerateKey(requestKey, name); wsSupport.getAndCheckDescription(request); wsSupport.getAndCheckUrl(request); wsSupport.getAndCheckAvatar(request); try (DbSession dbSession = dbClient.openSession(false)) { checkKeyIsNotUsed(dbSession, key, requestKey, name); OrganizationDto dto = createOrganizationDto(request, name, key); dbClient.organizationDao().insert(dbSession, dto); GroupDto group = createOwnersGroup(dbSession, dto); addCurrentUserToGroup(dbSession, group); dbSession.commit(); writeResponse(request, response, dto); } }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkPermission(GlobalPermissions.SYSTEM_ADMIN); String key = request.mandatoryParam(PARAM_KEY); preventDeletionOfDefaultOrganization(key, defaultOrganizationProvider.get()); try (DbSession dbSession = dbClient.openSession(false)) { dbClient.organizationDao().deleteByKey(dbSession, key); dbSession.commit(); response.noContent(); } }
private boolean checkKeyIsUsed(DbSession dbSession, String key) { return dbClient.organizationDao().selectByKey(dbSession, key).isPresent(); }