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/SQXMLMapperBuilder.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; import java.io.InputStream; import java.util.Map; import org.apache.ibatis.builder.xml.XMLMapperBuilder; import org.apache.ibatis.parsing.XNode; import org.apache.ibatis.session.Configuration; /** * Subclass of {@link XMLMapperBuilder} which fixes the fact that {@link XMLMapperBuilder} does not support loading * Mapper interfaces which belongs to the ClassLoader of a plugin. */ public class SQXMLMapperBuilder extends XMLMapperBuilder { private final Class<?> mapperType; public SQXMLMapperBuilder(Class<?> mapperType, InputStream inputStream, Configuration configuration, Map<String, XNode> sqlFragments) { super(inputStream, configuration, mapperType.getName(), sqlFragments); this.mapperType = mapperType; } @Override public void parse() { if (!configuration.isResourceLoaded(mapperType.getName())) { super.parse(); retryBindMapperForNamespace(); } super.parse(); } private void retryBindMapperForNamespace() { if (!configuration.hasMapper(mapperType)) { // Spring may not know the real resource name so we set a flag // to prevent loading again this resource from the mapper interface // look at MapperAnnotationBuilder#loadXmlResource configuration.addLoadedResource("namespace:" + mapperType.getName()); configuration.addMapper(mapperType); } } }
2,216
35.95
137
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/StartMyBatis.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; import org.sonar.api.Startable; /* * The only purpose of this class is to start MyBatis. * MyBatis is not Startable because in the unit tests it's cached and added to the container, and in that situation we don't want it to be started. */ public class StartMyBatis implements Startable { private final MyBatis myBatis; public StartMyBatis(MyBatis myBatis) { this.myBatis = myBatis; } public void start() { myBatis.start(); } public void stop() { // nothing to do } }
1,366
30.790698
147
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/WildcardPosition.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; public enum WildcardPosition { BEFORE, AFTER, BEFORE_AND_AFTER }
933
36.36
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/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; import javax.annotation.ParametersAreNonnullByDefault;
953
37.16
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/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.alm; import javax.annotation.ParametersAreNonnullByDefault;
957
37.32
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDao.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.alm.pat; import java.util.Optional; 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.DbSession; import org.sonar.db.alm.setting.AlmSettingDto; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.PersonalAccessTokenNewValue; import org.sonar.db.user.UserDto; public class AlmPatDao implements Dao { private final System2 system2; private final UuidFactory uuidFactory; private final AuditPersister auditPersister; public AlmPatDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) { this.system2 = system2; this.uuidFactory = uuidFactory; this.auditPersister = auditPersister; } private static AlmPatMapper getMapper(DbSession dbSession) { return dbSession.getMapper(AlmPatMapper.class); } public Optional<AlmPatDto> selectByUuid(DbSession dbSession, String uuid) { return Optional.ofNullable(getMapper(dbSession).selectByUuid(uuid)); } public Optional<AlmPatDto> selectByUserAndAlmSetting(DbSession dbSession, String userUuid, AlmSettingDto almSettingDto) { return Optional.ofNullable(getMapper(dbSession).selectByUserAndAlmSetting(userUuid, almSettingDto.getUuid())); } public void insert(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) { String uuid = uuidFactory.create(); long now = system2.now(); almPatDto.setUuid(uuid); almPatDto.setCreatedAt(now); almPatDto.setUpdatedAt(now); getMapper(dbSession).insert(almPatDto); auditPersister.addPersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey)); } public void update(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) { long now = system2.now(); almPatDto.setUpdatedAt(now); getMapper(dbSession).update(almPatDto); auditPersister.updatePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey)); } public void delete(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) { int deletedRows = getMapper(dbSession).deleteByUuid(almPatDto.getUuid()); if (deletedRows > 0) { auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey)); } } public void deleteByUser(DbSession dbSession, UserDto user) { int deletedRows = getMapper(dbSession).deleteByUser(user.getUuid()); if (deletedRows > 0) { auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(user)); } } public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) { int deletedRows = getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid()); if (deletedRows > 0) { auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almSetting)); } } }
3,921
39.854167
128
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDto.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.alm.pat; public class AlmPatDto { private String uuid; private String personalAccessToken; private String userUuid; private String almSettingUuid; private long updatedAt; private long createdAt; public String getAlmSettingUuid() { return almSettingUuid; } public AlmPatDto setAlmSettingUuid(String almSettingUuid) { this.almSettingUuid = almSettingUuid; return this; } public String getUuid() { return uuid; } void setUuid(String uuid) { this.uuid = uuid; } public String getUserUuid() { return userUuid; } public AlmPatDto setUserUuid(String userUuid) { this.userUuid = userUuid; return this; } public String getPersonalAccessToken() { return personalAccessToken; } public AlmPatDto setPersonalAccessToken(String personalAccessToken) { this.personalAccessToken = personalAccessToken; return this; } public long getUpdatedAt() { return updatedAt; } public void setUpdatedAt(long updatedAt) { this.updatedAt = updatedAt; } public long getCreatedAt() { return createdAt; } public void setCreatedAt(long createdAt) { this.createdAt = createdAt; } }
2,045
23.650602
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatMapper.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.alm.pat; import javax.annotation.CheckForNull; import org.apache.ibatis.annotations.Param; public interface AlmPatMapper { @CheckForNull AlmPatDto selectByUuid(@Param("uuid") String uuid); @CheckForNull AlmPatDto selectByUserAndAlmSetting(@Param("userUuid") String userUuid, @Param("almSettingUuid") String almSettingUuid); void insert(@Param("dto") AlmPatDto almPatDto); void update(@Param("dto") AlmPatDto almPatDto); int deleteByUuid(@Param("uuid") String uuid); int deleteByUser(@Param("userUuid") String userUuid); int deleteByAlmSetting(@Param("almSettingUuid") String almSettingUuid); }
1,485
33.55814
122
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/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.alm.pat; import javax.annotation.ParametersAreNonnullByDefault;
961
37.48
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ALM.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.alm.setting; import java.util.Locale; public enum ALM { GITHUB, BITBUCKET, BITBUCKET_CLOUD, AZURE_DEVOPS, GITLAB; public static ALM fromId(String almId) { return ALM.valueOf(almId.toUpperCase(Locale.ENGLISH)); } public String getId() { return this.name().toLowerCase(Locale.ENGLISH); } }
1,182
29.333333
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDao.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.alm.setting; import java.util.List; 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; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue; import org.sonar.db.audit.model.SecretNewValue; public class AlmSettingDao implements Dao { private final System2 system2; private final UuidFactory uuidFactory; private final AuditPersister auditPersister; public AlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) { this.system2 = system2; this.uuidFactory = uuidFactory; this.auditPersister = auditPersister; } private static AlmSettingMapper getMapper(DbSession dbSession) { return dbSession.getMapper(AlmSettingMapper.class); } public void insert(DbSession dbSession, AlmSettingDto almSettingDto) { String uuid = uuidFactory.create(); long now = system2.now(); almSettingDto.setUuid(uuid); almSettingDto.setCreatedAt(now); almSettingDto.setUpdatedAt(now); getMapper(dbSession).insert(almSettingDto); auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto)); } public Optional<AlmSettingDto> selectByUuid(DbSession dbSession, String uuid) { return Optional.ofNullable(getMapper(dbSession).selectByUuid(uuid)); } public Optional<AlmSettingDto> selectByKey(DbSession dbSession, String key) { return Optional.ofNullable(getMapper(dbSession).selectByKey(key)); } public Optional<AlmSettingDto> selectByAlmAndAppId(DbSession dbSession, ALM alm, String appId) { return selectByAlm(dbSession, alm) .stream() .filter(almSettingDto -> appId.equals(almSettingDto.getAppId())) .findAny(); } public List<AlmSettingDto> selectByAlm(DbSession dbSession, ALM alm) { return getMapper(dbSession).selectByAlm(alm.getId()); } public List<AlmSettingDto> selectAll(DbSession dbSession) { return getMapper(dbSession).selectAll(); } public void delete(DbSession dbSession, AlmSettingDto almSettingDto) { int deletedRows = getMapper(dbSession).deleteByKey(almSettingDto.getKey()); if (deletedRows > 0) { auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(), almSettingDto.getKey())); } } public void update(DbSession dbSession, AlmSettingDto almSettingDto, boolean updateSecret) { long now = system2.now(); almSettingDto.setUpdatedAt(now); getMapper(dbSession).update(almSettingDto); if (updateSecret) { auditPersister.updateDevOpsPlatformSecret(dbSession, new SecretNewValue("DevOpsPlatform", almSettingDto.getRawAlm())); } auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto)); } }
3,757
36.58
144
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.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.alm.setting; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.config.internal.Encryption; import static com.google.common.base.Strings.isNullOrEmpty; public class AlmSettingDto { /** * Not empty. Max size is 40. Obviously it is unique. */ private String uuid; /** * Non-empty and unique functional key. Max size is 40. */ private String key; /** * Identifier of the ALM, like 'bitbucketcloud' or 'github', can't be null. Max size is 40. * Note that the db column is named alm_id. * * @see org.sonar.db.alm.setting.ALM for the list of available values */ private String rawAlm; /** * URL of the ALM. Max size is 2000. * This column will only be fed when alm is GitHub or Bitbucket. * It will be null when the ALM is Azure DevOps. */ private String url; /** * Application ID of the GitHub instance. Max size is 80. * This column will only be fed when alm is GitHub. * It will be null when the ALM is Azure DevOps or Bitbucket. */ private String appId; /** * Application private key of the GitHub instance. Max size is 2000. * This column will only be fed when alm is GitHub. * It will be null when the ALM is Azure DevOps or Bitbucket. */ private String privateKey; /** * Personal access token of the Azure DevOps / Bitbucket instance. Max size is 2000. * This column will only be fed when alm is Azure DevOps or Bitbucket. * It will be null when the ALM is GitHub. */ private String personalAccessToken; /** * Application client Id of the GitHub instance. Max size is 40. * This column will only be fed when alm is GitHub. * It will be null when the ALM is Azure DevOps or Bitbucket. */ private String clientId; /** * Application client secret of the GitHub instance. Max size is 80. * This column will only be fed when alm is GitHub. * It will be null when the ALM is Azure DevOps or Bitbucket. */ private String clientSecret; /** * Webhook secret of the GitHub instance. Max size is 160. * This column will only be fed when alm is GitHub. * It will be null when the ALM is Azure DevOps or Bitbucket. */ private String webhookSecret; private long updatedAt; private long createdAt; public String getUuid() { return uuid; } AlmSettingDto setUuid(String uuid) { this.uuid = uuid; return this; } public String getKey() { return key; } public AlmSettingDto setKey(String key) { this.key = key; return this; } public ALM getAlm() { return ALM.fromId(rawAlm); } public AlmSettingDto setAlm(ALM alm) { rawAlm = alm.getId(); return this; } public String getRawAlm() { return rawAlm; } public AlmSettingDto setRawAlm(String rawAlm) { this.rawAlm = rawAlm; return this; } @CheckForNull public String getUrl() { return url; } public AlmSettingDto setUrl(@Nullable String url) { this.url = url; return this; } @CheckForNull public String getAppId() { return appId; } public AlmSettingDto setAppId(@Nullable String appId) { this.appId = appId; return this; } @CheckForNull public String getDecryptedPrivateKey(Encryption encryption) { if (!isNullOrEmpty(privateKey) && encryption.isEncrypted(privateKey)) { return encryption.decrypt(privateKey); } return privateKey; } public AlmSettingDto setPrivateKey(@Nullable String privateKey) { this.privateKey = privateKey; return this; } @CheckForNull public String getDecryptedPersonalAccessToken(Encryption encryption) { if (!isNullOrEmpty(personalAccessToken) && encryption.isEncrypted(personalAccessToken)) { return encryption.decrypt(personalAccessToken); } return personalAccessToken; } public AlmSettingDto setPersonalAccessToken(@Nullable String personalAccessToken) { this.personalAccessToken = personalAccessToken; return this; } @CheckForNull public String getClientId() { return clientId; } public AlmSettingDto setClientId(@Nullable String clientId) { this.clientId = clientId; return this; } @CheckForNull public String getDecryptedClientSecret(Encryption encryption) { if (!isNullOrEmpty(clientSecret) && encryption.isEncrypted(clientSecret)) { return encryption.decrypt(clientSecret); } return clientSecret; } public AlmSettingDto setClientSecret(@Nullable String clientSecret) { this.clientSecret = clientSecret; return this; } @CheckForNull public String getDecryptedWebhookSecret(Encryption encryption) { if (!isNullOrEmpty(webhookSecret) && encryption.isEncrypted(webhookSecret)) { return encryption.decrypt(webhookSecret); } return webhookSecret; } public AlmSettingDto setWebhookSecret(@Nullable String webhookSecret) { this.webhookSecret = webhookSecret; return this; } public long getUpdatedAt() { return updatedAt; } void setUpdatedAt(long updatedAt) { this.updatedAt = updatedAt; } public long getCreatedAt() { return createdAt; } void setCreatedAt(long createdAt) { this.createdAt = createdAt; } }
6,078
25.090129
93
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingMapper.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.alm.setting; import java.util.List; import javax.annotation.CheckForNull; import org.apache.ibatis.annotations.Param; public interface AlmSettingMapper { @CheckForNull AlmSettingDto selectByUuid(@Param("uuid") String uuid); @CheckForNull AlmSettingDto selectByKey(@Param("key") String key); List<AlmSettingDto> selectByAlm(String alm); List<AlmSettingDto> selectAll(); void insert(@Param("dto") AlmSettingDto almSettingDto); void update(@Param("dto") AlmSettingDto almSettingDto); int deleteByKey(@Param("key") String key); }
1,418
30.533333
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmKeyAndProject.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.alm.setting; public class ProjectAlmKeyAndProject { private String projectUuid; private String almId; private String url; public ProjectAlmKeyAndProject() { // keep empty } public String getProjectUuid() { return projectUuid; } public ProjectAlmKeyAndProject setProjectUuid(String projectUuid) { this.projectUuid = projectUuid; return this; } public String getAlmId() { return almId; } public ProjectAlmKeyAndProject setAlmId(String almId) { this.almId = almId; return this; } public String getUrl() { return url; } public ProjectAlmKeyAndProject setUrl(String url) { this.url = url; return this; } }
1,548
25.254237
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.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.alm.setting; import java.util.List; import java.util.Optional; import java.util.Set; 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.audit.AuditPersister; import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue; import org.sonar.db.project.ProjectDto; import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class ProjectAlmSettingDao implements Dao { private final System2 system2; private final UuidFactory uuidFactory; private final AuditPersister auditPersister; public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) { this.system2 = system2; this.uuidFactory = uuidFactory; this.auditPersister = auditPersister; } public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto, String key, String projectName, String projectKey) { String uuid = uuidFactory.create(); long now = system2.now(); ProjectAlmSettingMapper mapper = getMapper(dbSession); boolean isUpdate = true; if (mapper.update(projectAlmSettingDto, now) == 0) { mapper.insert(projectAlmSettingDto, uuid, now); projectAlmSettingDto.setUuid(uuid); projectAlmSettingDto.setCreatedAt(now); isUpdate = false; } projectAlmSettingDto.setUpdatedAt(now); DevOpsPlatformSettingNewValue value = new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, projectName, projectKey); if (isUpdate) { auditPersister.updateDevOpsPlatformSetting(dbSession, value); } else { auditPersister.addDevOpsPlatformSetting(dbSession, value); } } public void deleteByProject(DbSession dbSession, ProjectDto project) { int deletedRows = getMapper(dbSession).deleteByProjectUuid(project.getUuid()); if (deletedRows > 0) { auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(project)); } } public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) { getMapper(dbSession).deleteByAlmSettingUuid(almSetting.getUuid()); } public int countByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) { return getMapper(dbSession).countByAlmSettingUuid(almSetting.getUuid()); } public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, ProjectDto project) { return selectByProject(dbSession, project.getUuid()); } public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, String projectUuid) { return Optional.ofNullable(getMapper(dbSession).selectByProjectUuid(projectUuid)); } private static ProjectAlmSettingMapper getMapper(DbSession dbSession) { return dbSession.getMapper(ProjectAlmSettingMapper.class); } public List<ProjectAlmSettingDto> selectByAlmSettingAndSlugs(DbSession dbSession, AlmSettingDto almSettingDto, Set<String> almSlugs) { return executeLargeInputs(almSlugs, slugs -> getMapper(dbSession).selectByAlmSettingAndSlugs(almSettingDto.getUuid(), slugs)); } public List<ProjectAlmSettingDto> selectByAlmSettingAndRepos(DbSession dbSession, AlmSettingDto almSettingDto, Set<String> almRepos) { return executeLargeInputs(almRepos, repos -> getMapper(dbSession).selectByAlmSettingAndRepos(almSettingDto.getUuid(), repos)); } public List<ProjectAlmKeyAndProject> selectAlmTypeAndUrlByProject(DbSession dbSession) { return getMapper(dbSession).selectAlmTypeAndUrlByProject(); } }
4,387
39.256881
145
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDto.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.alm.setting; import javax.annotation.CheckForNull; import javax.annotation.Nullable; public class ProjectAlmSettingDto { /** * Not empty. Max size is 40. Obviously it is unique. */ private String uuid; /** * Non-null UUID of project. Max size is 40. * @see org.sonar.db.entity.EntityDto#getUuid() */ private String projectUuid; /** * Non-null UUID of the ALM Setting UUID. Max size is 40. * @see AlmSettingDto#getUuid() */ private String almSettingUuid; /** * Identifier of the repository in the ALM. Max size is 256. * This column will only be fed when alm is GitHub or Bitbucket. * It will be null when the ALM is Azure DevOps. */ private String almRepo; /** * Slug of the repository in the ALM. Max size is 256. * This column will only be fed when alm is Bitbucket. * It will be null when the ALM is Azure DevOps, or GitHub. */ private String almSlug; /** * Boolean flag which enable/disable inserting summary of analysis as a comment * It will be null when the ALM is other than GitHub */ private Boolean summaryCommentEnabled; /** * Boolean to know if this SonarQube project is part of a monorepo * default value is false */ private Boolean monorepo; private long updatedAt; private long createdAt; String getUuid() { return uuid; } void setUuid(String uuid) { this.uuid = uuid; } public String getProjectUuid() { return projectUuid; } public ProjectAlmSettingDto setProjectUuid(String projectUuid) { this.projectUuid = projectUuid; return this; } public String getAlmSettingUuid() { return almSettingUuid; } public ProjectAlmSettingDto setAlmSettingUuid(String almSettingUuid) { this.almSettingUuid = almSettingUuid; return this; } @CheckForNull public String getAlmRepo() { return almRepo; } public ProjectAlmSettingDto setAlmRepo(@Nullable String almRepo) { this.almRepo = almRepo; return this; } @CheckForNull public String getAlmSlug() { return almSlug; } public ProjectAlmSettingDto setAlmSlug(@Nullable String almSlug) { this.almSlug = almSlug; return this; } public Boolean getSummaryCommentEnabled() { return summaryCommentEnabled; } public ProjectAlmSettingDto setSummaryCommentEnabled(@Nullable Boolean summaryCommentEnabled) { this.summaryCommentEnabled = summaryCommentEnabled; return this; } public Boolean getMonorepo() { return monorepo; } public ProjectAlmSettingDto setMonorepo(Boolean monorepo) { this.monorepo = monorepo; return this; } long getUpdatedAt() { return updatedAt; } void setUpdatedAt(long updatedAt) { this.updatedAt = updatedAt; } long getCreatedAt() { return createdAt; } void setCreatedAt(long createdAt) { this.createdAt = createdAt; } }
3,742
23.464052
97
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.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.alm.setting; import java.util.List; import javax.annotation.CheckForNull; import org.apache.ibatis.annotations.Param; public interface ProjectAlmSettingMapper { @CheckForNull ProjectAlmSettingDto selectByProjectUuid(@Param("projectUuid") String projectUuid); int countByAlmSettingUuid(@Param("almSettingUuid") String almSettingUuid); void insert(@Param("dto") ProjectAlmSettingDto projectAlmSettingDto, @Param("uuid") String uuid, @Param("now") long now); int update(@Param("dto") ProjectAlmSettingDto projectAlmSettingDto, @Param("now") long now); int deleteByProjectUuid(@Param("projectUuid") String projectUuid); void deleteByAlmSettingUuid(@Param("almSettingUuid") String almSettingUuid); List<ProjectAlmSettingDto> selectByAlmSettingAndSlugs(@Param("almSettingUuid") String almSettingUuid, @Param("slugs") List<String> slugs); List<ProjectAlmSettingDto> selectByAlmSettingAndRepos(@Param("almSettingUuid") String almSettingUuid, @Param("repos") List<String> repos); List<ProjectAlmKeyAndProject> selectAlmTypeAndUrlByProject(); }
1,929
40.956522
140
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/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.alm.setting; import javax.annotation.ParametersAreNonnullByDefault;
965
37.64
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditDao.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.audit; import java.util.List; 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.Pagination; import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE; public class AuditDao implements Dao { public static final int DEFAULT_PAGE_SIZE = 10000; public static final String EXCEEDED_LENGTH = "{ \"valueLengthExceeded\": true }"; private final UuidFactory uuidFactory; private final System2 system2; public AuditDao(System2 system2, UuidFactory uuidFactory) { this.system2 = system2; this.uuidFactory = uuidFactory; } private static AuditMapper getMapper(DbSession dbSession) { return dbSession.getMapper(AuditMapper.class); } public List<AuditDto> selectByPeriodPaginated(DbSession dbSession, long start, long end, int page) { return getMapper(dbSession).selectByPeriodPaginated(start, end, Pagination.forPage(page).andSize(DEFAULT_PAGE_SIZE)); } public void insert(DbSession dbSession, AuditDto auditDto) { if (auditDto.getUuid() == null) { auditDto.setUuid(uuidFactory.create()); } if (auditDto.getCreatedAt() == 0) { long now = system2.now(); auditDto.setCreatedAt(now); } if (auditDto.getNewValue().length() > MAX_SIZE) { auditDto.setNewValue(EXCEEDED_LENGTH); } getMapper(dbSession).insert(auditDto); } public List<AuditDto> selectOlderThan(DbSession dbSession, long beforeTimestamp) { return getMapper(dbSession).selectOlderThan(beforeTimestamp); } public long deleteBefore(DbSession dbSession, long threshold) { List<String> uuids = getMapper(dbSession).selectUuidsOlderThan(threshold); DatabaseUtils.executeLargeInputsWithoutOutput(uuids, list -> { getMapper(dbSession).purgeUuids(list); dbSession.commit(); }); return uuids.size(); } }
2,809
33.691358
121
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditDto.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.audit; import javax.annotation.Nullable; public class AuditDto { private String uuid; private String userUuid; private String userLogin; private boolean userTriggered; private String category; private String operation; private String newValue; private long createdAt; public String getUuid() { return uuid; } public void setUuid(String uuid) { this.uuid = uuid; } public String getUserUuid() { return userUuid; } public void setUserUuid(@Nullable String userUuid) { this.userUuid = userUuid; } public String getUserLogin() { return userLogin; } public void setUserLogin(@Nullable String userLogin) { this.userLogin = userLogin; } public boolean isUserTriggered() { return userTriggered; } public void setUserTriggered(boolean userTriggered) { this.userTriggered = userTriggered; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } public String getOperation() { return operation; } public void setOperation(String operation) { this.operation = operation; } public String getNewValue() { return newValue; } public void setNewValue(String newValue) { this.newValue = newValue; } public long getCreatedAt() { return createdAt; } public void setCreatedAt(long createdAt) { this.createdAt = createdAt; } }
2,298
22.222222
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditMapper.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.audit; import java.util.Collection; import java.util.List; import org.apache.ibatis.annotations.Param; import org.sonar.db.Pagination; public interface AuditMapper { void insert(@Param("dto") AuditDto auditDto); List<AuditDto> selectByPeriodPaginated(@Param("start")long start, @Param("end") long end, @Param("pagination") Pagination pagination); List<AuditDto> selectOlderThan(@Param("beforeTimestamp") long beforeTimestamp); List<String> selectUuidsOlderThan(@Param("beforeTimestamp") long beforeTimestamp); void purgeUuids(@Param("uuids") Collection<String> uuids); }
1,452
36.25641
136
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditPersister.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.audit; import org.sonar.core.extension.PlatformLevel; import org.sonar.db.DbSession; import org.sonar.db.audit.model.AbstractEditorNewValue; import org.sonar.db.audit.model.ComponentKeyNewValue; import org.sonar.db.audit.model.ComponentNewValue; import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue; import org.sonar.db.audit.model.GroupPermissionNewValue; import org.sonar.db.audit.model.LicenseNewValue; import org.sonar.db.audit.model.PermissionTemplateNewValue; import org.sonar.db.audit.model.PersonalAccessTokenNewValue; import org.sonar.db.audit.model.PluginNewValue; import org.sonar.db.audit.model.ProjectBadgeTokenNewValue; import org.sonar.db.audit.model.PropertyNewValue; import org.sonar.db.audit.model.SecretNewValue; import org.sonar.db.audit.model.UserGroupNewValue; import org.sonar.db.audit.model.UserNewValue; import org.sonar.db.audit.model.UserPermissionNewValue; import org.sonar.db.audit.model.UserTokenNewValue; import org.sonar.db.audit.model.WebhookNewValue; @PlatformLevel(1) public interface AuditPersister { void addUserGroup(DbSession dbSession, UserGroupNewValue newValue); void updateUserGroup(DbSession dbSession, UserGroupNewValue newValue); void deleteUserGroup(DbSession dbSession, UserGroupNewValue newValue); void addUser(DbSession dbSession, UserNewValue newValue); void updateUser(DbSession dbSession, UserNewValue newValue); void updateUserPassword(DbSession dbSession, SecretNewValue newValue); void updateWebhookSecret(DbSession dbSession, SecretNewValue newValue); void updateDevOpsPlatformSecret(DbSession dbSession, SecretNewValue newValue); void deactivateUser(DbSession dbSession, UserNewValue newValue); void addUserToGroup(DbSession dbSession, UserGroupNewValue newValue); void deleteUserFromGroup(DbSession dbSession, UserGroupNewValue newValue); void addProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty); void updateProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty); void deleteProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty); void addUserToken(DbSession dbSession, UserTokenNewValue newValue); void addProjectBadgeToken(DbSession dbSession, ProjectBadgeTokenNewValue newValue); void updateProjectBadgeToken(DbSession session, ProjectBadgeTokenNewValue projectBadgeTokenNewValue); void updateUserToken(DbSession dbSession, UserTokenNewValue newValue); void deleteUserToken(DbSession dbSession, UserTokenNewValue newValue); void addGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue); void deleteGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue); void addUserPermission(DbSession dbSession, UserPermissionNewValue newValue); void deleteUserPermission(DbSession dbSession, UserPermissionNewValue newValue); void addPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void updatePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void deletePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void addUserToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void deleteUserFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void addGroupToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void deleteGroupFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void addQualityGateEditor(DbSession dbSession, AbstractEditorNewValue newValue); void deleteQualityGateEditor(DbSession dbSession, AbstractEditorNewValue newValue); void addQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue); void deleteQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue); void addCharacteristicToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void updateCharacteristicInPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue); void addPlugin(DbSession dbSession, PluginNewValue newValue); void updatePlugin(DbSession dbSession, PluginNewValue newValue); void generateSecretKey(DbSession dbSession); void setLicense(DbSession dbSession, boolean isSet, LicenseNewValue newValue); void addWebhook(DbSession dbSession, WebhookNewValue newValue); void updateWebhook(DbSession dbSession, WebhookNewValue newValue); void deleteWebhook(DbSession dbSession, WebhookNewValue newValue); void addDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue); void updateDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue); void deleteDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue); void addPersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue); void updatePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue); void deletePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue); boolean isTrackedProperty(String propertyKey); void addComponent(DbSession dbSession, ComponentNewValue newValue); void deleteComponent(DbSession dbSession, ComponentNewValue newValue); void updateComponent(DbSession dbSession, ComponentNewValue newValue); void updateComponentVisibility(DbSession session, ComponentNewValue componentNewValue); void componentKeyUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier); void componentKeyBranchUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier); }
6,587
40.696203
112
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/NoOpAuditPersister.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.audit; import javax.annotation.Priority; import org.sonar.db.DbSession; import org.sonar.db.audit.model.ComponentKeyNewValue; import org.sonar.db.audit.model.ComponentNewValue; import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue; import org.sonar.db.audit.model.AbstractEditorNewValue; import org.sonar.db.audit.model.GroupPermissionNewValue; import org.sonar.db.audit.model.LicenseNewValue; import org.sonar.db.audit.model.PermissionTemplateNewValue; import org.sonar.db.audit.model.PersonalAccessTokenNewValue; import org.sonar.db.audit.model.PluginNewValue; import org.sonar.db.audit.model.ProjectBadgeTokenNewValue; import org.sonar.db.audit.model.PropertyNewValue; import org.sonar.db.audit.model.SecretNewValue; import org.sonar.db.audit.model.UserGroupNewValue; import org.sonar.db.audit.model.UserNewValue; import org.sonar.db.audit.model.UserPermissionNewValue; import org.sonar.db.audit.model.UserTokenNewValue; import org.sonar.db.audit.model.WebhookNewValue; @Priority(2) public class NoOpAuditPersister implements AuditPersister { @Override public void addUserGroup(DbSession dbSession, UserGroupNewValue newValue) { // no op } @Override public void updateUserGroup(DbSession dbSession, UserGroupNewValue newValue) { // no op } @Override public void deleteUserGroup(DbSession dbSession, UserGroupNewValue newValue) { // no op } @Override public void addUser(DbSession dbSession, UserNewValue newValue) { // no op } @Override public void updateUser(DbSession dbSession, UserNewValue newValue) { // no op } @Override public void updateUserPassword(DbSession dbSession, SecretNewValue newValue) { // no op } @Override public void updateWebhookSecret(DbSession dbSession, SecretNewValue newValue) { // no op } @Override public void updateDevOpsPlatformSecret(DbSession dbSession, SecretNewValue newValue) { // no op } @Override public void deactivateUser(DbSession dbSession, UserNewValue newValue) { // no op } @Override public void addUserToGroup(DbSession dbSession, UserGroupNewValue newValue) { // no op } @Override public void deleteUserFromGroup(DbSession dbSession, UserGroupNewValue newValue) { // no op } @Override public void addProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty) { // no op } @Override public void updateProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty) { // no op } @Override public void deleteProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty) { // no op } @Override public void addUserToken(DbSession dbSession, UserTokenNewValue newValue) { // no op } @Override public void addProjectBadgeToken(DbSession dbSession, ProjectBadgeTokenNewValue newValue) { // no op } @Override public void updateProjectBadgeToken(DbSession session, ProjectBadgeTokenNewValue projectBadgeTokenNewValue) { // no op } @Override public void updateUserToken(DbSession dbSession, UserTokenNewValue newValue) { // no op } @Override public void deleteUserToken(DbSession dbSession, UserTokenNewValue newValue) { // no op } @Override public void addGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue) { // no op } @Override public void deleteGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue) { // no op } @Override public void addUserPermission(DbSession dbSession, UserPermissionNewValue newValue) { // no op } @Override public void deleteUserPermission(DbSession dbSession, UserPermissionNewValue newValue) { // no op } @Override public void addPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void updatePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void deletePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void addUserToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void deleteUserFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void addGroupToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void deleteGroupFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void addQualityGateEditor(DbSession dbSession, AbstractEditorNewValue newValue) { // no op } @Override public void deleteQualityGateEditor(DbSession dbSession, AbstractEditorNewValue newValue) { // no op } @Override public void addQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue) { // no op } @Override public void deleteQualityProfileEditor(DbSession dbSession, AbstractEditorNewValue newValue) { // no op } @Override public void addCharacteristicToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void updateCharacteristicInPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) { // no op } @Override public void addPlugin(DbSession dbSession, PluginNewValue newValue) { // no op } @Override public void updatePlugin(DbSession dbSession, PluginNewValue newValue) { // no op } @Override public void generateSecretKey(DbSession dbSession) { // no op } @Override public void setLicense(DbSession dbSession, boolean isSet, LicenseNewValue newValue) { // no op } @Override public void addWebhook(DbSession dbSession, WebhookNewValue newValue) { // no op } @Override public void updateWebhook(DbSession dbSession, WebhookNewValue newValue) { // no op } @Override public void deleteWebhook(DbSession dbSession, WebhookNewValue newValue) { // no op } @Override public void addDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue) { // no op } @Override public void updateDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue) { // no op } @Override public void deleteDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue) { // no op } @Override public void addPersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue) { // no op } @Override public void updatePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue) { // no op } @Override public void deletePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue) { // no op } @Override public boolean isTrackedProperty(String propertyKey) { return false; } @Override public void addComponent(DbSession dbSession, ComponentNewValue newValue) { // no op } @Override public void deleteComponent(DbSession dbSession, ComponentNewValue newValue) { // no op } @Override public void updateComponent(DbSession dbSession, ComponentNewValue newValue) { // no op } @Override public void updateComponentVisibility(DbSession session, ComponentNewValue componentNewValue) { // no op } @Override public void componentKeyUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier) { // no op } @Override public void componentKeyBranchUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier) { // no op } }
8,670
25.762346
120
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/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.audit; import javax.annotation.ParametersAreNonnullByDefault;
958
38.958333
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/AbstractEditorNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; public abstract class AbstractEditorNewValue extends NewValue { @Nullable protected String qualityGateUuid; @Nullable protected String qualityGateName; @Nullable protected String qualityProfileUuid; @Nullable protected String qualityProfileName; @CheckForNull public String getQualityGateUuid() { return this.qualityGateUuid; } @CheckForNull public String getQualityGateName() { return this.qualityGateName; } @CheckForNull public String getQualityProfileUuid() { return this.qualityProfileUuid; } @CheckForNull public String getQualityProfileName() { return this.qualityProfileName; } }
1,599
28.090909
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentKeyNewValue.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.audit.model; import static com.google.common.base.Preconditions.checkNotNull; public class ComponentKeyNewValue extends NewValue { private final String componentUuid; private final String oldKey; private final String newKey; public ComponentKeyNewValue(String componentUuid, String oldKey, String newKey) { checkNotNull(componentUuid, oldKey, newKey); this.componentUuid = componentUuid; this.oldKey = oldKey; this.newKey = newKey; } public String getComponentUuid() { return componentUuid; } public String getOldKey() { return oldKey; } public String getNewKey() { return newKey; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"componentUuid\": ", this.getComponentUuid(), true); addField(sb, "\"oldKey\": ", this.getOldKey(), true); addField(sb, "\"newKey\": ", this.getNewKey(), true); endString(sb); return sb.toString(); } }
1,833
29.566667
83
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.ObjectUtils; import org.sonar.db.component.ComponentDto; import org.sonar.db.project.ProjectDto; import static java.util.Objects.requireNonNull; public class ComponentNewValue extends NewValue { private final String componentUuid; private final String componentKey; private final String componentName; private final String description; private final Boolean isPrivate; private final String qualifier; private Boolean isEnabled; private String path; public ComponentNewValue(ProjectDto project) { this(project.getUuid(), project.getName(), project.getKey(), project.isPrivate(), project.getDescription(), project.getQualifier()); } public ComponentNewValue(ComponentDto component) { this(component.uuid(), component.name(), component.getKey(), component.isPrivate(), component.description(), component.qualifier()); } public ComponentNewValue(String componentUuid, String componentName, String componentKey, String qualifier) { this(componentUuid, componentName, componentKey, null, null, qualifier); } public ComponentNewValue(String componentUuid, String componentName, String componentKey, boolean isPrivate, String qualifier) { this(componentUuid, isPrivate, componentName, componentKey, null, qualifier); } public ComponentNewValue(String uuid, String name, String key, boolean enabled, String path, String qualifier) { this(uuid, name, key, null, null, qualifier); this.isEnabled = enabled; this.path = path; } public ComponentNewValue(String uuid, @Nullable Boolean isPrivate, String name, String key, @Nullable String description, String qualifier) { this(uuid, name, key, isPrivate, description, qualifier); } private ComponentNewValue(String uuid, String name, String key, @Nullable Boolean isPrivate, @Nullable String description, String qualifier) { this.componentUuid = requireNonNull(uuid); this.componentName = name; this.componentKey = key; this.isPrivate = isPrivate; this.description = description; this.qualifier = qualifier; } public String getComponentUuid() { return componentUuid; } public String getComponentName() { return componentName; } @CheckForNull public String getDescription() { return description; } public String getComponentKey() { return componentKey; } @CheckForNull public Boolean isPrivate() { return isPrivate; } public String getQualifier() { return qualifier; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"componentUuid\": ", this.componentUuid, true); addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"qualifier\": ", getQualifier(qualifier), true); addField(sb, "\"description\": ", this.description, true); addField(sb, "\"path\": ", this.path, true); addField(sb, "\"isPrivate\": ", ObjectUtils.toString(this.isPrivate), false); addField(sb, "\"isEnabled\": ", ObjectUtils.toString(this.isEnabled), false); endString(sb); return sb.toString(); } }
4,136
34.358974
144
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.ObjectUtils; import org.sonar.db.alm.setting.AlmSettingDto; import org.sonar.db.alm.setting.ProjectAlmSettingDto; import org.sonar.db.project.ProjectDto; public class DevOpsPlatformSettingNewValue extends NewValue { @Nullable private String devOpsPlatformSettingUuid; @Nullable private String key; @Nullable private String devOpsPlatformName; @Nullable private String url; @Nullable private String appId; @Nullable private String clientId; @Nullable private String projectUuid; @Nullable private String projectKey; @Nullable private String projectName; @Nullable private String almRepo; @Nullable private String almSlug; @Nullable private Boolean isSummaryCommentEnabled; @Nullable private Boolean isMonorepo; public DevOpsPlatformSettingNewValue(String devOpsPlatformSettingUuid, String key) { this.devOpsPlatformSettingUuid = devOpsPlatformSettingUuid; this.key = key; } public DevOpsPlatformSettingNewValue(AlmSettingDto dto) { this.devOpsPlatformSettingUuid = dto.getUuid(); this.key = dto.getKey(); this.devOpsPlatformName = dto.getAppId(); this.url = dto.getUrl(); this.appId = dto.getAppId(); this.clientId = dto.getClientId(); } public DevOpsPlatformSettingNewValue(ProjectAlmSettingDto dto, String key, String projectName, String projectKey) { this.devOpsPlatformSettingUuid = dto.getAlmSettingUuid(); this.key = key; this.projectUuid = dto.getProjectUuid(); this.projectKey = projectKey; this.projectName = projectName; this.almRepo = dto.getAlmRepo(); this.almSlug = dto.getAlmSlug(); this.isSummaryCommentEnabled = dto.getSummaryCommentEnabled(); this.isMonorepo = dto.getMonorepo(); } public DevOpsPlatformSettingNewValue(ProjectDto projectDto) { this.projectUuid = projectDto.getUuid(); this.projectKey = projectDto.getKey(); this.projectName = projectDto.getName(); } @CheckForNull public String getDevOpsPlatformSettingUuid() { return this.devOpsPlatformSettingUuid; } @CheckForNull public String getKey() { return this.key; } @CheckForNull public String getDevOpsPlatformName() { return this.devOpsPlatformName; } @CheckForNull public String getUrl() { return this.url; } @CheckForNull public String getAppId() { return this.appId; } @CheckForNull public String getClientId() { return this.clientId; } @CheckForNull public String getProjectUuid() { return this.projectUuid; } @CheckForNull public String getProjectKey() { return this.projectKey; } @CheckForNull public String getProjectName() { return this.projectName; } @CheckForNull public String getAlmRepo() { return this.almRepo; } @CheckForNull public String getAlmSlug() { return this.almSlug; } @CheckForNull public Boolean isSummaryCommentEnabled() { return this.isSummaryCommentEnabled; } @CheckForNull public Boolean isMonorepo() { return this.isMonorepo; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"devOpsPlatformSettingUuid\": ", this.devOpsPlatformSettingUuid, true); addField(sb, "\"key\": ", this.key, true); addField(sb, "\"devOpsPlatformName\": ", this.devOpsPlatformName, true); addField(sb, "\"url\": ", this.url, true); addField(sb, "\"appId\": ", this.appId, true); addField(sb, "\"clientId\": ", this.clientId, true); addField(sb, "\"projectUuid\": ", this.projectUuid, true); addField(sb, "\"projectKey\": ", this.projectKey, true); addField(sb, "\"projectName\": ", this.projectName, true); addField(sb, "\"almRepo\": ", this.almRepo, true); addField(sb, "\"almSlug\": ", this.almSlug, true); addField(sb, "\"isSummaryCommentEnabled\": ", ObjectUtils.toString(this.isSummaryCommentEnabled), false); addField(sb, "\"isMonorepo\": ", ObjectUtils.toString(this.isMonorepo), false); endString(sb); return sb.toString(); } }
5,027
26.032258
117
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupEditorNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.db.qualitygate.QualityGateGroupPermissionsDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QProfileEditGroupsDto; import org.sonar.db.user.GroupDto; public class GroupEditorNewValue extends AbstractEditorNewValue { @Nullable private String groupUuid; @Nullable private String groupName; public GroupEditorNewValue(QualityGateGroupPermissionsDto qualityGateGroupPermissionsDto, String qualityGateName, String groupName) { this.qualityGateUuid = qualityGateGroupPermissionsDto.getQualityGateUuid(); this.qualityGateName = qualityGateName; this.groupUuid = qualityGateGroupPermissionsDto.getGroupUuid(); this.groupName = groupName; } public GroupEditorNewValue(QualityGateDto qualityGateDto, GroupDto groupDto) { this.qualityGateUuid = qualityGateDto.getUuid(); this.qualityGateName = qualityGateDto.getName(); this.groupUuid = groupDto.getUuid(); this.groupName = groupDto.getName(); } public GroupEditorNewValue(QualityGateDto qualityGateDto) { this.qualityGateUuid = qualityGateDto.getUuid(); this.qualityGateName = qualityGateDto.getName(); } public GroupEditorNewValue(GroupDto groupDto) { this.groupUuid = groupDto.getUuid(); this.groupName = groupDto.getName(); } public GroupEditorNewValue(QProfileEditGroupsDto qProfileEditGroupsDto, String qualityProfileName, String groupName) { this.qualityProfileUuid = qProfileEditGroupsDto.getQProfileUuid(); this.qualityProfileName = qualityProfileName; this.groupUuid = qProfileEditGroupsDto.getGroupUuid(); this.groupName = groupName; } public GroupEditorNewValue(QProfileDto qualityProfileDto, GroupDto groupDto) { this.qualityProfileUuid = qualityProfileDto.getKee(); this.qualityProfileName = qualityProfileDto.getName(); this.groupUuid = groupDto.getUuid(); this.groupName = groupDto.getName(); } public GroupEditorNewValue(QProfileDto qualityProfileDto) { this.qualityProfileUuid = qualityProfileDto.getKee(); this.qualityProfileName = qualityProfileDto.getName(); } @CheckForNull public String getGroupUuid() { return this.groupUuid; } @CheckForNull public String getGroupName() { return this.groupName; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"qualityGateUuid\": ", this.qualityGateUuid, true); addField(sb, "\"qualityGateName\": ", this.qualityGateName, true); addField(sb, "\"qualityProfileUuid\": ", this.qualityProfileUuid, true); addField(sb, "\"qualityProfileName\": ", this.qualityProfileName, true); addField(sb, "\"groupUuid\": ", this.groupUuid, true); addField(sb, "\"groupName\": ", this.groupName, true); endString(sb); return sb.toString(); } }
3,822
36.480392
135
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.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.audit.model; import javax.annotation.Nullable; import org.sonar.db.permission.GroupPermissionDto; import org.sonar.db.permission.template.PermissionTemplateDto; public class GroupPermissionNewValue extends PermissionNewValue { @Nullable private String groupUuid; @Nullable private String groupName; public GroupPermissionNewValue(String uuid, String componentUuid, String componentKey, String componentName, String role, String groupUuid, String groupName, String qualifier, @Nullable PermissionTemplateDto permissionTemplate) { super(uuid, componentUuid, componentKey, componentName, role, qualifier, permissionTemplate); this.groupUuid = groupUuid; this.groupName = groupName; } public GroupPermissionNewValue(String componentUuid, String componentKey, String componentName, String role, String groupUuid, String groupName, String qualifier) { this(null, componentUuid, componentKey, componentName, role, groupUuid, groupName, qualifier, null); } public GroupPermissionNewValue(GroupPermissionDto dto, @Nullable String componentKey, @Nullable String qualifier, @Nullable PermissionTemplateDto permissionTemplate) { this(dto.getUuid(), dto.getEntityUuid(), componentKey, dto.getEntityName(), dto.getRole(), dto.getGroupUuid(), dto.getGroupName(), qualifier, permissionTemplate); } @Nullable public String getGroupUuid() { return groupUuid; } @Nullable public String getGroupName() { return groupName; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"permissionUuid\": ", this.permissionUuid, true); addField(sb, "\"permission\": ", this.permission, true); addField(sb, "\"groupUuid\": ", this.groupUuid, true); addField(sb, "\"groupName\": ", this.groupName, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"permissionTemplateUuid\": ", this.permissionTemplateId, true); addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true); addField(sb, "\"qualifier\": ", getQualifier(this.qualifier), true); endString(sb); return sb.toString(); } }
3,170
40.723684
169
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/LicenseNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; public class LicenseNewValue extends NewValue { @Nullable private final String edition; public LicenseNewValue(@Nullable String edition) { this.edition = edition; } @CheckForNull public String getEdition() { return this.edition; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"edition\": ", this.edition, true); endString(sb); return sb.toString(); } }
1,401
29.478261
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/NewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import static com.google.common.base.Strings.isNullOrEmpty; import static org.sonar.api.resources.Qualifiers.APP; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.api.resources.Qualifiers.VIEW; public abstract class NewValue { protected void addField(StringBuilder sb, String field, @Nullable String value, boolean isString) { if (!isNullOrEmpty(value)) { sb.append(field); addQuote(sb, isString); if (value.contains("\"")) { value = value.replace("\"", "\\\""); } sb.append(value); addQuote(sb, isString); sb.append(", "); } } protected void endString(StringBuilder sb) { int length = sb.length(); if (sb.length() > 1) { sb.delete(length - 2, length - 1); } sb.append("}"); } private static void addQuote(StringBuilder sb, boolean isString) { if (isString) { sb.append("\""); } } @CheckForNull protected static String getQualifier(@Nullable String qualifier) { if (qualifier == null) { return null; } switch (qualifier) { case VIEW: return "portfolio"; case APP: return "application"; case PROJECT: return "project"; default: return null; } } @Override public abstract String toString(); }
2,275
27.810127
101
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.permission.template.PermissionTemplateDto; public abstract class PermissionNewValue extends NewValue { @Nullable protected String permissionUuid; @Nullable protected String componentUuid; @Nullable protected String componentKey; @Nullable protected String componentName; @Nullable protected String permission; @Nullable protected String qualifier; @Nullable protected String permissionTemplateId; @Nullable protected String permissionTemplateName; protected PermissionNewValue(@Nullable String permissionUuid, @Nullable String componentUuid, @Nullable String componentKey, @Nullable String componentName, @Nullable String permission, @Nullable String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { this.permissionUuid = permissionUuid; this.componentUuid = componentUuid; this.componentKey = componentKey; this.componentName = componentName; this.qualifier = qualifier; this.permission = permission; this.permissionTemplateId = permissionTemplateDto == null ? null : permissionTemplateDto.getUuid(); this.permissionTemplateName = permissionTemplateDto == null ? null : permissionTemplateDto.getName(); } @CheckForNull public String getPermissionUuid() { return this.permissionUuid; } @CheckForNull public String getComponentUuid() { return this.componentUuid; } @CheckForNull public String getPermission() { return this.permission; } @CheckForNull public String getComponentName() { return this.componentName; } @CheckForNull public String getComponentKey() { return this.componentKey; } @CheckForNull public String getQualifier() { return this.qualifier; } @CheckForNull public String getPermissionTemplateId() { return this.permissionTemplateId; } @CheckForNull public String getPermissionTemplateName() { return this.permissionTemplateName; } }
2,909
26.980769
149
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionTemplateNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.ObjectUtils; import org.sonar.db.permission.template.PermissionTemplateDto; public class PermissionTemplateNewValue extends NewValue { private String templateUuid; private String name; @Nullable private String keyPattern; @Nullable private String description; @Nullable private String permission; @Nullable private String userUuid; @Nullable private String userLogin; @Nullable private String groupUuid; @Nullable private String groupName; @Nullable private Boolean withProjectCreator; public PermissionTemplateNewValue(String templateUuid, String name) { this.templateUuid = templateUuid; this.name = name; } public PermissionTemplateNewValue(PermissionTemplateDto permissionTemplateDto) { this.templateUuid = permissionTemplateDto.getUuid(); this.name = permissionTemplateDto.getName(); this.keyPattern = permissionTemplateDto.getKeyPattern(); this.description = permissionTemplateDto.getDescription(); } public PermissionTemplateNewValue(@Nullable String templateUuid, @Nullable String name, @Nullable String permission, @Nullable String userUuid, @Nullable String userLogin, @Nullable String groupUuid, @Nullable String groupName) { this.templateUuid = templateUuid; this.name = name; this.permission = permission; this.userUuid = userUuid; this.userLogin = userLogin; this.groupUuid = groupUuid; this.groupName = groupName; } public PermissionTemplateNewValue(String templateUuid, String permission, String name, boolean withProjectCreator) { this.templateUuid = templateUuid; this.name = name; this.permission = permission; this.withProjectCreator = withProjectCreator; } public String getTemplateUuid() { return this.templateUuid; } public String getName() { return this.name; } @CheckForNull public String getKeyPattern() { return this.keyPattern; } @CheckForNull public String getDescription() { return this.description; } @CheckForNull public String getPermission() { return this.permission; } @CheckForNull public String getUserUuid() { return this.userUuid; } @CheckForNull public String getUserLogin() { return this.userLogin; } @CheckForNull public String getGroupUuid() { return this.groupUuid; } @CheckForNull public String getGroupName() { return this.groupName; } @CheckForNull public Boolean isWithProjectCreator() { return this.withProjectCreator; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"templateUuid\": ", this.templateUuid, true); addField(sb, "\"name\": ", this.name, true); addField(sb, "\"keyPattern\": ", this.keyPattern, true); addField(sb, "\"description\": ", this.description, true); addField(sb, "\"permission\": ", this.permission, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"groupUuid\": ", this.groupUuid, true); addField(sb, "\"groupName\": ", this.groupName, true); addField(sb, "\"withProjectCreator\": ", ObjectUtils.toString(this.withProjectCreator), false); endString(sb); return sb.toString(); } }
4,267
27.453333
118
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PersonalAccessTokenNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.alm.pat.AlmPatDto; import org.sonar.db.alm.setting.AlmSettingDto; import org.sonar.db.user.UserDto; public class PersonalAccessTokenNewValue extends NewValue { @Nullable private String patUuid; @Nullable private String userUuid; @Nullable private String userLogin; @Nullable private String almSettingUuid; @Nullable private String almSettingKey; public PersonalAccessTokenNewValue(AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) { this.patUuid = almPatDto.getUuid(); this.userUuid = almPatDto.getUserUuid(); this.almSettingUuid = almPatDto.getAlmSettingUuid(); this.userLogin = userLogin; this.almSettingKey = almSettingKey; } public PersonalAccessTokenNewValue(UserDto userDto) { this.userUuid = userDto.getUuid(); this.userLogin = userDto.getLogin(); } public PersonalAccessTokenNewValue(AlmSettingDto almSettingDto) { this.almSettingUuid = almSettingDto.getUuid(); this.almSettingKey = almSettingDto.getKey(); } @CheckForNull public String getPatUuid() { return this.patUuid; } @CheckForNull public String getUserUuid() { return this.userUuid; } @CheckForNull public String getUserLogin() { return this.userLogin; } @CheckForNull public String getAlmSettingUuid() { return this.almSettingUuid; } @CheckForNull public String getAlmSettingKey() { return this.almSettingKey; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"patUuid\": ", this.patUuid, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"almSettingUuid\": ", this.almSettingUuid, true); addField(sb, "\"almSettingKey\": ", this.almSettingKey, true); endString(sb); return sb.toString(); } }
2,858
27.878788
119
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PluginNewValue.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.audit.model; import org.sonar.db.plugin.PluginDto; public class PluginNewValue extends NewValue { private final String pluginUuid; private final String kee; private final String basePluginKey; private final String type; public PluginNewValue(PluginDto pluginDto) { this.pluginUuid = pluginDto.getUuid(); this.kee = pluginDto.getKee(); this.basePluginKey = pluginDto.getBasePluginKey(); this.type = pluginDto.getType().name(); } public String getPluginUuid() { return this.pluginUuid; } public String getKee() { return this.kee; } public String getBasePluginKey() { return this.basePluginKey; } public String getType() { return this.type; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"pluginUuid\": ", this.pluginUuid, true); addField(sb, "\"kee\": ", this.kee, true); addField(sb, "\"basePluginKey\": ", this.basePluginKey, true); addField(sb, "\"type\": ", this.type, true); endString(sb); return sb.toString(); } }
1,935
29.25
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ProjectBadgeTokenNewValue.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.audit.model; public class ProjectBadgeTokenNewValue extends NewValue { private final String projectKey; private final String userUuid; private final String userLogin; public ProjectBadgeTokenNewValue(String projectKey, String userUuid, String userLogin) { this.projectKey = projectKey; this.userUuid = userUuid; this.userLogin = userLogin; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"projectKey\": ", this.projectKey, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); endString(sb); return sb.toString(); } }
1,548
34.204545
90
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.property.PropertyDto; public class PropertyNewValue extends NewValue { private String propertyKey; @Nullable private String propertyValue; @Nullable private String userUuid; @Nullable private String userLogin; @Nullable private String componentUuid; @Nullable private String componentKey; @Nullable private String componentName; @Nullable private String qualifier; public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String componentKey, @Nullable String componentName, @Nullable String qualifier) { this.propertyKey = propertyDto.getKey(); this.userUuid = propertyDto.getUserUuid(); this.userLogin = userLogin; this.componentUuid = propertyDto.getEntityUuid(); this.componentKey = componentKey; this.componentName = componentName; this.qualifier = qualifier; setValue(propertyKey, propertyDto.getValue()); } public PropertyNewValue(String propertyKey) { this.propertyKey = propertyKey; } public PropertyNewValue(String propertyKey, @Nullable String userUuid, String userLogin) { this.propertyKey = propertyKey; this.userUuid = userUuid; this.userLogin = userLogin; } public PropertyNewValue(String propertyKey, String propertyValue) { this.propertyKey = propertyKey; setValue(propertyKey, propertyValue); } public PropertyNewValue(String propertyKey, @Nullable String projectUuid, @Nullable String componentKey, @Nullable String componentName, @Nullable String qualifier, @Nullable String userUuid) { this.propertyKey = propertyKey; this.componentUuid = projectUuid; this.componentKey = componentKey; this.componentName = componentName; this.userUuid = userUuid; this.qualifier = qualifier; } public String getPropertyKey() { return this.propertyKey; } @CheckForNull public String getPropertyValue() { return this.propertyValue; } @CheckForNull public String getUserUuid() { return this.userUuid; } @CheckForNull public String getUserLogin() { return this.userLogin; } @CheckForNull public String getComponentUuid() { return this.componentUuid; } @CheckForNull public String getComponentKey() { return this.componentKey; } @CheckForNull public String getComponentName() { return this.componentName; } @CheckForNull public String getQualifier() { return this.qualifier; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"propertyKey\": ", this.propertyKey, true); addField(sb, "\"propertyValue\": ", this.propertyValue, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"qualifier\": ", getQualifier(this.qualifier), true); endString(sb); return sb.toString(); } private void setValue(String propertyKey, String value) { if (!propertyKey.contains(".secured")) { this.propertyValue = value; } } }
4,220
27.52027
171
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/SecretNewValue.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.audit.model; public class SecretNewValue extends NewValue { private String targetKey; private String targetValue; public SecretNewValue(String targetKey, String targetValue) { this.targetKey = targetKey; this.targetValue = targetValue; } @Override public String toString() { return String.format("{\"%s\":\"%s\"}", targetKey, targetValue); } }
1,237
33.388889
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserEditorNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.db.qualitygate.QualityGateUserPermissionsDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.QProfileEditUsersDto; import org.sonar.db.user.UserDto; public class UserEditorNewValue extends AbstractEditorNewValue { @Nullable private String userUuid; @Nullable private String userLogin; public UserEditorNewValue(QualityGateUserPermissionsDto qualityGateUserPermissionsDto, String qualityGateName, String userLogin) { this.qualityGateUuid = qualityGateUserPermissionsDto.getQualityGateUuid(); this.qualityGateName = qualityGateName; this.userUuid = qualityGateUserPermissionsDto.getUserUuid(); this.userLogin = userLogin; } public UserEditorNewValue(QualityGateDto qualityGateDto, UserDto userDto) { this.qualityGateUuid = qualityGateDto.getUuid(); this.qualityGateName = qualityGateDto.getName(); this.userUuid = userDto.getUuid(); this.userLogin = userDto.getLogin(); } public UserEditorNewValue(QualityGateDto qualityGateDto) { this.qualityGateUuid = qualityGateDto.getUuid(); this.qualityGateName = qualityGateDto.getName(); } public UserEditorNewValue(UserDto userDto) { this.userUuid = userDto.getUuid(); this.userLogin = userDto.getLogin(); } public UserEditorNewValue(QProfileEditUsersDto qProfileEditUsersDto, String qualityProfileName, String userLogin) { this.qualityProfileUuid = qProfileEditUsersDto.getQProfileUuid(); this.qualityProfileName = qualityProfileName; this.userUuid = qProfileEditUsersDto.getUserUuid(); this.userLogin = userLogin; } public UserEditorNewValue(QProfileDto qProfileDto, UserDto userDto) { this.qualityProfileUuid = qProfileDto.getKee(); this.qualityProfileName = qProfileDto.getName(); this.userUuid = userDto.getUuid(); this.userLogin = userDto.getLogin(); } public UserEditorNewValue(QProfileDto qProfileDto) { this.qualityProfileUuid = qProfileDto.getKee(); this.qualityProfileName = qProfileDto.getName(); } @CheckForNull public String getUserUuid() { return this.userUuid; } @CheckForNull public String getUserLogin() { return this.userLogin; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"qualityGateUuid\": ", this.qualityGateUuid, true); addField(sb, "\"qualityGateName\": ", this.qualityGateName, true); addField(sb, "\"qualityProfileUuid\": ", this.qualityProfileUuid, true); addField(sb, "\"qualityProfileName\": ", this.qualityProfileName, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); endString(sb); return sb.toString(); } }
3,746
35.735294
132
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserGroupNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserGroupDto; import static com.google.common.base.Preconditions.checkState; public class UserGroupNewValue extends NewValue { private final String groupUuid; private final String name; private final String userUuid; private final String userLogin; private final String description; public UserGroupNewValue(String groupUuid, String name) { this(groupUuid, name, null, null, null); } public UserGroupNewValue(GroupDto groupDto) { this(groupDto.getUuid(), groupDto.getName(), null, null, groupDto.getDescription()); } public UserGroupNewValue(GroupDto groupDto, UserDto userDto) { this(groupDto.getUuid(), groupDto.getName(), userDto.getUuid(), userDto.getLogin(), null); } public UserGroupNewValue(UserDto userDto) { this(null, null, userDto.getUuid(), userDto.getLogin(), null); } public UserGroupNewValue(UserGroupDto userGroupDto, String groupName, String userLogin) { this(userGroupDto.getGroupUuid(), groupName, userGroupDto.getUserUuid(), userLogin, null); } private UserGroupNewValue(@Nullable String groupUuid, @Nullable String name, @Nullable String userUuid, @Nullable String userLogin, @Nullable String description) { checkState((groupUuid != null && name != null) || (userUuid != null && userLogin != null)); this.groupUuid = groupUuid; this.name = name; this.userUuid = userUuid; this.userLogin = userLogin; this.description = description; } @CheckForNull public String getGroupUuid() { return this.groupUuid; } @CheckForNull public String getName() { return this.name; } @CheckForNull public String getDescription() { return this.description; } @CheckForNull public String getUserUuid() { return this.userUuid; } @CheckForNull public String getUserLogin() { return this.userLogin; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"groupUuid\": ", this.groupUuid, true); addField(sb, "\"name\": ", this.name, true); addField(sb, "\"description\": ", this.description, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); endString(sb); return sb.toString(); } }
3,309
31.135922
165
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserNewValue.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.audit.model; import java.util.ArrayList; import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.ObjectUtils; import org.sonar.api.utils.DateUtils; import org.sonar.db.user.UserDto; import static java.util.Objects.requireNonNull; public class UserNewValue extends NewValue { private String userUuid; private String userLogin; @Nullable private String name; @Nullable private String email; @Nullable private Boolean isActive; private List<String> scmAccounts = new ArrayList<>(); @Nullable private String externalId; @Nullable private String externalLogin; @Nullable private String externalIdentityProvider; @Nullable private Boolean local; @Nullable private Long lastConnectionDate; public UserNewValue(String userUuid, String userLogin) { this.userUuid = requireNonNull(userUuid); this.userLogin = requireNonNull(userLogin); } public UserNewValue(UserDto userDto) { this.userUuid = userDto.getUuid(); this.userLogin = userDto.getLogin(); this.name = userDto.getName(); this.email = userDto.getEmail(); this.isActive = userDto.isActive(); this.scmAccounts = userDto.getSortedScmAccounts(); this.externalId = userDto.getExternalId(); this.externalLogin = userDto.getExternalLogin(); this.externalIdentityProvider = userDto.getExternalIdentityProvider(); this.local = userDto.isLocal(); this.lastConnectionDate = userDto.getLastConnectionDate(); } public String getUserUuid() { return this.userUuid; } public String getUserLogin() { return this.userLogin; } @CheckForNull public String getName() { return this.name; } @CheckForNull public String getEmail() { return this.email; } @CheckForNull public Boolean isActive() { return this.isActive; } public List<String> getScmAccounts() { return this.scmAccounts; } @CheckForNull public String getExternalId() { return this.externalId; } @CheckForNull public String getExternalLogin() { return this.externalLogin; } @CheckForNull public String getExternalIdentityProvider() { return this.externalIdentityProvider; } @CheckForNull public Boolean isLocal() { return this.local; } @CheckForNull public Long getLastConnectionDate() { return this.lastConnectionDate; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"name\": ", this.name, true); addField(sb, "\"email\": ", this.email, true); addField(sb, "\"isActive\": ", ObjectUtils.toString(this.isActive), false); addField(sb, "\"scmAccounts\": ", String.join(",", scmAccounts), true); addField(sb, "\"externalId\": ", this.externalId, true); addField(sb, "\"externalLogin\": ", this.externalLogin, true); addField(sb, "\"externalIdentityProvider\": ", this.externalIdentityProvider, true); addField(sb, "\"local\": ", ObjectUtils.toString(this.local), false); addField(sb, "\"lastConnectionDate\": ", this.lastConnectionDate == null ? "" : DateUtils.formatDateTime(this.lastConnectionDate), true); endString(sb); return sb.toString(); } }
4,220
26.769737
88
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.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.audit.model; import javax.annotation.Nullable; import org.sonar.db.permission.UserPermissionDto; import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.user.UserId; public class UserPermissionNewValue extends PermissionNewValue { @Nullable private final String userUuid; @Nullable private final String userLogin; public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String componentKey, @Nullable String componentName, @Nullable UserId userId, @Nullable String qualifier, @Nullable PermissionTemplateDto templateDto) { super(permissionDto.getUuid(), permissionDto.getEntityUuid(), componentKey, componentName, permissionDto.getPermission(), qualifier, templateDto); this.userUuid = userId != null ? userId.getUuid() : null; this.userLogin = userId != null ? userId.getLogin() : null; } public UserPermissionNewValue(UserId userId, @Nullable String qualifier) { this(null, null, null, null, userId, qualifier); } public UserPermissionNewValue(@Nullable String role, @Nullable String componentUuid, @Nullable String componentKey, @Nullable String componentName, UserId userId, @Nullable String qualifier) { super(null, componentUuid, componentKey, componentName, role, qualifier, null); this.userUuid = userId != null ? userId.getUuid() : null; this.userLogin = userId != null ? userId.getLogin() : null; } @Nullable public String getUserUuid() { return userUuid; } @Nullable public String getUserLogin() { return userLogin; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"permissionUuid\": ", this.permissionUuid, true); addField(sb, "\"permission\": ", this.permission, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"permissionTemplateUuid\": ", this.permissionTemplateId, true); addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"qualifier\": ", getQualifier(this.qualifier), true); endString(sb); return sb.toString(); } }
3,250
39.135802
150
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserTokenNewValue.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.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.utils.DateUtils; import org.sonar.db.user.TokenType; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserTokenDto; public class UserTokenNewValue extends NewValue { @Nullable private String tokenUuid; @Nullable private String userUuid; @Nullable private String userLogin; @Nullable private String tokenName; @Nullable private Long lastConnectionDate; @Nullable private String projectKey; @Nullable private String type; public UserTokenNewValue(UserTokenDto userTokenDto, @Nullable String userLogin) { this.tokenUuid = userTokenDto.getUuid(); this.tokenName = userTokenDto.getName(); this.userUuid = userTokenDto.getUserUuid(); this.lastConnectionDate = userTokenDto.getLastConnectionDate(); this.projectKey = userTokenDto.getProjectKey(); this.type = userTokenDto.getType(); this.userLogin = userLogin; } public UserTokenNewValue(UserDto userDto) { this.userUuid = userDto.getUuid(); this.userLogin = userDto.getLogin(); } public UserTokenNewValue(UserDto userDto, String tokenName) { this(userDto); this.tokenName = tokenName; } public UserTokenNewValue(String projectKey) { this.projectKey = projectKey; this.type = TokenType.PROJECT_ANALYSIS_TOKEN.name(); } @CheckForNull public String getTokenUuid() { return this.tokenUuid; } public String getUserUuid() { return this.userUuid; } @CheckForNull public String getUserLogin() { return this.userLogin; } @CheckForNull public String getTokenName() { return this.tokenName; } @CheckForNull public Long getLastConnectionDate() { return this.lastConnectionDate; } @CheckForNull public String getProjectKey() { return this.projectKey; } @CheckForNull public String getType() { return this.type; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"tokenUuid\": ", this.tokenUuid, true); addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"tokenName\": ", this.tokenName, true); addField(sb, "\"lastConnectionDate\": ", this.lastConnectionDate == null ? "" : DateUtils.formatDateTime(this.lastConnectionDate), false); addField(sb, "\"projectKey\": ", this.projectKey, true); addField(sb, "\"type\": ", this.type, true); endString(sb); return sb.toString(); } }
3,434
26.701613
142
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.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.audit.model; import java.util.function.UnaryOperator; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.project.ProjectDto; import org.sonar.db.webhook.WebhookDto; public class WebhookNewValue extends NewValue { @Nullable private String webhookUuid; @Nullable private String name; @Nullable private String url; @Nullable private String projectUuid; @Nullable private String projectKey; @Nullable private String projectName; public WebhookNewValue(WebhookDto dto, @Nullable String projectKey, @Nullable String projectName) { this(dto.getUuid(), dto.getName(), dto.getProjectUuid(), projectKey, projectName, dto.getUrl()); } public WebhookNewValue(String webhookUuid, String webhookName) { this.webhookUuid = webhookUuid; this.name = webhookName; } public WebhookNewValue(String webhookUuid, String webhookName, @Nullable String projectUuid, @Nullable String projectKey, @Nullable String projectName, @Nullable String url) { this.webhookUuid = webhookUuid; this.name = webhookName; this.url = url; this.projectUuid = projectUuid; this.projectKey = projectKey; this.projectName = projectName; } public WebhookNewValue(ProjectDto projectDto) { this.projectUuid = projectDto.getUuid(); this.projectKey = projectDto.getKey(); this.projectName = projectDto.getName(); } public void sanitizeUrl(UnaryOperator<String> sanitizer) { if (this.url != null) { this.url = sanitizer.apply(this.url); } } @CheckForNull public String getWebhookUuid() { return this.webhookUuid; } @CheckForNull public String getName() { return this.name; } @CheckForNull public String getUrl() { return this.url; } @CheckForNull public String getProjectUuid() { return this.projectUuid; } @CheckForNull public String getProjectKey() { return this.projectKey; } @CheckForNull public String getProjectName() { return this.projectName; } @Override public String toString() { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"webhookUuid\": ", this.webhookUuid, true); addField(sb, "\"name\": ", this.name, true); addField(sb, "\"url\": ", this.url, true); addField(sb, "\"projectUuid\": ", this.projectUuid, true); addField(sb, "\"projectKey\": ", this.projectKey, true); addField(sb, "\"projectName\": ", this.projectName, true); endString(sb); return sb.toString(); } }
3,380
26.942149
123
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/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.audit.model; import javax.annotation.ParametersAreNonnullByDefault;
965
37.64
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.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.ce; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.Pagination; import static org.sonar.db.DatabaseUtils.executeLargeUpdates; public class CeActivityDao implements Dao { private final System2 system2; public CeActivityDao(System2 system2) { this.system2 = system2; } public Optional<CeActivityDto> selectByUuid(DbSession dbSession, String uuid) { return Optional.ofNullable(mapper(dbSession).selectByUuid(uuid)); } public void insert(DbSession dbSession, CeActivityDto dto) { dto.setCreatedAt(system2.now()); dto.setUpdatedAt(system2.now()); boolean isLast = dto.getStatus() != CeActivityDto.Status.CANCELED; dto.setIsLast(isLast); CeActivityMapper ceActivityMapper = mapper(dbSession); if (isLast) { ceActivityMapper.clearIsLast(dto.getIsLastKey(), dto.getUpdatedAt()); ceActivityMapper.clearMainIsLast(dto.getMainIsLastKey(), dto.getUpdatedAt()); } ceActivityMapper.insert(dto); } public List<CeActivityDto> selectOlderThan(DbSession dbSession, long beforeDate) { return mapper(dbSession).selectOlderThan(beforeDate); } public List<CeActivityDto> selectNewerThan(DbSession dbSession, long beforeDate) { return mapper(dbSession).selectNewerThan(beforeDate); } public List<CeActivityDto> selectByTaskType(DbSession dbSession, String taskType) { return mapper(dbSession).selectByTaskType(taskType); } public void deleteByUuids(DbSession dbSession, Set<String> uuids) { executeLargeUpdates(uuids, mapper(dbSession)::deleteByUuids); } /** * Ordered by id desc -> newest to oldest */ public List<CeActivityDto> selectByQuery(DbSession dbSession, CeTaskQuery query, Pagination pagination) { if (query.isShortCircuitedByEntityUuids()) { return Collections.emptyList(); } return mapper(dbSession).selectByQuery(query, pagination); } public int countByQuery(DbSession dbSession, CeTaskQuery query) { return mapper(dbSession).countByQuery(query); } public int countLastByStatusAndEntityUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String entityUuid) { return mapper(dbSession).countLastByStatusAndEntityUuid(status, entityUuid); } public Optional<CeActivityDto> selectLastByComponentUuidAndTaskType(DbSession dbSession, String componentUuid, String taskType) { return Optional.ofNullable(mapper(dbSession).selectLastByComponentUuidAndTaskType(componentUuid, taskType)); } public boolean hasAnyFailedOrCancelledIssueSyncTask(DbSession dbSession) { return mapper(dbSession).hasAnyFailedOrCancelledIssueSyncTask() > 0; } private static CeActivityMapper mapper(DbSession dbSession) { return dbSession.getMapper(CeActivityMapper.class); } }
3,798
34.504673
131
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.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.ce; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.DbSession; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; public class CeActivityDto { private static final int ERROR_MESSAGE_MAX_SIZE = 1000; private static final int NODE_NAME_MAX_SIZE = 100; public enum Status { SUCCESS, FAILED, CANCELED } private String uuid; /** * Can be {@code null} when task is not associated to any data in table COMPONENTS, but must always be non {@code null} * at the same time as {@link #entityUuid}. * <p> * The component uuid of any component (project or not) is its own UUID. */ private String componentUuid; /** * Can be {@code null} when task is not associated to any component, but must always be non {@code null} * at the same time as {@link #componentUuid}. * <p> */ private String entityUuid; private String analysisUuid; private Status status; private String taskType; private boolean isLast; private String isLastKey; private boolean mainIsLast; private String mainIsLastKey; private String submitterUuid; private String workerUuid; private long submittedAt; private Long startedAt; private Long executedAt; private long createdAt; private long updatedAt; private Long executionTimeMs; /** * The error message of the activity. Shall be non null only when status is FAILED. When status is FAILED, can be null * (eg. for activity created before the column has been introduced). * <p> * This property is populated when inserting <strong>AND when reading</strong> * </p> */ private String errorMessage; /** * The error stacktrace (if any). Shall be non null only when status is FAILED. When status is FAILED, can be null * because exception such as MessageException do not have a stacktrace (ie. functional exceptions). * <p> * This property can be populated when inserting but <strong>is populated only when reading by a specific UUID.</strong> * </p> * * @see CeActivityDao#selectByUuid(DbSession, String) */ private String errorStacktrace; /** * Optional free-text type of error. It may be set only when {@link #errorMessage} is not null. */ @Nullable private String errorType; /** * Flag indicating whether the analysis of the current activity has a scanner context or not. * <p> * This property can not be populated when inserting but <strong>is populated when reading</strong>. */ private boolean hasScannerContext; /** * Messages attached to the current activity. * <p> * This property can not be populated when inserting but <strong>is populated when retrieving the activity</strong>. */ private List<CeTaskMessageDto> ceTaskMessageDtos; private String nodeName; CeActivityDto() { // required for MyBatis } public CeActivityDto(CeQueueDto queueDto) { this.uuid = queueDto.getUuid(); this.taskType = queueDto.getTaskType(); this.componentUuid = queueDto.getComponentUuid(); this.entityUuid = queueDto.getEntityUuid(); this.isLastKey = format("%s%s", taskType, Strings.nullToEmpty(componentUuid)); this.mainIsLastKey = format("%s%s", taskType, Strings.nullToEmpty(entityUuid)); this.submitterUuid = queueDto.getSubmitterUuid(); this.workerUuid = queueDto.getWorkerUuid(); this.submittedAt = queueDto.getCreatedAt(); this.startedAt = queueDto.getStartedAt(); } public String getUuid() { return uuid; } public CeActivityDto setUuid(@Nullable String s) { validateUuid(s, "UUID"); this.uuid = s; return this; } public String getTaskType() { return taskType; } public CeActivityDto setTaskType(String s) { this.taskType = s; return this; } @CheckForNull public String getComponentUuid() { return componentUuid; } public CeActivityDto setComponentUuid(@Nullable String s) { validateUuid(s, "COMPONENT_UUID"); this.componentUuid = s; return this; } @CheckForNull public String getEntityUuid() { return entityUuid; } public CeActivityDto setEntityUuid(@Nullable String s) { validateUuid(s, "ENTITY_UUID"); this.entityUuid = s; return this; } private static void validateUuid(@Nullable String s, String columnName) { checkArgument(s == null || s.length() <= 40, "Value is too long for column CE_ACTIVITY.%s: %s", columnName, s); } public Status getStatus() { return status; } public CeActivityDto setStatus(Status s) { this.status = s; return this; } public boolean getIsLast() { return isLast; } CeActivityDto setIsLast(boolean b) { this.isLast = b; this.mainIsLast = b; return this; } public String getIsLastKey() { return isLastKey; } public boolean getMainIsLast() { return mainIsLast; } public String getMainIsLastKey() { return mainIsLastKey; } @CheckForNull public String getSubmitterUuid() { return submitterUuid; } public long getSubmittedAt() { return submittedAt; } public CeActivityDto setSubmittedAt(long submittedAt) { this.submittedAt = submittedAt; return this; } @CheckForNull public Long getStartedAt() { return startedAt; } public CeActivityDto setStartedAt(@Nullable Long l) { this.startedAt = l; return this; } @CheckForNull public Long getExecutedAt() { return executedAt; } public CeActivityDto setExecutedAt(@Nullable Long l) { this.executedAt = l; return this; } public long getCreatedAt() { return createdAt; } public CeActivityDto setCreatedAt(long l) { this.createdAt = l; return this; } public long getUpdatedAt() { return updatedAt; } public CeActivityDto setUpdatedAt(long l) { this.updatedAt = l; return this; } @CheckForNull public Long getExecutionTimeMs() { return executionTimeMs; } public CeActivityDto setExecutionTimeMs(@Nullable Long l) { checkArgument(l == null || l >= 0, "Execution time must be positive: %s", l); this.executionTimeMs = l; return this; } @CheckForNull public String getAnalysisUuid() { return analysisUuid; } public CeActivityDto setAnalysisUuid(@Nullable String s) { this.analysisUuid = s; return this; } @CheckForNull public String getWorkerUuid() { return workerUuid; } public CeActivityDto setWorkerUuid(String workerUuid) { this.workerUuid = workerUuid; return this; } @CheckForNull public String getErrorMessage() { return errorMessage; } public CeActivityDto setErrorMessage(@Nullable String errorMessage) { this.errorMessage = ensureNotTooBig(removeCharZeros(errorMessage), ERROR_MESSAGE_MAX_SIZE); return this; } @CheckForNull public String getErrorType() { return errorType; } public CeActivityDto setErrorType(@Nullable String s) { this.errorType = ensureNotTooBig(s, 20); return this; } @CheckForNull public String getErrorStacktrace() { return errorStacktrace; } @CheckForNull public CeActivityDto setErrorStacktrace(@Nullable String errorStacktrace) { this.errorStacktrace = removeCharZeros(errorStacktrace); return this; } public boolean isHasScannerContext() { return hasScannerContext; } protected CeActivityDto setHasScannerContext(boolean hasScannerContext) { this.hasScannerContext = hasScannerContext; return this; } public List<CeTaskMessageDto> getCeTaskMessageDtos() { return ceTaskMessageDtos; } @VisibleForTesting protected CeActivityDto setCeTaskMessageDtos(List<CeTaskMessageDto> ceTaskMessageDtos) { this.ceTaskMessageDtos = ceTaskMessageDtos; return this; } @CheckForNull public String getNodeName() { return nodeName; } public CeActivityDto setNodeName(@Nullable String nodeName) { this.nodeName = ensureNotTooBig(nodeName, NODE_NAME_MAX_SIZE); return this; } @Override public String toString() { return "CeActivityDto{" + "uuid='" + uuid + '\'' + ", nodeName='" + nodeName + '\'' + ", componentUuid='" + componentUuid + '\'' + ", entityUuid='" + entityUuid + '\'' + ", analysisUuid='" + analysisUuid + '\'' + ", status=" + status + ", taskType='" + taskType + '\'' + ", isLast=" + isLast + ", isLastKey='" + isLastKey + '\'' + ", mainIsLast=" + mainIsLast + ", mainIsLastKey='" + mainIsLastKey + '\'' + ", submitterUuid='" + submitterUuid + '\'' + ", workerUuid='" + workerUuid + '\'' + ", submittedAt=" + submittedAt + ", startedAt=" + startedAt + ", executedAt=" + executedAt + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", executionTimeMs=" + executionTimeMs + ", errorMessage='" + errorMessage + '\'' + ", errorStacktrace='" + errorStacktrace + '\'' + ", hasScannerContext=" + hasScannerContext + '}'; } @CheckForNull private static String ensureNotTooBig(@Nullable String str, int maxSize) { if (str == null) { return null; } if (str.length() <= maxSize) { return str; } return str.substring(0, maxSize); } @CheckForNull private static String removeCharZeros(@Nullable String str) { if (str == null || str.isEmpty()) { return str; } return str.codePoints() .filter(c -> c != "\u0000".codePointAt(0)) .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) .toString(); } }
10,584
25.729798
122
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.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.ce; import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; import org.sonar.db.Pagination; public interface CeActivityMapper { @CheckForNull CeActivityDto selectByUuid(@Param("uuid") String uuid); List<CeActivityDto> selectByQuery(@Param("query") CeTaskQuery query, @Param("pagination") Pagination pagination); List<CeActivityDto> selectOlderThan(@Param("beforeDate") long beforeDate); List<CeActivityDto> selectNewerThan(@Param("afterDate") long afterDate); int countByQuery(@Param("query") CeTaskQuery query); int countLastByStatusAndEntityUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("entityUuid") String entityUuid); void insert(CeActivityDto dto); void clearIsLast(@Param("isLastKey") String isLastKey, @Param("updatedAt") long updatedAt); void clearMainIsLast(@Param("mainIsLastKey") String mainIsLastKey, @Param("updatedAt") long updatedAt); void deleteByUuids(@Param("uuids") List<String> uuids); @CheckForNull CeActivityDto selectLastByComponentUuidAndTaskType(@Param("componentUuid") String componentUuid, @Param("taskType") String taskType); short hasAnyFailedOrCancelledIssueSyncTask(); List<CeActivityDto> selectByTaskType(@Param("taskType") String taskType); }
2,191
36.793103
135
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.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.ce; import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; 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.Pagination; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; import static org.sonar.db.DatabaseUtils.executeLargeUpdates; import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS; import static org.sonar.db.ce.CeQueueDto.Status.PENDING; public class CeQueueDao implements Dao { private static final Pagination ONE_RESULT_PAGINATION = Pagination.forPage(1).andSize(1); private final System2 system2; public CeQueueDao(System2 system2) { this.system2 = system2; } /** * Ordered by ascending id: oldest to newest */ public List<CeQueueDto> selectAllInAscOrder(DbSession session) { return mapper(session).selectAllInAscOrder(); } public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int pageSize) { return selectByQueryInDescOrder(dbSession, query, 1, pageSize); } public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int page, int pageSize) { if (query.isShortCircuitedByEntityUuids() || query.isOnlyCurrents() || query.getMaxExecutedAt() != null) { return emptyList(); } int offset = (page - 1) * pageSize; int limit = page * pageSize; return mapper(dbSession).selectByQueryInDescOrder(query, new RowBounds(offset, limit)); } public int countByQuery(DbSession dbSession, CeTaskQuery query) { if (query.isShortCircuitedByEntityUuids() || query.isOnlyCurrents() || query.getMaxExecutedAt() != null) { return 0; } return mapper(dbSession).countByQuery(query); } /** * Ordered by ascending id: oldest to newest */ public List<CeQueueDto> selectByEntityUuid(DbSession session, String projectUuid) { return mapper(session).selectByEntityUuid(projectUuid); } public Optional<CeQueueDto> selectByUuid(DbSession session, String uuid) { return Optional.ofNullable(mapper(session).selectByUuid(uuid)); } public List<CeQueueDto> selectPending(DbSession dbSession) { return mapper(dbSession).selectPending(); } public List<CeQueueDto> selectWornout(DbSession dbSession) { return mapper(dbSession).selectWornout(); } public List<CeQueueDto> selectInProgressStartedBefore(DbSession dbSession, long date) { return mapper(dbSession).selectInProgressStartedBefore(date); } public void resetTasksWithUnknownWorkerUUIDs(DbSession dbSession, Set<String> knownWorkerUUIDs) { if (knownWorkerUUIDs.isEmpty()) { mapper(dbSession).resetAllInProgressTasks(system2.now()); } else { // executeLargeUpdates won't call the SQL command if knownWorkerUUIDs is empty executeLargeUpdates(knownWorkerUUIDs, uuids -> mapper(dbSession).resetTasksWithUnknownWorkerUUIDs(uuids, system2.now())); } } public CeQueueDto insert(DbSession session, CeQueueDto dto) { if (dto.getCreatedAt() == 0L || dto.getUpdatedAt() == 0L) { long now = system2.now(); dto.setCreatedAt(now); dto.setUpdatedAt(now); } mapper(session).insert(dto); return dto; } public int deleteByUuid(DbSession session, String uuid) { return deleteByUuid(session, uuid, null); } public int deleteByUuid(DbSession session, String uuid, @Nullable DeleteIf deleteIf) { return mapper(session).deleteByUuid(uuid, deleteIf); } public void resetToPendingByUuid(DbSession session, String uuid) { mapper(session).resetToPendingByUuid(uuid, system2.now()); } public List<CeQueueDto> selectNotPendingForWorker(DbSession session, String uuid) { return mapper(session).selectNotPendingForWorker(uuid); } public int countByStatus(DbSession dbSession, CeQueueDto.Status status) { return mapper(dbSession).countByStatusAndEntityUuid(status, null); } public int countByStatusAndEntityUuid(DbSession dbSession, CeQueueDto.Status status, @Nullable String entityUuid) { return mapper(dbSession).countByStatusAndEntityUuid(status, entityUuid); } public Optional<Long> selectCreationDateOfOldestPendingByEntityUuid(DbSession dbSession, @Nullable String entityUuid) { return Optional.ofNullable(mapper(dbSession).selectCreationDateOfOldestPendingByEntityUuid(entityUuid)); } /** * Counts entries in the queue with the specified status for each specified entity uuid. * The returned map doesn't contain any entry for entity uuids for which there is no entry in the queue (ie. * all entries have a value >= 0). */ public Map<String, Integer> countByStatusAndEntityUuids(DbSession dbSession, CeQueueDto.Status status, Set<String> projectUuids) { if (projectUuids.isEmpty()) { return emptyMap(); } ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder(); executeLargeUpdates( projectUuids, partitionOfProjectUuids -> { List<QueueCount> i = mapper(dbSession).countByStatusAndEntityUuids(status, partitionOfProjectUuids); i.forEach(o -> builder.put(o.getEntityUuid(), o.getTotal())); }); return builder.build(); } public Optional<CeQueueDto> tryToPeek(DbSession session, String eligibleTaskUuid, String workerUuid) { long now = system2.now(); int touchedRows = mapper(session).updateIf(eligibleTaskUuid, new UpdateIf.NewProperties(IN_PROGRESS, workerUuid, now, now), new UpdateIf.OldProperties(PENDING)); if (touchedRows != 1) { return Optional.empty(); } CeQueueDto result = mapper(session).selectByUuid(eligibleTaskUuid); session.commit(); return Optional.ofNullable(result); } public boolean hasAnyIssueSyncTaskPendingOrInProgress(DbSession dbSession) { return mapper(dbSession).hasAnyIssueSyncTaskPendingOrInProgress(); } private static CeQueueMapper mapper(DbSession session) { return session.getMapper(CeQueueMapper.class); } /** * Only returns tasks for projects that currently have no other tasks running */ public Optional<CeTaskDtoLight> selectEligibleForPeek(DbSession session, boolean excludeIndexationJob, boolean excludeView) { return mapper(session).selectEligibleForPeek(ONE_RESULT_PAGINATION, excludeIndexationJob, excludeView); } public List<PrOrBranchTask> selectOldestPendingPrOrBranch(DbSession session) { return mapper(session).selectOldestPendingPrOrBranch(); } public List<PrOrBranchTask> selectInProgressWithCharacteristics(DbSession session) { return mapper(session).selectInProgressWithCharacteristics(); } }
7,669
35.00939
132
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDto.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.ce; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkArgument; public class CeQueueDto { public enum Status { PENDING, IN_PROGRESS } private String uuid; private String taskType; /** * Can be {@code null} when task is not associated to any data in the components table, but must always be non {@code null} * at the same time as {@link #entityUuid}. * <p> * The component uuid of any component is its own UUID. */ private String componentUuid; /** * Can be {@code null} when task is not associated to any entity, but must always be non {@code null} * at the same time as {@link #componentUuid}. * <p> */ private String entityUuid; private Status status; private String submitterUuid; /** * UUID of the worker that is executing, or of the last worker that executed, the current task. */ private String workerUuid; private Long startedAt; private long createdAt; private long updatedAt; public String getUuid() { return uuid; } public CeQueueDto setUuid(String s) { checkUuid(s, "UUID"); this.uuid = s; return this; } @CheckForNull public String getComponentUuid() { return componentUuid; } public CeQueueDto setComponentUuid(@Nullable String s) { checkUuid(s, "COMPONENT_UUID"); this.componentUuid = s; return this; } @CheckForNull public String getEntityUuid() { return entityUuid; } public CeQueueDto setEntityUuid(@Nullable String s) { checkUuid(s, "ENTITY_UUID"); this.entityUuid = s; return this; } private static void checkUuid(@Nullable String s, String columnName) { checkArgument(s == null || s.length() <= 40, "Value is too long for column CE_QUEUE.%s: %s", columnName, s); } public Status getStatus() { return status; } public CeQueueDto setStatus(Status s) { this.status = s; return this; } public String getTaskType() { return taskType; } public CeQueueDto setTaskType(String s) { checkArgument(s.length() <= 40, "Value of task type is too long: %s", s); this.taskType = s; return this; } @CheckForNull public String getSubmitterUuid() { return submitterUuid; } public CeQueueDto setSubmitterUuid(@Nullable String s) { checkArgument(s == null || s.length() <= 255, "Value of submitter uuid is too long: %s", s); this.submitterUuid = s; return this; } public String getWorkerUuid() { return workerUuid; } public CeQueueDto setWorkerUuid(@Nullable String workerUuid) { this.workerUuid = workerUuid; return this; } @CheckForNull public Long getStartedAt() { return startedAt; } public CeQueueDto setStartedAt(@Nullable Long l) { this.startedAt = l; return this; } public long getCreatedAt() { return createdAt; } public CeQueueDto setCreatedAt(long l) { this.createdAt = l; return this; } public long getUpdatedAt() { return updatedAt; } public CeQueueDto setUpdatedAt(long l) { this.updatedAt = l; return this; } @Override public String toString() { return "CeQueueDto{" + "uuid='" + uuid + '\'' + ", taskType='" + taskType + '\'' + ", componentUuid='" + componentUuid + '\'' + ", entityUuid='" + entityUuid + '\'' + ", status=" + status + ", submitterLogin='" + submitterUuid + '\'' + ", workerUuid='" + workerUuid + '\'' + ", startedAt=" + startedAt + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; } @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } CeQueueDto that = (CeQueueDto) o; return uuid.equals(that.uuid); } @Override public int hashCode() { return uuid.hashCode(); } }
4,810
23.671795
125
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.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.ce; import java.util.List; import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.RowBounds; import org.sonar.db.Pagination; public interface CeQueueMapper { List<CeQueueDto> selectByEntityUuid(@Param("entityUuid") String entityUuid); List<CeQueueDto> selectAllInAscOrder(); List<CeQueueDto> selectByQueryInDescOrder(@Param("query") CeTaskQuery query, RowBounds rowBounds); int countByQuery(@Param("query") CeTaskQuery query); Optional<CeTaskDtoLight> selectEligibleForPeek(@Param("pagination") Pagination pagination, @Param("excludeIndexationJob") boolean excludeIndexationJob, @Param("excludeViewRefresh") boolean excludeViewRefresh); @CheckForNull CeQueueDto selectByUuid(@Param("uuid") String uuid); /** * Select all pending tasks */ List<CeQueueDto> selectPending(); List<PrOrBranchTask> selectInProgressWithCharacteristics(); /** * Select all pending tasks which have already been started. */ List<CeQueueDto> selectWornout(); /** * The tasks that are in the in-progress status for too long */ List<CeQueueDto> selectInProgressStartedBefore(@Param("date") long date); /** * Select all tasks whose worker UUID is not present in {@code knownWorkerUUIDs} */ void resetTasksWithUnknownWorkerUUIDs(@Param("knownWorkerUUIDs") List<String> knownWorkerUUIDs, @Param("updatedAt") long updatedAt); /** * Reset all IN_PROGRESS TASKS */ void resetAllInProgressTasks(@Param("updatedAt") long updatedAt); int countByStatusAndEntityUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("entityUuid") String entityUuid); @CheckForNull Long selectCreationDateOfOldestPendingByEntityUuid(@Nullable @Param("entityUuid") String entityUuid); List<QueueCount> countByStatusAndEntityUuids(@Param("status") CeQueueDto.Status status, @Param("entityUuids") List<String> entityUuids); void insert(CeQueueDto dto); List<CeQueueDto> selectNotPendingForWorker(@Param("workerUuid") String workerUuid); void resetToPendingByUuid(@Param("uuid") String uuid, @Param("updatedAt") long updatedAt); int updateIf(@Param("uuid") String uuid, @Param("new") UpdateIf.NewProperties newProperties, @Param("old") UpdateIf.OldProperties oldProperties); int deleteByUuid(@Param("uuid") String uuid, @Nullable @Param("deleteIf") DeleteIf deleteIf); boolean hasAnyIssueSyncTaskPendingOrInProgress(); List<PrOrBranchTask> selectOldestPendingPrOrBranch(); }
3,504
35.134021
138
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeScannerContextDao.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.ce; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; import java.util.Optional; import java.util.Set; import org.apache.commons.io.IOUtils; import org.sonar.api.utils.System2; import org.sonar.core.util.CloseableIterator; 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 java.nio.charset.StandardCharsets.UTF_8; public class CeScannerContextDao implements Dao { private final System2 system; public CeScannerContextDao(System2 system) { this.system = system; } /** * @throws IllegalArgumentException if {@code scannerContextLines} is empty or fully read. */ public void insert(DbSession dbSession, String taskUuid, CloseableIterator<String> scannerContextLines) { checkArgument(scannerContextLines.hasNext(), "Scanner context can not be empty"); long now = system.now(); Connection connection = dbSession.getConnection(); try (PreparedStatement stmt = connection.prepareStatement( "INSERT INTO ce_scanner_context (task_uuid, created_at, updated_at, context_data) VALUES (?, ?, ?, ?)"); InputStream inputStream = new LogsIteratorInputStream(scannerContextLines, UTF_8)) { stmt.setString(1, taskUuid); stmt.setLong(2, now); stmt.setLong(3, now); stmt.setBinaryStream(4, inputStream); stmt.executeUpdate(); connection.commit(); } catch (SQLException | IOException e) { throw new IllegalStateException("Fail to insert scanner context for task " + taskUuid, e); } } /** * The scanner context is very likely to contain lines, which are forcefully separated by {@code \n} characters, * whichever the platform SQ is running on ({@see LogsIteratorInputStream}). */ public Optional<String> selectScannerContext(DbSession dbSession, String taskUuid) { try (PreparedStatement stmt = dbSession.getConnection().prepareStatement("select context_data from ce_scanner_context where task_uuid=?")) { stmt.setString(1, taskUuid); try (ResultSet rs = stmt.executeQuery()) { if (rs.next()) { return Optional.of(IOUtils.toString(rs.getBinaryStream(1), UTF_8)); } return Optional.empty(); } } catch (SQLException | IOException e) { throw new IllegalStateException("Fail to retrieve scanner context of task " + taskUuid, e); } } public Set<String> selectOlderThan(DbSession dbSession, long beforeDate) { return mapper(dbSession).selectOlderThan(beforeDate); } public void deleteByUuids(DbSession dbSession, Collection<String> uuids) { DatabaseUtils.executeLargeUpdates(uuids, mapper(dbSession)::deleteByUuids); } private static CeScannerContextMapper mapper(DbSession dbSession) { return dbSession.getMapper(CeScannerContextMapper.class); } }
3,882
37.83
144
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeScannerContextMapper.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.ce; import java.util.List; import java.util.Set; import org.apache.ibatis.annotations.Param; public interface CeScannerContextMapper { void deleteByUuids(@Param("uuids") List<String> uuids); Set<String> selectOlderThan(@Param("beforeDate") long beforeDate); }
1,132
34.40625
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDao.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.ce; import java.util.Collection; import java.util.List; import java.util.Set; import org.sonar.db.Dao; import org.sonar.db.DbSession; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeUpdates; public class CeTaskCharacteristicDao implements Dao { public void insert(DbSession dbSession, Collection<CeTaskCharacteristicDto> characteristics) { for (CeTaskCharacteristicDto dto : characteristics) { insert(dbSession, dto); } } public void insert(DbSession dbSession, CeTaskCharacteristicDto dto) { mapper(dbSession).insert(dto); } public List<CeTaskCharacteristicDto> selectByTaskUuids(DbSession dbSession, Collection<String> taskUuids) { return executeLargeInputs(taskUuids, uuid -> mapper(dbSession).selectByTaskUuids(uuid)); } public void deleteByTaskUuids(DbSession dbSession, Set<String> taskUuids) { executeLargeUpdates(taskUuids, mapper(dbSession)::deleteByTaskUuids); } private static CeTaskCharacteristicMapper mapper(DbSession session) { return session.getMapper(CeTaskCharacteristicMapper.class); } }
1,995
35.290909
109
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.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.ce; import java.util.Set; public class CeTaskCharacteristicDto { public static final String BRANCH_KEY = "branch"; public static final String BRANCH_TYPE_KEY = "branchType"; public static final String PULL_REQUEST = "pullRequest"; public static final Set<String> SUPPORTED_KEYS = Set.of(BRANCH_KEY, BRANCH_TYPE_KEY, PULL_REQUEST); private String uuid; private String taskUuid; private String key; private String value; public String getUuid() { return uuid; } public CeTaskCharacteristicDto setUuid(String uuid) { this.uuid = uuid; return this; } public String getTaskUuid() { return taskUuid; } public CeTaskCharacteristicDto setTaskUuid(String taskUuid) { this.taskUuid = taskUuid; return this; } public String getKey() { return key; } public CeTaskCharacteristicDto setKey(String key) { this.key = key; return this; } public String getValue() { return value; } public CeTaskCharacteristicDto setValue(String value) { this.value = value; return this; } }
1,929
25.805556
101
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicMapper.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.ce; import java.util.List; import org.apache.ibatis.annotations.Param; public interface CeTaskCharacteristicMapper { List<CeTaskCharacteristicDto> selectByTaskUuids(@Param("taskUuids") List<String> taskUuids); void insert(CeTaskCharacteristicDto taskCharacteristic); void deleteByTaskUuids(@Param("taskUuids") List<String> taskUuids); }
1,212
35.757576
94
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskDtoLight.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.ce; import java.util.Comparator; import java.util.Objects; public class CeTaskDtoLight implements Comparable<CeTaskDtoLight> { private String ceTaskUuid; private long createdAt; public void setCeTaskUuid(String ceTaskUuid) { this.ceTaskUuid = ceTaskUuid; } public void setCreatedAt(long createdAt) { this.createdAt = createdAt; } public long getCreatedAt() { return createdAt; } public String getCeTaskUuid() { return ceTaskUuid; } @Override public int compareTo(CeTaskDtoLight o) { return Comparator.comparingLong(CeTaskDtoLight::getCreatedAt).thenComparing(CeTaskDtoLight::getCeTaskUuid).compare(this, o); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } CeTaskDtoLight that = (CeTaskDtoLight) o; return createdAt == that.createdAt && Objects.equals(ceTaskUuid, that.ceTaskUuid); } @Override public int hashCode() { return Objects.hash(ceTaskUuid, createdAt); } }
1,930
27.397059
128
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskInputDao.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.ce; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; import java.util.List; import java.util.Optional; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbInputStream; import org.sonar.db.DatabaseUtils; import org.sonar.db.DbSession; public class CeTaskInputDao implements Dao { private final System2 system; public CeTaskInputDao(System2 system) { this.system = system; } public void insert(DbSession dbSession, String taskUuid, InputStream data) { long now = system.now(); Connection connection = dbSession.getConnection(); try (PreparedStatement stmt = connection.prepareStatement( "INSERT INTO ce_task_input (task_uuid, created_at, updated_at, input_data) VALUES (?, ?, ?, ?)")) { stmt.setString(1, taskUuid); stmt.setLong(2, now); stmt.setLong(3, now); stmt.setBinaryStream(4, data); stmt.executeUpdate(); connection.commit(); } catch (SQLException e) { throw new IllegalStateException("Fail to insert data of CE task " + taskUuid, e); } } public Optional<DbInputStream> selectData(DbSession dbSession, String taskUuid) { PreparedStatement stmt = null; ResultSet rs = null; DbInputStream result = null; try { stmt = dbSession.getConnection().prepareStatement("SELECT input_data FROM ce_task_input WHERE task_uuid=? AND input_data IS NOT NULL"); stmt.setString(1, taskUuid); rs = stmt.executeQuery(); if (rs.next()) { result = new DbInputStream(stmt, rs, rs.getBinaryStream(1)); return Optional.of(result); } return Optional.empty(); } catch (SQLException e) { throw new IllegalStateException("Fail to select data of CE task " + taskUuid, e); } finally { if (result == null) { DatabaseUtils.closeQuietly(rs); DatabaseUtils.closeQuietly(stmt); } } } public List<String> selectUuidsNotInQueue(DbSession dbSession) { return dbSession.getMapper(CeTaskInputMapper.class).selectUuidsNotInQueue(); } public void deleteByUuids(DbSession dbSession, Collection<String> uuids) { CeTaskInputMapper mapper = dbSession.getMapper(CeTaskInputMapper.class); DatabaseUtils.executeLargeUpdates(uuids, mapper::deleteByUuids); } }
3,265
34.5
141
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskInputMapper.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.ce; import java.util.List; import org.apache.ibatis.annotations.Param; public interface CeTaskInputMapper { void deleteByUuids(@Param("uuids") List<String> uuids); List<String> selectUuidsNotInQueue(); }
1,077
32.6875
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.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.ce; import java.util.List; import java.util.Optional; import org.sonar.db.Dao; import org.sonar.db.DbSession; public class CeTaskMessageDao implements Dao { public void insert(DbSession dbSession, CeTaskMessageDto dto) { getMapper(dbSession).insert(dto); } public Optional<CeTaskMessageDto> selectByUuid(DbSession dbSession, String uuid) { return getMapper(dbSession).selectByUuid(uuid); } /** * @return the non dismissed messages for the specific task and specific user, if any, in ascending order of column {@code CREATED_AT}. */ public List<CeTaskMessageDto> selectNonDismissedByUserAndTask(DbSession dbSession, String taskUuid, String userUuid) { return getMapper(dbSession).selectNonDismissedByUserAndTask(taskUuid, userUuid); } public void deleteByType(DbSession session, CeTaskMessageType type) { getMapper(session).deleteByType(type.name()); } private static CeTaskMessageMapper getMapper(DbSession dbSession) { return dbSession.getMapper(CeTaskMessageMapper.class); } }
1,898
35.519231
137
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDto.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.ce; import com.google.common.annotations.VisibleForTesting; import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang.StringUtils.abbreviate; public class CeTaskMessageDto { @VisibleForTesting static final int MAX_MESSAGE_SIZE = 4000; /** * Unique identifier of each message. Not null */ private String uuid; /** * UUID of the task the message belongs to. Not null */ private String taskUuid; /** * The text of the message. Not null */ private String message; /** * Type of the message */ private CeTaskMessageType type; /** * Timestamp the message was created. Not null */ private long createdAt; public String getUuid() { return uuid; } public CeTaskMessageDto setUuid(String uuid) { this.uuid = uuid; return this; } public String getTaskUuid() { return taskUuid; } public CeTaskMessageDto setTaskUuid(String taskUuid) { this.taskUuid = taskUuid; return this; } public String getMessage() { return message; } public CeTaskMessageDto setMessage(String message) { checkArgument(message != null && !message.isEmpty(), "message can't be null nor empty"); this.message = abbreviate(message, MAX_MESSAGE_SIZE); return this; } public CeTaskMessageType getType() { return type; } public CeTaskMessageDto setType(CeTaskMessageType type) { this.type = type; return this; } public long getCreatedAt() { return createdAt; } public CeTaskMessageDto setCreatedAt(long createdAt) { this.createdAt = createdAt; return this; } }
2,495
24.731959
92
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.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.ce; import java.util.List; import java.util.Optional; import org.apache.ibatis.annotations.Param; public interface CeTaskMessageMapper { void insert(@Param("dto") CeTaskMessageDto dto); Optional<CeTaskMessageDto> selectByUuid(@Param("uuid") String uuid); List<CeTaskMessageDto> selectNonDismissedByUserAndTask(@Param("taskUuid") String taskUuid, @Param("userUuid") String userUuid); void deleteByType(@Param("ceMessageType") String ceMessageType); }
1,327
36.942857
129
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageType.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.ce; public enum CeTaskMessageType { INFO(false, false), GENERIC(false, true), SUGGEST_DEVELOPER_EDITION_UPGRADE(true, true); private final boolean dismissible; private final boolean isWarning; CeTaskMessageType(boolean dismissible, boolean isWarning) { this.dismissible = dismissible; this.isWarning = isWarning; } public boolean isDismissible() { return dismissible; } public boolean isWarning() { return isWarning; } }
1,328
29.906977
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskQuery.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.ce; import java.util.ArrayList; import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.DatabaseUtils; import static com.google.common.collect.Lists.newArrayList; /** * Db Query used for CE_QUEUE and CE_ACTIVITY tables */ public class CeTaskQuery { public static final int MAX_COMPONENT_UUIDS = DatabaseUtils.PARTITION_SIZE_FOR_ORACLE; private boolean onlyCurrents = false; // SONAR-7681 a public implementation of List must be used in MyBatis - potential concurrency exceptions otherwise @Nullable private ArrayList<String> entityUuids; @Nullable private ArrayList<String> statuses; @Nullable private String type; @Nullable private Long minSubmittedAt; @Nullable private Long maxExecutedAt; @Nullable private Long minExecutedAt; @Nullable private ArrayList<String> errorTypes; @CheckForNull public List<String> getEntityUuids() { return entityUuids; } public CeTaskQuery setEntityUuids(@Nullable List<String> l) { this.entityUuids = l == null ? null : newArrayList(l); return this; } public boolean isShortCircuitedByEntityUuids() { return entityUuids != null && (entityUuids.isEmpty() || entityUuids.size() > MAX_COMPONENT_UUIDS); } public CeTaskQuery setEntityUuid(@Nullable String s) { if (s == null) { this.entityUuids = null; } else { this.entityUuids = newArrayList(s); } return this; } public boolean isOnlyCurrents() { return onlyCurrents; } public CeTaskQuery setOnlyCurrents(boolean onlyCurrents) { this.onlyCurrents = onlyCurrents; return this; } @CheckForNull public List<String> getStatuses() { return statuses; } public CeTaskQuery setStatuses(@Nullable List<String> statuses) { this.statuses = statuses == null ? null : newArrayList(statuses); return this; } @CheckForNull public List<String> getErrorTypes() { return errorTypes; } public CeTaskQuery setErrorTypes(@Nullable List<String> l) { this.errorTypes = l == null ? null : newArrayList(l); return this; } @CheckForNull public String getType() { return type; } public CeTaskQuery setType(@Nullable String type) { this.type = type; return this; } @CheckForNull public Long getMaxExecutedAt() { return maxExecutedAt; } public CeTaskQuery setMaxExecutedAt(@Nullable Long l) { this.maxExecutedAt = l; return this; } @CheckForNull public Long getMinExecutedAt() { return minExecutedAt; } public CeTaskQuery setMinExecutedAt(@Nullable Long l) { this.minExecutedAt = l; return this; } @CheckForNull public Long getMinSubmittedAt() { return minSubmittedAt; } public CeTaskQuery setMinSubmittedAt(@Nullable Long l) { this.minSubmittedAt = l; return this; } }
3,718
24.472603
116
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskTypes.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.ce; public final class CeTaskTypes { public static final String AUDIT_PURGE = "AUDIT_PURGE"; public static final String BRANCH_ISSUE_SYNC = "ISSUE_SYNC"; public static final String REPORT = "REPORT"; public static final String PROJECT_EXPORT = "PROJECT_EXPORT"; private CeTaskTypes() { // only statics } }
1,192
34.088235
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/DeleteIf.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.ce; public class DeleteIf { public final CeQueueDto.Status expectedStatus; public DeleteIf(CeQueueDto.Status expectedStatus) { this.expectedStatus = expectedStatus; } }
1,045
35.068966
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/LogsIteratorInputStream.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.ce; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import org.sonar.core.util.CloseableIterator; import static com.google.common.base.Preconditions.checkArgument; /** * An {@link InputStream} that will read from a {@link CloseableIterator} of {@link String}, inserting {@code \n} between * each element of the Iterator. */ final class LogsIteratorInputStream extends InputStream { private static final int UNSET = -1; private static final int END_OF_STREAM = -1; private final Charset charset; private final byte[] lineFeed; private CloseableIterator<String> logsIterator; private byte[] buf; private int nextChar = UNSET; LogsIteratorInputStream(CloseableIterator<String> logsIterator, Charset charset) { checkArgument(logsIterator.hasNext(), "LogsIterator can't be empty or already read"); this.charset = charset; this.lineFeed = "\n".getBytes(charset); this.logsIterator = logsIterator; } @Override public int read() { if (nextChar == UNSET || nextChar >= buf.length) { fill(); if (nextChar == UNSET) { return END_OF_STREAM; } } byte signedByte = buf[nextChar]; nextChar++; return signedByte & 0xFF; } private void fill() { if (logsIterator.hasNext()) { byte[] line = logsIterator.next().getBytes(charset); boolean hasNextLine = logsIterator.hasNext(); int bufLength = hasNextLine ? (line.length + lineFeed.length) : line.length; // empty last line if (bufLength == 0) { this.buf = null; this.nextChar = UNSET; } else { this.buf = new byte[bufLength]; System.arraycopy(line, 0, buf, 0, line.length); if (hasNextLine) { System.arraycopy(lineFeed, 0, buf, line.length, lineFeed.length); } this.nextChar = 0; } } else { this.buf = null; this.nextChar = UNSET; } } @Override public void close() throws IOException { this.logsIterator.close(); this.buf = null; super.close(); } }
2,936
30.244681
121
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/PrOrBranchTask.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.ce; public class PrOrBranchTask extends CeTaskDtoLight { private String entityUuid; private String taskType; private String branchType; private String componentUuid; public String getEntityUuid() { return entityUuid; } public String getBranchType() { return branchType; } public String getComponentUuid() { return componentUuid; } public String getTaskType() { return taskType; } }
1,292
27.733333
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/QueueCount.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.ce; public class QueueCount { // set by reflection by MyBatis private String entityUuid; private int total; public String getEntityUuid() { return entityUuid; } public int getTotal() { return total; } }
1,092
30.228571
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/UpdateIf.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.ce; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; public final class UpdateIf { private UpdateIf() { // just a wrapping class, prevent instantiation } @Immutable public static class NewProperties { private final CeQueueDto.Status status; private final String workerUuid; private final Long startedAt; private final long updatedAt; public NewProperties(CeQueueDto.Status status, @Nullable String workerUuid, long startedAt, long updatedAt) { checkArgument(workerUuid == null || workerUuid.length() <= 40, "worker uuid is too long: %s", workerUuid); this.status = requireNonNull(status, "status can't be null"); this.workerUuid = workerUuid; this.startedAt = startedAt; this.updatedAt = updatedAt; } public CeQueueDto.Status getStatus() { return status; } @CheckForNull public String getWorkerUuid() { return workerUuid; } public Long getStartedAt() { return startedAt; } public long getUpdatedAt() { return updatedAt; } } @Immutable public static class OldProperties { private final CeQueueDto.Status status; public OldProperties(CeQueueDto.Status status) { this.status = requireNonNull(status, "status can't be null"); } public CeQueueDto.Status getStatus() { return status; } } }
2,416
28.47561
112
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/ce/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.ce; import javax.annotation.ParametersAreNonnullByDefault;
956
37.28
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.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.component; import java.util.Collection; import java.util.List; 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 java.util.Objects.requireNonNull; public class AnalysisPropertiesDao implements Dao { private static final int VARCHAR_MAXSIZE = 4000; private final System2 system2; public AnalysisPropertiesDao(System2 system2) { this.system2 = system2; } public List<AnalysisPropertyDto> selectByAnalysisUuid(DbSession session, String analysisUuid) { requireNonNull(analysisUuid); return getMapper(session).selectByAnalysisUuid(analysisUuid); } public List<AnalysisPropertyDto> selectByKeyAndAnalysisUuids(DbSession session, String key, Collection<String> snapshotUuids) { requireNonNull(snapshotUuids); var mapper = getMapper(session); return DatabaseUtils.executeLargeInputs(snapshotUuids, input -> mapper.selectByKeyAnAnalysisUuids(input, key)); } public void insert(DbSession session, List<AnalysisPropertyDto> analysisPropertyDto) { analysisPropertyDto.forEach(a -> insert(session, a)); } public void insert(DbSession session, AnalysisPropertyDto analysisPropertyDto) { requireNonNull(analysisPropertyDto.getUuid(), "uuid cannot be null"); requireNonNull(analysisPropertyDto.getKey(), "key cannot be null"); requireNonNull(analysisPropertyDto.getAnalysisUuid(), "analysis uuid cannot be null"); requireNonNull(analysisPropertyDto.getValue(), "value cannot be null"); String value = analysisPropertyDto.getValue(); long now = system2.now(); if (isEmpty(value)) { getMapper(session).insertAsEmpty(analysisPropertyDto, now); } else if (mustBeStoredInClob(value)) { getMapper(session).insertAsClob(analysisPropertyDto, now); } else { getMapper(session).insertAsText(analysisPropertyDto, now); } } public List<AnalysisPropertyValuePerProject> selectAnalysisPropertyValueInLastAnalysisPerProject(DbSession session, String analysisPropertyKey) { return getMapper(session).selectAnalysisPropertyValueInLastAnalysisPerProject(analysisPropertyKey); } private static boolean mustBeStoredInClob(String value) { return value.length() > VARCHAR_MAXSIZE; } private static boolean isEmpty(@Nullable String str) { return str == null || str.isEmpty(); } private static AnalysisPropertiesMapper getMapper(DbSession session) { return session.getMapper(AnalysisPropertiesMapper.class); } }
3,418
36.988889
147
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.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.component; import java.util.Collection; import java.util.List; import org.apache.ibatis.annotations.Param; public interface AnalysisPropertiesMapper { List<AnalysisPropertyDto> selectByAnalysisUuid(@Param("analysisUuid") String analysisUuid); void insertAsEmpty(@Param("analysisPropertyDto") AnalysisPropertyDto analysisPropertyDto, @Param("createdAt") long createdAt); void insertAsClob(@Param("analysisPropertyDto") AnalysisPropertyDto analysisPropertyDto, @Param("createdAt") long createdAt); void insertAsText(@Param("analysisPropertyDto") AnalysisPropertyDto analysisPropertyDto, @Param("createdAt") long createdAt); List<AnalysisPropertyValuePerProject> selectAnalysisPropertyValueInLastAnalysisPerProject(@Param("analysisPropertyKey") String analysisPropertyKey); List<AnalysisPropertyDto> selectByKeyAnAnalysisUuids(@Param("analysisUuids") Collection<String> analysisUuids, @Param("analysisPropertyKey") String analysisPropertyKey); }
1,828
43.609756
171
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyDto.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.component; import java.util.Objects; import static java.util.Objects.requireNonNull; public class AnalysisPropertyDto { private String uuid; private String analysisUuid; private String key; private String value; private Long createdAt; public String getUuid() { return uuid; } public AnalysisPropertyDto setUuid(String uuid) { requireNonNull(uuid, "uuid cannot be null"); this.uuid = uuid; return this; } public String getAnalysisUuid() { return analysisUuid; } public AnalysisPropertyDto setAnalysisUuid(String analysisUuid) { requireNonNull(analysisUuid, "analysisUuid cannot be null"); this.analysisUuid = analysisUuid; return this; } public String getKey() { return key; } public AnalysisPropertyDto setKey(String key) { requireNonNull(key, "key cannot be null"); this.key = key; return this; } public String getValue() { return value; } public AnalysisPropertyDto setValue(String value) { requireNonNull(value, "value cannot be null"); this.value = value; return this; } public Long getCreatedAt() { return createdAt; } public AnalysisPropertyDto setCreatedAt(Long createdAt) { this.createdAt = createdAt; return this; } @Override public String toString() { return "AnalysisPropertyDto{" + "uuid='" + uuid + '\'' + ", analysisUuid='" + analysisUuid + '\'' + ", key='" + key + '\'' + ", value='" + value + "'" + ", createdAt=" + createdAt + '}'; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof AnalysisPropertyDto)) { return false; } AnalysisPropertyDto that = (AnalysisPropertyDto) o; return Objects.equals(uuid, that.uuid) && Objects.equals(analysisUuid, that.analysisUuid) && Objects.equals(key, that.key) && Objects.equals(value, that.value) && Objects.equals(createdAt, that.createdAt); } @Override public int hashCode() { return Objects.hash(uuid, analysisUuid, key, value, createdAt); } }
2,973
24.86087
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyValuePerProject.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.component; public class AnalysisPropertyValuePerProject { private String projectUuid; private String propertyValue; public AnalysisPropertyValuePerProject() { //nothing to do here } public String getPropertyValue() { return propertyValue; } public void setPropertyValue(String propertyValue) { this.propertyValue = propertyValue; } public String getProjectUuid() { return projectUuid; } public void setProjectUuid(String projectUuid) { this.projectUuid = projectUuid; } }
1,386
29.152174
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsDao.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.component; import java.util.Collection; import java.util.List; import java.util.Set; 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.project.ProjectDto; public class ApplicationProjectsDao implements Dao { private final System2 system2; private final UuidFactory uuidFactory; public ApplicationProjectsDao(System2 system2, UuidFactory uuidFactory) { this.system2 = system2; this.uuidFactory = uuidFactory; } public void addProject(DbSession dbSession, String applicationUuid, String projectUuid) { getMapper(dbSession).addProject(uuidFactory.create(), applicationUuid, projectUuid, system2.now()); } public void removeApplicationProjectsByApplicationAndProject(DbSession dbSession, String applicationUuid, String projectUuid) { getMapper(dbSession).removeApplicationBranchProjectBranchesByApplicationAndProject(applicationUuid, projectUuid); getMapper(dbSession).removeApplicationProjectsByApplicationAndProject(applicationUuid, projectUuid); } public int countApplicationProjects(DbSession dbSession, String applicationUuid) { return getMapper(dbSession).countApplicationProjects(applicationUuid); } public Set<ProjectDto> selectProjects(DbSession dbSession, String applicationUuid) { return getMapper(dbSession).selectProjects(applicationUuid); } public void addProjectBranchToAppBranch(DbSession dbSession, BranchDto applicationBranch, BranchDto projectBranch) { getMapper(dbSession).addProjectBranchToAppBranch( uuidFactory.create(), applicationBranch.getProjectUuid(), applicationBranch.getUuid(), projectBranch.getProjectUuid(), projectBranch.getUuid(), system2.now()); } public void addProjectBranchToAppBranch(DbSession dbSession, String applicationUuid, String applicationBranchUuid, String projectUuid, String projectBranchUuid) { getMapper(dbSession).addProjectBranchToAppBranch( uuidFactory.create(), applicationUuid, applicationBranchUuid, projectUuid, projectBranchUuid, system2.now()); } public void removeProjectBranchFromAppBranch(DbSession dbSession, String applicationBranchUuid, String projectBranchUuid) { getMapper(dbSession).removeProjectBranchFromAppBranch(applicationBranchUuid, projectBranchUuid); } public Set<BranchDto> selectProjectBranchesFromAppBranchUuid(DbSession dbSession, String applicationBranchUuid) { return getMapper(dbSession).selectProjectBranchesFromAppBranchUuid(applicationBranchUuid); } public Set<BranchDto> selectProjectBranchesFromAppBranchKey(DbSession dbSession, String applicationUuid, String applicationBranchKey) { return getMapper(dbSession).selectProjectBranchesFromAppBranchKey(applicationUuid, applicationBranchKey); } public Set<ProjectDto> selectApplicationsFromProjectBranch(DbSession dbSession, String projectUuid, String branchKey) { return getMapper(dbSession).selectApplicationsFromProjectBranch(projectUuid, branchKey); } public Set<ProjectDto> selectApplicationsFromProjects(DbSession dbSession, Collection<String> projectUuids) { return getMapper(dbSession).selectApplicationsFromProjects(projectUuids); } public List<BranchDto> selectProjectsMainBranchesOfApplication(DbSession dbSession, String applicationUuid) { return getMapper(dbSession).selectProjectsMainBranchesOfApplication(applicationUuid); } private static ApplicationProjectsMapper getMapper(DbSession session) { return session.getMapper(ApplicationProjectsMapper.class); } }
4,487
41.742857
164
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsMapper.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.component; import java.util.Collection; import java.util.List; import java.util.Set; import org.apache.ibatis.annotations.Param; import org.sonar.db.project.ProjectDto; public interface ApplicationProjectsMapper { void addProject( @Param("uuid") String uuid, @Param("applicationUuid") String applicationUuid, @Param("projectUuid") String projectUuid, @Param("now") long now); void removeApplicationBranchProjectBranchesByApplicationAndProject( @Param("applicationUuid") String applicationUuid, @Param("projectUuid") String projectUuid); void removeApplicationProjectsByApplicationAndProject( @Param("applicationUuid") String applicationUuid, @Param("projectUuid") String projectUuid); Set<ProjectDto> selectProjects(@Param("applicationUuid") String applicationUuid); void addProjectBranchToAppBranch( @Param("uuid") String uuid, @Param("applicationUuid") String applicationUuid, @Param("applicationBranchUuid") String applicationBranchUuid, @Param("projectUuid") String projectUuid, @Param("projectBranchUuid") String projectBranchUuid, @Param("now") long now); void removeProjectBranchFromAppBranch(@Param("applicationBranchUuid") String applicationBranchUuid, @Param("projectBranchUuid") String projectBranchUuid); Set<BranchDto> selectProjectBranchesFromAppBranchUuid(@Param("applicationBranchUuid") String applicationBranchUuid); Set<BranchDto> selectProjectBranchesFromAppBranchKey(@Param("applicationUuid") String applicationUuid, @Param("applicationBranchKey") String applicationBranchKey); int countApplicationProjects(@Param("applicationUuid") String applicationUuid); Set<ProjectDto> selectApplicationsFromProjectBranch(@Param("projectUuid") String projectUuid, @Param("branchKey") String branchKey); Set<ProjectDto> selectApplicationsFromProjects(@Param("projectUuids") Collection<String> projectUuids); List<BranchDto> selectProjectsMainBranchesOfApplication(String applicationUuid); }
2,855
41.626866
165
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.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.component; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.project.ProjectDto; import static java.util.Collections.emptyList; import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class BranchDao implements Dao { private final System2 system2; public BranchDao(System2 system2) { this.system2 = system2; } public void insert(DbSession dbSession, BranchDto dto) { BranchMapper mapper = mapper(dbSession); mapper.insert(dto, system2.now()); } public void upsert(DbSession dbSession, BranchDto dto) { BranchMapper mapper = mapper(dbSession); long now = system2.now(); if (mapper.update(dto, now) == 0) { mapper.insert(dto, now); } } public int updateBranchName(DbSession dbSession, String branchUuid, String newBranchKey) { long now = system2.now(); return mapper(dbSession).updateBranchName(branchUuid, newBranchKey, now); } public int updateExcludeFromPurge(DbSession dbSession, String branchUuid, boolean excludeFromPurge) { long now = system2.now(); return mapper(dbSession).updateExcludeFromPurge(branchUuid, excludeFromPurge, now); } public Optional<BranchDto> selectByBranchKey(DbSession dbSession, String projectUuid, String key) { return selectByKey(dbSession, projectUuid, key, BranchType.BRANCH); } public List<BranchDto> selectByBranchKeys(DbSession dbSession, Map<String, String> branchKeyByProjectUuid) { if (branchKeyByProjectUuid.isEmpty()) { return emptyList(); } return mapper(dbSession).selectByBranchKeys(branchKeyByProjectUuid); } public List<BranchDto> selectByPullRequestKeys(DbSession dbSession, Map<String, String> prKeyByProjectUuid) { if (prKeyByProjectUuid.isEmpty()) { return emptyList(); } return mapper(dbSession).selectByPullRequestKeys(prKeyByProjectUuid); } public Optional<BranchDto> selectByPullRequestKey(DbSession dbSession, String projectUuid, String key) { return selectByKey(dbSession, projectUuid, key, BranchType.PULL_REQUEST); } private static Optional<BranchDto> selectByKey(DbSession dbSession, String projectUuid, String key, BranchType branchType) { return Optional.ofNullable(mapper(dbSession).selectByKey(projectUuid, key, branchType)); } public List<BranchDto> selectByKeys(DbSession dbSession, String projectUuid, Set<String> branchKeys) { if (branchKeys.isEmpty()) { return emptyList(); } return executeLargeInputs(branchKeys, partition -> mapper(dbSession).selectByKeys(projectUuid, partition)); } /* * Returns collection of branches that are in the same project as the component */ public Collection<BranchDto> selectByComponent(DbSession dbSession, ComponentDto component) { BranchDto branchDto = mapper(dbSession).selectByUuid(component.branchUuid()); if (branchDto == null) { return List.of(); } return mapper(dbSession).selectByProjectUuid(branchDto.getProjectUuid()); } public Collection<BranchDto> selectByProject(DbSession dbSession, ProjectDto project) { return selectByProjectUuid(dbSession, project.getUuid()); } public Collection<BranchDto> selectByProjectUuid(DbSession dbSession, String projectUuid) { return mapper(dbSession).selectByProjectUuid(projectUuid); } public Optional<BranchDto> selectMainBranchByProjectUuid(DbSession dbSession, String projectUuid) { return mapper(dbSession).selectMainBranchByProjectUuid(projectUuid); } public List<BranchDto> selectMainBranchesByProjectUuids(DbSession dbSession, Collection<String> projectUuids) { if (projectUuids.isEmpty()) { return List.of(); } return executeLargeInputs(projectUuids, partition -> mapper(dbSession).selectMainBranchesByProjectUuids(partition)); } public List<PrBranchAnalyzedLanguageCountByProjectDto> countPrBranchAnalyzedLanguageByProjectUuid(DbSession dbSession) { return mapper(dbSession).countPrBranchAnalyzedLanguageByProjectUuid(); } public List<BranchDto> selectByUuids(DbSession session, Collection<String> uuids) { if (uuids.isEmpty()) { return emptyList(); } return executeLargeInputs(uuids, mapper(session)::selectByUuids); } public Optional<BranchDto> selectByUuid(DbSession session, String uuid) { return Optional.ofNullable(mapper(session).selectByUuid(uuid)); } public List<String> selectProjectUuidsWithIssuesNeedSync(DbSession session, Collection<String> uuids) { if (uuids.isEmpty()) { return emptyList(); } return executeLargeInputs(uuids, mapper(session)::selectProjectUuidsWithIssuesNeedSync); } public boolean hasAnyBranchWhereNeedIssueSync(DbSession session, boolean needIssueSync) { return mapper(session).hasAnyBranchWhereNeedIssueSync(needIssueSync) > 0; } public long countByTypeAndCreationDate(DbSession dbSession, BranchType branchType, long sinceDate) { return mapper(dbSession).countByTypeAndCreationDate(branchType.name(), sinceDate); } public int countByNeedIssueSync(DbSession session, boolean needIssueSync) { return mapper(session).countByNeedIssueSync(needIssueSync); } public int countAll(DbSession session) { return mapper(session).countAll(); } private static BranchMapper mapper(DbSession dbSession) { return dbSession.getMapper(BranchMapper.class); } public List<BranchDto> selectBranchNeedingIssueSync(DbSession dbSession) { return mapper(dbSession).selectBranchNeedingIssueSync(); } public List<BranchDto> selectBranchNeedingIssueSyncForProject(DbSession dbSession, String projectUuid) { return mapper(dbSession).selectBranchNeedingIssueSyncForProject(projectUuid); } public long updateAllNeedIssueSync(DbSession dbSession) { return mapper(dbSession).updateAllNeedIssueSync(system2.now()); } public long updateAllNeedIssueSyncForProject(DbSession dbSession, String projectUuid) { return mapper(dbSession).updateAllNeedIssueSyncForProject(projectUuid, system2.now()); } public long updateNeedIssueSync(DbSession dbSession, String branchUuid, boolean needIssueSync) { long now = system2.now(); return mapper(dbSession).updateNeedIssueSync(branchUuid, needIssueSync, now); } public boolean doAnyOfComponentsNeedIssueSync(DbSession session, List<String> components) { if (!components.isEmpty()) { List<Boolean> result = new LinkedList<>(); return executeLargeInputs(components, input -> { boolean groupNeedIssueSync = mapper(session).doAnyOfComponentsNeedIssueSync(input) > 0; result.add(groupNeedIssueSync); return result; }).stream() .anyMatch(b -> b); } return false; } public boolean isBranchNeedIssueSync(DbSession session, String branchUuid) { return selectByUuid(session, branchUuid) .map(BranchDto::isNeedIssueSync) .orElse(false); } public List<BranchMeasuresDto> selectBranchMeasuresWithCaycMetric(DbSession dbSession) { long yesterday = ZonedDateTime.now(ZoneId.systemDefault()).minusDays(1).toInstant().toEpochMilli(); return mapper(dbSession).selectBranchMeasuresWithCaycMetric(yesterday); } }
8,254
36.522727
126
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.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.component; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Objects; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.protobuf.DbProjectBranches; import static com.google.common.base.Preconditions.checkArgument; public class BranchDto { public static final String DEFAULT_MAIN_BRANCH_NAME = "main"; /** * Maximum length of column "kee" */ public static final int KEE_MAX_LENGTH = 255; /** * Branch UUID is the projects.uuid that reference projects, branches or pull requests * (projects.qualifier="TRK"). * Not null. * Important - the table project_branches does NOT have its own UUIDs for the time being. * All values must exist in projects.uuid. */ private String uuid; /** * UUID of the project that represents the main branch. * On main branches, projectUuid equals uuid. * Not null. */ private String projectUuid; /** * Key that identifies a branch or a pull request. * For keyType=BRANCH, this is the name of the branch, for example "feature/foo". * For keyType=PULL_REQUEST, this is the ID of the pull request in some external system, for example 123 in GitHub. */ private String kee; /** * Branch type, as provided by {@link BranchType}. * Not null. */ private BranchType branchType; /** * UUID of the branch: * - in which the pull request will be merged into * - that is the base of a branch. * <p> * Can be null if information is not known. */ @Nullable private String mergeBranchUuid; /** * Pull Request data, such as branch name, title, url, and provider specific attributes */ @Nullable private byte[] pullRequestBinary; private boolean excludeFromPurge; private boolean needIssueSync = false; private Boolean isMain; public String getUuid() { return uuid; } public BranchDto setUuid(String s) { this.uuid = s; return this; } public String getProjectUuid() { return projectUuid; } public BranchDto setProjectUuid(String s) { this.projectUuid = s; return this; } public boolean isMain() { return isMain; } public BranchDto setIsMain(boolean isMain) { this.isMain = isMain; return this; } /** * This is the getter used by MyBatis mapper. */ private String getKee() { return kee; } public String getKey() { return kee; } /** * This is the setter used by MyBatis mapper. */ private void setKee(String s) { this.kee = s; } public BranchDto setKey(String s) { checkArgument(s.length() <= KEE_MAX_LENGTH, "Maximum length of branch name or pull request id is %s: %s", KEE_MAX_LENGTH, s); setKee(s); return this; } public BranchType getBranchType() { return branchType; } public BranchDto setBranchType(BranchType b) { this.branchType = b; return this; } @Nullable public String getMergeBranchUuid() { return mergeBranchUuid; } public BranchDto setMergeBranchUuid(@Nullable String s) { this.mergeBranchUuid = s; return this; } public BranchDto setPullRequestData(DbProjectBranches.PullRequestData pullRequestData) { this.pullRequestBinary = encodePullRequestData(pullRequestData); return this; } @CheckForNull public DbProjectBranches.PullRequestData getPullRequestData() { if (pullRequestBinary == null) { return null; } return decodePullRequestData(pullRequestBinary); } public boolean isExcludeFromPurge() { return excludeFromPurge; } public BranchDto setExcludeFromPurge(boolean excludeFromPurge) { this.excludeFromPurge = excludeFromPurge; return this; } private static byte[] encodePullRequestData(DbProjectBranches.PullRequestData pullRequestData) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { pullRequestData.writeTo(outputStream); return outputStream.toByteArray(); } catch (IOException e) { throw new IllegalStateException("Fail to serialize pull request data", e); } } private static DbProjectBranches.PullRequestData decodePullRequestData(byte[] pullRequestBinary) { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(pullRequestBinary)) { return DbProjectBranches.PullRequestData.parseFrom(inputStream); } catch (IOException e) { throw new IllegalStateException("Fail to deserialize pull request data", e); } } public boolean isNeedIssueSync() { return needIssueSync; } public BranchDto setNeedIssueSync(boolean needIssueSync) { this.needIssueSync = needIssueSync; return this; } @CheckForNull public String getBranchKey() { return branchType == BranchType.BRANCH ? kee : null; } @CheckForNull public String getPullRequestKey() { return branchType == BranchType.PULL_REQUEST ? kee : null; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } BranchDto branchDto = (BranchDto) o; return Objects.equals(uuid, branchDto.uuid) && Objects.equals(projectUuid, branchDto.projectUuid) && Objects.equals(isMain, branchDto.isMain) && Objects.equals(kee, branchDto.kee) && branchType == branchDto.branchType && Objects.equals(mergeBranchUuid, branchDto.mergeBranchUuid) && needIssueSync == branchDto.needIssueSync; } @Override public int hashCode() { return Objects.hash(uuid, projectUuid, isMain, kee, branchType, mergeBranchUuid, needIssueSync); } @Override public String toString() { return "BranchDto{" + "uuid='" + uuid + '\'' + ", projectUuid='" + projectUuid + '\'' + ", isMain='" + isMain + '\'' + ", kee='" + kee + '\'' + ", branchType=" + branchType + ", mergeBranchUuid='" + mergeBranchUuid + '\'' + ", excludeFromPurge=" + excludeFromPurge + ", needIssueSync=" + needIssueSync + '}'; } }
6,947
26.035019
129
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.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.component; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; import org.apache.ibatis.annotations.Param; public interface BranchMapper { void insert(@Param("dto") BranchDto dto, @Param("now") long now); int update(@Param("dto") BranchDto dto, @Param("now") long now); int updateBranchName(@Param("branchUuid") String branchUuid, @Param("newBranchName") String newBranchName, @Param("now") long now); int updateExcludeFromPurge(@Param("uuid") String uuid, @Param("excludeFromPurge") boolean excludeFromPurge, @Param("now") long now); BranchDto selectByKey(@Param("projectUuid") String projectUuid, @Param("key") String key, @Param("branchType") BranchType branchType); List<BranchDto> selectByKeys(@Param("projectUuid") String projectUuid, @Param("keys") Collection<String> branchKeys); BranchDto selectByUuid(@Param("uuid") String uuid); Collection<BranchDto> selectByProjectUuid(@Param("projectUuid") String projectUuid); List<PrBranchAnalyzedLanguageCountByProjectDto> countPrBranchAnalyzedLanguageByProjectUuid(); List<BranchDto> selectByBranchKeys(@Param("branchKeyByProjectUuid") Map<String, String> branchKeyByProjectUuid); List<BranchDto> selectByPullRequestKeys(@Param("prKeyByProjectUuid") Map<String, String> prKeyByProjectUuid); List<BranchDto> selectByUuids(@Param("uuids") Collection<String> uuids); List<String> selectProjectUuidsWithIssuesNeedSync(@Param("projectUuids") Collection<String> uuids); long countByTypeAndCreationDate(@Param("branchType") String branchType, @Param("sinceDate") long sinceDate); short hasAnyBranchWhereNeedIssueSync(@Param("needIssueSync") boolean needIssueSync); int countByNeedIssueSync(@Param("needIssueSync") boolean needIssueSync); int countAll(); List<BranchDto> selectBranchNeedingIssueSync(); List<BranchDto> selectBranchNeedingIssueSyncForProject(@Param("projectUuid") String projectUuid); long updateAllNeedIssueSync(@Param("now") long now); long updateAllNeedIssueSyncForProject(@Param("projectUuid") String projectUuid, @Param("now") long now); long updateNeedIssueSync(@Param("uuid") String uuid, @Param("needIssueSync")boolean needIssueSync,@Param("now") long now); short doAnyOfComponentsNeedIssueSync(@Param("componentKeys") List<String> components); Optional<BranchDto> selectMainBranchByProjectUuid(String projectUuid); List<BranchDto> selectMainBranchesByProjectUuids(@Param("projectUuids") Collection<String> projectUuids); List<BranchMeasuresDto> selectBranchMeasuresWithCaycMetric(long yesterday); }
3,464
40.746988
136
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMeasuresDto.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.component; public class BranchMeasuresDto { private String branchUuid; private String projectUuid; private String branchKey; private boolean excludeFromPurge; private int greenQualityGateCount; private int analysisCount; public BranchMeasuresDto(String branchUuid, String projectUuid, String branchKey, boolean excludeFromPurge, int greenQualityGateCount, int analysisCount) { this.branchUuid = branchUuid; this.projectUuid = projectUuid; this.branchKey = branchKey; this.excludeFromPurge = excludeFromPurge; this.greenQualityGateCount = greenQualityGateCount; this.analysisCount = analysisCount; } public String getBranchUuid() { return branchUuid; } public String getProjectUuid() { return projectUuid; } public boolean getExcludeFromPurge() { return excludeFromPurge; } public int getGreenQualityGateCount() { return greenQualityGateCount; } public int getAnalysisCount() { return analysisCount; } public String getBranchKey() { return branchKey; } }
1,915
28.9375
157
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchType.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.component; public enum BranchType { BRANCH, PULL_REQUEST }
928
34.730769
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.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.component; import com.google.common.collect.Ordering; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.sonar.api.resources.Qualifiers; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.ComponentNewValue; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Collections.emptyList; import static org.sonar.db.DatabaseUtils.checkThatNotTooManyConditions; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeInputsIntoSet; import static org.sonar.db.DatabaseUtils.executeLargeUpdates; public class ComponentDao implements Dao { private final AuditPersister auditPersister; public ComponentDao(AuditPersister auditPersister) { this.auditPersister = auditPersister; } /* * SELECT BY UUID */ public Optional<ComponentDto> selectByUuid(DbSession session, String uuid) { return Optional.ofNullable(mapper(session).selectByUuid(uuid)); } public ComponentDto selectOrFailByUuid(DbSession session, String uuid) { return selectByUuid(session, uuid).orElseThrow(() -> new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid))); } public List<ComponentDto> selectByUuids(DbSession session, Collection<String> uuids) { return executeLargeInputs(uuids, mapper(session)::selectByUuids); } public List<String> selectExistingUuids(DbSession session, Collection<String> uuids) { return executeLargeInputs(uuids, mapper(session)::selectExistingUuids); } public List<ComponentDto> selectSubProjectsByComponentUuids(DbSession session, Collection<String> uuids) { if (uuids.isEmpty()) { return emptyList(); } return mapper(session).selectSubProjectsByComponentUuids(uuids); } public List<ComponentDto> selectEnabledViewsFromRootView(DbSession session, String rootViewUuid) { return mapper(session).selectEnabledViewsFromRootView(rootViewUuid); } public List<FilePathWithHashDto> selectEnabledFilesFromProject(DbSession session, String rootComponentUuid) { return mapper(session).selectEnabledFilesFromProject(rootComponentUuid); } /** * Retrieves all components with a specific branch UUID, no other filtering is done by this method. */ public List<ComponentDto> selectByBranchUuid(String branchUuid, DbSession dbSession) { return mapper(dbSession).selectByBranchUuid(branchUuid); } /* SELECT BY QUERY */ /** * @throws IllegalArgumentException if parameter query#getComponentIds() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values * @throws IllegalArgumentException if parameter query#getComponentKeys() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values * @throws IllegalArgumentException if parameter query#getMainComponentUuids() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values */ public List<ComponentDto> selectByQuery(DbSession dbSession, ComponentQuery query, int offset, int limit) { return selectByQueryImpl(dbSession, query, offset, limit); } /** * @throws IllegalArgumentException if parameter query#getComponentIds() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values * @throws IllegalArgumentException if parameter query#getComponentKeys() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values * @throws IllegalArgumentException if parameter query#getMainComponentUuids() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values */ public int countByQuery(DbSession session, ComponentQuery query) { return countByQueryImpl(session, query); } private static List<ComponentDto> selectByQueryImpl(DbSession session, ComponentQuery query, int offset, int limit) { if (query.hasEmptySetOfComponents()) { return emptyList(); } checkThatNotTooManyComponents(query); return mapper(session).selectByQuery(query, new RowBounds(offset, limit)); } private static int countByQueryImpl(DbSession session, ComponentQuery query) { if (query.hasEmptySetOfComponents()) { return 0; } checkThatNotTooManyComponents(query); return mapper(session).countByQuery(query); } /* SELECT BY KEY */ /** * Return all components of a project (including disable ones) */ public List<KeyWithUuidDto> selectUuidsByKeyFromProjectKey(DbSession session, String projectKey) { return mapper(session).selectUuidsByKeyFromProjectKeyAndBranchOrPr(projectKey, null, null); } public List<KeyWithUuidDto> selectUuidsByKeyFromProjectKeyAndBranch(DbSession session, String projectKey, String branch) { return mapper(session).selectUuidsByKeyFromProjectKeyAndBranchOrPr(projectKey, branch, null); } public List<KeyWithUuidDto> selectUuidsByKeyFromProjectKeyAndPullRequest(DbSession session, String projectKey, String pullrequest) { return mapper(session).selectUuidsByKeyFromProjectKeyAndBranchOrPr(projectKey, null, pullrequest); } public List<ComponentDto> selectByKeys(DbSession session, Collection<String> keys) { return selectByKeys(session, keys, null, null); } /** * If no branch or pull request is provided, returns components in the main branch */ public List<ComponentDto> selectByKeys(DbSession session, Collection<String> keys, @Nullable String branch, @Nullable String pullRequest) { checkState(branch == null || pullRequest == null, "Can't set both branch and pull request"); return executeLargeInputs(keys, subKeys -> mapper(session).selectByKeysAndBranchOrPr(subKeys, branch, pullRequest)); } /** * Returns components in the main branch */ public Optional<ComponentDto> selectByKey(DbSession session, String key) { return Optional.ofNullable(mapper(session).selectByKeyAndBranchOrPr(key, null, null)); } public Optional<ComponentDto> selectByKeyAndBranch(DbSession session, String key, String branch) { return Optional.ofNullable(mapper(session).selectByKeyAndBranchOrPr(key, branch, null)); } public Optional<ComponentDto> selectByKeyAndPullRequest(DbSession session, String key, String pullRequestId) { return Optional.ofNullable(mapper(session).selectByKeyAndBranchOrPr(key, null, pullRequestId)); } public List<ComponentDto> selectByKeyCaseInsensitive(DbSession session, String key) { return mapper(session).selectByKeyCaseInsensitive(key); } /** * List of ancestors, ordered from root to parent. The list is empty * if the component is a tree root. Disabled components are excluded by design * as tree represents the more recent analysis. */ public List<ComponentDto> selectAncestors(DbSession dbSession, ComponentDto component) { if (component.isRoot()) { return Collections.emptyList(); } List<String> ancestorUuids = component.getUuidPathAsList(); List<ComponentDto> ancestors = selectByUuids(dbSession, ancestorUuids); return Ordering.explicit(ancestorUuids).onResultOf(ComponentDto::uuid).immutableSortedCopy(ancestors); } /** * Select the children or the leaves of a base component, given by its UUID. The components that are not present in last * analysis are ignored. * <p> * An empty list is returned if the base component does not exist or if the base component is a leaf. */ public List<ComponentDto> selectDescendants(DbSession dbSession, ComponentTreeQuery query) { Optional<ComponentDto> componentOpt = selectByUuid(dbSession, query.getBaseUuid()); if (!componentOpt.isPresent()) { return emptyList(); } ComponentDto component = componentOpt.get(); return mapper(dbSession).selectDescendants(query, componentOpt.get().uuid(), query.getUuidPath(component)); } public List<ComponentDto> selectChildren(DbSession dbSession, String branchUuid, Collection<ComponentDto> components) { Set<String> uuidPaths = components.stream().map(c -> c.getUuidPath() + c.uuid() + ".").collect(Collectors.toSet()); return mapper(dbSession).selectChildren(branchUuid, uuidPaths); } /* SELECT ALL */ public List<UuidWithBranchUuidDto> selectAllViewsAndSubViews(DbSession session) { return mapper(session).selectUuidsForQualifiers(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW); } /** * Used by Governance */ public Set<String> selectViewKeysWithEnabledCopyOfProject(DbSession session, Set<String> projectUuids) { return executeLargeInputsIntoSet(projectUuids, partition -> mapper(session).selectViewKeysWithEnabledCopyOfProject(partition), i -> i); } public List<String> selectProjectBranchUuidsFromView(DbSession session, String viewUuid, String rootViewUuid) { // TODO why not query by scope/qualifier, using the view as the branchUuid? var escapedViewUuid = viewUuid.replace("_", "\\_").replace("%", "\\%"); return mapper(session).selectProjectsFromView("%." + escapedViewUuid + ".%", rootViewUuid); } /** * Retrieve enabled components keys with given qualifiers * <p> * Used by Views plugin */ public Set<ComponentDto> selectComponentsByQualifiers(DbSession dbSession, Set<String> qualifiers) { checkArgument(!qualifiers.isEmpty(), "Qualifiers cannot be empty"); return new HashSet<>(mapper(dbSession).selectComponentsByQualifiers(qualifiers)); } /** * Returns components with open issues from P/Rs that use a certain branch as reference (reference branch). * Excludes components from the current branch. */ public List<KeyWithUuidDto> selectComponentsFromPullRequestsTargetingCurrentBranchThatHaveOpenIssues(DbSession dbSession, String referenceBranchUuid, String currentBranchUuid) { return mapper(dbSession).selectComponentsFromPullRequestsTargetingCurrentBranchThatHaveOpenIssues(referenceBranchUuid, currentBranchUuid); } /** * Returns components with open issues from the given branches */ public List<KeyWithUuidDto> selectComponentsFromBranchesThatHaveOpenIssues(DbSession dbSession, Set<String> branchUuids) { if (branchUuids.isEmpty()) { return emptyList(); } return executeLargeInputs(branchUuids, input -> mapper(dbSession).selectComponentsFromBranchesThatHaveOpenIssues(input)); } /** * Scroll all <strong>enabled</strong> files of the specified project (same project_uuid) in no specific order with * 'SOURCE' source and a non null path. */ public void scrollAllFilesForFileMove(DbSession session, String branchUuid, ResultHandler<FileMoveRowDto> handler) { mapper(session).scrollAllFilesForFileMove(branchUuid, handler); } public boolean existAnyOfComponentsWithQualifiers(DbSession session, Collection<String> componentKeys, Set<String> qualifiers) { if (!componentKeys.isEmpty()) { List<Boolean> result = new LinkedList<>(); return executeLargeInputs(componentKeys, input -> { boolean groupNeedIssueSync = mapper(session).checkIfAnyOfComponentsWithQualifiers(input, qualifiers) > 0; result.add(groupNeedIssueSync); return result; }).stream().anyMatch(b -> b); } return false; } /* INSERT / UPDATE */ public void insert(DbSession session, ComponentDto item, boolean isMainBranch) { mapper(session).insert(item); if (isMainBranch) { auditPersister.addComponent(session, new ComponentNewValue(item)); } } public void insertOnMainBranch(DbSession session, ComponentDto item) { insert(session, item, true); } public void insert(DbSession session, Collection<ComponentDto> items, boolean isMainBranch) { insert(session, items.stream(), isMainBranch); } private void insert(DbSession session, Stream<ComponentDto> items, boolean isMainBranch) { items.forEach(item -> insert(session, item, isMainBranch)); } public void update(DbSession session, ComponentUpdateDto component, String qualifier) { auditPersister.updateComponent(session, new ComponentNewValue(component.getUuid(), component.getBName(), component.getBKey(), component.isBEnabled(), component.getBPath(), qualifier)); mapper(session).update(component); } public void updateBEnabledToFalse(DbSession session, Collection<String> uuids) { executeLargeUpdates(uuids, mapper(session)::updateBEnabledToFalse); } public void applyBChangesForBranchUuid(DbSession session, String branchUuid) { mapper(session).applyBChangesForBranchUuid(branchUuid); } public void resetBChangedForBranchUuid(DbSession session, String branchUuid) { mapper(session).resetBChangedForBranchUuid(branchUuid); } public void setPrivateForBranchUuidWithoutAudit(DbSession session, String branchUuid, boolean isPrivate) { mapper(session).setPrivateForBranchUuid(branchUuid, isPrivate); } public void setPrivateForBranchUuid(DbSession session, String branchUuid, boolean isPrivate, String qualifier, String componentKey, String componentName) { ComponentNewValue componentNewValue = new ComponentNewValue(branchUuid, componentName, componentKey, isPrivate, qualifier); //TODO we should log change to the visibility in EntityDao, not ComponentDao auditPersister.updateComponentVisibility(session, componentNewValue); mapper(session).setPrivateForBranchUuid(branchUuid, isPrivate); } public void setPrivateForBranchUuidWithoutAuditLog(DbSession session, String branchUuid, boolean isPrivate) { mapper(session).setPrivateForBranchUuid(branchUuid, isPrivate); } /* UTIL */ private static ComponentMapper mapper(DbSession session) { return session.getMapper(ComponentMapper.class); } private static void checkThatNotTooManyComponents(ComponentQuery query) { checkThatNotTooManyConditions(query.getComponentKeys(), "Too many component keys in query"); checkThatNotTooManyConditions(query.getComponentUuids(), "Too many component UUIDs in query"); } }
15,280
41.803922
179
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.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.component; import com.google.common.base.Splitter; import com.google.common.base.Strings; import java.util.Date; import java.util.List; import java.util.Objects; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.resources.Scopes; import org.sonar.db.WildcardPosition; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; import static org.apache.commons.lang.StringUtils.substringBeforeLast; import static org.sonar.db.DaoUtils.buildLikeValue; import static org.sonar.db.component.ComponentValidator.checkComponentKey; import static org.sonar.db.component.ComponentValidator.checkComponentLongName; import static org.sonar.db.component.ComponentValidator.checkComponentName; public class ComponentDto { /** * Separator used to generate the key of the branch */ public static final String BRANCH_KEY_SEPARATOR = ":BRANCH:"; public static final String PULL_REQUEST_SEPARATOR = ":PULL_REQUEST:"; public static final String UUID_PATH_SEPARATOR = "."; public static final String UUID_PATH_OF_ROOT = UUID_PATH_SEPARATOR; private static final Splitter UUID_PATH_SPLITTER = Splitter.on(UUID_PATH_SEPARATOR).omitEmptyStrings(); /** * Non-empty and unique functional key. Do not rename, used by MyBatis. */ private String kee; /** * Not empty . Max size is 50 (note that effective UUID values are 40 characters with * the current algorithm in use). Obviously it is unique. * It is generated by Compute Engine. */ private String uuid; /** * Not empty path of ancestor UUIDS, excluding itself. Value is suffixed by a dot in * order to support LIKE conditions when requesting descendants of a component * and to avoid Oracle NULL on root components. * Example: * - on root: UUID="1" UUID_PATH="." * - on directory: UUID="3" UUID_PATH=".1.2." * - on file: UUID="4" UUID_PATH=".1.2.3." * - on view: UUID="5" UUID_PATH="." * - on sub-view: UUID="6" UUID_PATH=".5." * * @since 6.0 */ private String uuidPath; /** * Non-null UUID of root component. Equals UUID column on root components * Example: * - on root: UUID="1" PROJECT_UUID="1" * - on directory: UUID="3" PROJECT_UUID="1" * - on file: UUID="4" PROJECT_UUID="1" * - on view: UUID="5" PROJECT_UUID="5" * - on sub-view: UUID="6" PROJECT_UUID="5" */ private String branchUuid; private String copyComponentUuid; private String scope; private String qualifier; private String path; private String name; private String longName; private String language; private String description; private boolean enabled = true; private boolean isPrivate = false; private Date createdAt; public static String formatUuidPathFromParent(ComponentDto parent) { checkArgument(!Strings.isNullOrEmpty(parent.getUuidPath())); checkArgument(!Strings.isNullOrEmpty(parent.uuid())); return parent.getUuidPath() + parent.uuid() + UUID_PATH_SEPARATOR; } public String getUuidPathLikeIncludingSelf() { return buildLikeValue(formatUuidPathFromParent(this), WildcardPosition.AFTER); } public String uuid() { return uuid; } public ComponentDto setUuid(String uuid) { this.uuid = uuid; return this; } public String getUuidPath() { return uuidPath; } public ComponentDto setUuidPath(String s) { this.uuidPath = s; return this; } /** * List of ancestor UUIDs, ordered by depth in tree. */ public List<String> getUuidPathAsList() { return UUID_PATH_SPLITTER.splitToList(uuidPath); } public String getKey() { return kee; } public ComponentDto setKey(String key) { this.kee = checkComponentKey(key); return this; } public String scope() { return scope; } public ComponentDto setScope(String scope) { this.scope = scope; return this; } public String qualifier() { return qualifier; } public ComponentDto setQualifier(String qualifier) { this.qualifier = qualifier; return this; } /** * Return the root project uuid. On a root project, return itself */ public String branchUuid() { return branchUuid; } public ComponentDto setBranchUuid(String branchUuid) { this.branchUuid = branchUuid; return this; } public boolean isRoot() { return UUID_PATH_OF_ROOT.equals(uuidPath); } @CheckForNull public String path() { return path; } public ComponentDto setPath(@Nullable String path) { this.path = path; return this; } public String name() { return name; } public ComponentDto setName(String name) { this.name = checkComponentName(name); return this; } public String longName() { return longName; } public ComponentDto setLongName(String longName) { this.longName = checkComponentLongName(longName); return this; } @CheckForNull public String language() { return language; } public ComponentDto setLanguage(@Nullable String language) { this.language = language; return this; } @CheckForNull public String description() { return description; } public ComponentDto setDescription(@Nullable String description) { this.description = description; return this; } public boolean isEnabled() { return enabled; } public ComponentDto setEnabled(boolean enabled) { this.enabled = enabled; return this; } @CheckForNull public String getCopyComponentUuid() { return copyComponentUuid; } public ComponentDto setCopyComponentUuid(@Nullable String copyComponentUuid) { this.copyComponentUuid = copyComponentUuid; return this; } public Date getCreatedAt() { return createdAt; } public ComponentDto setCreatedAt(Date datetime) { this.createdAt = datetime; return this; } public boolean isRootProject() { return uuid.equals(branchUuid) && Scopes.PROJECT.equals(scope); } public boolean isPrivate() { return isPrivate; } public ComponentDto setPrivate(boolean flag) { this.isPrivate = flag; return this; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ComponentDto that = (ComponentDto) o; return Objects.equals(uuid, that.uuid); } @Override public int hashCode() { return uuid != null ? uuid.hashCode() : 0; } @Override public String toString() { return new ToStringBuilder(this) .append("uuid", uuid) .append("uuidPath", uuidPath) .append("kee", kee) .append("scope", scope) .append("qualifier", qualifier) .append("branchUuid", branchUuid) .append("copyComponentUuid", copyComponentUuid) .append("path", path) .append("name", name) .append("longName", longName) .append("language", language) .append("enabled", enabled) .append("private", isPrivate) .toString(); } public ComponentDto copy() { ComponentDto copy = new ComponentDto(); copy.kee = kee; copy.uuid = uuid; copy.uuidPath = uuidPath; copy.branchUuid = branchUuid; copy.copyComponentUuid = copyComponentUuid; copy.scope = scope; copy.qualifier = qualifier; copy.path = path; copy.name = name; copy.longName = longName; copy.language = language; copy.description = description; copy.enabled = enabled; copy.isPrivate = isPrivate; copy.createdAt = createdAt; return copy; } public static String generateBranchKey(String componentKey, String branch) { return format("%s%s%s", componentKey, BRANCH_KEY_SEPARATOR, branch); } public static String removeBranchAndPullRequestFromKey(String componentKey) { return substringBeforeLast(substringBeforeLast(componentKey, ComponentDto.BRANCH_KEY_SEPARATOR), ComponentDto.PULL_REQUEST_SEPARATOR); } }
8,866
25.468657
138
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.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.component; import com.google.common.annotations.VisibleForTesting; import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.function.BiConsumer; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.ComponentKeyNewValue; /** * Class used to rename the key of a project and its resources. * * @since 3.2 */ public class ComponentKeyUpdaterDao implements Dao { private final AuditPersister auditPersister; public ComponentKeyUpdaterDao(AuditPersister auditPersister) { this.auditPersister = auditPersister; } public void updateKey(DbSession dbSession, String projectUuid, String projectOldKey, String newKey) { ComponentKeyUpdaterMapper mapper = dbSession.getMapper(ComponentKeyUpdaterMapper.class); checkExistentKey(mapper, newKey); // must SELECT first everything List<ResourceDto> resources = new LinkedList<>(); // add all branch components dbSession.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid) .forEach(branch -> { resources.addAll(mapper.selectBranchResources(branch.getUuid())); resources.add(mapper.selectComponentByUuid(branch.getUuid())); }); // and then proceed with the batch UPDATE at once runBatchUpdateForAllResources(resources, projectOldKey, newKey, mapper, (resource, oldKey) -> { }, dbSession); } @VisibleForTesting static String computeNewKey(String key, String stringToReplace, String replacementString) { return key.replace(stringToReplace, replacementString); } private void runBatchUpdateForAllResources(Collection<ResourceDto> resources, String oldKey, String newKey, ComponentKeyUpdaterMapper mapper, @Nullable BiConsumer<ResourceDto, String> consumer, DbSession dbSession) { for (ResourceDto resource : resources) { String oldResourceKey = resource.getKey(); String newResourceKey = newKey + oldResourceKey.substring(oldKey.length()); resource.setKey(newResourceKey); String oldResourceDeprecatedKey = resource.getDeprecatedKey(); if (StringUtils.isNotBlank(oldResourceDeprecatedKey)) { String newResourceDeprecatedKey = newKey + oldResourceDeprecatedKey.substring(oldKey.length()); resource.setDeprecatedKey(newResourceDeprecatedKey); } mapper.updateComponent(resource); if (resource.getScope().equals(Scopes.PROJECT) && (resource.getQualifier().equals(Qualifiers.PROJECT) || resource.getQualifier().equals(Qualifiers.APP))) { auditPersister.componentKeyUpdate(dbSession, new ComponentKeyNewValue(resource.getUuid(), oldResourceKey, newResourceKey), resource.getQualifier()); mapper.updateProject(oldResourceKey, newResourceKey); } if (consumer != null) { consumer.accept(resource, oldResourceKey); } } } public static void checkExistentKey(ComponentKeyUpdaterMapper mapper, String resourceKey) { if (mapper.countComponentsByKey(resourceKey) > 0) { throw new IllegalArgumentException("Impossible to update key: a component with key \"" + resourceKey + "\" already exists."); } } }
4,210
40.693069
161
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.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.component; import java.util.List; import org.apache.ibatis.annotations.Param; public interface ComponentKeyUpdaterMapper { int countComponentsByKey(String key); ResourceDto selectComponentByUuid(@Param("uuid") String uuid); List<ResourceDto> selectBranchResources(@Param("branchUuid") String branchUuid); void updateComponent(ResourceDto resource); void updateProject(@Param("oldProjectKey") String oldProjectKey, @Param("newProjectKey") String newProjectKey); }
1,345
34.421053
113
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.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.component; import java.util.Collection; import java.util.List; import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; public interface ComponentMapper { @CheckForNull List<ComponentDto> selectByKeyCaseInsensitive(@Param("key") String key); @CheckForNull ComponentDto selectByKeyAndBranchOrPr(@Param("key") String key, @Nullable @Param("branch") String branch, @Nullable @Param("pullRequest") String pullRequest); @CheckForNull ComponentDto selectByUuid(@Param("uuid") String uuid); /** * Return sub project of component keys */ List<ComponentDto> selectSubProjectsByComponentUuids(@Param("uuids") Collection<String> uuids); List<ComponentDto> selectByKeysAndBranchOrPr(@Param("keys") Collection<String> keys, @Nullable @Param("branch") String branch, @Nullable @Param("pullRequest") String pullRequest); List<ComponentDto> selectByUuids(@Param("uuids") Collection<String> uuids); List<ComponentDto> selectByBranchUuid(@Param("branchUuid") String branchUuid); List<String> selectExistingUuids(@Param("uuids") Collection<String> uuids); List<ComponentDto> selectComponentsByQualifiers(@Param("qualifiers") Collection<String> qualifiers); List<ComponentDto> selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds); int countByQuery(@Param("query") ComponentQuery query); List<ComponentDto> selectDescendants(@Param("query") ComponentTreeQuery query, @Param("baseUuid") String baseUuid, @Param("baseUuidPath") String baseUuidPath); List<ComponentDto> selectChildren(@Param("branchUuid") String branchUuid, @Param("uuidPaths") Set<String> uuidPaths); /** * Return all descendant views (including itself) from a given root view */ List<ComponentDto> selectEnabledViewsFromRootView(@Param("rootViewUuid") String rootViewUuid); /** * Return all files from a given project uuid and scope */ List<FilePathWithHashDto> selectEnabledFilesFromProject(@Param("projectUuid") String projectUuid); /** * Return uuids and project uuids from list of qualifiers * <p/> * It's using a join on snapshots in order to use he indexed columns snapshots.qualifier */ List<UuidWithBranchUuidDto> selectUuidsForQualifiers(@Param("qualifiers") String... qualifiers); /** * Return keys and UUIDs of all components belonging to a project */ List<KeyWithUuidDto> selectUuidsByKeyFromProjectKeyAndBranchOrPr(@Param("projectKey") String projectKey, @Nullable @Param("branch") String branch, @Nullable @Param("pullRequest") String pullRequest); Set<String> selectViewKeysWithEnabledCopyOfProject(@Param("projectUuids") Collection<String> projectUuids); /** * Return technical projects from a view or a sub-view */ List<String> selectProjectsFromView(@Param("viewUuidLikeQuery") String viewUuidLikeQuery, @Param("rootViewUuid") String rootViewUuid); void scrollAllFilesForFileMove(@Param("branchUuid") String branchUuid, ResultHandler<FileMoveRowDto> handler); void insert(ComponentDto componentDto); void update(ComponentUpdateDto component); void updateBEnabledToFalse(@Param("uuids") List<String> uuids); void applyBChangesForBranchUuid(@Param("branchUuid") String branchUuid); void resetBChangedForBranchUuid(@Param("branchUuid") String branchUuid); void setPrivateForBranchUuid(@Param("branchUuid") String branchUuid, @Param("isPrivate") boolean isPrivate); List<KeyWithUuidDto> selectComponentsFromPullRequestsTargetingCurrentBranchThatHaveOpenIssues(@Param("referenceBranchUuid") String referenceBranchUuid, @Param("currentBranchUuid") String currentBranchUuid); List<KeyWithUuidDto> selectComponentsFromBranchesThatHaveOpenIssues(@Param("branchUuids") List<String> branchUuids); short checkIfAnyOfComponentsWithQualifiers(@Param("componentKeys") Collection<String> componentKeys, @Param("qualifiers") Set<String> qualifiers); }
4,915
41.37931
161
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.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.component; import java.util.Date; import java.util.Locale; import java.util.Set; import java.util.stream.Stream; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.WildcardPosition; import static com.google.common.base.Preconditions.checkArgument; import static org.sonar.db.DaoUtils.buildLikeValue; public class ComponentQuery { private final String nameOrKeyQuery; private final boolean partialMatchOnKey; private final String[] qualifiers; private final Boolean isPrivate; private final Set<String> componentUuids; private final Set<String> componentKeys; private final Long analyzedBefore; private final Long anyBranchAnalyzedBefore; private final Long anyBranchAnalyzedAfter; private final Long allBranchesAnalyzedBefore; private final Date createdAfter; private final boolean onProvisionedOnly; private ComponentQuery(Builder builder) { this.nameOrKeyQuery = builder.nameOrKeyQuery; this.partialMatchOnKey = builder.partialMatchOnKey == null ? false : builder.partialMatchOnKey; this.qualifiers = builder.qualifiers; this.componentUuids = builder.componentUuids; this.componentKeys = builder.componentKeys; this.isPrivate = builder.isPrivate; this.analyzedBefore = builder.analyzedBefore; this.anyBranchAnalyzedBefore = builder.anyBranchAnalyzedBefore; this.anyBranchAnalyzedAfter = builder.anyBranchAnalyzedAfter; this.allBranchesAnalyzedBefore = builder.allBranchesAnalyzedBefore; this.createdAfter = builder.createdAfter; this.onProvisionedOnly = builder.onProvisionedOnly; } public String[] getQualifiers() { return qualifiers; } @CheckForNull public String getNameOrKeyQuery() { return nameOrKeyQuery; } /** * Used by MyBatis mapper */ @CheckForNull public String getNameOrKeyUpperLikeQuery() { return buildLikeValue(nameOrKeyQuery, WildcardPosition.BEFORE_AND_AFTER).toUpperCase(Locale.ENGLISH); } /** * Used by MyBatis mapper */ public boolean isPartialMatchOnKey() { return partialMatchOnKey; } @CheckForNull public Set<String> getComponentUuids() { return componentUuids; } @CheckForNull public Set<String> getComponentKeys() { return componentKeys; } @CheckForNull public Boolean getPrivate() { return isPrivate; } @CheckForNull public Long getAnalyzedBefore() { return analyzedBefore; } @CheckForNull public Long getAnyBranchAnalyzedBefore() { return anyBranchAnalyzedBefore; } @CheckForNull public Long getAnyBranchAnalyzedAfter() { return anyBranchAnalyzedAfter; } @CheckForNull public Long getAllBranchesAnalyzedBefore() { return allBranchesAnalyzedBefore; } @CheckForNull public Date getCreatedAfter() { return createdAfter; } public boolean isOnProvisionedOnly() { return onProvisionedOnly; } boolean hasEmptySetOfComponents() { return Stream.of(componentKeys, componentUuids) .anyMatch(list -> list != null && list.isEmpty()); } public static Builder builder() { return new Builder(); } public static class Builder { private String nameOrKeyQuery; private Boolean partialMatchOnKey; private String[] qualifiers; private Boolean isPrivate; private Set<String> componentUuids; private Set<String> componentKeys; private Long analyzedBefore; private Long anyBranchAnalyzedBefore; private Long anyBranchAnalyzedAfter; private Long allBranchesAnalyzedBefore; private Date createdAfter; private boolean onProvisionedOnly = false; public Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) { this.nameOrKeyQuery = nameOrKeyQuery; return this; } /** * Beware, can be resource intensive! Should be used with precautions. */ public Builder setPartialMatchOnKey(@Nullable Boolean partialMatchOnKey) { this.partialMatchOnKey = partialMatchOnKey; return this; } public Builder setQualifiers(String... qualifiers) { this.qualifiers = qualifiers; return this; } public Builder setComponentUuids(@Nullable Set<String> componentUuids) { this.componentUuids = componentUuids; return this; } public Builder setComponentKeys(@Nullable Set<String> componentKeys) { this.componentKeys = componentKeys; return this; } public Builder setPrivate(@Nullable Boolean isPrivate) { this.isPrivate = isPrivate; return this; } public Builder setAnalyzedBefore(@Nullable Long l) { this.analyzedBefore = l; return this; } public Builder setAllBranchesAnalyzedBefore(@Nullable Long l) { this.allBranchesAnalyzedBefore = l; return this; } /** * Filter on date of last analysis. On projects, all branches and pull requests are taken into * account. For example the analysis of a branch is included in the filter * even if the main branch has never been analyzed. */ public Builder setAnyBranchAnalyzedAfter(@Nullable Long l) { this.anyBranchAnalyzedAfter = l; return this; } public Builder setAnyBranchAnalyzedBefore(@Nullable Long l) { this.anyBranchAnalyzedBefore = l; return this; } public Builder setCreatedAfter(@Nullable Date l) { this.createdAfter = l; return this; } public Builder setOnProvisionedOnly(boolean onProvisionedOnly) { this.onProvisionedOnly = onProvisionedOnly; return this; } public ComponentQuery build() { checkArgument(qualifiers != null && qualifiers.length > 0, "At least one qualifier must be provided"); checkArgument(nameOrKeyQuery != null || partialMatchOnKey == null, "A query must be provided if a partial match on key is specified."); return new ComponentQuery(this); } } }
6,735
28.414847
141
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentTreeQuery.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.component; import java.util.ArrayList; import java.util.Collection; import java.util.Locale; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.WildcardPosition; import static com.google.common.collect.Lists.newArrayList; import static java.util.Objects.requireNonNull; import static org.sonar.db.DaoUtils.buildLikeValue; import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER; public class ComponentTreeQuery { public enum Strategy { CHILDREN, LEAVES } @CheckForNull private final String nameOrKeyQuery; // SONAR-7681 a public implementation of List must be used in MyBatis - potential concurrency exceptions otherwise @CheckForNull private final ArrayList<String> qualifiers; @CheckForNull private final ArrayList<String> scopes; private final String baseUuid; private final Strategy strategy; private ComponentTreeQuery(Builder builder) { this.nameOrKeyQuery = builder.nameOrKeyQuery; this.qualifiers = builder.qualifiers == null ? null : newArrayList(builder.qualifiers); this.scopes = builder.scopes == null ? null : newArrayList(builder.scopes); this.baseUuid = builder.baseUuid; this.strategy = requireNonNull(builder.strategy); } @CheckForNull public Collection<String> getQualifiers() { return qualifiers; } @CheckForNull public Collection<String> getScopes() { return scopes; } @CheckForNull public String getNameOrKeyQuery() { return nameOrKeyQuery; } /** * Used by MyBatis mapper */ @CheckForNull public String getNameOrKeyUpperLikeQuery() { return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, BEFORE_AND_AFTER).toUpperCase(Locale.ENGLISH); } public String getBaseUuid() { return baseUuid; } public Strategy getStrategy() { return strategy; } public String getUuidPath(ComponentDto component) { switch (strategy) { case CHILDREN: return component.getUuidPath() + component.uuid() + "."; case LEAVES: return buildLikeValue(component.getUuidPath() + component.uuid() + ".", WildcardPosition.AFTER); default: throw new IllegalArgumentException("Unknown strategy : " + strategy); } } public static Builder builder() { return new Builder(); } public static class Builder { @CheckForNull private String nameOrKeyQuery; @CheckForNull private Collection<String> qualifiers; @CheckForNull private Collection<String> scopes; private String baseUuid; private Strategy strategy; private Builder() { // private constructor } public ComponentTreeQuery build() { requireNonNull(baseUuid); return new ComponentTreeQuery(this); } public Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) { this.nameOrKeyQuery = nameOrKeyQuery; return this; } public Builder setQualifiers(Collection<String> qualifiers) { this.qualifiers = qualifiers; return this; } public Builder setScopes(Collection<String> scopes) { this.scopes = scopes; return this; } public Builder setBaseUuid(String uuid) { this.baseUuid = uuid; return this; } public Builder setStrategy(Strategy strategy) { this.strategy = requireNonNull(strategy); return this; } } }
4,229
27.389262
120
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.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.component; import javax.annotation.CheckForNull; import javax.annotation.Nullable; public class ComponentUpdateDto { private String uuid; /** * if true, the component is being updated * See https://jira.sonarsource.com/browse/SONAR-7700 */ private boolean bChanged; /** * Component keys are normally immutable. But in SQ 7.6 we have to migrate component keys to drop modules. */ private String bKey; private String bCopyComponentUuid; private String bDescription; private boolean bEnabled; private String bUuidPath; private String bLanguage; private String bLongName; private String bName; private String bPath; private String bQualifier; public ComponentUpdateDto setUuid(String uuid) { this.uuid = uuid; return this; } public String getUuid() { return uuid; } public boolean isBChanged() { return bChanged; } public String getBKey() { return bKey; } @CheckForNull public String getBCopyComponentUuid() { return bCopyComponentUuid; } @CheckForNull public String getBDescription() { return bDescription; } public boolean isBEnabled() { return bEnabled; } public String getBUuidPath() { return bUuidPath; } @CheckForNull public String getBLanguage() { return bLanguage; } @CheckForNull public String getBLongName() { return bLongName; } @CheckForNull public String getBName() { return bName; } @CheckForNull public String getBPath() { return bPath; } @CheckForNull public String getBQualifier() { return bQualifier; } public ComponentUpdateDto setBChanged(boolean b) { this.bChanged = b; return this; } public ComponentUpdateDto setBKey(String s) { this.bKey = s; return this; } public ComponentUpdateDto setBCopyComponentUuid(@Nullable String s) { this.bCopyComponentUuid = s; return this; } public ComponentUpdateDto setBEnabled(boolean b) { this.bEnabled = b; return this; } public ComponentUpdateDto setBUuidPath(String bUuidPath) { this.bUuidPath = bUuidPath; return this; } public ComponentUpdateDto setBName(@Nullable String s) { this.bName = s; return this; } public ComponentUpdateDto setBLongName(@Nullable String s) { this.bLongName = s; return this; } public ComponentUpdateDto setBDescription(@Nullable String s) { this.bDescription = s; return this; } public ComponentUpdateDto setBPath(@Nullable String s) { this.bPath = s; return this; } public ComponentUpdateDto setBLanguage(@Nullable String s) { this.bLanguage = s; return this; } public ComponentUpdateDto setBQualifier(@Nullable String s) { this.bQualifier = s; return this; } /** * Copy the A-fields to B-fields. The field bChanged is kept to false. */ public static ComponentUpdateDto copyFrom(ComponentDto from) { return new ComponentUpdateDto() .setUuid(from.uuid()) .setBChanged(false) .setBKey(from.getKey()) .setBCopyComponentUuid(from.getCopyComponentUuid()) .setBDescription(from.description()) .setBEnabled(from.isEnabled()) .setBUuidPath(from.getUuidPath()) .setBLanguage(from.language()) .setBLongName(from.longName()) .setBName(from.name()) .setBPath(from.path()) // We don't have a b_scope. The applyBChangesForRootComponentUuid query is using a case ... when to infer scope from the qualifier .setBQualifier(from.qualifier()); } }
4,399
23.175824
136
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentValidator.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.component; import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; import static org.sonar.core.component.ComponentKeys.MAX_COMPONENT_KEY_LENGTH; public class ComponentValidator { // b_name column is 500 characters wide public static final int MAX_COMPONENT_NAME_LENGTH = 500; public static final int MAX_COMPONENT_DESCRIPTION_LENGTH = 2_000; private static final int MAX_COMPONENT_QUALIFIER_LENGTH = 10; private ComponentValidator() { // prevent instantiation } public static String checkComponentName(String name) { checkArgument(!isNullOrEmpty(name), "Component name can't be empty"); checkArgument(name.length() <= MAX_COMPONENT_NAME_LENGTH, "Component name length (%s) is longer than the maximum authorized (%s). '%s' was provided.", name.length(), MAX_COMPONENT_NAME_LENGTH, name); return name; } public static String checkComponentLongName(@Nullable String value) { if (value == null) { return null; } checkArgument(value.length() <= MAX_COMPONENT_NAME_LENGTH, "Component name length (%s) is longer than the maximum authorized (%s). '%s' was provided.", value.length(), MAX_COMPONENT_NAME_LENGTH, value); return value; } public static String checkDescription(@Nullable String value) { if (value == null) { return null; } checkArgument(value.length() <= MAX_COMPONENT_NAME_LENGTH, "Component description length (%s) is longer than the maximum authorized (%s). '%s' was provided.", value.length(), MAX_COMPONENT_DESCRIPTION_LENGTH, value); return value; } public static String checkComponentKey(String key) { checkArgument(!isNullOrEmpty(key), "Component key can't be empty"); checkArgument(key.length() <= MAX_COMPONENT_KEY_LENGTH, "Component key length (%s) is longer than the maximum authorized (%s). '%s' was provided.", key.length(), MAX_COMPONENT_KEY_LENGTH, key); return key; } public static String checkComponentQualifier(String qualifier) { checkArgument(!isNullOrEmpty(qualifier), "Component qualifier can't be empty"); checkArgument(qualifier.length() <= MAX_COMPONENT_QUALIFIER_LENGTH, "Component qualifier length (%s) is longer than the maximum authorized (%s). '%s' was provided.", qualifier.length(), MAX_COMPONENT_QUALIFIER_LENGTH, qualifier); return qualifier; } }
3,311
41.461538
169
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/DbTagsReader.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.component; import com.google.common.base.Splitter; import java.util.List; import javax.annotation.Nullable; import static com.google.common.base.Strings.nullToEmpty; public class DbTagsReader { private static final char TAGS_SEPARATOR = ','; private static final Splitter TAGS_SPLITTER = Splitter.on(TAGS_SEPARATOR).trimResults().omitEmptyStrings(); private DbTagsReader() { // prevent instantiation } public static List<String> readDbTags(@Nullable String tagsString) { return TAGS_SPLITTER.splitToList(nullToEmpty(tagsString)); } }
1,423
34.6
109
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/FileMoveRowDto.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.component; public class FileMoveRowDto { private String kee; private String uuid; private String path; private int lineCount; public String getKey() { return kee; } public String getUuid() { return uuid; } public String getPath() { return path; } public int getLineCount() { return lineCount; } @Override public String toString() { return "FileMoveRowDto{" + "kee='" + kee + '\'' + ", uuid='" + uuid + '\'' + ", path='" + path + '\'' + ", lineCount=" + lineCount + '}'; } }
1,424
25.388889
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/FilePathWithHashDto.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.component; import javax.annotation.CheckForNull; public class FilePathWithHashDto { private String uuid; private String path; private String srcHash; private String revision; public String getSrcHash() { return srcHash; } public void setSrcHash(String srcHash) { this.srcHash = srcHash; } @CheckForNull public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getRevision() { return revision; } public void setRevision(String revision) { this.revision = revision; } public String getUuid() { return uuid; } public void setUuid(String uuid) { this.uuid = uuid; } }
1,567
23.123077
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/KeyWithUuidDto.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.component; import javax.annotation.concurrent.Immutable; @Immutable public record KeyWithUuidDto(String kee, String uuid) { public String key() { return kee; } }
1,037
32.483871
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrBranchAnalyzedLanguageCountByProjectDto.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.component; public class PrBranchAnalyzedLanguageCountByProjectDto { private String projectUuid = null; private Long pullRequest = null; private Long branch = null; public String getProjectUuid() { return projectUuid; } public void setProjectUuid(String projectUuid) { this.projectUuid = projectUuid; } public Long getPullRequest() { return pullRequest; } public void setPullRequest(Long pullRequest) { this.pullRequest = pullRequest; } public Long getBranch() { return branch; } public void setBranch(Long branch) { this.branch = branch; } }
1,469
26.735849
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectLastAnalysisDateDto.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.component; public class ProjectLastAnalysisDateDto { private final String projectUuid; private final Long date; public ProjectLastAnalysisDateDto(String projectUuid, Long date) { this.projectUuid = projectUuid; this.date = date; } public String getProjectUuid() { return projectUuid; } public Long getDate() { return date; } }
1,227
30.487179
75
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectLinkDao.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.component; import java.util.List; import javax.annotation.CheckForNull; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class ProjectLinkDao implements Dao { private final System2 system2; public ProjectLinkDao(System2 system2) { this.system2 = system2; } public List<ProjectLinkDto> selectByProjectUuid(DbSession session, String projectUuid) { return session.getMapper(ProjectLinkMapper.class).selectByProjectUuid(projectUuid); } public List<ProjectLinkDto> selectByProjectUuids(DbSession dbSession, List<String> projectUuids) { return executeLargeInputs(projectUuids, mapper(dbSession)::selectByProjectUuids); } @CheckForNull public ProjectLinkDto selectByUuid(DbSession session, String uuid) { return session.getMapper(ProjectLinkMapper.class).selectByUuid(uuid); } public ProjectLinkDto insert(DbSession session, ProjectLinkDto dto) { long now = system2.now(); session.getMapper(ProjectLinkMapper.class).insert(dto.setCreatedAt(now).setUpdatedAt(now)); return dto; } public void update(DbSession session, ProjectLinkDto dto) { session.getMapper(ProjectLinkMapper.class).update(dto.setUpdatedAt(system2.now())); } public void delete(DbSession session, String uuid) { session.getMapper(ProjectLinkMapper.class).delete(uuid); } private static ProjectLinkMapper mapper(DbSession dbSession) { return dbSession.getMapper(ProjectLinkMapper.class); } }
2,414
33.5
100
java
sonarqube
sonarqube-master/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectLinkDto.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.component; import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; public class ProjectLinkDto { public static final String TYPE_HOME_PAGE = "homepage"; public static final String TYPE_CI = "ci"; public static final String TYPE_ISSUE_TRACKER = "issue"; public static final String TYPE_SOURCES = "scm"; public static final String TYPE_SOURCES_DEV = "scm_dev"; public static final List<String> PROVIDED_TYPES = List.of( TYPE_HOME_PAGE, TYPE_CI, TYPE_ISSUE_TRACKER, TYPE_SOURCES, TYPE_SOURCES_DEV ); private String uuid; private String projectUuid; private String type; private String name; private String href; private long createdAt; private long updatedAt; public String getUuid() { return uuid; } public ProjectLinkDto setUuid(String uuid) { this.uuid = uuid; return this; } @CheckForNull public String getName() { return name; } public ProjectLinkDto setName(@Nullable String name) { this.name = name; return this; } public String getProjectUuid() { return projectUuid; } public ProjectLinkDto setProjectUuid(String projectUuid) { this.projectUuid = projectUuid; return this; } public String getHref() { return href; } public ProjectLinkDto setHref(String href) { this.href = href; return this; } public String getType() { return type; } public ProjectLinkDto setType(String type) { this.type = type; return this; } public long getCreatedAt() { return createdAt; } public ProjectLinkDto setCreatedAt(long createdAt) { this.createdAt = createdAt; return this; } public long getUpdatedAt() { return updatedAt; } public ProjectLinkDto setUpdatedAt(long updatedAt) { this.updatedAt = updatedAt; return this; } }
2,722
22.885965
75
java