3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.telemetry;
22 import java.util.HashMap;
23 import java.util.List;
25 import org.sonar.db.DbClient;
26 import org.sonar.db.DbSession;
27 import org.sonar.db.user.UserDto;
28 import org.sonar.db.user.UserQuery;
29 import org.sonar.server.util.DigestUtil;
30 import org.sonar.telemetry.core.Dimension;
31 import org.sonar.telemetry.core.Granularity;
32 import org.sonar.telemetry.core.TelemetryDataProvider;
33 import org.sonar.telemetry.core.TelemetryDataType;
35 public class TelemetryUserEnabledProvider implements TelemetryDataProvider<Boolean> {
37 private final DbClient dbClient;
39 public TelemetryUserEnabledProvider(DbClient dbClient) {
40 this.dbClient = dbClient;
44 public String getMetricKey() {
45 return "user_enabled";
49 public Dimension getDimension() {
50 return Dimension.USER;
54 public Granularity getGranularity() {
55 return Granularity.DAILY;
59 public TelemetryDataType getType() {
60 return TelemetryDataType.BOOLEAN;
64 public Map<String, Boolean> getUuidValues() {
65 Map<String, Boolean> result = new HashMap<>();
68 try (DbSession dbSession = dbClient.openSession(false)) {
69 List<UserDto> userDtos;
71 userDtos = dbClient.userDao().selectUsers(dbSession, UserQuery.builder().build(), page, pageSize);
72 for (UserDto userDto : userDtos) {
73 String anonymizedUuid = DigestUtil.sha3_224Hex(userDto.getUuid());
74 result.put(anonymizedUuid, userDto.isActive());
77 } while (!userDtos.isEmpty());