Search in sources :

Example 1 with PARAM_NAME

use of org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_NAME in project sonarqube by SonarSource.

the class UpdateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    try (DbSession dbSession = dbClient.openSession(false)) {
        organizationFlags.checkEnabled(dbSession);
        String key = request.mandatoryParam(PARAM_KEY);
        UpdateOrganizationRequest updateRequest = new UpdateOrganizationRequest(request.getParam(PARAM_NAME, (rqt, paramKey) -> wsSupport.getAndCheckName(rqt)), request.getParam(PARAM_DESCRIPTION, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckDescription(rqt))), request.getParam(PARAM_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckUrl(rqt))), request.getParam(PARAM_AVATAR_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckAvatar(rqt))));
        OrganizationDto dto = getDto(dbSession, key);
        userSession.checkPermission(ADMINISTER, dto);
        dto.setName(updateRequest.getName().or(dto::getName)).setDescription(updateRequest.getDescription().or(dto::getDescription)).setUrl(updateRequest.getUrl().or(dto::getUrl)).setAvatarUrl(updateRequest.getAvatar().or(dto::getAvatarUrl));
        dbClient.organizationDao().update(dbSession, dto);
        dbSession.commit();
        writeResponse(request, response, dto);
    }
}
Also used : OrganizationFlags(org.sonar.server.organization.OrganizationFlags) PARAM_AVATAR_URL(org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_AVATAR_URL) ADMINISTER(org.sonar.db.permission.OrganizationPermission.ADMINISTER) PARAM_KEY(org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_KEY) DbSession(org.sonar.db.DbSession) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Organizations(org.sonarqube.ws.Organizations) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) WebService(org.sonar.api.server.ws.WebService) PARAM_DESCRIPTION(org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_DESCRIPTION) PARAM_URL(org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_URL) Response(org.sonar.api.server.ws.Response) Optional(java.util.Optional) OrganizationDto(org.sonar.db.organization.OrganizationDto) UserSession(org.sonar.server.user.UserSession) PARAM_NAME(org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_NAME) CheckForNull(javax.annotation.CheckForNull) Nullable(javax.annotation.Nullable) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Aggregations

String.format (java.lang.String.format)1 Optional (java.util.Optional)1 CheckForNull (javax.annotation.CheckForNull)1 Nullable (javax.annotation.Nullable)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 WebService (org.sonar.api.server.ws.WebService)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 ADMINISTER (org.sonar.db.permission.OrganizationPermission.ADMINISTER)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1 OrganizationFlags (org.sonar.server.organization.OrganizationFlags)1 PARAM_AVATAR_URL (org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_AVATAR_URL)1 PARAM_DESCRIPTION (org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_DESCRIPTION)1 PARAM_KEY (org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_KEY)1 PARAM_NAME (org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_NAME)1 PARAM_URL (org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_URL)1 UserSession (org.sonar.server.user.UserSession)1 WsUtils.writeProtobuf (org.sonar.server.ws.WsUtils.writeProtobuf)1