repo stringlengths 1 191 ⌀ | file stringlengths 23 351 | code stringlengths 0 5.32M | file_length int64 0 5.32M | avg_line_length float64 0 2.9k | max_line_length int64 0 288k | extension_type stringclasses 1 value |
|---|---|---|---|---|---|---|
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.qualityprofile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import org.sonar.db.KeyLongValue;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.project.ProjectDto;
import static java.util.Collections.emptyList;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeUpdates;
public class QualityProfileDao implements Dao {
private final System2 system;
private final UuidFactory uuidFactory;
public QualityProfileDao(UuidFactory uuidFactory, System2 system) {
this.uuidFactory = uuidFactory;
this.system = system;
}
@CheckForNull
public QProfileDto selectByUuid(DbSession dbSession, String uuid) {
return mapper(dbSession).selectByUuid(uuid);
}
public QProfileDto selectOrFailByUuid(DbSession dbSession, String uuid) {
QProfileDto dto = selectByUuid(dbSession, uuid);
if (dto == null) {
throw new RowNotFoundException("Quality profile not found: " + uuid);
}
return dto;
}
public List<QProfileDto> selectByUuids(DbSession dbSession, List<String> uuids) {
return executeLargeInputs(uuids, mapper(dbSession)::selectByUuids);
}
public List<QProfileDto> selectAll(DbSession dbSession) {
return mapper(dbSession).selectAll();
}
public List<RulesProfileDto> selectBuiltInRuleProfiles(DbSession dbSession) {
return mapper(dbSession).selectBuiltInRuleProfiles();
}
public List<RulesProfileDto> selectBuiltInRuleProfilesWithActiveRules(DbSession dbSession) {
return mapper(dbSession).selectBuiltInRuleProfilesWithActiveRules();
}
@CheckForNull
public RulesProfileDto selectRuleProfile(DbSession dbSession, String ruleProfileUuid) {
return mapper(dbSession).selectRuleProfile(ruleProfileUuid);
}
public void insert(DbSession dbSession, RulesProfileDto dto) {
QualityProfileMapper mapper = mapper(dbSession);
mapper.insertRuleProfile(dto, new Date(system.now()));
}
public void insert(DbSession dbSession, OrgQProfileDto dto) {
QualityProfileMapper mapper = mapper(dbSession);
mapper.insertOrgQProfile(dto, system.now());
}
public void insert(DbSession dbSession, QProfileDto profile, QProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(dbSession);
doInsert(mapper, profile);
for (QProfileDto other : otherProfiles) {
doInsert(mapper, other);
}
}
private void doInsert(QualityProfileMapper mapper, QProfileDto profile) {
long now = system.now();
RulesProfileDto rulesProfile = RulesProfileDto.from(profile);
mapper.insertRuleProfile(rulesProfile, new Date(now));
mapper.insertOrgQProfile(OrgQProfileDto.from(profile), now);
}
public void update(DbSession dbSession, QProfileDto profile, QProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(dbSession);
long now = system.now();
doUpdate(mapper, profile, now);
for (QProfileDto otherProfile : otherProfiles) {
doUpdate(mapper, otherProfile, now);
}
}
public int updateLastUsedDate(DbSession dbSession, QProfileDto profile, long lastUsedDate) {
return mapper(dbSession).updateLastUsedDate(profile.getKee(), lastUsedDate, system.now());
}
public void update(DbSession dbSession, RulesProfileDto rulesProfile) {
QualityProfileMapper mapper = mapper(dbSession);
long now = system.now();
mapper.updateRuleProfile(rulesProfile, new Date(now));
}
public void update(DbSession dbSession, OrgQProfileDto profile) {
QualityProfileMapper mapper = mapper(dbSession);
long now = system.now();
mapper.updateOrgQProfile(profile, now);
}
private static void doUpdate(QualityProfileMapper mapper, QProfileDto profile, long now) {
mapper.updateRuleProfile(RulesProfileDto.from(profile), new Date(now));
mapper.updateOrgQProfile(OrgQProfileDto.from(profile), now);
}
public List<QProfileDto> selectDefaultProfiles(DbSession dbSession, Collection<String> languages) {
return executeLargeInputs(languages, partition -> mapper(dbSession).selectDefaultProfiles(partition));
}
public List<QProfileDto> selectDefaultBuiltInProfilesWithoutActiveRules(DbSession dbSession, Set<String> languages) {
return executeLargeInputs(languages, partition -> mapper(dbSession).selectDefaultBuiltInProfilesWithoutActiveRules(partition));
}
@CheckForNull
public QProfileDto selectDefaultProfile(DbSession dbSession, String language) {
return mapper(dbSession).selectDefaultProfile(language);
}
@CheckForNull
public String selectDefaultProfileUuid(DbSession dbSession, String language) {
return mapper(dbSession).selectDefaultProfileUuid(language);
}
@CheckForNull
public QProfileDto selectAssociatedToProjectAndLanguage(DbSession dbSession, ProjectDto project, String language) {
return mapper(dbSession).selectAssociatedToProjectUuidAndLanguage(project.getUuid(), language);
}
public List<QProfileDto> selectAssociatedToProjectAndLanguages(DbSession dbSession, ProjectDto project, Collection<String> languages) {
return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getUuid(), partition));
}
public List<QProfileDto> selectQProfilesByProjectUuid(DbSession dbSession, String projectUuid) {
return mapper(dbSession).selectQProfilesByProjectUuid(projectUuid);
}
public List<QProfileDto> selectByLanguage(DbSession dbSession, String language) {
return mapper(dbSession).selectByLanguage(language);
}
public List<QProfileDto> selectChildren(DbSession dbSession, Collection<QProfileDto> profiles) {
List<String> uuids = profiles.stream().map(QProfileDto::getKee).toList();
return DatabaseUtils.executeLargeInputs(uuids, chunk -> mapper(dbSession).selectChildren(chunk));
}
/**
* All descendants, in any order. The specified profiles are not included into results.
*/
public Collection<QProfileDto> selectDescendants(DbSession dbSession, Collection<QProfileDto> profiles) {
if (profiles.isEmpty()) {
return emptyList();
}
Collection<QProfileDto> children = selectChildren(dbSession, profiles);
List<QProfileDto> descendants = new ArrayList<>(children);
descendants.addAll(selectDescendants(dbSession, children));
return descendants;
}
@CheckForNull
public QProfileDto selectByNameAndLanguage(DbSession dbSession, String name, String language) {
return mapper(dbSession).selectByNameAndLanguage(name, language);
}
@CheckForNull
public QProfileDto selectByRuleProfileUuid(DbSession dbSession, String ruleProfileKee) {
return mapper(dbSession).selectByRuleProfileUuid(ruleProfileKee);
}
public List<QProfileDto> selectByNameAndLanguages(DbSession dbSession, String name, Collection<String> languages) {
return mapper(dbSession).selectByNameAndLanguages(name, languages);
}
public Map<String, Long> countProjectsByProfiles(DbSession dbSession, List<QProfileDto> profiles) {
List<String> profileUuids = profiles.stream().map(QProfileDto::getKee).toList();
return KeyLongValue.toMap(executeLargeInputs(profileUuids, partition -> mapper(dbSession).countProjectsByProfiles(partition)));
}
public void insertProjectProfileAssociation(DbSession dbSession, ProjectDto project, QProfileDto profile) {
mapper(dbSession).insertProjectProfileAssociation(uuidFactory.create(), project.getUuid(), profile.getKee());
}
public void deleteProjectProfileAssociation(DbSession dbSession, ProjectDto project, QProfileDto profile) {
mapper(dbSession).deleteProjectProfileAssociation(project.getUuid(), profile.getKee());
}
public void updateProjectProfileAssociation(DbSession dbSession, ProjectDto project, String newProfileUuid, String oldProfileUuid) {
mapper(dbSession).updateProjectProfileAssociation(project.getUuid(), newProfileUuid, oldProfileUuid);
}
public void deleteProjectAssociationsByProfileUuids(DbSession dbSession, Collection<String> profileUuids) {
QualityProfileMapper mapper = mapper(dbSession);
DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteProjectAssociationByProfileUuids);
}
public List<ProjectQprofileAssociationDto> selectSelectedProjects(DbSession dbSession, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
return mapper(dbSession).selectSelectedProjects(profile.getKee(), nameQuery);
}
public List<ProjectQprofileAssociationDto> selectDeselectedProjects(DbSession dbSession, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
return mapper(dbSession).selectDeselectedProjects(profile.getKee(), nameQuery);
}
public List<ProjectQprofileAssociationDto> selectProjectAssociations(DbSession dbSession, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
return mapper(dbSession).selectProjectAssociations(profile.getKee(), nameQuery);
}
public Collection<String> selectUuidsOfCustomRulesProfiles(DbSession dbSession, String language, String name) {
return mapper(dbSession).selectUuidsOfCustomRuleProfiles(language, name);
}
public void renameRulesProfilesAndCommit(DbSession dbSession, Collection<String> rulesProfileUuids, String newName) {
QualityProfileMapper mapper = mapper(dbSession);
Date now = new Date(system.now());
executeLargeUpdates(rulesProfileUuids, partition -> {
mapper.renameRuleProfiles(newName, now, partition);
dbSession.commit();
});
}
public void deleteOrgQProfilesByUuids(DbSession dbSession, Collection<String> profileUuids) {
QualityProfileMapper mapper = mapper(dbSession);
DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteOrgQProfilesByUuids);
}
public void deleteRulesProfilesByUuids(DbSession dbSession, Collection<String> rulesProfileUuids) {
QualityProfileMapper mapper = mapper(dbSession);
DatabaseUtils.executeLargeUpdates(rulesProfileUuids, mapper::deleteRuleProfilesByUuids);
}
public List<QProfileDto> selectQProfilesByRuleProfile(DbSession dbSession, RulesProfileDto rulesProfile) {
return mapper(dbSession).selectQProfilesByRuleProfileUuid(rulesProfile.getUuid());
}
private static String sqlQueryString(@Nullable String query) {
if (query == null) {
return "%";
}
return "%" + query.toUpperCase(Locale.ENGLISH) + "%";
}
private static QualityProfileMapper mapper(DbSession dbSession) {
return dbSession.getMapper(QualityProfileMapper.class);
}
}
| 11,757 | 40.25614 | 145 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.qualityprofile;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class QualityProfileExportDao implements Dao {
public List<ExportRuleDto> selectRulesByProfile(DbSession dbSession, QProfileDto profile) {
List<ExportRuleDto> exportRules = mapper(dbSession).selectByProfileUuid(profile.getKee());
Map<String, ExportRuleDto> exportRulesByUuid = exportRules.stream().collect(Collectors.toMap(ExportRuleDto::getActiveRuleUuid, x -> x));
Map<String, List<ExportRuleParamDto>> rulesParams = selectParamsByActiveRuleUuids(dbSession, exportRulesByUuid.keySet());
rulesParams.forEach((uuid, rules) -> exportRulesByUuid.get(uuid).setParams(rules));
return exportRules;
}
private static Map<String, List<ExportRuleParamDto>> selectParamsByActiveRuleUuids(DbSession dbSession, Collection<String> activeRuleUuids) {
return executeLargeInputs(activeRuleUuids, uuids -> mapper(dbSession).selectParamsByActiveRuleUuids(uuids))
.stream()
.collect(Collectors.groupingBy(ExportRuleParamDto::getActiveRuleUuid));
}
private static QualityProfileExportMapper mapper(DbSession dbSession) {
return dbSession.getMapper(QualityProfileExportMapper.class);
}
}
| 2,241 | 41.301887 | 143 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileExportMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.qualityprofile;
import java.util.Collection;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface QualityProfileExportMapper {
List<ExportRuleDto> selectByProfileUuid(String uuid);
List<ExportRuleParamDto> selectParamsByActiveRuleUuids(@Param("activeRuleUuids") Collection<String> activeRuleUuids);
}
| 1,203 | 37.83871 | 119 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.qualityprofile;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.sonar.db.KeyLongValue;
public interface QualityProfileMapper {
void insertOrgQProfile(@Param("dto") OrgQProfileDto dto, @Param("now") long now);
void insertRuleProfile(@Param("dto") RulesProfileDto dto, @Param("now") Date now);
void updateRuleProfile(@Param("dto") RulesProfileDto dto, @Param("now") Date now);
void updateOrgQProfile(@Param("dto") OrgQProfileDto dto, @Param("now") long now);
void deleteRuleProfilesByUuids(@Param("uuids") Collection<String> uuids);
void deleteOrgQProfilesByUuids(@Param("uuids") Collection<String> uuids);
List<RulesProfileDto> selectBuiltInRuleProfiles();
List<RulesProfileDto> selectBuiltInRuleProfilesWithActiveRules();
@CheckForNull
RulesProfileDto selectRuleProfile(@Param("uuid") String ruleProfileUuid);
List<QProfileDto> selectAll();
@CheckForNull
QProfileDto selectDefaultProfile(@Param("language") String language);
List<QProfileDto> selectDefaultBuiltInProfilesWithoutActiveRules(@Param("languages") List<String> languages);
List<QProfileDto> selectDefaultProfiles(
@Param("languages") Collection<String> languages);
@CheckForNull
String selectDefaultProfileUuid(@Param("language") String language);
@CheckForNull
QProfileDto selectByNameAndLanguage(
@Param("name") String name,
@Param("language") String language);
@CheckForNull
QProfileDto selectByRuleProfileUuid(@Param("ruleProfileUuid") String ruleProfileKee);
List<QProfileDto> selectByNameAndLanguages(@Param("name") String name, @Param("languages") Collection<String> languages);
@CheckForNull
QProfileDto selectByUuid(String uuid);
List<QProfileDto> selectByUuids(@Param("uuids") Collection<String> uuids);
List<QProfileDto> selectByLanguage(@Param("language") String language);
// INHERITANCE
List<QProfileDto> selectChildren(@Param("uuids") Collection<String> uuids);
// PROJECTS
List<KeyLongValue> countProjectsByProfiles(@Param("profileUuids") List<String> profiles);
@CheckForNull
QProfileDto selectAssociatedToProjectUuidAndLanguage(
@Param("projectUuid") String projectUuid,
@Param("language") String language);
List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(
@Param("projectUuid") String projectUuid,
@Param("languages") Collection<String> languages);
List<QProfileDto> selectQProfilesByProjectUuid(@Param("projectUuid") String projectUuid);
void insertProjectProfileAssociation(
@Param("uuid") String uuid,
@Param("projectUuid") String projectUuid,
@Param("profileUuid") String profileUuid);
void updateProjectProfileAssociation(
@Param("projectUuid") String projectUuid,
@Param("profileUuid") String profileUuid,
@Param("oldProfileUuid") String oldProfileUuid);
void deleteProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileUuid") String profileUuid);
void deleteProjectAssociationByProfileUuids(@Param("profileUuids") Collection<String> profileUuids);
List<ProjectQprofileAssociationDto> selectSelectedProjects(
@Param("profileUuid") String profileUuid,
@Param("nameOrKeyQuery") String nameOrKeyQuery);
List<ProjectQprofileAssociationDto> selectDeselectedProjects(
@Param("profileUuid") String profileUuid,
@Param("nameOrKeyQuery") String nameOrKeyQuery);
List<ProjectQprofileAssociationDto> selectProjectAssociations(
@Param("profileUuid") String profileUuid,
@Param("nameOrKeyQuery") String nameOrKeyQuery);
List<String> selectUuidsOfCustomRuleProfiles(@Param("language") String language, @Param("name") String name);
void renameRuleProfiles(@Param("newName") String newName, @Param("updatedAt") Date updatedAt, @Param("uuids") Collection<String> uuids);
List<QProfileDto> selectQProfilesByRuleProfileUuid(@Param("rulesProfileUuid") String rulesProfileUuid);
int updateLastUsedDate(
@Param("uuid") String uuid,
@Param("lastUsedDate") long lastUsedDate,
@Param("now") long now);
}
| 5,009 | 35.838235 | 138 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.qualityprofile;
import java.util.Date;
import org.sonar.core.util.UtcDateUtils;
/**
* Maps the table "rules_profiles", which represents
* a group of active rules.
*
* Can be:
* - a built-in profile, referenced by multiple organizations
* through table "org_qprofiles".
* - a profile created by user and referenced by one, and only one,
* organization in the table "org_qprofiles"
*/
public class RulesProfileDto {
/**
* UUID
*/
private String uuid;
/**
* Name displayed to users, for example "Sonar way". Not null.
*/
private String name;
/**
* Language key, for example "java". Not null.
*/
private String language;
/**
* Date of last update of rule configuration (activation/deactivation/change of parameter).
* It does not include profile renaming.
* Not null.
*/
private String rulesUpdatedAt;
/**
* Whether profile is built-in or created by a user.
* A built-in profile is read-only. Its definition is provided by a language plugin.
*/
private boolean isBuiltIn;
public String getUuid() {
return uuid;
}
public RulesProfileDto setUuid(String s) {
this.uuid = s;
return this;
}
public String getName() {
return name;
}
public RulesProfileDto setName(String name) {
this.name = name;
return this;
}
public String getLanguage() {
return language;
}
public RulesProfileDto setLanguage(String language) {
this.language = language;
return this;
}
public String getRulesUpdatedAt() {
return rulesUpdatedAt;
}
public RulesProfileDto setRulesUpdatedAt(String s) {
this.rulesUpdatedAt = s;
return this;
}
public RulesProfileDto setRulesUpdatedAtAsDate(Date d) {
this.rulesUpdatedAt = UtcDateUtils.formatDateTime(d);
return this;
}
public boolean isBuiltIn() {
return isBuiltIn;
}
public RulesProfileDto setIsBuiltIn(boolean b) {
this.isBuiltIn = b;
return this;
}
public static RulesProfileDto from(QProfileDto qProfileDto) {
return new RulesProfileDto()
.setUuid(qProfileDto.getRulesProfileUuid())
.setLanguage(qProfileDto.getLanguage())
.setName(qProfileDto.getName())
.setIsBuiltIn(qProfileDto.isBuiltIn())
.setRulesUpdatedAt(qProfileDto.getRulesUpdatedAt());
}
}
| 3,167 | 24.548387 | 93 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/SearchQualityProfilePermissionQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.qualityprofile;
import java.util.Locale;
import org.sonar.db.user.SearchPermissionQuery;
import static java.util.Objects.requireNonNull;
import static org.sonar.db.DaoUtils.buildLikeValue;
import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER;
public class SearchQualityProfilePermissionQuery extends SearchPermissionQuery {
private final String qProfileUuid;
public SearchQualityProfilePermissionQuery(Builder builder) {
this.qProfileUuid = builder.profile.getKee();
this.query = builder.getQuery();
this.membership = builder.getMembership();
this.querySql = query == null ? null : buildLikeValue(query, BEFORE_AND_AFTER);
this.querySqlLowercase = querySql == null ? null : querySql.toLowerCase(Locale.ENGLISH);
}
public String getQProfileUuid() {
return qProfileUuid;
}
public static Builder builder() {
return new Builder();
}
public static class Builder extends SearchPermissionQuery.Builder<Builder> {
private QProfileDto profile;
public Builder setProfile(QProfileDto profile) {
this.profile = profile;
return this;
}
public SearchQualityProfilePermissionQuery build() {
requireNonNull(profile, "Quality profile cant be null.");
initMembership();
return new SearchQualityProfilePermissionQuery(this);
}
}
}
| 2,190 | 33.234375 | 92 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.qualityprofile;
import javax.annotation.ParametersAreNonnullByDefault;
| 968 | 37.76 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/IssueFindingDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.sonar.api.rules.RuleType;
import org.sonar.db.rule.RuleDto;
public class IssueFindingDto {
private String kee;
private String message;
private int type;
private String severity;
private boolean isManualSeverity;
private String ruleKey;
private String ruleRepository;
private String ruleName;
private String status;
private String resolution;
private String fileName;
private Integer line;
private String securityStandards;
private boolean isNewCodeReferenceIssue;
private long creationDate;
private List<String> comments;
public String getStatus() {
return status;
}
@CheckForNull
public String getRuleName() {
return ruleName;
}
public String getKey() {
return kee;
}
public Set<String> getSecurityStandards() {
return RuleDto.deserializeSecurityStandardsString(securityStandards);
}
public boolean isManualSeverity() {
return isManualSeverity;
}
@CheckForNull
public String getResolution() {
return resolution;
}
@CheckForNull
public String getMessage() {
return message;
}
public RuleType getType() {
return RuleType.valueOf(type);
}
public String getSeverity() {
return severity;
}
public String getRuleKey() {
return ruleKey;
}
public String getRuleRepository() {
return ruleRepository;
}
@CheckForNull
public String getFileName() {
return fileName;
}
@CheckForNull
public Integer getLine() {
return line;
}
public boolean isNewCodeReferenceIssue() {
return isNewCodeReferenceIssue;
}
public long getCreationDate() {
return creationDate;
}
public List<String> getComments() {
return comments;
}
}
| 2,656 | 22.104348 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/RegulatoryReportDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import org.apache.ibatis.session.ResultHandler;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
public class RegulatoryReportDao implements Dao {
public void scrollIssues(DbSession dbSession, String branchUuid, ResultHandler<IssueFindingDto> handler) {
mapper(dbSession).scrollIssues(branchUuid, handler);
}
private static RegulatoryReportMapper mapper(DbSession dbSession) {
return dbSession.getMapper(RegulatoryReportMapper.class);
}
}
| 1,337 | 37.228571 | 108 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/RegulatoryReportMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import org.apache.ibatis.session.ResultHandler;
public interface RegulatoryReportMapper {
void scrollIssues(String branchUuid, ResultHandler<IssueFindingDto> handler);
}
| 1,046 | 37.777778 | 79 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import java.util.List;
import java.util.Optional;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
public class ReportScheduleDao implements Dao {
public Optional<ReportScheduleDto> selectByBranch(DbSession dbSession, String branchUuid) {
return mapper(dbSession).selectByBranch(branchUuid);
}
public Optional<ReportScheduleDto> selectByPortfolio(DbSession dbSession, String portfolioUuid) {
return mapper(dbSession).selectByPortfolio(portfolioUuid);
}
public void upsert(DbSession dbSession, ReportScheduleDto reportScheduleDto) {
if (!mapper(dbSession).update(reportScheduleDto)) {
mapper(dbSession).insert(reportScheduleDto);
}
}
private static ReportScheduleMapper mapper(DbSession dbSession) {
return dbSession.getMapper(ReportScheduleMapper.class);
}
public List<ReportScheduleDto> selectAll(DbSession dbSession) {
return mapper(dbSession).selectAll();
}
}
| 1,798 | 34.98 | 99 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
public class ReportScheduleDto {
private String uuid;
private String portfolioUuid;
private String branchUuid;
private long lastSendTimeInMs;
public ReportScheduleDto() {
//Default constructor
}
public String getUuid() {
return uuid;
}
public ReportScheduleDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getPortfolioUuid() {
return portfolioUuid;
}
public ReportScheduleDto setPortfolioUuid(String portfolioUuid) {
this.portfolioUuid = portfolioUuid;
return this;
}
public String getBranchUuid() {
return branchUuid;
}
public ReportScheduleDto setBranchUuid(String branchUuid) {
this.branchUuid = branchUuid;
return this;
}
public long getLastSendTimeInMs() {
return lastSendTimeInMs;
}
public ReportScheduleDto setLastSendTimeInMs(long lastSendTimeInMs) {
this.lastSendTimeInMs = lastSendTimeInMs;
return this;
}
}
| 1,823 | 25.057143 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
public interface ReportScheduleMapper {
Optional<ReportScheduleDto> selectByBranch(@Param("branchUuid") String branchUuid);
Optional<ReportScheduleDto> selectByPortfolio(@Nullable @Param("portfolioUuid") String portfolioUuid);
List<ReportScheduleDto> selectAll();
boolean insert(ReportScheduleDto reportScheduleDto);
boolean update(ReportScheduleDto reportScheduleDto);
}
| 1,388 | 35.552632 | 104 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.apache.ibatis.annotations.Param;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
public class ReportSubscriptionDao implements Dao {
public Optional<ReportSubscriptionDto> selectByUserAndPortfolio(DbSession dbSession, String portfolioUuid, String userUuid) {
return mapper(dbSession).selectByUserAndPortfolio(portfolioUuid, userUuid);
}
public Optional<ReportSubscriptionDto> selectByUserAndBranch(DbSession dbSession, @Param("branchUuid") String branchUuid, @Param("userUuid") String userUuid) {
return mapper(dbSession).selectByUserAndBranch(branchUuid, userUuid);
}
public List<ReportSubscriptionDto> selectByPortfolio(DbSession dbSession, String portfolioUuid) {
return mapper(dbSession).selectByPortfolio(portfolioUuid);
}
public List<ReportSubscriptionDto> selectByProjectBranch(DbSession dbSession, String branchUuid) {
return mapper(dbSession).selectByBranch(branchUuid);
}
public Set<ReportSubscriptionDto> selectAll(DbSession dbSession) {
return mapper(dbSession).selectAll();
}
public void delete(DbSession dbSession, ReportSubscriptionDto subscriptionDto) {
mapper(dbSession).delete(subscriptionDto);
}
public void insert(DbSession dbSession, ReportSubscriptionDto subscriptionDto) {
mapper(dbSession).insert(subscriptionDto);
}
private static ReportSubscriptionMapper mapper(DbSession dbSession) {
return dbSession.getMapper(ReportSubscriptionMapper.class);
}
}
| 2,414 | 36.153846 | 161 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import javax.annotation.Nullable;
public class ReportSubscriptionDto {
private String uuid;
private String portfolioUuid;
private String branchUuid;
private String userUuid;
public ReportSubscriptionDto() {
//Default constructor
}
public String getUuid() {
return uuid;
}
public ReportSubscriptionDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getPortfolioUuid() {
return portfolioUuid;
}
public ReportSubscriptionDto setPortfolioUuid(@Nullable String portfolioUuid) {
this.portfolioUuid = portfolioUuid;
return this;
}
public String getBranchUuid() {
return branchUuid;
}
public ReportSubscriptionDto setBranchUuid(@Nullable String branchUuid) {
this.branchUuid = branchUuid;
return this;
}
public String getUserUuid() {
return userUuid;
}
public ReportSubscriptionDto setUserUuid(String userUuid) {
this.userUuid = userUuid;
return this;
}
}
| 1,851 | 25.084507 | 81 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.report;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.apache.ibatis.annotations.Param;
public interface ReportSubscriptionMapper {
Optional<ReportSubscriptionDto> selectByUserAndPortfolio(@Param("portfolioUuid") String portfolioUuid, @Param("userUuid") String userUuid);
Optional<ReportSubscriptionDto> selectByUserAndBranch(@Param("branchUuid") String branchUuid, @Param("userUuid") String userUuid);
List<ReportSubscriptionDto> selectByPortfolio(String portfolioUuid);
List<ReportSubscriptionDto> selectByBranch(String projectBranchUuid);
Set<ReportSubscriptionDto> selectAll();
void insert(ReportSubscriptionDto subscriptionDto);
void delete(ReportSubscriptionDto subscriptionDto);
}
| 1,610 | 37.357143 | 141 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/report/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.report;
import javax.annotation.ParametersAreNonnullByDefault;
| 960 | 37.44 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/DeprecatedRuleKeyDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import java.util.Objects;
import javax.annotation.CheckForNull;
/**
* Map the table "deprecated_rule_keys"
*/
public class DeprecatedRuleKeyDto {
/**
* Uuid of the deprecated key
*/
private String uuid;
/**
* the uuid of the current rule for this deprecated key
*/
private String ruleUuid;
/**
* repository key that was deprecated
*/
private String oldRepositoryKey;
/**
* rule key that was deprecated, not nullable
*/
private String oldRuleKey;
/**
* creation date of the row
*/
private Long createdAt;
/**
* current repository key retrieved from an external join on rule_id
*/
private String newRepositoryKey;
/**
* current rule key retrieved from an external join on rule_id
*/
private String newRuleKey;
public DeprecatedRuleKeyDto() {
// nothing to do here
}
public String getUuid() {
return uuid;
}
public DeprecatedRuleKeyDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getRuleUuid() {
return ruleUuid;
}
public DeprecatedRuleKeyDto setRuleUuid(String ruleUuid) {
this.ruleUuid = ruleUuid;
return this;
}
public String getOldRepositoryKey() {
return oldRepositoryKey;
}
public DeprecatedRuleKeyDto setOldRepositoryKey(String oldRepositoryKey) {
this.oldRepositoryKey = oldRepositoryKey;
return this;
}
public String getOldRuleKey() {
return oldRuleKey;
}
public DeprecatedRuleKeyDto setOldRuleKey(String oldRuleKey) {
this.oldRuleKey = oldRuleKey;
return this;
}
/**
* This value may be null if the rule has been deleted
*
* @return the current repository key
*/
@CheckForNull
public String getNewRepositoryKey() {
return newRepositoryKey;
}
/**
* This value may be null if the rule has been deleted
*
* @return the current rule key
*/
@CheckForNull
public String getNewRuleKey() {
return newRuleKey;
}
public long getCreatedAt() {
return createdAt;
}
public DeprecatedRuleKeyDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
@Override
public int hashCode() {
return Objects.hash(uuid);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final DeprecatedRuleKeyDto other = (DeprecatedRuleKeyDto) obj;
return Objects.equals(this.uuid, other.uuid);
}
}
| 3,379 | 22.310345 | 76 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleQuery;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.RowNotFoundException;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toMap;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
import static org.sonar.db.DatabaseUtils.executeLargeUpdates;
public class RuleDao implements Dao {
private final UuidFactory uuidFactory;
public RuleDao(UuidFactory uuidFactory) {
this.uuidFactory = uuidFactory;
}
public Optional<RuleDto> selectByKey(DbSession session, RuleKey key) {
return Optional.ofNullable(mapper(session).selectByKey(key));
}
public RuleDto selectOrFailByKey(DbSession session, RuleKey key) {
return Optional.ofNullable(mapper(session).selectByKey(key))
.orElseThrow(() -> new RowNotFoundException(String.format("Rule with key '%s' does not exist", key)));
}
public Optional<RuleDto> selectByUuid(String uuid, DbSession session) {
return Optional.ofNullable(mapper(session).selectByUuid(uuid));
}
public List<RuleDto> selectByUuids(DbSession session, Collection<String> uuids) {
if (uuids.isEmpty()) {
return emptyList();
}
return executeLargeInputs(uuids, chunk -> mapper(session).selectByUuids(chunk));
}
public List<RuleDto> selectByKeys(DbSession session, Collection<RuleKey> keys) {
if (keys.isEmpty()) {
return emptyList();
}
return executeLargeInputs(keys, chunk -> mapper(session).selectByKeys(chunk));
}
public List<RuleDto> selectEnabled(DbSession session) {
return mapper(session).selectEnabled();
}
public List<RuleDto> selectAll(DbSession session) {
return mapper(session).selectAll();
}
public List<RuleDto> selectByTypeAndLanguages(DbSession session, List<Integer> types, List<String> languages) {
return executeLargeInputs(languages, chunk -> mapper(session).selectByTypeAndLanguages(types, chunk));
}
public List<RuleDto> selectByLanguage(DbSession session, String language) {
return mapper(session).selectByLanguage(language);
}
public List<RuleDto> selectByQuery(DbSession session, RuleQuery ruleQuery) {
return mapper(session).selectByQuery(ruleQuery);
}
public void insert(DbSession session, RuleDto ruleDto) {
checkNotNull(ruleDto.getUuid(), "RuleDto has no 'uuid'.");
RuleMapper mapper = mapper(session);
mapper.insertRule(ruleDto);
updateRuleDescriptionSectionDtos(ruleDto, mapper);
}
public void update(DbSession session, RuleDto ruleDto) {
RuleMapper mapper = mapper(session);
mapper.updateRule(ruleDto);
updateRuleDescriptionSectionDtos(ruleDto, mapper);
}
private static void updateRuleDescriptionSectionDtos(RuleDto ruleDto, RuleMapper mapper) {
mapper.deleteRuleDescriptionSection(ruleDto.getUuid());
insertRuleDescriptionSectionDtos(ruleDto, mapper);
}
private static void insertRuleDescriptionSectionDtos(RuleDto ruleDto, RuleMapper mapper) {
ruleDto.getRuleDescriptionSectionDtos()
.forEach(section -> mapper.insertRuleDescriptionSection(ruleDto.getUuid(), section));
}
public void scrollIndexingRuleExtensionsByIds(DbSession dbSession, Collection<String> ruleExtensionIds, Consumer<RuleExtensionForIndexingDto> consumer) {
RuleMapper mapper = mapper(dbSession);
executeLargeInputsWithoutOutput(ruleExtensionIds,
pageOfRuleExtensionIds -> mapper
.selectIndexingRuleExtensionsByIds(pageOfRuleExtensionIds)
.forEach(consumer));
}
public void selectIndexingRulesByKeys(DbSession dbSession, Collection<String> ruleUuids, Consumer<RuleForIndexingDto> consumer) {
RuleMapper mapper = mapper(dbSession);
executeLargeInputsWithoutOutput(ruleUuids,
pageOfRuleUuids -> {
List<RuleDto> ruleDtos = mapper.selectByUuids(pageOfRuleUuids);
processRuleDtos(ruleDtos, consumer, mapper);
});
}
public void selectIndexingRules(DbSession dbSession, Consumer<RuleForIndexingDto> consumer) {
RuleMapper mapper = mapper(dbSession);
executeLargeInputsWithoutOutput(mapper.selectAll(),
ruleDtos -> processRuleDtos(ruleDtos, consumer, mapper));
}
private static RuleForIndexingDto toRuleForIndexingDto(RuleDto r, Map<String, RuleDto> templateDtos) {
RuleForIndexingDto ruleForIndexingDto = RuleForIndexingDto.fromRuleDto(r);
if (templateDtos.containsKey(r.getTemplateUuid())) {
ruleForIndexingDto.setTemplateRuleKey(templateDtos.get(r.getTemplateUuid()).getRuleKey());
ruleForIndexingDto.setTemplateRepository(templateDtos.get(r.getTemplateUuid()).getRepositoryKey());
}
return ruleForIndexingDto;
}
private static void processRuleDtos(List<RuleDto> ruleDtos, Consumer<RuleForIndexingDto> consumer, RuleMapper mapper) {
List<String> templateRuleUuids = ruleDtos.stream()
.map(RuleDto::getTemplateUuid)
.filter(Objects::nonNull)
.toList();
Map<String, RuleDto> templateDtos = findTemplateDtos(mapper, templateRuleUuids);
ruleDtos.stream().map(r -> toRuleForIndexingDto(r, templateDtos)).forEach(consumer);
}
private static Map<String, RuleDto> findTemplateDtos(RuleMapper mapper, List<String> templateRuleUuids) {
if (!templateRuleUuids.isEmpty()) {
return mapper.selectByUuids(templateRuleUuids).stream().collect(toMap(RuleDto::getUuid, Function.identity()));
}else{
return Collections.emptyMap();
}
}
private static RuleMapper mapper(DbSession session) {
return session.getMapper(RuleMapper.class);
}
/**
* RuleParams
*/
public List<RuleParamDto> selectRuleParamsByRuleKey(DbSession session, RuleKey key) {
return mapper(session).selectParamsByRuleKey(key);
}
public List<RuleParamDto> selectRuleParamsByRuleKeys(DbSession session, Collection<RuleKey> ruleKeys) {
return executeLargeInputs(ruleKeys, mapper(session)::selectParamsByRuleKeys);
}
public List<RuleParamDto> selectAllRuleParams(DbSession session) {
return mapper(session).selectAllRuleParams();
}
public List<RuleParamDto> selectRuleParamsByRuleUuids(DbSession dbSession, Collection<String> ruleUuids) {
return executeLargeInputs(ruleUuids, mapper(dbSession)::selectParamsByRuleUuids);
}
public void insertRuleParam(DbSession session, RuleDto rule, RuleParamDto param) {
checkNotNull(rule.getUuid(), "Rule uuid must be set");
param.setRuleUuid(rule.getUuid());
param.setUuid(uuidFactory.create());
mapper(session).insertParameter(param);
}
public RuleParamDto updateRuleParam(DbSession session, RuleDto rule, RuleParamDto param) {
checkNotNull(rule.getUuid(), "Rule uuid must be set");
checkNotNull(param.getUuid(), "Rule parameter is not yet persisted must be set");
param.setRuleUuid(rule.getUuid());
mapper(session).updateParameter(param);
return param;
}
public void deleteRuleParam(DbSession session, String ruleParameterUuid) {
mapper(session).deleteParameter(ruleParameterUuid);
}
public Set<DeprecatedRuleKeyDto> selectAllDeprecatedRuleKeys(DbSession session) {
return mapper(session).selectAllDeprecatedRuleKeys();
}
public Set<DeprecatedRuleKeyDto> selectDeprecatedRuleKeysByRuleUuids(DbSession session, Collection<String> ruleUuids) {
return mapper(session).selectDeprecatedRuleKeysByRuleUuids(ruleUuids);
}
public void deleteDeprecatedRuleKeys(DbSession dbSession, Collection<String> uuids) {
if (uuids.isEmpty()) {
return;
}
executeLargeUpdates(uuids, mapper(dbSession)::deleteDeprecatedRuleKeys);
}
public void insert(DbSession dbSession, DeprecatedRuleKeyDto deprecatedRuleKey) {
mapper(dbSession).insertDeprecatedRuleKey(deprecatedRuleKey);
}
}
| 9,043 | 37 | 155 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionContextDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import java.util.Objects;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
import static org.sonar.api.utils.Preconditions.checkArgument;
public class RuleDescriptionSectionContextDto {
static final String KEY_MUST_BE_SET_ERROR = "key must be set";
static final String DISPLAY_NAME_MUST_BE_SET_ERROR = "displayName must be set";
private final String key;
private final String displayName;
private RuleDescriptionSectionContextDto(String key, String displayName) {
checkArgument(isNotEmpty(key), KEY_MUST_BE_SET_ERROR);
checkArgument(isNotEmpty(displayName), DISPLAY_NAME_MUST_BE_SET_ERROR);
this.key = key;
this.displayName = displayName;
}
public static RuleDescriptionSectionContextDto of(String key, String displayName) {
return new RuleDescriptionSectionContextDto(key, displayName);
}
public String getKey() {
return key;
}
public String getDisplayName() {
return displayName;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RuleDescriptionSectionContextDto that = (RuleDescriptionSectionContextDto) o;
return getKey().equals(that.getKey()) && getDisplayName().equals(that.getDisplayName());
}
@Override
public int hashCode() {
return Objects.hash(getKey(), getDisplayName());
}
@Override
public String toString() {
return "RuleDescriptionSectionContextDto[" +
"key='" + key + '\'' +
", displayName='" + displayName + '\'' +
']';
}
}
| 2,458 | 30.525641 | 92 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDescriptionSectionDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import java.util.StringJoiner;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import static org.sonar.api.utils.Preconditions.checkArgument;
public class RuleDescriptionSectionDto {
public static final String DEFAULT_KEY = "default";
private String uuid;
private String key;
private String content;
private RuleDescriptionSectionContextDto context;
private RuleDescriptionSectionDto() {
}
private RuleDescriptionSectionDto(String uuid, String key, String content, @Nullable RuleDescriptionSectionContextDto context) {
this.uuid = uuid;
this.key = key;
this.content = content;
this.context = context;
}
public String getUuid() {
return uuid;
}
public String getKey() {
return key;
}
public String getContent() {
return content;
}
@CheckForNull
public RuleDescriptionSectionContextDto getContext() {
return context;
}
public static RuleDescriptionSectionDto createDefaultRuleDescriptionSection(String uuid, String description) {
return RuleDescriptionSectionDto.builder()
.setDefault()
.uuid(uuid)
.content(description)
.build();
}
public static RuleDescriptionSectionDtoBuilder builder() {
return new RuleDescriptionSectionDtoBuilder();
}
public boolean isDefault() {
return DEFAULT_KEY.equals(key);
}
@Override
public String toString() {
return new StringJoiner(", ", RuleDescriptionSectionDto.class.getSimpleName() + "[", "]")
.add("uuid='" + uuid + "'")
.add("key='" + key + "'")
.add("content='" + content + "'")
.add("context='" + context + "'")
.toString();
}
public static final class RuleDescriptionSectionDtoBuilder {
private String uuid;
private String key = null;
private String content;
private RuleDescriptionSectionContextDto context;
private RuleDescriptionSectionDtoBuilder() {
}
public RuleDescriptionSectionDtoBuilder uuid(String uuid) {
this.uuid = uuid;
return this;
}
public RuleDescriptionSectionDtoBuilder setDefault() {
checkArgument(this.key == null, "Only one of setDefault and key methods can be called");
this.key = DEFAULT_KEY;
return this;
}
public RuleDescriptionSectionDtoBuilder key(String key) {
checkArgument(this.key == null, "Only one of setDefault and key methods can be called");
this.key = key;
return this;
}
public RuleDescriptionSectionDtoBuilder content(String content) {
this.content = content;
return this;
}
public RuleDescriptionSectionDtoBuilder context(@Nullable RuleDescriptionSectionContextDto context) {
this.context = context;
return this;
}
public RuleDescriptionSectionDto build() {
return new RuleDescriptionSectionDto(uuid, key, content, context);
}
}
}
| 3,741 | 27.135338 | 130 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Arrays.asList;
import static java.util.Collections.emptySet;
import static java.util.Optional.ofNullable;
import static org.sonar.db.rule.RuleDescriptionSectionDto.DEFAULT_KEY;
public class RuleDto {
static final String ERROR_MESSAGE_SECTION_ALREADY_EXISTS = "A section with key '%s' and context key '%s' already exists";
public enum Format {
HTML, MARKDOWN
}
public enum Scope {
MAIN, TEST, ALL
}
private static final Splitter SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings();
private String uuid = null;
private String repositoryKey = null;
private String ruleKey = null;
private final Set<RuleDescriptionSectionDto> ruleDescriptionSectionDtos = new HashSet<>();
private String educationPrinciplesField = null;
/**
* Description format can be null on external rule, otherwise it should never be null
*/
private RuleDto.Format descriptionFormat = null;
private RuleStatus status = null;
private String name = null;
private String configKey = null;
/**
* Severity can be null on external rule, otherwise it should never be null
*/
private Integer severity = null;
private boolean isTemplate = false;
/**
* This flag specify that this is an external rule, meaning that generated issues from this rule will be provided by the analyzer without being activated on a quality profile.
*/
private boolean isExternal = false;
/**
* When an external rule is defined as ad hoc, it means that it's not defined using {@link org.sonar.api.server.rule.RulesDefinition.Context#createExternalRepository(String, String)}.
* As the opposite, an external rule not being defined as ad hoc is declared by using {@link org.sonar.api.server.rule.RulesDefinition.Context#createExternalRepository(String, String)}.
* This flag is only used for external rules (it can only be set to true for when {@link #isExternal()} is true)
*/
private boolean isAdHoc = false;
private String language = null;
private String templateUuid = null;
private String defRemediationFunction = null;
private String defRemediationGapMultiplier = null;
private String defRemediationBaseEffort = null;
private String gapDescription = null;
private String systemTagsField = null;
private String securityStandardsField = null;
private int type = 0;
private Scope scope = null;
private RuleKey key = null;
private String pluginKey = null;
private String noteData = null;
private String noteUserUuid = null;
private Long noteCreatedAt = null;
private Long noteUpdatedAt = null;
private String remediationFunction = null;
private String remediationGapMultiplier = null;
private String remediationBaseEffort = null;
private String tags = null;
/**
* Name of on ad hoc rule.
*/
private String adHocName = null;
/**
* Optional description of on ad hoc rule.
*/
private String adHocDescription = null;
/**
* Severity of on ad hoc rule.
* When {@link RuleDto#isAdHoc()} is true, this field should always be set
*/
private String adHocSeverity = null;
/**
* Type of on ad hoc rule.
* When {@link RuleDto#isAdHoc()} is true, this field should always be set
*/
private Integer adHocType = null;
private long createdAt = 0;
private long updatedAt = 0;
public RuleKey getKey() {
if (key == null) {
key = RuleKey.of(getRepositoryKey(), getRuleKey());
}
return key;
}
RuleDto setKey(RuleKey key) {
this.key = key;
setRepositoryKey(key.repository());
setRuleKey(key.rule());
return this;
}
public String getUuid() {
return uuid;
}
public RuleDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getRepositoryKey() {
return repositoryKey;
}
public RuleDto setRepositoryKey(String repositoryKey) {
checkArgument(repositoryKey.length() <= 255, "Rule repository is too long: %s", repositoryKey);
this.repositoryKey = repositoryKey;
return this;
}
public String getRuleKey() {
return ruleKey;
}
public RuleDto setRuleKey(String ruleKey) {
checkArgument(ruleKey.length() <= 200, "Rule key is too long: %s", ruleKey);
this.ruleKey = ruleKey;
return this;
}
public RuleDto setRuleKey(RuleKey ruleKey) {
this.repositoryKey = ruleKey.repository();
this.ruleKey = ruleKey.rule();
this.key = ruleKey;
return this;
}
@CheckForNull
public String getPluginKey() {
return pluginKey;
}
public RuleDto setPluginKey(@Nullable String pluginKey) {
this.pluginKey = pluginKey;
return this;
}
public Set<RuleDescriptionSectionDto> getRuleDescriptionSectionDtos() {
return ruleDescriptionSectionDtos;
}
@CheckForNull
public RuleDescriptionSectionDto getDefaultRuleDescriptionSection() {
return ruleDescriptionSectionDtos.stream()
.filter(ruleDesc -> ruleDesc.getKey().equals(DEFAULT_KEY))
.findAny()
.orElse(null);
}
public RuleDto replaceRuleDescriptionSectionDtos(Collection<RuleDescriptionSectionDto> ruleDescriptionSectionDtos) {
this.ruleDescriptionSectionDtos.clear();
ruleDescriptionSectionDtos.forEach(this::addRuleDescriptionSectionDto);
return this;
}
public RuleDto addRuleDescriptionSectionDto(RuleDescriptionSectionDto ruleDescriptionSectionDto) {
checkArgument(!hasDescriptionSectionWithSameKeyAndContext(ruleDescriptionSectionDto),
ERROR_MESSAGE_SECTION_ALREADY_EXISTS, ruleDescriptionSectionDto.getKey(),
Optional.ofNullable(ruleDescriptionSectionDto.getContext()).map(RuleDescriptionSectionContextDto::getKey).orElse(null));
ruleDescriptionSectionDtos.add(ruleDescriptionSectionDto);
return this;
}
private boolean hasDescriptionSectionWithSameKeyAndContext(RuleDescriptionSectionDto ruleDescriptionSectionDto) {
return ruleDescriptionSectionDtos.stream()
.anyMatch(ruleDesc -> hasSameKeyAndContextKey(ruleDescriptionSectionDto, ruleDesc));
}
private static boolean hasSameKeyAndContextKey(RuleDescriptionSectionDto ruleDescriptionSectionDto, RuleDescriptionSectionDto other) {
if (!ruleDescriptionSectionDto.getKey().equals(other.getKey())) {
return false;
}
String contextKey = ofNullable(ruleDescriptionSectionDto.getContext()).map(RuleDescriptionSectionContextDto::getKey).orElse(null);
String otherContextKey = ofNullable(other.getContext()).map(RuleDescriptionSectionContextDto::getKey).orElse(null);
return Objects.equals(contextKey, otherContextKey);
}
public Set<String> getEducationPrinciples() {
return deserializeStringSet(educationPrinciplesField);
}
public RuleDto setEducationPrinciples(Set<String> educationPrinciples){
this.educationPrinciplesField = serializeStringSet(educationPrinciples);
return this;
}
@CheckForNull
public Format getDescriptionFormat() {
return descriptionFormat;
}
public RuleDto setDescriptionFormat(Format descriptionFormat) {
this.descriptionFormat = descriptionFormat;
return this;
}
public RuleStatus getStatus() {
return status;
}
public RuleDto setStatus(@Nullable RuleStatus status) {
this.status = status;
return this;
}
public String getName() {
return name;
}
public RuleDto setName(@Nullable String name) {
checkArgument(name == null || name.length() <= 255, "Rule name is too long: %s", name);
this.name = name;
return this;
}
public String getConfigKey() {
return configKey;
}
public RuleDto setConfigKey(@Nullable String configKey) {
this.configKey = configKey;
return this;
}
public Scope getScope() {
return scope;
}
public RuleDto setScope(Scope scope) {
this.scope = scope;
return this;
}
@CheckForNull
public Integer getSeverity() {
return severity;
}
@CheckForNull
public String getSeverityString() {
return severity != null ? SeverityUtil.getSeverityFromOrdinal(severity) : null;
}
public RuleDto setSeverity(@Nullable String severity) {
return this.setSeverity(severity != null ? SeverityUtil.getOrdinalFromSeverity(severity) : null);
}
public RuleDto setSeverity(@Nullable Integer severity) {
this.severity = severity;
return this;
}
public boolean isExternal() {
return isExternal;
}
public RuleDto setIsExternal(boolean isExternal) {
this.isExternal = isExternal;
return this;
}
public boolean isAdHoc() {
return isAdHoc;
}
public RuleDto setIsAdHoc(boolean isAdHoc) {
this.isAdHoc = isAdHoc;
return this;
}
public boolean isTemplate() {
return isTemplate;
}
public RuleDto setIsTemplate(boolean isTemplate) {
this.isTemplate = isTemplate;
return this;
}
@CheckForNull
public String getLanguage() {
return language;
}
public RuleDto setLanguage(String language) {
this.language = language;
return this;
}
@CheckForNull
public String getTemplateUuid() {
return templateUuid;
}
public RuleDto setTemplateUuid(@Nullable String templateUuid) {
this.templateUuid = templateUuid;
return this;
}
public boolean isCustomRule() {
return getTemplateUuid() != null;
}
public RuleDto setSystemTags(Set<String> tags) {
this.systemTagsField = serializeStringSet(tags);
return this;
}
public RuleDto setSecurityStandards(Set<String> standards) {
this.securityStandardsField = serializeStringSet(standards);
return this;
}
public Set<String> getSystemTags() {
return deserializeTagsString(systemTagsField);
}
public Set<String> getSecurityStandards() {
return deserializeSecurityStandardsString(securityStandardsField);
}
public int getType() {
return type;
}
public RuleDto setType(int type) {
this.type = type;
return this;
}
public RuleDto setType(RuleType type) {
this.type = type.getDbConstant();
return this;
}
public long getCreatedAt() {
return createdAt;
}
public RuleDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public long getUpdatedAt() {
return updatedAt;
}
public RuleDto setUpdatedAt(long updatedAt) {
this.updatedAt = updatedAt;
return this;
}
@CheckForNull
public String getDefRemediationFunction() {
return defRemediationFunction;
}
public RuleDto setDefRemediationFunction(@Nullable String defaultRemediationFunction) {
this.defRemediationFunction = defaultRemediationFunction;
return this;
}
@CheckForNull
public String getDefRemediationGapMultiplier() {
return defRemediationGapMultiplier;
}
public RuleDto setDefRemediationGapMultiplier(@Nullable String defaultRemediationGapMultiplier) {
this.defRemediationGapMultiplier = defaultRemediationGapMultiplier;
return this;
}
@CheckForNull
public String getDefRemediationBaseEffort() {
return defRemediationBaseEffort;
}
public RuleDto setDefRemediationBaseEffort(@Nullable String defaultRemediationBaseEffort) {
this.defRemediationBaseEffort = defaultRemediationBaseEffort;
return this;
}
@CheckForNull
public String getGapDescription() {
return gapDescription;
}
public RuleDto setGapDescription(@Nullable String s) {
this.gapDescription = s;
return this;
}
public static Set<String> deserializeTagsString(@Nullable String tags) {
return deserializeStringSet(tags);
}
public static Set<String> deserializeSecurityStandardsString(@Nullable String securityStandards) {
return deserializeStringSet(securityStandards);
}
private static Set<String> deserializeStringSet(@Nullable String str) {
if (str == null || str.isEmpty()) {
return emptySet();
}
return ImmutableSet.copyOf(SPLITTER.split(str));
}
@CheckForNull
public String getNoteData() {
return noteData;
}
public RuleDto setNoteData(@Nullable String s) {
this.noteData = s;
return this;
}
@CheckForNull
public String getNoteUserUuid() {
return noteUserUuid;
}
public RuleDto setNoteUserUuid(@Nullable String noteUserUuid) {
this.noteUserUuid = noteUserUuid;
return this;
}
@CheckForNull
public Long getNoteCreatedAt() {
return noteCreatedAt;
}
public RuleDto setNoteCreatedAt(@Nullable Long noteCreatedAt) {
this.noteCreatedAt = noteCreatedAt;
return this;
}
@CheckForNull
public Long getNoteUpdatedAt() {
return noteUpdatedAt;
}
public RuleDto setNoteUpdatedAt(@Nullable Long noteUpdatedAt) {
this.noteUpdatedAt = noteUpdatedAt;
return this;
}
@CheckForNull
public String getRemediationFunction() {
return remediationFunction;
}
public RuleDto setRemediationFunction(@Nullable String remediationFunction) {
this.remediationFunction = remediationFunction;
return this;
}
@CheckForNull
public String getRemediationGapMultiplier() {
return remediationGapMultiplier;
}
public RuleDto setRemediationGapMultiplier(@Nullable String remediationGapMultiplier) {
this.remediationGapMultiplier = remediationGapMultiplier;
return this;
}
@CheckForNull
public String getRemediationBaseEffort() {
return remediationBaseEffort;
}
public RuleDto setRemediationBaseEffort(@Nullable String remediationBaseEffort) {
this.remediationBaseEffort = remediationBaseEffort;
return this;
}
public Set<String> getTags() {
return tags == null ? new HashSet<>() : new TreeSet<>(asList(StringUtils.split(tags, ',')));
}
String getTagsAsString() {
return tags;
}
public RuleDto setTags(Set<String> tags) {
String raw = tags.isEmpty() ? null : String.join(",", tags);
checkArgument(raw == null || raw.length() <= 4000, "Rule tags are too long: %s", raw);
this.tags = raw;
return this;
}
private String getTagsField() {
return tags;
}
void setTagsField(String s) {
tags = s;
}
@CheckForNull
public String getAdHocName() {
return adHocName;
}
public RuleDto setAdHocName(@Nullable String adHocName) {
this.adHocName = adHocName;
return this;
}
@CheckForNull
public String getAdHocDescription() {
return adHocDescription;
}
public RuleDto setAdHocDescription(@Nullable String adHocDescription) {
this.adHocDescription = adHocDescription;
return this;
}
@CheckForNull
public String getAdHocSeverity() {
return adHocSeverity;
}
public RuleDto setAdHocSeverity(@Nullable String adHocSeverity) {
this.adHocSeverity = adHocSeverity;
return this;
}
@CheckForNull
public Integer getAdHocType() {
return adHocType;
}
public RuleDto setAdHocType(@Nullable Integer adHocType) {
this.adHocType = adHocType;
return this;
}
public RuleDto setAdHocType(@Nullable RuleType adHocType) {
setAdHocType(adHocType != null ? adHocType.getDbConstant() : null);
return this;
}
private static String serializeStringSet(@Nullable Set<String> strings) {
return strings == null || strings.isEmpty() ? null : String.join(",", strings);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof RuleDto)) {
return false;
}
if (this == obj) {
return true;
}
RuleDto other = (RuleDto) obj;
return Objects.equals(this.uuid, other.uuid);
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(this.uuid)
.toHashCode();
}
}
| 16,906 | 25.625197 | 187 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleExtensionForIndexingDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
import org.sonar.api.rule.RuleKey;
public class RuleExtensionForIndexingDto {
private static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings();
private String ruleUuid;
private String pluginName;
private String pluginRuleKey;
private String tags;
public String getPluginName() {
return pluginName;
}
public RuleExtensionForIndexingDto setPluginName(String pluginName) {
this.pluginName = pluginName;
return this;
}
public String getPluginRuleKey() {
return pluginRuleKey;
}
public RuleExtensionForIndexingDto setPluginRuleKey(String pluginRuleKey) {
this.pluginRuleKey = pluginRuleKey;
return this;
}
public String getRuleUuid() {
return ruleUuid;
}
public void setRuleUuid(String ruleUuid) {
this.ruleUuid = ruleUuid;
}
public String getTags() {
return tags;
}
public RuleExtensionForIndexingDto setTags(String tags) {
this.tags = tags;
return this;
}
public RuleKey getRuleKey() {
return RuleKey.of(pluginName, pluginRuleKey);
}
public Set<String> getTagsAsSet() {
return ImmutableSet.copyOf(TAGS_SPLITTER.split(tags == null ? "" : tags));
}
}
| 2,173 | 26.175 | 98 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
public class RuleForIndexingDto {
private String uuid;
private String repository;
private String pluginRuleKey;
private String name;
private RuleDto.Format descriptionFormat;
private Integer severity;
private RuleStatus status;
private boolean isTemplate;
private Set<String> systemTags;
private Set<String> tags;
private Set<String> securityStandards;
private String templateRuleKey;
private String templateRepository;
private String internalKey;
private String language;
private boolean isExternal;
private int type;
private long createdAt;
private long updatedAt;
private Set<RuleDescriptionSectionDto> ruleDescriptionSectionsDtos = new HashSet<>();
@VisibleForTesting
public RuleForIndexingDto() {
// nothing to do here
}
public static RuleForIndexingDto fromRuleDto(RuleDto r) {
RuleForIndexingDto ruleForIndexingDto = new RuleForIndexingDto();
ruleForIndexingDto.createdAt = r.getCreatedAt();
ruleForIndexingDto.uuid = r.getUuid();
ruleForIndexingDto.repository = r.getRepositoryKey();
ruleForIndexingDto.pluginRuleKey = r.getRuleKey();
ruleForIndexingDto.name = r.getName();
ruleForIndexingDto.descriptionFormat = r.getDescriptionFormat();
ruleForIndexingDto.severity = r.getSeverity();
ruleForIndexingDto.status = r.getStatus();
ruleForIndexingDto.isTemplate = r.isTemplate();
ruleForIndexingDto.systemTags = Sets.newHashSet(r.getSystemTags());
ruleForIndexingDto.tags = r.getTags() != null ? Sets.newHashSet(r.getTags()) : Collections.emptySet();
ruleForIndexingDto.securityStandards = Sets.newHashSet(r.getSecurityStandards());
ruleForIndexingDto.internalKey = r.getConfigKey();
ruleForIndexingDto.language = r.getLanguage();
ruleForIndexingDto.isExternal = r.isExternal();
ruleForIndexingDto.type = r.getType();
ruleForIndexingDto.createdAt = r.getCreatedAt();
ruleForIndexingDto.updatedAt = r.getUpdatedAt();
if (r.getRuleDescriptionSectionDtos() != null) {
ruleForIndexingDto.setRuleDescriptionSectionsDtos(Sets.newHashSet(r.getRuleDescriptionSectionDtos()));
}
return ruleForIndexingDto;
}
public String getUuid() {
return uuid;
}
public String getRepository() {
return repository;
}
public void setRepository(String repository) {
this.repository = repository;
}
public String getPluginRuleKey() {
return pluginRuleKey;
}
public void setPluginRuleKey(String pluginRuleKey) {
this.pluginRuleKey = pluginRuleKey;
}
public String getName() {
return name;
}
public RuleDto.Format getDescriptionFormat() {
return descriptionFormat;
}
public void setDescriptionFormat(RuleDto.Format descriptionFormat) {
this.descriptionFormat = descriptionFormat;
}
public Integer getSeverity() {
return severity;
}
public RuleStatus getStatus() {
return status;
}
public boolean isTemplate() {
return isTemplate;
}
public Set<String> getSystemTags() {
return Collections.unmodifiableSet(systemTags);
}
public Set<String> getTags() {
return Collections.unmodifiableSet(tags);
}
public Set<String> getSecurityStandards() {
return Collections.unmodifiableSet(securityStandards);
}
public String getTemplateRuleKey() {
return templateRuleKey;
}
public String getTemplateRepository() {
return templateRepository;
}
public String getInternalKey() {
return internalKey;
}
public String getLanguage() {
return language;
}
public int getType() {
return type;
}
public boolean isExternal() {
return isExternal;
}
public long getCreatedAt() {
return createdAt;
}
public long getUpdatedAt() {
return updatedAt;
}
@CheckForNull
public RuleType getTypeAsRuleType() {
return RuleType.valueOfNullable(type);
}
public String getSeverityAsString() {
return severity != null ? SeverityUtil.getSeverityFromOrdinal(severity) : null;
}
public RuleKey getRuleKey() {
return RuleKey.of(repository, pluginRuleKey);
}
public Set<RuleDescriptionSectionDto> getRuleDescriptionSectionsDtos() {
return Collections.unmodifiableSet(ruleDescriptionSectionsDtos);
}
public void setRuleDescriptionSectionsDtos(Set<RuleDescriptionSectionDto> ruleDescriptionSectionsDtos) {
this.ruleDescriptionSectionsDtos = ruleDescriptionSectionsDtos;
}
public void setTemplateRuleKey(String templateRuleKey) {
this.templateRuleKey = templateRuleKey;
}
public void setTemplateRepository(String templateRepository) {
this.templateRepository = templateRepository;
}
public void setType(int type) {
this.type = type;
}
}
| 5,878 | 27.129187 | 108 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.apache.ibatis.annotations.Param;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleQuery;
public interface RuleMapper {
List<RuleDto> selectAll();
List<RuleDto> selectEnabled();
RuleDto selectByUuid(@Param("uuid") String uuid);
List<RuleDto> selectByUuids(@Param("uuids") List<String> uuids);
RuleDto selectByKey(@Param("ruleKey") RuleKey ruleKey);
List<RuleDto> selectByKeys(@Param("ruleKeys") List<RuleKey> keys);
List<RuleExtensionForIndexingDto> selectIndexingRuleExtensionsByIds(@Param("ruleExtensionIds") List<String> ruleExtensionIds);
List<RuleDto> selectByQuery(@Param("query") RuleQuery ruleQuery);
List<RuleDto> selectByTypeAndLanguages(@Param("types") List<Integer> types, @Param("languages") List<String> languages);
List<RuleDto> selectByLanguage(@Param("language") String language);
void insertRule(RuleDto ruleDefinitionDto);
void insertRuleDescriptionSection(@Param("ruleUuid") String ruleUuid, @Param("dto") RuleDescriptionSectionDto ruleDescriptionSectionDto);
void updateRule(RuleDto ruleDefinitionDto);
void deleteRuleDescriptionSection(String ruleUuid);
List<RuleParamDto> selectParamsByRuleUuids(@Param("ruleUuids") List<String> ruleUuids);
List<RuleParamDto> selectParamsByRuleKey(RuleKey ruleKey);
List<RuleParamDto> selectParamsByRuleKeys(@Param("ruleKeys") List<RuleKey> ruleKeys);
List<RuleParamDto> selectAllRuleParams();
void insertParameter(RuleParamDto param);
void updateParameter(RuleParamDto param);
void deleteParameter(String paramUuid);
Set<DeprecatedRuleKeyDto> selectAllDeprecatedRuleKeys();
Set<DeprecatedRuleKeyDto> selectDeprecatedRuleKeysByRuleUuids(@Param("ruleUuids") Collection<String> ruleUuids);
void deleteDeprecatedRuleKeys(@Param("uuids") List<String> uuids);
void insertDeprecatedRuleKey(DeprecatedRuleKeyDto deprecatedRuleKeyDto);
}
| 2,835 | 34.012346 | 139 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import static com.google.common.base.Preconditions.checkArgument;
public class RuleParamDto {
private String uuid;
private String ruleUuid;
private String name;
private String type;
private String defaultValue;
private String description;
public RuleParamDto() {
// nothing to do here
}
public String getUuid() {
return uuid;
}
public RuleParamDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getRuleUuid() {
return ruleUuid;
}
public RuleParamDto setRuleUuid(String ruleUuid) {
this.ruleUuid = ruleUuid;
return this;
}
public String getName() {
return name;
}
public RuleParamDto setName(String s) {
checkArgument(s.length() <= 128, "Rule parameter name is too long: %s", s);
this.name = s;
return this;
}
public String getType() {
return type;
}
public RuleParamDto setType(String type) {
this.type = type;
return this;
}
@CheckForNull
public String getDefaultValue() {
return defaultValue;
}
public RuleParamDto setDefaultValue(@Nullable String s) {
checkArgument(s == null || s.length() <= 4000, "Rule parameter default value is too long: %s", s);
this.defaultValue = s;
return this;
}
public String getDescription() {
return description;
}
public RuleParamDto setDescription(@Nullable String s) {
checkArgument(s == null || s.length() <= 4000, "Rule parameter description is too long: %s", s);
this.description = s;
return this;
}
@Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
public static RuleParamDto createFor(RuleDto rule) {
// Should eventually switch to RuleKey (RuleKey is available before insert)
return new RuleParamDto().setRuleUuid(rule.getUuid());
}
}
| 2,935 | 25.45045 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleRepositoryDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang.StringUtils.isBlank;
public class RuleRepositoryDao implements Dao {
private static final String PERCENT_SIGN = "%";
private final System2 system2;
public RuleRepositoryDao(System2 system2) {
this.system2 = system2;
}
/**
* @return a non-null list ordered by key (as implemented by database, order may
* depend on case sensitivity)
*/
public List<RuleRepositoryDto> selectAll(DbSession dbSession) {
return dbSession.getMapper(RuleRepositoryMapper.class).selectAll();
}
public Set<String> selectAllKeys(DbSession dbSession) {
return dbSession.getMapper(RuleRepositoryMapper.class).selectAllKeys();
}
public List<RuleRepositoryDto> selectByQueryAndLanguage(DbSession dbSession, @Nullable String query, @Nullable String language){
String queryUpgraded = toLowerCaseAndSurroundWithPercentSigns(query);
return dbSession.getMapper(RuleRepositoryMapper.class).selectByQueryAndLanguage(queryUpgraded,language);
}
public void insert(DbSession dbSession, Collection<RuleRepositoryDto> dtos) {
RuleRepositoryMapper mapper = dbSession.getMapper(RuleRepositoryMapper.class);
long now = system2.now();
for (RuleRepositoryDto dto : dtos) {
mapper.insert(dto, now);
}
}
public void update(DbSession dbSession, Collection<RuleRepositoryDto> dtos) {
RuleRepositoryMapper mapper = dbSession.getMapper(RuleRepositoryMapper.class);
for (RuleRepositoryDto dto : dtos) {
mapper.update(dto);
}
}
public void deleteIfKeyNotIn(DbSession dbSession, Collection<String> keys) {
checkArgument(keys.size() < DatabaseUtils.PARTITION_SIZE_FOR_ORACLE, "too many rule repositories: %s", keys.size());
dbSession.getMapper(RuleRepositoryMapper.class).deleteIfKeyNotIn(keys);
}
private static String toLowerCaseAndSurroundWithPercentSigns(@Nullable String query) {
return isBlank(query) ? PERCENT_SIGN : (PERCENT_SIGN + query.toLowerCase(Locale.ENGLISH) + PERCENT_SIGN);
}
}
| 3,204 | 35.83908 | 130 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleRepositoryDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
public class RuleRepositoryDto {
// do not rename "key" as MyBatis maps it with the db column "kee"
private String kee;
private String language;
private String name;
public RuleRepositoryDto() {
// used by MyBatis
}
public RuleRepositoryDto(String kee, String language, String name) {
this.kee = kee;
this.language = language;
this.name = name;
}
public String getKey() {
return kee;
}
public String getLanguage() {
return language;
}
public String getName() {
return name;
}
public RuleRepositoryDto setKey(String s) {
this.kee = s;
return this;
}
public RuleRepositoryDto setLanguage(String s) {
this.language = s;
return this;
}
public RuleRepositoryDto setName(String s) {
this.name = s;
return this;
}
}
| 1,681 | 24.484848 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleRepositoryMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
public interface RuleRepositoryMapper {
List<RuleRepositoryDto> selectAll();
Set<String> selectAllKeys();
List<RuleRepositoryDto> selectByQueryAndLanguage(@Param("query") String query,@Param("language") @Nullable String language);
void insert(@Param("repository") RuleRepositoryDto repository, @Param("now") long now);
void update(@Param("repository") RuleRepositoryDto repository);
void deleteIfKeyNotIn(@Param("keys") Collection<String> keys);
}
| 1,490 | 34.5 | 126 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/SeverityUtil.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.rule;
import org.sonar.api.rule.Severity;
public class SeverityUtil {
private SeverityUtil() {
// Only static stuff
}
public static String getSeverityFromOrdinal(int ordinal) {
return Severity.ALL.get(ordinal);
}
public static int getOrdinalFromSeverity(String severity) {
return Severity.ALL.indexOf(severity);
}
}
| 1,209 | 30.842105 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/rule/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.rule;
import javax.annotation.ParametersAreNonnullByDefault;
| 958 | 37.36 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scannercache/ScannerAnalysisCacheDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scannercache;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import javax.annotation.CheckForNull;
import org.sonar.db.Dao;
import org.sonar.db.DbInputStream;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
public class ScannerAnalysisCacheDao implements Dao {
public void removeAll(DbSession session) {
mapper(session).removeAll();
}
public void remove(DbSession session, String branchUuid) {
mapper(session).remove(branchUuid);
}
public void insert(DbSession dbSession, String branchUuid, InputStream data) {
Connection connection = dbSession.getConnection();
try (PreparedStatement stmt = connection.prepareStatement(
"INSERT INTO scanner_analysis_cache (branch_uuid, data) VALUES (?, ?)")) {
stmt.setString(1, branchUuid);
stmt.setBinaryStream(2, data);
stmt.executeUpdate();
connection.commit();
} catch (SQLException e) {
throw new IllegalStateException("Fail to insert cache for branch " + branchUuid, e);
}
}
public void cleanOlderThan7Days(DbSession session) {
long timestamp = LocalDateTime.now().minusDays(7).toInstant(ZoneOffset.UTC).toEpochMilli();
mapper(session).cleanOlderThan(timestamp);
}
@CheckForNull
public DbInputStream selectData(DbSession dbSession, String branchUuid) {
PreparedStatement stmt = null;
ResultSet rs = null;
DbInputStream result = null;
try {
stmt = dbSession.getConnection().prepareStatement("SELECT data FROM scanner_analysis_cache WHERE branch_uuid=?");
stmt.setString(1, branchUuid);
rs = stmt.executeQuery();
if (rs.next()) {
result = new DbInputStream(stmt, rs, rs.getBinaryStream(1));
return result;
}
return null;
} catch (SQLException e) {
throw new IllegalStateException("Fail to select cache for branch " + branchUuid, e);
} finally {
if (result == null) {
DatabaseUtils.closeQuietly(rs);
DatabaseUtils.closeQuietly(stmt);
}
}
}
private static ScannerAnalysisCacheMapper mapper(DbSession session) {
return session.getMapper(ScannerAnalysisCacheMapper.class);
}
}
| 3,176 | 34.3 | 119 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scannercache/ScannerAnalysisCacheMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scannercache;
import org.apache.ibatis.annotations.Param;
public interface ScannerAnalysisCacheMapper {
void removeAll();
void remove(@Param("branchUuid") String branchUuid);
void cleanOlderThan(@Param("timestamp") long timestamp);
}
| 1,108 | 34.774194 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scannercache/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.scannercache;
import javax.annotation.ParametersAreNonnullByDefault;
| 966 | 37.68 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/schemamigration/SchemaMigrationDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.schemamigration;
import java.util.List;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
public class SchemaMigrationDao implements Dao {
public List<Integer> selectVersions(DbSession dbSession) {
return getMapper(dbSession).selectVersions();
}
public void insert(DbSession dbSession, String version) {
requireNonNull(version, "version can't be null");
checkArgument(!version.isEmpty(), "version can't be empty");
getMapper(dbSession).insert(version);
}
private static SchemaMigrationMapper getMapper(DbSession dbSession) {
return dbSession.getMapper(SchemaMigrationMapper.class);
}
}
| 1,607 | 35.545455 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/schemamigration/SchemaMigrationDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.schemamigration;
/**
* Maps the table SCHEMA_MIGRATIONS
* @since 3.0
*/
public class SchemaMigrationDto {
private String version;// NOSONAR this field is assigned by MyBatis
public String getVersion() {
return version;
}
}
| 1,103 | 32.454545 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/schemamigration/SchemaMigrationMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.schemamigration;
import java.util.List;
public interface SchemaMigrationMapper {
List<Integer> selectVersions();
void insert(String version);
}
| 1,015 | 34.034483 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/schemamigration/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.schemamigration;
import javax.annotation.ParametersAreNonnullByDefault;
| 969 | 37.8 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimGroupDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.session.RowBounds;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
public class ScimGroupDao implements Dao {
private final UuidFactory uuidFactory;
public ScimGroupDao(UuidFactory uuidFactory) {
this.uuidFactory = uuidFactory;
}
public List<ScimGroupDto> findAll(DbSession dbSession) {
return mapper(dbSession).findAll();
}
public List<ScimGroupDto> findScimGroups(DbSession dbSession, ScimGroupQuery query, int offset, int limit) {
return mapper(dbSession).findScimGroups(query, new RowBounds(offset, limit));
}
public Optional<ScimGroupDto> findByScimUuid(DbSession dbSession, String scimGroupUuid) {
return Optional.ofNullable(mapper(dbSession).findByScimUuid(scimGroupUuid));
}
public Optional<ScimGroupDto> findByGroupUuid(DbSession dbSession, String groupUuid) {
return Optional.ofNullable(mapper(dbSession).findByGroupUuid(groupUuid));
}
public int countScimGroups(DbSession dbSession, ScimGroupQuery query) {
return mapper(dbSession).countScimGroups(query);
}
public ScimGroupDto enableScimForGroup(DbSession dbSession, String groupUuid) {
ScimGroupDto scimGroupDto = new ScimGroupDto(uuidFactory.create(), groupUuid);
mapper(dbSession).insert(scimGroupDto);
return scimGroupDto;
}
public void deleteByGroupUuid(DbSession dbSession, String groupUuid) {
mapper(dbSession).deleteByGroupUuid(groupUuid);
}
public void deleteByScimUuid(DbSession dbSession, String scimUuid) {
mapper(dbSession).deleteByScimUuid(scimUuid);
}
private static ScimGroupMapper mapper(DbSession session) {
return session.getMapper(ScimGroupMapper.class);
}
public String getManagedGroupSqlFilter(boolean filterByManaged) {
return String.format("%s exists (select group_uuid from scim_groups sg where sg.group_uuid = uuid)", filterByManaged ? "" : "not");
}
public void deleteAll(DbSession dbSession) {
mapper(dbSession).deleteAll();
}
}
| 2,932 | 34.768293 | 135 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimGroupDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
public class ScimGroupDto {
private final String scimGroupUuid;
private final String groupUuid;
public ScimGroupDto(String scimGroupUuid, String groupUuid) {
this.scimGroupUuid = scimGroupUuid;
this.groupUuid = groupUuid;
}
public String getScimGroupUuid() {
return scimGroupUuid;
}
public String getGroupUuid() {
return groupUuid;
}
}
| 1,243 | 30.1 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimGroupMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
import java.util.List;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
public interface ScimGroupMapper {
List<ScimGroupDto> findAll();
@CheckForNull
ScimGroupDto findByScimUuid(@Param("scimGroupUuid") String scimGroupUuid);
@CheckForNull
ScimGroupDto findByGroupUuid(@Param("groupUuid") String groupUuid);
List<ScimGroupDto> findScimGroups(@Param("query") ScimGroupQuery query, RowBounds rowBounds);
int countScimGroups(@Param("query") ScimGroupQuery query);
void insert(@Param("scimGroupDto") ScimGroupDto scimGroupDto);
void deleteByGroupUuid(@Param("groupUuid") String groupUuid);
void deleteByScimUuid(@Param("scimUuid") String scimUuid);
void deleteAll();
}
| 1,645 | 32.591837 | 95 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimGroupQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
import com.google.common.annotations.VisibleForTesting;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
import static org.apache.commons.lang.StringUtils.isBlank;
public class ScimGroupQuery {
private static final Pattern DISPLAY_NAME_FILTER_PATTERN = Pattern.compile("^displayName\\s+eq\\s+\"([^\"]*?)\"$", CASE_INSENSITIVE);
private static final String UNSUPPORTED_FILTER = "Unsupported filter or value: %s. The only supported filter and operator is 'displayName eq \"displayName\"";
@VisibleForTesting
static final ScimGroupQuery ALL = new ScimGroupQuery(null);
private final String displayName;
@VisibleForTesting
protected ScimGroupQuery(@Nullable String displayName) {
this.displayName = displayName;
}
public static ScimGroupQuery fromScimFilter(@Nullable String filter) {
if (isBlank(filter)) {
return ALL;
}
String userName = getDisplayNameFromFilter(filter)
.orElseThrow(() -> new IllegalArgumentException(String.format(UNSUPPORTED_FILTER, filter)));
return new ScimGroupQuery(userName);
}
private static Optional<String> getDisplayNameFromFilter(String filter) {
Matcher matcher = DISPLAY_NAME_FILTER_PATTERN.matcher(filter.trim());
return matcher.find()
? Optional.of(matcher.group(1))
: Optional.empty();
}
public String getDisplayName() {
return displayName;
}
}
| 2,374 | 34.984848 | 160 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimUserDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import org.apache.ibatis.session.RowBounds;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import static org.sonar.api.utils.Preconditions.checkState;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class ScimUserDao implements Dao {
private final UuidFactory uuidFactory;
public ScimUserDao(UuidFactory uuidFactory) {
this.uuidFactory = uuidFactory;
}
public List<ScimUserDto> findAll(DbSession dbSession) {
return mapper(dbSession).findAll();
}
public Optional<ScimUserDto> findByScimUuid(DbSession dbSession, String scimUserUuid) {
return Optional.ofNullable(mapper(dbSession).findByScimUuid(scimUserUuid));
}
public Optional<ScimUserDto> findByUserUuid(DbSession dbSession, String userUuid) {
return Optional.ofNullable(mapper(dbSession).findByUserUuid(userUuid));
}
public ScimUserDto enableScimForUser(DbSession dbSession, String userUuid) {
ScimUserDto scimUserDto = new ScimUserDto(uuidFactory.create(), userUuid);
mapper(dbSession).insert(scimUserDto);
return scimUserDto;
}
public List<ScimUserDto> findScimUsers(DbSession dbSession, ScimUserQuery scimUserQuery, int offset, int limit) {
checkState(scimUserQuery.getUserUuids() == null || scimUserQuery.getScimUserUuids() == null,
"Only one of userUuids & scimUserUuids request parameter is supported.");
if (scimUserQuery.getScimUserUuids() != null) {
return executeLargeInputs(
scimUserQuery.getScimUserUuids(),
partialSetOfUsers -> createPartialQuery(scimUserQuery, partialSetOfUsers,
(builder, scimUserUuids) -> builder.scimUserUuids(new HashSet<>(scimUserUuids)),
dbSession, offset, limit)
);
}
if (scimUserQuery.getUserUuids() != null) {
return executeLargeInputs(
scimUserQuery.getUserUuids(),
partialSetOfUsers -> createPartialQuery(scimUserQuery, partialSetOfUsers,
(builder, userUuids) -> builder.userUuids(new HashSet<>(userUuids)),
dbSession, offset, limit)
);
}
return mapper(dbSession).findScimUsers(scimUserQuery, new RowBounds(offset, limit));
}
private static List<ScimUserDto> createPartialQuery(ScimUserQuery completeQuery, List<String> strings,
BiFunction<ScimUserQuery.ScimUserQueryBuilder, List<String>, ScimUserQuery.ScimUserQueryBuilder> queryModifier,
DbSession dbSession, int offset, int limit) {
ScimUserQuery.ScimUserQueryBuilder partialScimUserQuery = ScimUserQuery.builder()
.userName(completeQuery.getUserName());
partialScimUserQuery = queryModifier.apply(partialScimUserQuery, strings);
return mapper(dbSession).findScimUsers(partialScimUserQuery.build(), new RowBounds(offset, limit));
}
public int countScimUsers(DbSession dbSession, ScimUserQuery scimUserQuery) {
return mapper(dbSession).countScimUsers(scimUserQuery);
}
private static ScimUserMapper mapper(DbSession session) {
return session.getMapper(ScimUserMapper.class);
}
public void deleteByUserUuid(DbSession dbSession, String userUuid) {
mapper(dbSession).deleteByUserUuid(userUuid);
}
public void deleteByScimUuid(DbSession dbSession, String scimUuid) {
mapper(dbSession).deleteByScimUuid(scimUuid);
}
public String getManagedUserSqlFilter(boolean filterByManaged) {
return String.format("%s exists (select user_uuid from scim_users su where su.user_uuid = uuid)", filterByManaged ? "" : "not");
}
public void deleteAll(DbSession dbSession) {
mapper(dbSession).deleteAll();
}
}
| 4,564 | 38.695652 | 132 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimUserDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
import java.util.Objects;
public class ScimUserDto {
private final String scimUserUuid;
private final String userUuid;
public ScimUserDto(String scimUserUuid, String userUuid) {
this.scimUserUuid = scimUserUuid;
this.userUuid = userUuid;
}
public String getScimUserUuid() {
return scimUserUuid;
}
public String getUserUuid() {
return userUuid;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ScimUserDto that = (ScimUserDto) o;
return Objects.equals(scimUserUuid, that.scimUserUuid) && Objects.equals(userUuid, that.userUuid);
}
@Override
public int hashCode() {
return Objects.hash(scimUserUuid, userUuid);
}
}
| 1,668 | 26.816667 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimUserMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
import java.util.List;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
public interface ScimUserMapper {
List<ScimUserDto> findAll();
@CheckForNull
ScimUserDto findByScimUuid(@Param("scimUserUuid") String scimUserUuid);
@CheckForNull
ScimUserDto findByUserUuid(@Param("userUuid") String userUuid);
void insert(@Param("scimUserDto") ScimUserDto scimUserDto);
List<ScimUserDto> findScimUsers(@Param("query") ScimUserQuery scimUserQuery, RowBounds rowBounds);
int countScimUsers(@Param("query") ScimUserQuery scimUserQuery);
void deleteByUserUuid(@Param("userUuid") String userUuid);
void deleteByScimUuid(@Param("scimUuid") String scimUuid);
void deleteAll();
}
| 1,641 | 32.510204 | 100 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/ScimUserQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.scim;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
import static org.apache.commons.lang.StringUtils.isBlank;
public class ScimUserQuery {
private static final Pattern USERNAME_FILTER_PATTERN = Pattern.compile("^userName\\s+eq\\s+\"([^\"]*?)\"$", CASE_INSENSITIVE);
private static final String UNSUPPORTED_FILTER = "Unsupported filter value: %s. Format should be 'userName eq \"username\"'";
private final String userName;
private final Set<String> scimUserUuids;
private final Set<String> userUuids;
private final String groupUuid;
private ScimUserQuery(@Nullable String userName, @Nullable Set<String> scimUserUuids,
@Nullable Set<String> userUuids, @Nullable String groupUuid) {
this.userName = userName;
this.scimUserUuids = scimUserUuids;
this.userUuids = userUuids;
this.groupUuid = groupUuid;
}
@CheckForNull
public String getUserName() {
return userName;
}
@CheckForNull
public Set<String> getScimUserUuids() {
return scimUserUuids;
}
@CheckForNull
public Set<String> getUserUuids() {
return userUuids;
}
@CheckForNull
public String getGroupUuid() {
return groupUuid;
}
public static ScimUserQuery empty() {
return builder().build();
}
public static ScimUserQuery fromScimFilter(@Nullable String filter) {
if (isBlank(filter)) {
return empty();
}
String userName = getUserNameFromFilter(filter)
.orElseThrow(() -> new IllegalStateException(String.format(UNSUPPORTED_FILTER, filter)));
return builder().userName(userName).build();
}
private static Optional<String> getUserNameFromFilter(String filter) {
Matcher matcher = USERNAME_FILTER_PATTERN.matcher(filter.trim());
return matcher.find()
? Optional.of(matcher.group(1))
: Optional.empty();
}
public static ScimUserQueryBuilder builder() {
return new ScimUserQueryBuilder();
}
public static final class ScimUserQueryBuilder {
private String userName;
private Set<String> scimUserUuids;
private Set<String> userUuids;
private String groupUuid;
private ScimUserQueryBuilder() {
}
public ScimUserQueryBuilder userName(@Nullable String userName) {
this.userName = userName;
return this;
}
public ScimUserQueryBuilder scimUserUuids(Set<String> scimUserUuids) {
this.scimUserUuids = scimUserUuids;
return this;
}
public ScimUserQueryBuilder userUuids(Set<String> userUuids) {
this.userUuids = userUuids;
return this;
}
public ScimUserQueryBuilder groupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}
public ScimUserQuery build() {
return new ScimUserQuery(userName, scimUserUuids, userUuids, groupUuid);
}
}
}
| 3,838 | 28.305344 | 128 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/scim/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.scim;
import javax.annotation.ParametersAreNonnullByDefault;
| 958 | 37.36 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileHashesDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.source;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
public class FileHashesDto {
protected String uuid;
protected String fileUuid;
protected String srcHash;
protected String dataHash;
protected String revision;
protected long updatedAt;
@Nullable
protected Integer lineHashesVersion;
public int getLineHashesVersion() {
return lineHashesVersion != null ? lineHashesVersion : LineHashVersion.WITHOUT_SIGNIFICANT_CODE.getDbValue();
}
public String getUuid() {
return uuid;
}
public String getFileUuid() {
return fileUuid;
}
public FileHashesDto setFileUuid(String fileUuid) {
this.fileUuid = fileUuid;
return this;
}
@CheckForNull
public String getDataHash() {
return dataHash;
}
/**
* MD5 of column BINARY_DATA. Used to know to detect data changes and need for update.
*/
public FileHashesDto setDataHash(String s) {
this.dataHash = s;
return this;
}
@CheckForNull
public String getSrcHash() {
return srcHash;
}
/**
* Hash of file content. Value is computed by batch.
*/
public FileHashesDto setSrcHash(@Nullable String srcHash) {
this.srcHash = srcHash;
return this;
}
public String getRevision() {
return revision;
}
public FileHashesDto setRevision(@Nullable String revision) {
this.revision = revision;
return this;
}
public long getUpdatedAt() {
return updatedAt;
}
}
| 2,319 | 23.946237 | 113 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.source;
import com.google.common.base.Splitter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.annotation.CheckForNull;
import org.apache.ibatis.session.ResultHandler;
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import static org.sonar.db.DatabaseUtils.toUniqueAndSortedPartitions;
public class FileSourceDao implements Dao {
private static final Splitter END_OF_LINE_SPLITTER = Splitter.on('\n');
@CheckForNull
public FileSourceDto selectByFileUuid(DbSession session, String fileUuid) {
return mapper(session).selectByFileUuid(fileUuid);
}
@CheckForNull
public LineHashVersion selectLineHashesVersion(DbSession dbSession, String fileUuid) {
Integer version = mapper(dbSession).selectLineHashesVersion(fileUuid);
return version == null ? null : LineHashVersion.valueOf(version);
}
/**
* The returning object doesn't contain all fields filled. For example, binary data is not loaded.
*/
public void scrollFileHashesByProjectUuid(DbSession dbSession, String projectUuid, ResultHandler<FileHashesDto> rowHandler) {
mapper(dbSession).scrollHashesForProject(projectUuid, rowHandler);
}
@CheckForNull
public List<String> selectLineHashes(DbSession dbSession, String fileUuid) {
Connection connection = dbSession.getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=?");
pstmt.setString(1, fileUuid);
rs = pstmt.executeQuery();
if (rs.next()) {
String string = rs.getString(1);
if (string == null) {
return Collections.emptyList();
}
return END_OF_LINE_SPLITTER.splitToList(string);
}
return null;
} catch (SQLException e) {
throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
} finally {
DatabaseUtils.closeQuietly(rs);
DatabaseUtils.closeQuietly(pstmt);
DatabaseUtils.closeQuietly(connection);
}
}
/**
* Scroll line hashes of all <strong>enabled</strong> components (should be files, but not enforced) with specified
* uuids in no specific order with 'SOURCE' source and a non null path.
*/
public void scrollLineHashes(DbSession dbSession, Collection<String> fileUUids, ResultHandler<LineHashesWithUuidDto> rowHandler) {
for (List<String> fileUuidsPartition : toUniqueAndSortedPartitions(fileUUids)) {
mapper(dbSession).scrollLineHashes(fileUuidsPartition, rowHandler);
}
}
public void insert(DbSession session, FileSourceDto dto) {
mapper(session).insert(dto);
}
public void update(DbSession session, FileSourceDto dto) {
mapper(session).update(dto);
}
private static FileSourceMapper mapper(DbSession session) {
return session.getMapper(FileSourceMapper.class);
}
}
| 3,944 | 35.527778 | 132 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.source;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.InvalidProtocolBufferException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import org.apache.commons.io.IOUtils;
import org.sonar.db.protobuf.DbFileSources;
import static com.google.common.base.Splitter.on;
import static java.lang.String.format;
public class FileSourceDto extends FileHashesDto {
private static final String SIZE_LIMIT_EXCEEDED_EXCEPTION_MESSAGE = "Protocol message was too large. May be malicious. " +
"Use CodedInputStream.setSizeLimit() to increase the size limit.";
private static final Joiner LINE_RETURN_JOINER = Joiner.on('\n');
public static final Splitter LINES_HASHES_SPLITTER = on('\n');
public static final int LINE_COUNT_NOT_POPULATED = -1;
private String projectUuid;
private long createdAt;
private String lineHashes;
/**
* When {@code line_count} column has been added, it's been populated with value {@link #LINE_COUNT_NOT_POPULATED -1},
* which implies all existing files sources have this value at the time SonarQube is upgraded.
* <p>
* Column {@code line_count} is populated with the correct value from every new files and for existing files as the
* project they belong to is analyzed for the first time after the migration.
* <p>
* Method {@link #getLineCount()} hides this migration-only-related complexity by either returning the value
* of column {@code line_count} when its been populated, or computed the returned value from the value of column
* {@code line_hashes}.
*/
private int lineCount = LINE_COUNT_NOT_POPULATED;
private byte[] binaryData = new byte[0];
public FileSourceDto setLineHashesVersion(int lineHashesVersion) {
this.lineHashesVersion = lineHashesVersion;
return this;
}
public FileSourceDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getProjectUuid() {
return projectUuid;
}
public FileSourceDto setProjectUuid(String projectUuid) {
this.projectUuid = projectUuid;
return this;
}
@Override
public FileSourceDto setFileUuid(String fileUuid) {
this.fileUuid = fileUuid;
return this;
}
/**
* MD5 of column BINARY_DATA. Used to know to detect data changes and need for update.
*/
@Override
public FileSourceDto setDataHash(String s) {
this.dataHash = s;
return this;
}
public DbFileSources.Data decodeSourceData(byte[] binaryData) {
try {
return decodeRegularSourceData(binaryData);
} catch (IOException e) {
throw new IllegalStateException(
format("Fail to decompress and deserialize source data [uuid=%s,fileUuid=%s,projectUuid=%s]", uuid, fileUuid, projectUuid),
e);
}
}
private static DbFileSources.Data decodeRegularSourceData(byte[] binaryData) throws IOException {
try (LZ4BlockInputStream lz4Input = new LZ4BlockInputStream(new ByteArrayInputStream(binaryData))) {
return DbFileSources.Data.parseFrom(lz4Input);
} catch (InvalidProtocolBufferException e) {
if (SIZE_LIMIT_EXCEEDED_EXCEPTION_MESSAGE.equals(e.getMessage())) {
return decodeHugeSourceData(binaryData);
}
throw e;
}
}
private static DbFileSources.Data decodeHugeSourceData(byte[] binaryData) throws IOException {
try (LZ4BlockInputStream lz4Input = new LZ4BlockInputStream(new ByteArrayInputStream(binaryData))) {
CodedInputStream input = CodedInputStream.newInstance(lz4Input);
input.setSizeLimit(Integer.MAX_VALUE);
return DbFileSources.Data.parseFrom(input);
}
}
/**
* Serialize and compress protobuf message {@link org.sonar.db.protobuf.DbFileSources.Data}
* in the column BINARY_DATA.
*/
public static byte[] encodeSourceData(DbFileSources.Data data) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
LZ4BlockOutputStream compressedOutput = new LZ4BlockOutputStream(byteOutput);
try {
data.writeTo(compressedOutput);
compressedOutput.close();
return byteOutput.toByteArray();
} catch (IOException e) {
throw new IllegalStateException("Fail to serialize and compress source data", e);
} finally {
IOUtils.closeQuietly(compressedOutput);
}
}
/**
* Compressed value of serialized protobuf message {@link org.sonar.db.protobuf.DbFileSources.Data}
*/
public byte[] getBinaryData() {
return binaryData;
}
/**
* Set compressed value of the protobuf message {@link org.sonar.db.protobuf.DbFileSources.Data}
*/
public FileSourceDto setBinaryData(byte[] data) {
this.binaryData = data;
return this;
}
/**
* Decompressed value of serialized protobuf message {@link org.sonar.db.protobuf.DbFileSources.Data}
*/
public DbFileSources.Data getSourceData() {
return decodeSourceData(binaryData);
}
public FileSourceDto setSourceData(DbFileSources.Data data) {
this.binaryData = encodeSourceData(data);
return this;
}
/** Used by MyBatis */
public String getRawLineHashes() {
return lineHashes;
}
public void setRawLineHashes(@Nullable String lineHashes) {
this.lineHashes = lineHashes;
}
public List<String> getLineHashes() {
if (lineHashes == null) {
return Collections.emptyList();
}
return LINES_HASHES_SPLITTER.splitToList(lineHashes);
}
/**
* @return the value of column {@code line_count} if populated, otherwise the size of {@link #getLineHashes()}.
*/
public int getLineCount() {
if (lineCount == LINE_COUNT_NOT_POPULATED) {
return getLineHashes().size();
}
return lineCount;
}
public FileSourceDto setLineHashes(@Nullable List<String> lineHashes) {
if (lineHashes == null) {
this.lineHashes = null;
this.lineCount = 0;
} else if (lineHashes.isEmpty()) {
this.lineHashes = null;
this.lineCount = 1;
} else {
this.lineHashes = LINE_RETURN_JOINER.join(lineHashes);
this.lineCount = lineHashes.size();
}
return this;
}
/**
* Hash of file content. Value is computed by batch.
*/
@Override
public FileSourceDto setSrcHash(@Nullable String srcHash) {
this.srcHash = srcHash;
return this;
}
public long getCreatedAt() {
return createdAt;
}
public FileSourceDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public FileSourceDto setUpdatedAt(long updatedAt) {
this.updatedAt = updatedAt;
return this;
}
@Override
public FileSourceDto setRevision(@Nullable String revision) {
this.revision = revision;
return this;
}
}
| 7,785 | 31.041152 | 131 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.source;
import java.util.Collection;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.ResultHandler;
public interface FileSourceMapper {
void scrollHashesForProject(@Param("projectUuid") String projectUuid, ResultHandler<FileHashesDto> rowHandler);
@CheckForNull
FileSourceDto selectByFileUuid(@Param("fileUuid") String fileUuid);
void scrollLineHashes(@Param("fileUuids") Collection<String> fileUuids, ResultHandler<LineHashesWithUuidDto> rowHandler);
@CheckForNull
Integer selectLineHashesVersion(@Param("fileUuid") String fileUuid);
void insert(FileSourceDto dto);
void update(FileSourceDto dto);
}
| 1,556 | 35.209302 | 123 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/source/LineHashVersion.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.source;
public enum LineHashVersion {
WITHOUT_SIGNIFICANT_CODE(0), WITH_SIGNIFICANT_CODE(1);
private int value;
LineHashVersion(int value) {
this.value = value;
}
public int getDbValue() {
return value;
}
public static LineHashVersion valueOf(int version) {
if (version > 1 || version < 0) {
throw new IllegalArgumentException("Unknown line hash version: " + version);
}
return LineHashVersion.values()[version];
}
}
| 1,329 | 29.930233 | 82 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/source/LineHashesWithUuidDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.source;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import static org.sonar.db.source.FileSourceDto.LINES_HASHES_SPLITTER;
public class LineHashesWithUuidDto {
private String uuid;
private String path;
private String lineHashes;
public String getUuid() {
return uuid;
}
public String getPath() {
return path;
}
/** Used by MyBatis */
public String getRawLineHashes() {
return lineHashes;
}
/** Used by MyBatis */
public void setRawLineHashes(@Nullable String lineHashes) {
this.lineHashes = lineHashes;
}
public List<String> getLineHashes() {
if (lineHashes == null) {
return Collections.emptyList();
}
return LINES_HASHES_SPLITTER.splitToList(lineHashes);
}
}
| 1,640 | 27.293103 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/source/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.db.source;
import javax.annotation.ParametersAreNonnullByDefault;
| 960 | 37.44 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/ExternalGroupDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import java.util.Optional;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
public class ExternalGroupDao implements Dao {
public void insert(DbSession dbSession, ExternalGroupDto externalGroupDto) {
mapper(dbSession).insert(externalGroupDto);
}
public Optional<ExternalGroupDto> selectByGroupUuid(DbSession dbSession, String groupUuid) {
return mapper(dbSession).selectByGroupUuid(groupUuid);
}
public List<ExternalGroupDto> selectByIdentityProvider(DbSession dbSession, String identityProvider) {
return mapper(dbSession).selectByIdentityProvider(identityProvider);
}
public void deleteByGroupUuid(DbSession dbSession, String groupUuid) {
mapper(dbSession).deleteByGroupUuid(groupUuid);
}
public Optional<ExternalGroupDto> selectByExternalIdAndIdentityProvider(DbSession dbSession, String externalId, String identityProvider) {
return mapper(dbSession).selectByExternalIdAndIdentityProvider(externalId, identityProvider);
}
private static ExternalGroupMapper mapper(DbSession session) {
return session.getMapper(ExternalGroupMapper.class);
}
public String getManagedGroupSqlFilter(boolean filterByManaged) {
return String.format("%s exists (select group_uuid from external_groups eg where eg.group_uuid = uuid)", filterByManaged ? "" : "not");
}
public void deleteByExternalIdentityProvider(DbSession dbSession, String externalIdentityProvider) {
mapper(dbSession).deleteByExternalIdentityProvider(externalIdentityProvider);
}
}
| 2,405 | 38.442623 | 140 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/ExternalGroupDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Objects;
import javax.annotation.Nullable;
public record ExternalGroupDto(String groupUuid, String externalId, String externalIdentityProvider, @Nullable String name) {
public ExternalGroupDto(String groupUuid, String externalId, String externalIdentityProvider) {
this(groupUuid, externalId, externalIdentityProvider, null);
}
public String getNameOrThrow() {
return Objects.requireNonNull(name);
}
}
| 1,309 | 36.428571 | 125 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/ExternalGroupMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Param;
public interface ExternalGroupMapper {
void insert(ExternalGroupDto externalGroupDto);
Optional<ExternalGroupDto> selectByGroupUuid(@Param("groupUuid") String groupUuid);
List<ExternalGroupDto> selectByIdentityProvider(@Param("identityProvider") String identityProvider);
Optional<ExternalGroupDto> selectByExternalIdAndIdentityProvider(@Param("externalId") String externalId, @Param("identityProvider") String identityProvider);
void deleteByGroupUuid(@Param("groupUuid") String groupUuid);
void deleteByExternalIdentityProvider(String externalIdentityProvider);
}
| 1,550 | 37.775 | 159 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import javax.annotation.CheckForNull;
import org.apache.ibatis.session.RowBounds;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.UserGroupNewValue;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class GroupDao implements Dao {
private final System2 system;
private final AuditPersister auditPersister;
public GroupDao(System2 system, AuditPersister auditPersister) {
this.system = system;
this.auditPersister = auditPersister;
}
/**
* @param dbSession
* @param name non-null group name
* @return the group with the given name
*/
public Optional<GroupDto> selectByName(DbSession dbSession, String name) {
return Optional.ofNullable(mapper(dbSession).selectByName(name));
}
public List<GroupDto> selectByNames(DbSession dbSession, Collection<String> names) {
return executeLargeInputs(names, pageOfNames -> mapper(dbSession).selectByNames(pageOfNames));
}
@CheckForNull
public GroupDto selectByUuid(DbSession dbSession, String groupUuid) {
return mapper(dbSession).selectByUuid(groupUuid);
}
public List<GroupDto> selectByUuids(DbSession dbSession, List<String> uuids) {
return executeLargeInputs(uuids, mapper(dbSession)::selectByUuids);
}
public void deleteByUuid(DbSession dbSession, String groupUuid, String groupName) {
int deletedRows = mapper(dbSession).deleteByUuid(groupUuid);
if (deletedRows > 0) {
auditPersister.deleteUserGroup(dbSession, new UserGroupNewValue(groupUuid, groupName));
}
}
public int countByQuery(DbSession session, GroupQuery query) {
return mapper(session).countByQuery(query);
}
public List<GroupDto> selectByQuery(DbSession session, GroupQuery query, int offset, int limit) {
return mapper(session).selectByQuery(query, new RowBounds(offset, limit));
}
public GroupDto insert(DbSession session, GroupDto item) {
Date createdAt = new Date(system.now());
item.setCreatedAt(createdAt)
.setUpdatedAt(createdAt);
mapper(session).insert(item);
auditPersister.addUserGroup(session, new UserGroupNewValue(item.getUuid(), item.getName()));
return item;
}
public GroupDto update(DbSession session, GroupDto item) {
item.setUpdatedAt(new Date(system.now()));
mapper(session).update(item);
auditPersister.updateUserGroup(session, new UserGroupNewValue(item));
return item;
}
public List<GroupDto> selectByUserLogin(DbSession session, String login) {
return mapper(session).selectByUserLogin(login);
}
private static GroupMapper mapper(DbSession session) {
return session.getMapper(GroupMapper.class);
}
}
| 3,725 | 33.5 | 99 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
public class GroupDto {
private String uuid;
private String name;
private String description;
private Date createdAt;
private Date updatedAt;
public String getUuid() {
return uuid;
}
public GroupDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getName() {
return name;
}
public GroupDto setName(String name) {
this.name = name;
return this;
}
@CheckForNull
public String getDescription() {
return description;
}
public GroupDto setDescription(@Nullable String description) {
this.description = description;
return this;
}
public GroupDto setCreatedAt(Date d) {
this.createdAt = d;
return this;
}
public GroupDto setUpdatedAt(Date d) {
this.updatedAt = d;
return this;
}
public Date getCreatedAt() {
return this.createdAt;
}
public Date getUpdatedAt() {
return this.updatedAt;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("GroupDto{");
sb.append("id=").append(uuid);
sb.append(", name='").append(name).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append('}');
return sb.toString();
}
}
| 2,295 | 23.956522 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
public interface GroupMapper {
@CheckForNull
GroupDto selectByUuid(String groupUuid);
List<GroupDto> selectByUserLogin(String userLogin);
List<GroupDto> selectByNames(@Param("names") List<String> names);
void insert(GroupDto groupDto);
void update(GroupDto item);
List<GroupDto> selectByQuery(@Param("query") GroupQuery query, RowBounds rowBounds);
int countByQuery(@Param("query") GroupQuery query);
int deleteByUuid(String groupUuid);
@CheckForNull
GroupDto selectByName(@Param("name") String name);
List<GroupDto> selectByUuids(@Param("uuids") List<String> uuids);
}
| 1,625 | 30.882353 | 86 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.RowBounds;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class GroupMembershipDao implements Dao {
private static final String QUERY_PARAM_KEY = "query";
public List<GroupMembershipDto> selectGroups(DbSession session, GroupMembershipQuery query, String userUuid, int offset, int limit) {
Map<String, Object> params = ImmutableMap.of(QUERY_PARAM_KEY, query, "userUuid", userUuid);
return mapper(session).selectGroups(params, new RowBounds(offset, limit));
}
public int countGroups(DbSession session, GroupMembershipQuery query, String userUuid) {
Map<String, Object> params = ImmutableMap.of(QUERY_PARAM_KEY, query, "userUuid", userUuid);
return mapper(session).countGroups(params);
}
public List<UserMembershipDto> selectMembers(DbSession session, UserMembershipQuery query, int offset, int limit) {
Map<String, Object> params = ImmutableMap.of(QUERY_PARAM_KEY, query, "groupUuid", query.groupUuid());
return mapper(session).selectMembers(params, new RowBounds(offset, limit));
}
public int countMembers(DbSession session, UserMembershipQuery query) {
Map<String, Object> params = ImmutableMap.of(QUERY_PARAM_KEY, query, "groupUuid", query.groupUuid());
return mapper(session).countMembers(params);
}
public Map<String, Integer> countUsersByGroups(DbSession session, Collection<String> groupUuids) {
Map<String, Integer> result = new HashMap<>();
executeLargeInputs(
groupUuids,
input -> {
List<GroupUserCount> userCounts = mapper(session).countUsersByGroup(input);
for (GroupUserCount count : userCounts) {
result.put(count.groupName(), count.userCount());
}
return userCounts;
});
return result;
}
public List<String> selectGroupUuidsByUserUuid(DbSession dbSession, String userUuid) {
return mapper(dbSession).selectGroupUuidsByUserUuid(userUuid);
}
public Multimap<String, String> selectGroupsByLogins(DbSession session, Collection<String> logins) {
Multimap<String, String> result = ArrayListMultimap.create();
executeLargeInputs(
logins,
input -> {
List<LoginGroup> groupMemberships = mapper(session).selectGroupsByLogins(input);
for (LoginGroup membership : groupMemberships) {
result.put(membership.login(), membership.groupName());
}
return groupMemberships;
});
return result;
}
private static GroupMembershipMapper mapper(DbSession session) {
return session.getMapper(GroupMembershipMapper.class);
}
}
| 3,766 | 38.239583 | 135 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
/**
* @since 4.1
*/
public class GroupMembershipDto {
private String uuid;
private String name;
private String description;
private String userUuid;
public String getUuid() {
return uuid;
}
public GroupMembershipDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getName() {
return name;
}
public GroupMembershipDto setName(String name) {
this.name = name;
return this;
}
@CheckForNull
public String getDescription() {
return description;
}
public GroupMembershipDto setDescription(@Nullable String description) {
this.description = description;
return this;
}
@CheckForNull
public String getUserUuid() {
return userUuid;
}
public GroupMembershipDto setUserUuid(@Nullable String userUuid) {
this.userUuid = userUuid;
return this;
}
}
| 1,805 | 23.405405 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
public interface GroupMembershipMapper {
List<GroupMembershipDto> selectGroups(Map<String, Object> params, RowBounds rowBounds);
int countGroups(Map<String, Object> params);
List<UserMembershipDto> selectMembers(Map<String, Object> params, RowBounds rowBounds);
int countMembers(Map<String, Object> params);
List<GroupUserCount> countUsersByGroup(@Param("groupUuids") List<String> groupUuids);
List<LoginGroup> selectGroupsByLogins(@Param("logins") List<String> logins);
List<String> selectGroupUuidsByUserUuid(@Param("userUuid") String userUuid);
}
| 1,576 | 35.674419 | 89 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupMembershipQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
public class GroupMembershipQuery {
public static final int DEFAULT_PAGE_INDEX = 1;
public static final int DEFAULT_PAGE_SIZE = 100;
public static final String ANY = "ANY";
public static final String IN = "IN";
public static final String OUT = "OUT";
public static final Set<String> AVAILABLE_MEMBERSHIP = ImmutableSet.of(ANY, IN, OUT);
private final String membership;
private final String groupSearch;
// for internal use in MyBatis
final String groupSearchSql;
// max results per page
private final int pageSize;
// index of selected page. Start with 1.
private final int pageIndex;
private GroupMembershipQuery(Builder builder) {
this.membership = builder.membership;
this.groupSearch = builder.groupSearch;
this.groupSearchSql = groupSearchToSql(groupSearch);
this.pageSize = builder.pageSize;
this.pageIndex = builder.pageIndex;
}
private static String groupSearchToSql(@Nullable String s) {
String sql = null;
if (s != null) {
sql = StringUtils.replace(StringUtils.upperCase(s), "%", "/%");
sql = StringUtils.replace(sql, "_", "/_");
sql = "%" + sql + "%";
}
return sql;
}
@CheckForNull
public String membership() {
return membership;
}
/**
* Search for groups containing a given string
*/
@CheckForNull
public String groupSearch() {
return groupSearch;
}
public int pageSize() {
return pageSize;
}
public int pageIndex() {
return pageIndex;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String membership;
private String groupSearch;
private Integer pageIndex = DEFAULT_PAGE_INDEX;
private Integer pageSize = DEFAULT_PAGE_SIZE;
private Builder() {
}
public Builder membership(@Nullable String membership) {
this.membership = membership;
return this;
}
public Builder groupSearch(@Nullable String s) {
this.groupSearch = StringUtils.defaultIfBlank(s, null);
return this;
}
public Builder pageSize(@Nullable Integer i) {
this.pageSize = i;
return this;
}
public Builder pageIndex(@Nullable Integer i) {
this.pageIndex = i;
return this;
}
private void initMembership() {
membership = firstNonNull(membership, ANY);
checkArgument(AVAILABLE_MEMBERSHIP.contains(membership),
"Membership is not valid (got " + membership + "). Availables values are " + AVAILABLE_MEMBERSHIP);
}
private void initPageSize() {
pageSize = firstNonNull(pageSize, DEFAULT_PAGE_SIZE);
}
private void initPageIndex() {
pageIndex = firstNonNull(pageIndex, DEFAULT_PAGE_INDEX);
checkArgument(pageIndex > 0, "Page index must be greater than 0 (got " + pageIndex + ")");
}
public GroupMembershipQuery build() {
initMembership();
initPageIndex();
initPageSize();
return new GroupMembershipQuery(this);
}
}
}
| 4,190 | 26.572368 | 107 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Locale;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.db.DaoUtils;
import org.sonar.db.WildcardPosition;
public class GroupQuery {
private final String searchText;
private final String isManagedSqlClause;
GroupQuery(@Nullable String searchText, @Nullable String isManagedSqlClause) {
this.searchText = searchTextToSearchTextSql(searchText);
this.isManagedSqlClause = isManagedSqlClause;
}
private static String searchTextToSearchTextSql(@Nullable String text) {
if (text == null) {
return null;
}
String upperCasedNameQuery = StringUtils.upperCase(text, Locale.ENGLISH);
return DaoUtils.buildLikeValue(upperCasedNameQuery, WildcardPosition.BEFORE_AND_AFTER);
}
@CheckForNull
public String getSearchText() {
return searchText;
}
@CheckForNull
public String getIsManagedSqlClause() {
return isManagedSqlClause;
}
public static GroupQueryBuilder builder() {
return new GroupQueryBuilder();
}
public static final class GroupQueryBuilder {
private String searchText = null;
private String isManagedSqlClause = null;
private GroupQueryBuilder() {
}
public GroupQuery.GroupQueryBuilder searchText(@Nullable String searchText) {
this.searchText = searchText;
return this;
}
public GroupQuery.GroupQueryBuilder isManagedClause(@Nullable String isManagedSqlClause) {
this.isManagedSqlClause = isManagedSqlClause;
return this;
}
public GroupQuery build() {
return new GroupQuery(searchText, isManagedSqlClause);
}
}
}
| 2,539 | 29.238095 | 94 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/GroupUserCount.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class GroupUserCount {
private String groupName;
private int userCount;
public String groupName() {
return groupName;
}
public int userCount() {
return userCount;
}
}
| 1,068 | 29.542857 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/LoginGroup.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class LoginGroup {
private String login;
private String groupName;
public String login() {
return login;
}
public String groupName() {
return groupName;
}
}
| 1,058 | 29.257143 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/LoginGroupCount.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class LoginGroupCount {
private String login;
private int groupCount;
public LoginGroupCount() {
// nothing to do here
}
public String login() {
return login;
}
public int groupCount() {
return groupCount;
}
}
| 1,119 | 28.473684 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.sonar.api.web.UserRole;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.USER;
public class RoleDao implements Dao {
private static final Set<String> UNSUPPORTED_PROJECT_PERMISSIONS = ImmutableSet.of(USER, CODEVIEWER);
/**
* All the entities on which the user has {@code permission}, directly or through
* groups.
*
* @throws IllegalArgumentException this method does not support permissions {@link UserRole#USER user} nor
* {@link UserRole#CODEVIEWER codeviewer} because it does not support public root components.
*/
public List<String> selectEntityUuidsByPermissionAndUserUuidAndQualifier(DbSession dbSession, String permission, String userUuid, Collection<String> qualifiers) {
checkArgument(
!UNSUPPORTED_PROJECT_PERMISSIONS.contains(permission),
"Permissions %s are not supported by selectEntityUuidsByPermissionAndUserUuidAndQualifier", UNSUPPORTED_PROJECT_PERMISSIONS);
return mapper(dbSession).selectEntityUuidsByPermissionAndUserUuidAndQualifier(permission, userUuid, qualifiers);
}
public void deleteGroupRolesByGroupUuid(DbSession session, String groupUuid) {
mapper(session).deleteGroupRolesByGroupUuid(groupUuid);
}
private static RoleMapper mapper(DbSession session) {
return session.getMapper(RoleMapper.class);
}
}
| 2,477 | 41 | 164 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Collection;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface RoleMapper {
List<String> selectEntityUuidsByPermissionAndUserUuidAndQualifier(@Param("permission") String permission,
@Param("userUuid") String userUuid, @Param("qualifiers") Collection<String> qualifiers);
void deleteGroupRolesByGroupUuid(String groupUuid);
}
| 1,258 | 36.029412 | 107 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SamlMessageIdDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Optional;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
public class SamlMessageIdDao implements Dao {
private final System2 system2;
private final UuidFactory uuidFactory;
public SamlMessageIdDao(System2 system2, UuidFactory uuidFactory) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
}
public Optional<SamlMessageIdDto> selectByMessageId(DbSession session, String messageId) {
return Optional.ofNullable(mapper(session).selectByMessageId(messageId));
}
public SamlMessageIdDto insert(DbSession session, SamlMessageIdDto dto) {
long now = system2.now();
mapper(session).insert(dto
.setUuid(uuidFactory.create())
.setCreatedAt(now));
return dto;
}
public int deleteExpired(DbSession dbSession) {
return mapper(dbSession).deleteExpired(system2.now());
}
private static SamlMessageIdMapper mapper(DbSession session) {
return session.getMapper(SamlMessageIdMapper.class);
}
}
| 1,933 | 32.344828 | 92 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SamlMessageIdDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class SamlMessageIdDto {
private String uuid;
/**
* Message ID from the SAML response received during authentication.
*/
private String messageId;
/**
* Expiration date is coming from the NotOnOrAfter attribute of the SAML response.
*
* A row that contained an expired date can be safely deleted from database.
*/
private long expirationDate;
private long createdAt;
public String getUuid() {
return uuid;
}
SamlMessageIdDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getMessageId() {
return messageId;
}
public SamlMessageIdDto setMessageId(String messageId) {
this.messageId = messageId;
return this;
}
public long getExpirationDate() {
return expirationDate;
}
public SamlMessageIdDto setExpirationDate(long expirationDate) {
this.expirationDate = expirationDate;
return this;
}
public long getCreatedAt() {
return createdAt;
}
SamlMessageIdDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
}
| 1,951 | 24.684211 | 84 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SamlMessageIdMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
public interface SamlMessageIdMapper {
@CheckForNull
SamlMessageIdDto selectByMessageId(String messageId);
void insert(@Param("dto") SamlMessageIdDto dto);
int deleteExpired(@Param("now") long now);
}
| 1,167 | 32.371429 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SearchGroupMembershipDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class SearchGroupMembershipDto {
private String groupUuid;
// Set by MyBatis
private String uuid;
public String getGroupUuid() {
return groupUuid;
}
public SearchGroupMembershipDto setGroupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}
public boolean isSelected() {
return uuid != null;
}
}
| 1,229 | 28.285714 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SearchPermissionQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
public abstract class SearchPermissionQuery {
public static final String ANY = "ANY";
public static final String IN = "IN";
public static final String OUT = "OUT";
public static final Set<String> AVAILABLE_MEMBERSHIPS = Set.of(ANY, IN, OUT);
protected String query;
protected String membership;
// for internal use in MyBatis
protected String querySql;
protected String querySqlLowercase;
public String getMembership() {
return membership;
}
@CheckForNull
public String getQuery() {
return query;
}
public abstract static class Builder<T extends Builder<T>> {
private String query;
private String membership;
public String getQuery(){
return query;
}
public T setQuery(@Nullable String s) {
this.query = StringUtils.defaultIfBlank(s, null);
return self();
}
public String getMembership(){
return membership;
}
public T setMembership(@Nullable String membership) {
this.membership = membership;
return self();
}
public void initMembership() {
membership = firstNonNull(membership, ANY);
checkArgument(AVAILABLE_MEMBERSHIPS.contains(membership),
"Membership is not valid (got " + membership + "). Availables values are " + AVAILABLE_MEMBERSHIPS);
}
@SuppressWarnings("unchecked")
final T self() {
return (T) this;
}
}
}
| 2,532 | 28.114943 | 108 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SearchUserMembershipDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class SearchUserMembershipDto {
private String userUuid;
// Set by MyBatis
private String uuid;
public SearchUserMembershipDto() {
// Do nothing
}
public String getUserUuid() {
return userUuid;
}
public SearchUserMembershipDto setUserUuid(String userUuid) {
this.userUuid = userUuid;
return this;
}
public boolean isSelected() {
return uuid != null;
}
}
| 1,280 | 26.847826 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SessionTokenDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class SessionTokenDto {
private String uuid;
private String userUuid;
private long expirationDate;
private long createdAt;
private long updatedAt;
public String getUuid() {
return uuid;
}
SessionTokenDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getUserUuid() {
return userUuid;
}
public SessionTokenDto setUserUuid(String userUuid) {
this.userUuid = userUuid;
return this;
}
public long getExpirationDate() {
return expirationDate;
}
public SessionTokenDto setExpirationDate(long expirationDate) {
this.expirationDate = expirationDate;
return this;
}
public long getCreatedAt() {
return createdAt;
}
SessionTokenDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public long getUpdatedAt() {
return updatedAt;
}
SessionTokenDto setUpdatedAt(long updatedAt) {
this.updatedAt = updatedAt;
return this;
}
}
| 1,859 | 23.8 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SessionTokenMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
public interface SessionTokenMapper {
@CheckForNull
SessionTokenDto selectByUuid(String uuid);
void insert(@Param("dto") SessionTokenDto dto);
void update(@Param("dto") SessionTokenDto dto);
void deleteByUuid(@Param("uuid") String uuid);
void deleteByUserUuid(@Param("userUuid") String userUuid);
int deleteExpired(@Param("now") long now);
}
| 1,317 | 31.146341 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/SessionTokensDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Optional;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
public class SessionTokensDao implements Dao {
private final System2 system2;
private final UuidFactory uuidFactory;
public SessionTokensDao(System2 system2, UuidFactory uuidFactory) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
}
public Optional<SessionTokenDto> selectByUuid(DbSession session, String uuid) {
return Optional.ofNullable(mapper(session).selectByUuid(uuid));
}
public SessionTokenDto insert(DbSession session, SessionTokenDto dto) {
long now = system2.now();
mapper(session).insert(dto
.setUuid(uuidFactory.create())
.setCreatedAt(now)
.setUpdatedAt(now));
return dto;
}
public SessionTokenDto update(DbSession session, SessionTokenDto dto) {
long now = system2.now();
mapper(session).update(dto.setUpdatedAt(now));
return dto;
}
public void deleteByUuid(DbSession dbSession, String uuid) {
mapper(dbSession).deleteByUuid(uuid);
}
public void deleteByUser(DbSession dbSession, UserDto user) {
mapper(dbSession).deleteByUserUuid(user.getUuid());
}
public int deleteExpired(DbSession dbSession) {
return mapper(dbSession).deleteExpired(system2.now());
}
private static SessionTokenMapper mapper(DbSession session) {
return session.getMapper(SessionTokenMapper.class);
}
}
| 2,344 | 31.123288 | 81 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/TokenType.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public enum TokenType {
USER_TOKEN("u"),
GLOBAL_ANALYSIS_TOKEN("a"),
PROJECT_BADGE_TOKEN("b"),
PROJECT_ANALYSIS_TOKEN("p");
private final String identifier;
TokenType(String identifier) {
this.identifier = identifier;
}
public String getIdentifier() {
return identifier;
}
}
| 1,176 | 29.179487 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.Pagination;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.UserNewValue;
import org.sonar.db.entity.EntityDto;
import static java.util.Locale.ENGLISH;
import static java.util.concurrent.TimeUnit.DAYS;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
public class UserDao implements Dao {
private static final long WEEK_IN_MS = DAYS.toMillis(7L);
private final System2 system2;
private final UuidFactory uuidFactory;
private final AuditPersister auditPersister;
public UserDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
this.auditPersister = auditPersister;
}
@CheckForNull
public UserDto selectByUuid(DbSession session, String uuid) {
return mapper(session).selectByUuid(uuid);
}
@CheckForNull
public UserDto selectActiveUserByLogin(DbSession session, String login) {
UserMapper mapper = mapper(session);
return mapper.selectUserByLogin(login);
}
/**
* Select users by logins, including disabled users. An empty list is returned
* if list of logins is empty, without any db round trips.
*/
public List<UserDto> selectByLogins(DbSession session, Collection<String> logins) {
return executeLargeInputs(logins, mapper(session)::selectByLogins);
}
/**
* Select users by uuids, including disabled users. An empty list is returned
* if list of uuids is empty, without any db round trips.
*
* @return
*/
public List<UserDto> selectByUuids(DbSession session, Collection<String> uuids) {
return executeLargeInputs(uuids, mapper(session)::selectByUuids);
}
/**
* Gets a list users by their logins. The result does NOT contain {@code null} values for users not found, so
* the size of result may be less than the number of keys.
* A single user is returned if input keys contain multiple occurrences of a key.
* <p>Contrary to {@link #selectByLogins(DbSession, Collection)}, results are in the same order as input keys.</p>
*/
public List<UserDto> selectByOrderedLogins(DbSession session, Collection<String> logins) {
List<UserDto> unordered = selectByLogins(session, logins);
return logins.stream()
.map(new LoginToUser(unordered))
.filter(Objects::nonNull)
.toList();
}
public List<UserDto> selectUsers(DbSession dbSession, UserQuery userQuery) {
return selectUsers(dbSession, userQuery, Pagination.all());
}
public List<UserDto> selectUsers(DbSession dbSession, UserQuery userQuery, int offset, int limit) {
Pagination pagination = Pagination.forPage(offset).andSize(limit);
return selectUsers(dbSession, userQuery, pagination);
}
private static List<UserDto> selectUsers(DbSession dbSession, UserQuery userQuery, Pagination pagination) {
if (userQuery.getUserUuids() != null) {
return executeLargeInputs(
userQuery.getUserUuids(),
partialSetOfUsers -> mapper(dbSession).selectUsers(
UserQuery.copyWithNewRangeOfUserUuids(userQuery, partialSetOfUsers),
pagination)
);
}
return mapper(dbSession).selectUsers(userQuery, pagination);
}
public int countUsers(DbSession dbSession, UserQuery userQuery) {
return mapper(dbSession).countByQuery(userQuery);
}
public List<UserTelemetryDto> selectUsersForTelemetry(DbSession dbSession) {
return mapper(dbSession).selectUsersForTelemetry();
}
public UserDto insert(DbSession session, UserDto dto) {
long now = system2.now();
mapper(session).insert(dto.setUuid(uuidFactory.create()).setCreatedAt(now).setUpdatedAt(now));
insertScmAccounts(session, dto.getUuid(), dto.getSortedScmAccounts());
auditPersister.addUser(session, new UserNewValue(dto.getUuid(), dto.getLogin()));
return dto;
}
private static void insertScmAccounts(DbSession session, String userUuid, List<String> scmAccounts) {
scmAccounts.stream()
.filter(StringUtils::isNotBlank)
.forEach(scmAccount -> mapper(session).insertScmAccount(userUuid, scmAccount.toLowerCase(ENGLISH)));
}
public UserDto update(DbSession session, UserDto dto) {
return update(session, dto, true);
}
public UserDto update(DbSession session, UserDto dto, boolean track) {
mapper(session).update(dto.setUpdatedAt(system2.now()));
mapper(session).deleteAllScmAccounts(dto.getUuid());
insertScmAccounts(session, dto.getUuid(), dto.getSortedScmAccounts());
if (track) {
auditPersister.updateUser(session, new UserNewValue(dto));
}
return dto;
}
public void updateSonarlintLastConnectionDate(DbSession session, String login) {
mapper(session).updateSonarlintLastConnectionDate(login, system2.now());
}
public void deactivateUser(DbSession dbSession, UserDto user) {
mapper(dbSession).deactivateUser(user.getLogin(), system2.now());
mapper(dbSession).deleteAllScmAccounts(user.getUuid());
auditPersister.deactivateUser(dbSession, new UserNewValue(user.getUuid(), user.getLogin()));
}
public void cleanHomepage(DbSession dbSession, EntityDto entityDto) {
mapper(dbSession).clearHomepages("PROJECT", entityDto.getUuid(), system2.now());
}
public void cleanHomepage(DbSession dbSession, UserDto user) {
mapper(dbSession).clearHomepage(user.getLogin(), system2.now());
}
@CheckForNull
public UserDto selectByLogin(DbSession session, String login) {
return mapper(session).selectByLogin(login);
}
public List<UserDto> selectByScmAccountOrLoginOrEmail(DbSession session, String scmAccountOrLoginOrEmail) {
return mapper(session).selectNullableByScmAccountOrLoginOrEmail(scmAccountOrLoginOrEmail);
}
/**
* This method is optimized for the first analysis: we tried to keep performance optimal (<10ms) for projects with large number of contributors
*/
public List<UserIdDto> selectActiveUsersByScmAccountOrLoginOrEmail(DbSession session, String scmAccountOrLoginOrEmail) {
return mapper(session).selectActiveUsersByScmAccountOrLoginOrEmail(scmAccountOrLoginOrEmail);
}
/**
* Search for an active user with the given emailCaseInsensitive exits in database
* Select is case insensitive. Result for searching 'mail@emailCaseInsensitive.com' or 'Mail@Email.com' is the same
*/
public List<UserDto> selectByEmail(DbSession dbSession, String emailCaseInsensitive) {
return mapper(dbSession).selectByEmail(emailCaseInsensitive.toLowerCase(ENGLISH));
}
@CheckForNull
public UserDto selectByExternalIdAndIdentityProvider(DbSession dbSession, String externalId, String externalIdentityProvider) {
return mapper(dbSession).selectByExternalIdAndIdentityProvider(externalId, externalIdentityProvider);
}
public List<String> selectExternalIdentityProviders(DbSession dbSession) {
return mapper(dbSession).selectExternalIdentityProviders();
}
public List<UserDto> selectByExternalIdsAndIdentityProvider(DbSession dbSession, Collection<String> externalIds, String externalIdentityProvider) {
return executeLargeInputs(externalIds, e -> mapper(dbSession).selectByExternalIdsAndIdentityProvider(e, externalIdentityProvider));
}
@CheckForNull
public UserDto selectByExternalLoginAndIdentityProvider(DbSession dbSession, String externalLogin, String externalIdentityProvider) {
return mapper(dbSession).selectByExternalLoginAndIdentityProvider(externalLogin, externalIdentityProvider);
}
public long countSonarlintWeeklyUsers(DbSession dbSession) {
long threshold = system2.now() - WEEK_IN_MS;
return mapper(dbSession).countActiveSonarlintUsers(threshold);
}
public long countActiveUsers(DbSession dbSession) {
return mapper(dbSession).countActiveUsers();
}
public void scrollByUuids(DbSession dbSession, Collection<String> uuids, Consumer<UserDto> consumer) {
UserMapper mapper = mapper(dbSession);
executeLargeInputsWithoutOutput(uuids,
pageOfUuids -> mapper
.selectByUuids(pageOfUuids)
.forEach(consumer));
}
public void scrollAll(DbSession dbSession, Consumer<UserDto> consumer) {
mapper(dbSession).scrollAll(context -> {
UserDto user = context.getResultObject();
consumer.accept(user);
});
}
private static UserMapper mapper(DbSession session) {
return session.getMapper(UserMapper.class);
}
private static class LoginToUser implements Function<String, UserDto> {
private final Map<String, UserDto> map = new HashMap<>();
private LoginToUser(Collection<UserDto> unordered) {
for (UserDto dto : unordered) {
map.put(dto.getLogin(), dto);
}
}
@Override
public UserDto apply(@Nonnull String login) {
return map.get(login);
}
}
}
| 10,135 | 37.539924 | 149 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessageDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import org.sonar.db.ce.CeTaskMessageType;
public class UserDismissedMessageDto {
private String uuid;
/**
* Uuid of the user that dismissed the message type
*/
private String userUuid;
/**
* Uuid of the project for which the message type was dismissed
*/
private String projectUuid;
/**
* Message type of the dismissed message
*/
private CeTaskMessageType ceMessageType;
/**
* Technical creation date
*/
private long createdAt;
public UserDismissedMessageDto() {
// nothing to do here
}
public String getUuid() {
return uuid;
}
public UserDismissedMessageDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getUserUuid() {
return userUuid;
}
public UserDismissedMessageDto setUserUuid(String userUuid) {
this.userUuid = userUuid;
return this;
}
public String getProjectUuid() {
return projectUuid;
}
public UserDismissedMessageDto setProjectUuid(String projectUuid) {
this.projectUuid = projectUuid;
return this;
}
public CeTaskMessageType getCeMessageType() {
return ceMessageType;
}
public UserDismissedMessageDto setCeMessageType(CeTaskMessageType ceMessageType) {
this.ceMessageType = ceMessageType;
return this;
}
public long getCreatedAt() {
return createdAt;
}
public UserDismissedMessageDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
}
| 2,331 | 24.075269 | 84 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import java.util.Optional;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.ce.CeTaskMessageType;
import org.sonar.db.project.ProjectDto;
public class UserDismissedMessagesDao implements Dao {
private final System2 system2;
public UserDismissedMessagesDao(System2 system2) {
this.system2 = system2;
}
public UserDismissedMessageDto insert(DbSession session, UserDismissedMessageDto dto) {
long now = system2.now();
mapper(session).insert(dto.setCreatedAt(now));
return dto;
}
public Optional<UserDismissedMessageDto> selectByUserAndProjectAndMessageType(DbSession session, UserDto user, ProjectDto project,
CeTaskMessageType ceMessageType) {
return mapper(session).selectByUserUuidAndProjectUuidAndMessageType(user.getUuid(), project.getUuid(), ceMessageType.name());
}
public List<UserDismissedMessageDto> selectByUser(DbSession session, UserDto user) {
return mapper(session).selectByUserUuid(user.getUuid());
}
public void deleteByUser(DbSession session, UserDto user) {
mapper(session).deleteByUserUuid(user.getUuid());
}
public void deleteByType(DbSession session, CeTaskMessageType type) {
mapper(session).deleteByType(type.name());
}
private static UserDismissedMessagesMapper mapper(DbSession session) {
return session.getMapper(UserDismissedMessagesMapper.class);
}
}
| 2,312 | 35.140625 | 132 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Param;
public interface UserDismissedMessagesMapper {
void insert(@Param("dto") UserDismissedMessageDto dto);
Optional<UserDismissedMessageDto> selectByUserUuidAndProjectUuidAndMessageType(@Param("userUuid") String userUuid, @Param("projectUuid") String projectUuid,
@Param("ceMessageType") String ceMessageType);
List<UserDismissedMessageDto> selectByUserUuid(@Param("userUuid") String userUuid);
void deleteByUserUuid(@Param("userUuid") String userUuid);
void deleteByType(@Param("ceMessageType") String ceMessageType);
}
| 1,501 | 38.526316 | 158 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.core.user.DefaultUser;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static java.util.Comparator.comparing;
/**
* @since 3.2
*/
public class UserDto implements UserId {
public static final char SCM_ACCOUNTS_SEPARATOR = '\n';
/** Technical unique identifier, can't be null */
private String uuid;
private String login;
private String name;
private String email;
private boolean active = true;
private String externalId;
private String externalLogin;
private String externalIdentityProvider;
// Hashed password that may be null in case of external authentication
private String cryptedPassword;
// Salt used for PBKDF2, null when bcrypt is used or for external authentication
private String salt;
// Hash method used to generate cryptedPassword, my be null in case of external authentication
private String hashMethod;
private String homepageType;
private String homepageParameter;
private boolean local = true;
private boolean resetPassword = false;
private List<String> scmAccounts = new ArrayList<>();
/**
* Date of the last time the user has accessed to the server.
* Can be null when user has never been authenticated, or has not been authenticated since the creation of the column in SonarQube 7.7.
*/
@Nullable
private Long lastConnectionDate;
/**
* Date of the last time sonarlint connected to sonarqube WSs with this user's authentication.
* Can be null when user has never been authenticated, or has not been authenticated since the creation of the column in SonarQube 8.8.
*/
@Nullable
private Long lastSonarlintConnectionDate;
private Long createdAt;
private Long updatedAt;
public String getUuid() {
return uuid;
}
public UserDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
/**
* Spaces were authorized before SQ 5.4.
* For versions 5.4+ it's not possible to create a login with a space character.
*/
public String getLogin() {
return login;
}
public UserDto setLogin(String login) {
this.login = login;
return this;
}
public String getName() {
return name;
}
public UserDto setName(String name) {
this.name = name;
return this;
}
@CheckForNull
public String getEmail() {
return email;
}
public UserDto setEmail(@Nullable String email) {
this.email = email;
return this;
}
public boolean isActive() {
return active;
}
public UserDto setActive(boolean b) {
this.active = b;
return this;
}
/**
* Used by mybatis
*/
private List<String> getScmAccounts() {
return scmAccounts;
}
public List<String> getSortedScmAccounts() {
// needs to be done when reading, as mybatis do not use the setter
return scmAccounts.stream().sorted(comparing(s -> s, CASE_INSENSITIVE_ORDER)).toList();
}
public UserDto setScmAccounts(List<String> scmAccounts) {
this.scmAccounts = scmAccounts;
return this;
}
public String getExternalId() {
return externalId;
}
public UserDto setExternalId(String externalId) {
this.externalId = externalId;
return this;
}
public String getExternalLogin() {
return externalLogin;
}
public UserDto setExternalLogin(String externalLogin) {
this.externalLogin = externalLogin;
return this;
}
public String getExternalIdentityProvider() {
return externalIdentityProvider;
}
public UserDto setExternalIdentityProvider(String externalIdentityProvider) {
this.externalIdentityProvider = externalIdentityProvider;
return this;
}
public boolean isLocal() {
return local;
}
public UserDto setLocal(boolean local) {
this.local = local;
return this;
}
@CheckForNull
public String getCryptedPassword() {
return cryptedPassword;
}
public UserDto setCryptedPassword(@Nullable String cryptedPassword) {
this.cryptedPassword = cryptedPassword;
return this;
}
@CheckForNull
public String getSalt() {
return salt;
}
public UserDto setSalt(@Nullable String salt) {
this.salt = salt;
return this;
}
@CheckForNull
public String getHashMethod() {
return hashMethod;
}
public UserDto setHashMethod(@Nullable String hashMethod) {
this.hashMethod = hashMethod;
return this;
}
@CheckForNull
public String getHomepageType() {
return homepageType;
}
public UserDto setHomepageType(@Nullable String homepageType) {
this.homepageType = homepageType;
return this;
}
@CheckForNull
public String getHomepageParameter() {
return homepageParameter;
}
public UserDto setHomepageParameter(@Nullable String homepageParameter) {
this.homepageParameter = homepageParameter;
return this;
}
public boolean isResetPassword() {
return resetPassword;
}
public UserDto setResetPassword(boolean resetPassword) {
this.resetPassword = resetPassword;
return this;
}
@CheckForNull
public Long getLastConnectionDate() {
return lastConnectionDate;
}
public UserDto setLastConnectionDate(@Nullable Long lastConnectionDate) {
this.lastConnectionDate = lastConnectionDate;
return this;
}
@CheckForNull
public Long getLastSonarlintConnectionDate() {
return lastSonarlintConnectionDate;
}
public UserDto setLastSonarlintConnectionDate(@Nullable Long lastSonarlintConnectionDate) {
this.lastSonarlintConnectionDate = lastSonarlintConnectionDate;
return this;
}
public Long getCreatedAt() {
return createdAt;
}
UserDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public Long getUpdatedAt() {
return updatedAt;
}
UserDto setUpdatedAt(long updatedAt) {
this.updatedAt = updatedAt;
return this;
}
public DefaultUser toUser() {
return new DefaultUser()
.setLogin(login)
.setName(name)
.setEmail(email)
.setActive(active);
}
}
| 6,954 | 23.489437 | 137 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Set;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.UserGroupNewValue;
public class UserGroupDao implements Dao {
private final AuditPersister auditPersister;
public UserGroupDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
}
public UserGroupDto insert(DbSession session, UserGroupDto dto, String groupName, String login) {
mapper(session).insert(dto);
auditPersister.addUserToGroup(session, new UserGroupNewValue(dto, groupName, login));
return dto;
}
public Set<String> selectUserUuidsInGroup(DbSession session, String groupUuid) {
return mapper(session).selectUserUuidsInGroup(groupUuid);
}
public void delete(DbSession session, GroupDto group, UserDto user) {
int deletedRows = mapper(session).delete(group.getUuid(), user.getUuid());
if (deletedRows > 0) {
auditPersister.deleteUserFromGroup(session, new UserGroupNewValue(group, user));
}
}
public void deleteByGroupUuid(DbSession session, String groupUuid, String groupName) {
int deletedRows = mapper(session).deleteByGroupUuid(groupUuid);
if (deletedRows > 0) {
auditPersister.deleteUserFromGroup(session, new UserGroupNewValue(groupUuid, groupName));
}
}
public void deleteByUserUuid(DbSession dbSession, UserDto userDto) {
int deletedRows = mapper(dbSession).deleteByUserUuid(userDto.getUuid());
if (deletedRows > 0) {
auditPersister.deleteUserFromGroup(dbSession, new UserGroupNewValue(userDto));
}
}
private static UserGroupMapper mapper(DbSession session) {
return session.getMapper(UserGroupMapper.class);
}
}
| 2,592 | 34.040541 | 99 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class UserGroupDto {
private String userUuid;
private String groupUuid;
public String getUserUuid() {
return userUuid;
}
public UserGroupDto setUserUuid(String userUuid) {
this.userUuid = userUuid;
return this;
}
public String getGroupUuid() {
return groupUuid;
}
public UserGroupDto setGroupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}
}
| 1,289 | 27.666667 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserGroupMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.Set;
import org.apache.ibatis.annotations.Param;
public interface UserGroupMapper {
void insert(UserGroupDto dto);
Set<String> selectUserUuidsInGroup(@Param("groupUuid") String groupUuid);
int delete(@Param("groupUuid") String groupUuid, @Param("userUuid") String userUuid);
int deleteByGroupUuid(@Param("groupUuid") String groupUuid);
int deleteByUserUuid(@Param("userUuid") String userUuid);
}
| 1,301 | 33.263158 | 87 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserId.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public interface UserId {
String getUuid();
String getLogin();
}
| 940 | 35.192308 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserIdDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import static java.util.Objects.requireNonNull;
public class UserIdDto implements UserId {
private String uuid;
private String login;
public UserIdDto(String uuid, String login) {
this.uuid = uuid;
this.login = requireNonNull(login);
}
public UserIdDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public UserIdDto setLogin(String login) {
this.login = login;
return this;
}
public String getUuid() {
return uuid;
}
public String getLogin() {
return login;
}
public static UserIdDto from(UserDto dto) {
return new UserIdDto(dto.getUuid(), dto.getLogin());
}
}
| 1,513 | 26.527273 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.ResultHandler;
import org.sonar.db.Pagination;
public interface UserMapper {
@CheckForNull
UserDto selectByUuid(String uuid);
@CheckForNull
UserDto selectByLogin(String login);
/**
* Search for a user by SCM account, login or email.
* Can return multiple results if an email is used by many users (For instance, technical account can use the same email as a none technical account)
*/
@CheckForNull
List<UserDto> selectNullableByScmAccountOrLoginOrEmail(@Param("scmAccount") String scmAccountOrLoginOrEmail);
List<UserIdDto> selectActiveUsersByScmAccountOrLoginOrEmail(@Param("scmAccount") String scmAccountOrLoginOrEmail);
/**
* Select user by login. Note that disabled users are ignored.
*/
@CheckForNull
UserDto selectUserByLogin(String login);
List<UserDto> selectUsers(@Param("query") UserQuery query, @Param("pagination") Pagination pagination);
int countByQuery(@Param("query") UserQuery query);
List<UserTelemetryDto> selectUsersForTelemetry();
List<UserDto> selectByLogins(List<String> logins);
List<UserDto> selectByUuids(List<String> uuids);
List<UserDto> selectByEmail(String email);
@CheckForNull
UserDto selectByExternalIdAndIdentityProvider(@Param("externalId") String externalId, @Param("externalIdentityProvider") String externalExternalIdentityProvider);
List<UserDto> selectByExternalIdsAndIdentityProvider(@Param("externalIds") List<String> externalIds, @Param("externalIdentityProvider") String externalExternalIdentityProvider);
@CheckForNull
UserDto selectByExternalLoginAndIdentityProvider(@Param("externalLogin") String externalLogin, @Param("externalIdentityProvider") String externalExternalIdentityProvider);
List<String> selectExternalIdentityProviders();
void scrollAll(ResultHandler<UserDto> handler);
void updateSonarlintLastConnectionDate(@Param("login") String login, @Param("now") long now);
void insert(@Param("user") UserDto userDto);
void update(@Param("user") UserDto userDto);
void deactivateUser(@Param("login") String login, @Param("now") long now);
void clearHomepages(@Param("homepageType") String type, @Param("homepageParameter") String value, @Param("now") long now);
void clearHomepage(@Param("login") String login, @Param("now") long now);
long countActiveSonarlintUsers(@Param("sinceDate") long sinceDate);
long countActiveUsers();
void insertScmAccount(@Param("userUuid") String userUuid, @Param("scmAccount") String scmAccount);
void deleteAllScmAccounts(@Param("userUuid") String userUuid);
}
| 3,565 | 36.536842 | 179 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
public class UserMembershipDto {
private String uuid;
private String groupUuid;
private String login;
private String name;
public String getUuid() {
return uuid;
}
public UserMembershipDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public String getName() {
return name;
}
public UserMembershipDto setName(String name) {
this.name = name;
return this;
}
@CheckForNull
public String getLogin() {
return login;
}
public UserMembershipDto setLogin(@Nullable String login) {
this.login = login;
return this;
}
@CheckForNull
public String getGroupUuid() {
return groupUuid;
}
public UserMembershipDto setGroupUuid(@Nullable String groupUuid) {
this.groupUuid = groupUuid;
return this;
}
}
| 1,742 | 23.9 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMembershipQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import com.google.common.collect.ImmutableSet;
import java.util.Locale;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.sonar.db.DaoUtils.buildLikeValue;
import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER;
public class UserMembershipQuery {
public static final int DEFAULT_PAGE_INDEX = 1;
public static final int DEFAULT_PAGE_SIZE = 100;
public static final String ANY = "ANY";
public static final String IN = "IN";
public static final String OUT = "OUT";
public static final Set<String> AVAILABLE_MEMBERSHIPS = ImmutableSet.of(ANY, IN, OUT);
private final String groupUuid;
private final String membership;
private final String memberSearch;
// for internal use in MyBatis
final String memberSearchSql;
final String memberSearchSqlLowercase;
// max results per page
private final int pageSize;
// index of selected page. Start with 1.
private final int pageIndex;
private UserMembershipQuery(Builder builder) {
this.groupUuid = builder.groupUuid;
this.membership = builder.membership;
this.memberSearch = builder.memberSearch;
this.memberSearchSql = memberSearch == null ? null : buildLikeValue(memberSearch, BEFORE_AND_AFTER);
this.memberSearchSqlLowercase = memberSearchSql == null ? null : memberSearchSql.toLowerCase(Locale.ENGLISH);
this.pageSize = builder.pageSize;
this.pageIndex = builder.pageIndex;
}
public String groupUuid() {
return groupUuid;
}
@CheckForNull
public String membership() {
return membership;
}
/**
* Search for users email, login and name containing a given string
*/
@CheckForNull
public String memberSearch() {
return memberSearch;
}
public int pageSize() {
return pageSize;
}
public int pageIndex() {
return pageIndex;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String groupUuid;
private String membership;
private String memberSearch;
private Integer pageIndex = DEFAULT_PAGE_INDEX;
private Integer pageSize = DEFAULT_PAGE_SIZE;
private Builder() {
}
public Builder groupUuid(String groupUuid) {
this.groupUuid = groupUuid;
return this;
}
public Builder membership(@Nullable String membership) {
this.membership = membership;
return this;
}
public Builder memberSearch(@Nullable String s) {
this.memberSearch = StringUtils.defaultIfBlank(s, null);
return this;
}
public Builder pageSize(@Nullable Integer i) {
this.pageSize = i;
return this;
}
public Builder pageIndex(@Nullable Integer i) {
this.pageIndex = i;
return this;
}
private void initMembership() {
membership = firstNonNull(membership, ANY);
checkArgument(AVAILABLE_MEMBERSHIPS.contains(membership),
"Membership is not valid (got " + membership + "). Availables values are " + AVAILABLE_MEMBERSHIPS);
}
private void initPageSize() {
pageSize = firstNonNull(pageSize, DEFAULT_PAGE_SIZE);
}
private void initPageIndex() {
pageIndex = firstNonNull(pageIndex, DEFAULT_PAGE_INDEX);
checkArgument(pageIndex > 0, "Page index must be greater than 0 (got " + pageIndex + ")");
}
public UserMembershipQuery build() {
requireNonNull(groupUuid, "Group ID cant be null.");
initMembership();
initPageIndex();
initPageSize();
return new UserMembershipQuery(this);
}
}
}
| 4,654 | 28.27673 | 113 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserQuery.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
public class UserQuery {
private final String searchText;
private final Boolean isActive;
private final String isManagedSqlClause;
private final Long lastConnectionDateFrom;
private final Long lastConnectionDateTo;
private final Long sonarLintLastConnectionDateFrom;
private final Long sonarLintLastConnectionDateTo;
private final Set<String> userUuids;
private UserQuery(UserQuery userQuery, Collection<String> userUuids) {
this.searchText = userQuery.getSearchText();
this.isActive = userQuery.isActive();
this.isManagedSqlClause = userQuery.getIsManagedSqlClause();
this.lastConnectionDateFrom = userQuery.getLastConnectionDateFrom();
this.lastConnectionDateTo = userQuery.getLastConnectionDateTo();
this.sonarLintLastConnectionDateTo = userQuery.getSonarLintLastConnectionDateTo();
this.sonarLintLastConnectionDateFrom = userQuery.getSonarLintLastConnectionDateFrom();
this.userUuids = new HashSet<>(userUuids);
}
private UserQuery(@Nullable String searchText, @Nullable Boolean isActive, @Nullable String isManagedSqlClause,
@Nullable OffsetDateTime lastConnectionDateFrom, @Nullable OffsetDateTime lastConnectionDateTo,
@Nullable OffsetDateTime sonarLintLastConnectionDateFrom, @Nullable OffsetDateTime sonarLintLastConnectionDateTo, @Nullable Set<String> userUuids) {
this.searchText = searchTextToSearchTextSql(searchText);
this.isActive = isActive;
this.isManagedSqlClause = isManagedSqlClause;
this.lastConnectionDateFrom = parseDateToLong(lastConnectionDateFrom);
this.lastConnectionDateTo = formatDateToInput(lastConnectionDateTo);
this.sonarLintLastConnectionDateFrom = parseDateToLong(sonarLintLastConnectionDateFrom);
this.sonarLintLastConnectionDateTo = formatDateToInput(sonarLintLastConnectionDateTo);
this.userUuids = userUuids;
}
public static UserQuery copyWithNewRangeOfUserUuids(UserQuery userQuery, Collection<String> userUuids) {
return new UserQuery(userQuery, userUuids);
}
private static Long formatDateToInput(@Nullable OffsetDateTime dateTo) {
if (dateTo == null) {
return null;
} else {
// add 1 second to include all timestamp at the second precision.
return dateTo.toInstant().plus(1, ChronoUnit.SECONDS).toEpochMilli();
}
}
private static Long parseDateToLong(@Nullable OffsetDateTime date) {
if (date == null) {
return null;
} else {
return date.toInstant().toEpochMilli();
}
}
private static String searchTextToSearchTextSql(@Nullable String text) {
String sql = null;
if (text != null) {
sql = StringUtils.replace(text, "%", "/%");
sql = StringUtils.replace(sql, "_", "/_");
sql = "%" + sql + "%";
}
return sql;
}
@CheckForNull
public String getSearchText() {
return searchText;
}
@CheckForNull
public Boolean isActive() {
return isActive;
}
@CheckForNull
public String getIsManagedSqlClause() {
return isManagedSqlClause;
}
@CheckForNull
public Long getLastConnectionDateFrom() {
return lastConnectionDateFrom;
}
@CheckForNull
public Long getLastConnectionDateTo() {
return lastConnectionDateTo;
}
@CheckForNull
public Long getSonarLintLastConnectionDateFrom() {
return sonarLintLastConnectionDateFrom;
}
@CheckForNull
public Long getSonarLintLastConnectionDateTo() {
return sonarLintLastConnectionDateTo;
}
@CheckForNull
public Set<String> getUserUuids() {
return userUuids;
}
public static UserQueryBuilder builder() {
return new UserQueryBuilder();
}
public static final class UserQueryBuilder {
private String searchText = null;
private Boolean isActive = null;
private String isManagedSqlClause = null;
private OffsetDateTime lastConnectionDateFrom = null;
private OffsetDateTime lastConnectionDateTo = null;
private OffsetDateTime sonarLintLastConnectionDateFrom = null;
private OffsetDateTime sonarLintLastConnectionDateTo = null;
private Set<String> userUuids = null;
private UserQueryBuilder() {
}
public UserQueryBuilder searchText(@Nullable String searchText) {
this.searchText = searchText;
return this;
}
public UserQueryBuilder isActive(@Nullable Boolean isActive) {
this.isActive = isActive;
return this;
}
public UserQueryBuilder isManagedClause(@Nullable String isManagedSqlClause) {
this.isManagedSqlClause = isManagedSqlClause;
return this;
}
public UserQueryBuilder lastConnectionDateFrom(@Nullable OffsetDateTime lastConnectionDateFrom) {
this.lastConnectionDateFrom = lastConnectionDateFrom;
return this;
}
public UserQueryBuilder lastConnectionDateTo(@Nullable OffsetDateTime lastConnectionDateTo) {
this.lastConnectionDateTo = lastConnectionDateTo;
return this;
}
public UserQueryBuilder sonarLintLastConnectionDateFrom(@Nullable OffsetDateTime sonarLintLastConnectionDateFrom) {
this.sonarLintLastConnectionDateFrom = sonarLintLastConnectionDateFrom;
return this;
}
public UserQueryBuilder sonarLintLastConnectionDateTo(@Nullable OffsetDateTime sonarLintLastConnectionDateTo) {
this.sonarLintLastConnectionDateTo = sonarLintLastConnectionDateTo;
return this;
}
public UserQueryBuilder userUuids(@Nullable Set<String> userUuids) {
this.userUuids = userUuids;
return this;
}
public UserQuery build() {
return new UserQuery(
searchText, isActive, isManagedSqlClause, lastConnectionDateFrom, lastConnectionDateTo,
sonarLintLastConnectionDateFrom, sonarLintLastConnectionDateTo, userUuids);
}
}
}
| 6,843 | 33.22 | 152 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import javax.annotation.Nullable;
public class UserTelemetryDto {
private String uuid = null;
private boolean active = true;
private String externalIdentityProvider = null;
@Nullable
private Long lastConnectionDate = null;
@Nullable
private Long lastSonarlintConnectionDate = null;
@Nullable
private String scimUuid = null;
public String getUuid() {
return uuid;
}
public UserTelemetryDto setUuid(String uuid) {
this.uuid = uuid;
return this;
}
public boolean isActive() {
return active;
}
public UserTelemetryDto setActive(boolean active) {
this.active = active;
return this;
}
public String getExternalIdentityProvider() {
return externalIdentityProvider;
}
public UserTelemetryDto setExternalIdentityProvider(String externalIdentityProvider) {
this.externalIdentityProvider = externalIdentityProvider;
return this;
}
@Nullable
public Long getLastConnectionDate() {
return lastConnectionDate;
}
public UserTelemetryDto setLastConnectionDate(@Nullable Long lastConnectionDate) {
this.lastConnectionDate = lastConnectionDate;
return this;
}
@Nullable
public Long getLastSonarlintConnectionDate() {
return lastSonarlintConnectionDate;
}
public UserTelemetryDto setLastSonarlintConnectionDate(@Nullable Long lastSonarlintConnectionDate) {
this.lastSonarlintConnectionDate = lastSonarlintConnectionDate;
return this;
}
public UserTelemetryDto setScimUuid(@Nullable String scimUuid) {
this.scimUuid = scimUuid;
return this;
}
@Nullable
public String getScimUuid() {
return scimUuid;
}
}
| 2,512 | 26.021505 | 102 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTokenCount.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
public class UserTokenCount {
private String userUuid;
private Integer tokenCount;
public String getUserUuid() {
return userUuid;
}
public UserTokenCount setUserUuid(String userUuid) {
this.userUuid = userUuid;
return this;
}
public Integer tokenCount() {
return tokenCount;
}
public UserTokenCount setTokenCount(Integer tokenCount) {
this.tokenCount = tokenCount;
return this;
}
}
| 1,301 | 28.590909 | 75 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTokenDao.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.UserTokenNewValue;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class UserTokenDao implements Dao {
private final UuidFactory uuidFactory;
private final AuditPersister auditPersister;
public UserTokenDao(UuidFactory uuidFactory, AuditPersister auditPersister) {
this.uuidFactory = uuidFactory;
this.auditPersister = auditPersister;
}
public void insert(DbSession dbSession, UserTokenDto userTokenDto, String userLogin) {
userTokenDto.setUuid(uuidFactory.create());
mapper(dbSession).insert(userTokenDto);
auditPersister.addUserToken(dbSession, new UserTokenNewValue(userTokenDto, userLogin));
}
public void update(DbSession dbSession, UserTokenDto userTokenDto, @Nullable String userLogin) {
mapper(dbSession).update(userTokenDto);
auditPersister.updateUserToken(dbSession, new UserTokenNewValue(userTokenDto, userLogin));
}
public List<UserTokenDto> selectTokensExpiredInDays(DbSession dbSession, long days){
long timestamp = LocalDate.now().plusDays(days).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli();
return mapper(dbSession).selectTokensExpiredOnDate(timestamp);
}
public void updateWithoutAudit(DbSession dbSession, UserTokenDto userTokenDto) {
mapper(dbSession).update(userTokenDto);
}
@CheckForNull
public UserTokenDto selectByTokenHash(DbSession dbSession, String tokenHash) {
return mapper(dbSession).selectByTokenHash(tokenHash);
}
@CheckForNull
public UserTokenDto selectByUserAndName(DbSession dbSession, UserDto user, String name) {
return mapper(dbSession).selectByUserUuidAndName(user.getUuid(), name);
}
public List<UserTokenDto> selectByUser(DbSession dbSession, UserDto user) {
return mapper(dbSession).selectByUserUuid(user.getUuid());
}
public Map<String, Integer> countTokensByUsers(DbSession dbSession, Collection<UserDto> users) {
Map<String, Integer> result = new HashMap<>(users.size());
executeLargeInputs(
users.stream().map(UserDto::getUuid).toList(),
input -> {
List<UserTokenCount> userTokenCounts = mapper(dbSession).countTokensByUserUuids(input);
for (UserTokenCount userTokenCount : userTokenCounts) {
result.put(userTokenCount.getUserUuid(), userTokenCount.tokenCount());
}
return userTokenCounts;
});
return result;
}
public void deleteByUser(DbSession dbSession, UserDto user) {
int deletedRows = mapper(dbSession).deleteByUserUuid(user.getUuid());
if (deletedRows > 0) {
auditPersister.deleteUserToken(dbSession, new UserTokenNewValue(user));
}
}
public void deleteByUserAndName(DbSession dbSession, UserDto user, String name) {
int deletedRows = mapper(dbSession).deleteByUserUuidAndName(user.getUuid(), name);
if (deletedRows > 0) {
auditPersister.deleteUserToken(dbSession, new UserTokenNewValue(user, name));
}
}
public void deleteByProjectUuid(DbSession dbSession, String projectKey, String projectUuid) {
int deletedRows = mapper(dbSession).deleteByProjectUuid(projectUuid);
if (deletedRows > 0) {
auditPersister.deleteUserToken(dbSession, new UserTokenNewValue(projectKey));
}
}
private static UserTokenMapper mapper(DbSession dbSession) {
return dbSession.getMapper(UserTokenMapper.class);
}
}
| 4,604 | 36.137097 | 108 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTokenDto.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import static org.sonar.db.user.UserTokenValidator.checkTokenHash;
public class UserTokenDto {
private String uuid;
private String userUuid;
private String name;
private String tokenHash;
/**
* Date of the last time this token has been used.
* Can be null when user has never been used it.
*/
private Long lastConnectionDate;
private Long createdAt;
private String projectKey;
private String type;
private Long expirationDate;
private String projectName;
private String projectUuid;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getUserUuid() {
return userUuid;
}
public UserTokenDto setUserUuid(String userUuid) {
this.userUuid = userUuid;
return this;
}
public String getName() {
return name;
}
public UserTokenDto setName(String name) {
this.name = name;
return this;
}
public String getTokenHash() {
return tokenHash;
}
public UserTokenDto setTokenHash(String tokenHash) {
this.tokenHash = checkTokenHash(tokenHash);
return this;
}
@CheckForNull
public Long getLastConnectionDate() {
return lastConnectionDate;
}
public UserTokenDto setLastConnectionDate(@Nullable Long lastConnectionDate) {
this.lastConnectionDate = lastConnectionDate;
return this;
}
public Long getCreatedAt() {
return createdAt;
}
public UserTokenDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public String getProjectKey() {
return projectKey;
}
public UserTokenDto setProjectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}
public String getType() {
return type;
}
public UserTokenDto setType(String type) {
this.type = type;
return this;
}
public Long getExpirationDate() {
return expirationDate;
}
public UserTokenDto setExpirationDate(@Nullable Long expirationDate) {
this.expirationDate = expirationDate;
return this;
}
@CheckForNull
public String getProjectName() {
return projectName;
}
public UserTokenDto setProjectName(@Nullable String projectName) {
this.projectName = projectName;
return this;
}
public String getProjectUuid() {
return projectUuid;
}
public UserTokenDto setProjectUuid(@Nullable String projectUuid) {
this.projectUuid = projectUuid;
return this;
}
public boolean isExpired() {
return (this.expirationDate != null && this.getExpirationDate() < System.currentTimeMillis());
}
}
| 3,534 | 21.660256 | 98 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTokenMapper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface UserTokenMapper {
void insert(UserTokenDto userToken);
void update(UserTokenDto userToken);
UserTokenDto selectByTokenHash(String tokenHash);
UserTokenDto selectByUserUuidAndName(@Param("userUuid") String userUuid, @Param("name") String name);
List<UserTokenDto> selectByUserUuid(String userUuid);
int deleteByUserUuid(String userUuid);
int deleteByUserUuidAndName(@Param("userUuid") String userUuid, @Param("name") String name);
int deleteByProjectUuid(@Param("projectUuid") String projectUuid);
List<UserTokenCount> countTokensByUserUuids(@Param("userUuids") List<String> userUuids);
List<UserTokenDto> selectTokensExpiredOnDate(@Param("timestamp") long timestamp);
}
| 1,657 | 33.541667 | 103 | java |
sonarqube | sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTokenValidator.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db.user;
import static com.google.common.base.Preconditions.checkState;
public class UserTokenValidator {
private static final int MAX_TOKEN_HASH_LENGTH = 255;
private UserTokenValidator() {
// utility methods
}
static String checkTokenHash(String hash) {
checkState(hash.length() <= MAX_TOKEN_HASH_LENGTH, "Token hash length (%s) is longer than the maximum authorized (%s)", hash.length(), MAX_TOKEN_HASH_LENGTH);
return hash;
}
}
| 1,319 | 35.666667 | 162 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.