}
ProjectDto dto = toProject(reportMetadata.getProjectKey());
- analysisMetadata.setProject(Project.from(dto));
+ analysisMetadata.setProject(Project.fromProjectDtoWithTags(dto));
return () -> {
if (!mainComponentKey.equals(reportMetadata.getProjectKey())) {
throw MessageException.of(format(
private final System2 system2 = new AlwaysIncreasingSystem2(1000L);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
private final EntityDao entityDao = new EntityDao();
assertThat(entityDao.selectByUuid(db.getSession(), portfolio.getUuid()).get().getKey()).isEqualTo(portfolio.getKey());
}
+ @Test
+ public void getDescription_shouldNotReturnNull() {
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ assertThat(entityDao.selectByUuid(db.getSession(), project.projectUuid()).get().getDescription()).isNotNull();
+ assertThat(entityDao.selectByUuid(db.getSession(), portfolio.getUuid()).get().getDescription()).isNotNull();
+ }
+
@Test
public void selectEntityByUuid_whenNoMatch_shouldReturnEmpty() {
assertThat(entityDao.selectByUuid(db.getSession(), "unknown")).isEmpty();
package org.sonar.db.entity;
import java.util.Objects;
+import javax.annotation.CheckForNull;
import org.sonar.api.resources.Qualifiers;
/**
* Entities are stored either in the projects or portfolios tables.
*/
public class EntityDto {
+
protected String kee;
protected String uuid;
protected String name;
protected String qualifier;
+ protected String description;
protected boolean isPrivate;
// This field should be null for anything that is not subportfolio
return name;
}
+ @CheckForNull
+ public String getDescription() {
+ return description;
+ }
+
public boolean isPrivate() {
return isPrivate;
}
NONE, MANUAL, REGEXP, REST, TAGS
}
- private String description;
private String branchKey;
private String rootUuid;
return this;
}
- @CheckForNull
- public String getDescription() {
- return description;
- }
-
public PortfolioDto setDescription(@Nullable String description) {
this.description = description;
return this;
public class ProjectDto extends EntityDto {
private static final String TAGS_SEPARATOR = ",";
- private String description;
private String tags;
private long createdAt;
private long updatedAt;
return this;
}
- @CheckForNull
- public String getDescription() {
- return description;
- }
-
public ProjectDto setDescription(@Nullable String description) {
this.description = description;
return this;
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
<mapper namespace="org.sonar.db.entity.EntityMapper">
<sql id="entityProjectColumns">
- p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate, p.qualifier as qualifier, null as authUuid
+ p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate, p.description as description, p.qualifier as qualifier,
+ null as authUuid
</sql>
<sql id="entityPortfolioColumns">
- p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate,
+ p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate, p.description as description,
case when p.parent_uuid is null then 'VW' else 'SVW' end as qualifier,
case when p.root_uuid != p.uuid then p.root_uuid else null end as authUuid
</sql>
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.portfolio.PortfolioDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.project.ProjectDto;
import static java.util.Collections.emptyList;
return new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList());
}
- public static Project from(ProjectDto project) {
+ public static Project fromProjectDtoWithTags(ProjectDto project) {
return new Project(project.getUuid(), project.getKey(), project.getName(), project.getDescription(), project.getTags());
}
- public static Project from(PortfolioDto portfolio) {
- return new Project(portfolio.getUuid(), portfolio.getKey(), portfolio.getName(), portfolio.getDescription(), emptyList());
+ public static Project from(EntityDto entityDto) {
+ return new Project(entityDto.getUuid(), entityDto.getKey(), entityDto.getName(), entityDto.getDescription(), emptyList());
}
/**
package org.sonar.server.project;
import org.junit.Test;
+import org.sonar.db.entity.EntityDto;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class ProjectTest {
@Test
.isEqualTo("Project{uuid='U1', key='K1', name='N1', description='D1'}");
}
+ @Test
+ public void from_whenPortfolioPassed_shouldNotReturnNullFields() {
+ EntityDto entity = mock(EntityDto.class);
+
+ when(entity.getUuid()).thenReturn("U1");
+ when(entity.getKey()).thenReturn("K1");
+ when(entity.getName()).thenReturn("N1");
+ when(entity.getDescription()).thenReturn("D1");
+
+ Project underTest = Project.from(entity);
+
+ assertThat(underTest.getUuid()).isEqualTo("U1");
+ assertThat(underTest.getKey()).isEqualTo("K1");
+ assertThat(underTest.getName()).isEqualTo("N1");
+ assertThat(underTest.getDescription()).isEqualTo("D1");
+
+ assertThat(underTest.toString())
+ .isEqualTo(underTest.toString())
+ .isEqualTo("Project{uuid='U1', key='K1', name='N1', description='D1'}");
+ }
+
@Test
public void test_equals_and_hashCode() {
Project project1 = new Project("U1", "K1", "N1", null, emptyList());
.execute();
verifyDeletedKey("branch1");
- verify(projectLifeCycleListeners).onProjectBranchesDeleted(singleton(Project.from(project)));
+ verify(projectLifeCycleListeners).onProjectBranchesDeleted(singleton(Project.fromProjectDtoWithTags(project)));
}
@Test
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.project.Project;
import org.sonar.server.project.ProjectLifeCycleListeners;
import org.sonar.server.user.UserSession;
throw new IllegalArgumentException("Only non-main branches can be deleted");
}
componentCleanerService.deleteBranch(dbSession, branch);
- projectLifeCycleListeners.onProjectBranchesDeleted(singleton(from(project)));
+ projectLifeCycleListeners.onProjectBranchesDeleted(singleton(Project.fromProjectDtoWithTags(project)));
response.noContent();
}
}
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentQuery;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.project.Project;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.min;
import static java.lang.String.format;
+import static java.util.stream.Collectors.toSet;
import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.VIEW;
ComponentQuery query = buildDbQuery(searchRequest);
Set<ComponentDto> componentDtos = new HashSet<>(dbClient.componentDao().selectByQuery(dbSession, query, 0, Integer.MAX_VALUE));
+ List<EntityDto> entities = dbClient.entityDao().selectByKeys(dbSession, componentDtos.stream().map(ComponentDto::getKey).collect(toSet()));
try {
componentDtos.forEach(p -> componentCleanerService.deleteComponent(dbSession, p));
} finally {
- projectLifeCycleListeners.onProjectsDeleted(componentDtos.stream().map(Project::from).collect(MoreCollectors.toSet(componentDtos.size())));
+ projectLifeCycleListeners.onProjectsDeleted(entities.stream().map(Project::from).collect(MoreCollectors.toSet(componentDtos.size())));
}
}
response.noContent();
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.project.Project;
import org.sonar.server.project.ProjectLifeCycleListeners;
import org.sonar.server.user.UserSession;
ProjectDto project = componentFinder.getProjectByKey(dbSession, key);
checkPermission(project);
componentCleanerService.delete(dbSession, project);
- projectLifeCycleListeners.onProjectsDeleted(singleton(from(project)));
+ projectLifeCycleListeners.onProjectsDeleted(singleton(Project.fromProjectDtoWithTags(project)));
}
response.noContent();