ComponentDto component = null;
String componentUuid = taskDto.getComponentUuid();
if (componentUuid != null) {
- component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+ component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orElse(null);
}
CeTask task = convertToTask(taskDto, submission.getCharacteristics(), component);
return java.util.Optional.of(task);
package org.sonar.ce.task.projectanalysis.component;
import java.util.Date;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.api.utils.System2;
+import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.protobuf.DbProjectBranches;
-import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.ce.task.projectanalysis.analysis.Branch;
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
Branch branch = analysisMetadataHolder.getBranch();
String branchUuid = treeRootHolder.getRoot().getUuid();
- com.google.common.base.Optional<ComponentDto> branchComponentDtoOpt = dbClient.componentDao().selectByUuid(dbSession, branchUuid);
+ Optional<ComponentDto> branchComponentDtoOpt = dbClient.componentDao().selectByUuid(dbSession, branchUuid);
ComponentDto branchComponentDto;
if (branch.isMain()) {
branchComponentDto = branchComponentDtoOpt.get();
} else {
// inserts new row in table projects if it's the first time branch is analyzed
- branchComponentDto = branchComponentDtoOpt.or(() -> insertIntoProjectsTable(dbSession, branchUuid));
+ branchComponentDto = branchComponentDtoOpt.orElseGet(() -> insertIntoProjectsTable(dbSession, branchUuid));
}
// insert or update in table project_branches
private ComponentDto toProject(String projectKey) {
try (DbSession dbSession = dbClient.openSession(false)) {
- com.google.common.base.Optional<ComponentDto> opt = dbClient.componentDao().selectByKey(dbSession, projectKey);
+ Optional<ComponentDto> opt = dbClient.componentDao().selectByKey(dbSession, projectKey);
checkState(opt.isPresent(), "Project with key '%s' can't be found", projectKey);
return opt.get();
}
package org.sonar.ce.task.projectanalysis.step;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.sonar.api.utils.MessageException;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
private void validateAnalysisDate(Optional<ComponentDto> baseProject) {
if (baseProject.isPresent()) {
- java.util.Optional<SnapshotDto> snapshotDto = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, baseProject.get().uuid());
+ Optional<SnapshotDto> snapshotDto = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, baseProject.get().uuid());
long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate();
Long lastAnalysisDate = snapshotDto.map(SnapshotDto::getCreatedAt).orElse(null);
if (lastAnalysisDate != null && currentAnalysisDate <= lastAnalysisDate) {
@CheckForNull
private FileSourceDto insertContentOfFileInDb(String key, @Nullable String[] content) {
return dbTester.getDbClient().componentDao().selectByKey(dbTester.getSession(), key)
- .transform(file -> {
+ .map(file -> {
SourceLineHashesComputer linesHashesComputer = new SourceLineHashesComputer();
if (content != null) {
stream(content).forEach(linesHashesComputer::addLine);
dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), fileSourceDto);
dbTester.commit();
return fileSourceDto;
- }).orNull();
+ }).orElse(null);
}
private void setFilesInReport(Component... files) {
*/
package org.sonar.ce.task.projectanalysis.step;
-import com.google.common.base.Optional;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import static org.apache.commons.lang.StringUtils.isEmpty;
import static org.apache.commons.lang.StringUtils.trimToNull;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
ComponentDto component = null;
String componentUuid = taskDto.getComponentUuid();
if (componentUuid != null) {
- component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+ component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orElse(null);
}
Map<String, String> characteristics = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, singletonList(taskDto.getUuid())).stream()
.collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
*/
package org.sonar.db.component;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
}
public Optional<ComponentDto> selectById(DbSession session, long id) {
- return Optional.fromNullable(mapper(session).selectById(id));
+ return Optional.ofNullable(mapper(session).selectById(id));
}
public Optional<ComponentDto> selectByUuid(DbSession session, String uuid) {
- return Optional.fromNullable(mapper(session).selectByUuid(uuid));
+ return Optional.ofNullable(mapper(session).selectByUuid(uuid));
}
public ComponentDto selectOrFailByUuid(DbSession session, String uuid) {
}
public Optional<ComponentDto> selectByKey(DbSession session, String key) {
- return Optional.fromNullable(mapper(session).selectByKey(key));
+ return Optional.ofNullable(mapper(session).selectByKey(key));
}
- public java.util.Optional<ComponentDto> selectByKeyAndBranch(DbSession session, String key, String branch) {
- return java.util.Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generateBranchKey(key, branch), branch));
+ public Optional<ComponentDto> selectByKeyAndBranch(DbSession session, String key, String branch) {
+ return Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generateBranchKey(key, branch), branch));
}
- public java.util.Optional<ComponentDto> selectByKeyAndPullRequest(DbSession session, String key, String pullRequestId) {
- return java.util.Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generatePullRequestKey(key, pullRequestId), pullRequestId));
+ public Optional<ComponentDto> selectByKeyAndPullRequest(DbSession session, String key, String pullRequestId) {
+ return Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generatePullRequestKey(key, pullRequestId), pullRequestId));
}
public List<UuidWithProjectUuidDto> selectAllViewsAndSubViews(DbSession session) {
}
public void insert(DbSession session, Collection<ComponentDto> items) {
- for (ComponentDto item : items) {
- insert(session, item);
- }
+ insert(session, items.stream());
+ }
+
+ private void insert(DbSession session, Stream<ComponentDto> items) {
+ items.forEach(item -> insert(session, item));
}
public void insert(DbSession session, ComponentDto item, ComponentDto... others) {
- insert(session, Lists.asList(item, others));
+ insert(session, Stream.concat(Stream.of(item), Arrays.stream(others)));
}
public void update(DbSession session, ComponentUpdateDto component) {
*/
package org.sonar.db.component;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.function.Consumer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
-import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.utils.DateUtils.parseDate;
assertThat(result.getCopyResourceUuid()).isNull();
assertThat(result.isPrivate()).isTrue();
- assertThat(underTest.selectByUuid(dbSession, "UNKNOWN")).isAbsent();
+ assertThat(underTest.selectByUuid(dbSession, "UNKNOWN")).isEmpty();
}
@Test
assertThat(result.language()).isEqualTo("java");
assertThat(result.projectUuid()).isEqualTo(project.uuid());
- assertThat(underTest.selectByKey(dbSession, "unknown")).isAbsent();
+ assertThat(underTest.selectByKey(dbSession, "unknown")).isEmpty();
}
@Test
ComponentDto project = db.components().insertPrivateProject();
assertThat(underTest.selectById(dbSession, project.getId())).isPresent();
- assertThat(underTest.selectById(dbSession, 0L)).isAbsent();
+ assertThat(underTest.selectById(dbSession, 0L)).isEmpty();
}
@Test
underTest.delete(dbSession, project1.getId());
dbSession.commit();
- assertThat(underTest.selectByKey(dbSession, "PROJECT_1")).isAbsent();
+ assertThat(underTest.selectByKey(dbSession, "PROJECT_1")).isEmpty();
assertThat(underTest.selectByKey(dbSession, "PROJECT_2")).isPresent();
}
private Stream<WebhookDto> readWebHooksFrom(String projectUuid) {
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<ComponentDto> optionalComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull());
+ Optional<ComponentDto> optionalComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null));
ComponentDto componentDto = checkStateWithOptional(optionalComponentDto, "the requested project '%s' was not found", projectUuid);
if (componentDto.getMainBranchProjectUuid() != null && !componentDto.uuid().equals(componentDto.getMainBranchProjectUuid())) {
- Optional<ComponentDto> mainBranchComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, componentDto.getMainBranchProjectUuid()).orNull());
+ Optional<ComponentDto> mainBranchComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, componentDto.getMainBranchProjectUuid()).orElse(null));
componentDto = checkStateWithOptional(mainBranchComponentDto, "the requested project '%s' was not found", projectUuid);
}
*/
package org.sonar.server.ce.queue;
-import com.google.common.base.Optional;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
Optional<ComponentDto> component = dbClient.componentDao().selectByKey(dbSession, effectiveProjectKey);
validateProject(dbSession, component, projectKey);
ensureOrganizationIsConsistent(component, organizationDto);
- ComponentDto project = component.or(() -> createProject(dbSession, organizationDto, projectKey, deprecatedBranch, projectName));
+ ComponentDto project = component.orElseGet(() -> createProject(dbSession, organizationDto, projectKey, deprecatedBranch, projectName));
checkScanPermission(project);
return submitReport(dbSession, reportInput, project, characteristics);
}
if (componentUuid == null) {
throw insufficientPrivilegesException();
}
- com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
+ Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
if (!component.isPresent()) {
throw insufficientPrivilegesException();
}
Ce.TaskResponse.Builder wsTaskResponse = Ce.TaskResponse.newBuilder();
Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
if (queueDto.isPresent()) {
- com.google.common.base.Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
+ Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
checkPermission(component);
wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get()));
} else {
CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
- com.google.common.base.Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
+ Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
checkPermission(component);
Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
maskErrorStacktrace(ceActivityDto, additionalFields);
}
}
- private com.google.common.base.Optional<ComponentDto> loadComponent(DbSession dbSession, @Nullable String projectUuid) {
+ private Optional<ComponentDto> loadComponent(DbSession dbSession, @Nullable String projectUuid) {
if (projectUuid == null) {
- return com.google.common.base.Optional.absent();
+ return Optional.empty();
}
return dbClient.componentDao().selectByUuid(dbSession, projectUuid);
}
- private void checkPermission(com.google.common.base.Optional<ComponentDto> component) {
+ private void checkPermission(Optional<ComponentDto> component) {
if (component.isPresent()) {
String orgUuid = component.get().getOrganizationUuid();
if (!userSession.hasPermission(OrganizationPermission.ADMINISTER, orgUuid) &&
*/
package org.sonar.server.component;
-import com.google.common.base.Optional;
import java.util.Collection;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
public OrganizationDto getOrganization(DbSession dbSession, ComponentDto component) {
String organizationUuid = component.getOrganizationUuid();
- java.util.Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
+ Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
return checkFoundWithOptional(organizationDto, "Organization with uuid '%s' not found", organizationUuid);
}
* Components of the main branch won't be found
*/
public ComponentDto getByKeyAndBranch(DbSession dbSession, String key, String branch) {
- java.util.Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndBranch(dbSession, key, branch);
+ Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndBranch(dbSession, key, branch);
if (componentDto.isPresent() && componentDto.get().isEnabled()) {
return componentDto.get();
}
}
public ComponentDto getByKeyAndPullRequest(DbSession dbSession, String key, String pullRequest) {
- java.util.Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndPullRequest(dbSession, key, pullRequest);
+ Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndPullRequest(dbSession, key, pullRequest);
if (componentDto.isPresent() && componentDto.get().isEnabled()) {
return componentDto.get();
}
package org.sonar.server.duplication.ws;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
import java.io.Serializable;
import java.io.StringReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.xml.stream.XMLInputFactory;
if (component == null) {
Optional<ComponentDto> componentDtoOptional;
if (branch != null) {
- componentDtoOptional = Optional.fromNullable(componentDao.selectByKeyAndBranch(session, componentKey, branch).orElseGet(null));
+ componentDtoOptional = Optional.ofNullable(componentDao.selectByKeyAndBranch(session, componentKey, branch).orElseGet(null));
} else if (pullRequest != null) {
- componentDtoOptional = Optional.fromNullable(componentDao.selectByKeyAndPullRequest(session, componentKey, pullRequest).orElseGet(null));
+ componentDtoOptional = Optional.ofNullable(componentDao.selectByKeyAndPullRequest(session, componentKey, pullRequest).orElseGet(null));
} else {
componentDtoOptional = componentDao.selectByKey(session, componentKey);
}
package org.sonar.server.duplication.ws;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
private final IssueChangePostProcessor issueChangePostProcessor;
public IssueUpdater(DbClient dbClient, WebIssueStorage issueStorage, NotificationManager notificationService,
- IssueChangePostProcessor issueChangePostProcessor) {
+ IssueChangePostProcessor issueChangePostProcessor) {
this.dbClient = dbClient;
this.issueStorage = issueStorage;
this.notificationService = notificationService;
private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Nullable String componentUuid) {
String issueKey = issue.key();
checkState(componentUuid != null, "Issue '%s' has no component", issueKey);
- ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+ ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orElse(null);
checkState(component != null, "Component uuid '%s' for issue key '%s' cannot be found", componentUuid, issueKey);
return component;
}
private void checkMembership(DbSession dbSession, IssueDto issueDto, UserDto user) {
String projectUuid = requireNonNull(issueDto.getProjectUuid());
- ComponentDto project = Optional.ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull())
+ ComponentDto project = Optional.ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null))
.orElseThrow(() -> new IllegalStateException(format("Unknown project %s", projectUuid)));
OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, project.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException(format("Unknown organizationMember %s", project.getOrganizationUuid())));
*/
package org.sonar.server.issue.ws;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
private boolean isMember(DbSession dbSession, IssueDto issue) {
Optional<ComponentDto> project = dbClient.componentDao().selectByUuid(dbSession, issue.getProjectUuid());
checkState(project.isPresent(), "Cannot find the project with uuid %s from issue.id %s", issue.getProjectUuid(), issue.getId());
- java.util.Optional<OrganizationDto> organization = dbClient.organizationDao().selectByUuid(dbSession, project.get().getOrganizationUuid());
+ Optional<OrganizationDto> organization = dbClient.organizationDao().selectByUuid(dbSession, project.get().getOrganizationUuid());
checkState(organization.isPresent(), "Cannot find the organization with uuid %s from issue.id %s", project.get().getOrganizationUuid(), issue.getId());
return userSession.hasMembership(organization.get());
}
package org.sonar.server.measure.ws;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
private Optional<ComponentDto> getReferenceComponent(DbSession dbSession, ComponentDto component) {
if (component.getCopyResourceUuid() == null) {
- return Optional.absent();
+ return Optional.empty();
}
return dbClient.componentDao().selectByUuid(dbSession, component.getCopyResourceUuid());
private Optional<ComponentDto> getProjectByKeyOrId(DbSession dbSession, String component) {
try {
Long componentId = Long.parseLong(component);
- return ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orNull());
+ return ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orElse(null));
} catch (NumberFormatException e) {
- return ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orNull());
+ return ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orElse(null));
}
}
*/
package org.sonar.server.project.ws;
-import com.google.common.base.Optional;
+import java.util.Optional;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
}
private ComponentDto getProjectOrApplication(DbSession dbSession, SnapshotDto analysis) {
- ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, analysis.getComponentUuid()).orNull();
+ ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, analysis.getComponentUuid()).orElse(null);
checkState(project != null, "Project of analysis '%s' is not found", analysis.getUuid());
checkArgument(ALLOWED_QUALIFIERS.contains(project.qualifier()) && Scopes.PROJECT.equals(project.scope()),
"An event must be created on a project or an application");
private Optional<ComponentDto> loadComponent(DbSession dbSession, String component) {
try {
Long componentId = Long.parseLong(component);
- return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orNull());
+ return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orElse(null));
} catch (NumberFormatException e) {
- return Optional.ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orNull());
+ return Optional.ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orElse(null));
}
}
try {
long dbId = Long.parseLong(projectId);
- return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orNull());
+ return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orElse(null));
} catch (NumberFormatException e) {
return Optional.empty();
}
try {
long dbId = Long.parseLong(projectId);
- return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orNull());
+ return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orElse(null));
} catch (NumberFormatException e) {
return Optional.empty();
}
if (project.isRoot()) {
return project;
}
- ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, project.projectUuid()).orNull();
+ ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, project.projectUuid()).orElse(null);
checkState(component != null, "Project uuid of component uuid '%s' does not exist", project.uuid());
return component;
}
return of(projectUuid);
}
try (DbSession dbSession = dbClient.openSession(false)) {
- com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
+ Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
if (!component.isPresent()) {
return Optional.empty();
}
private Set<String> loadProjectPermissions(String projectUuid) {
try (DbSession dbSession = dbClient.openSession(false)) {
- com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, projectUuid);
+ Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, projectUuid);
if (!component.isPresent()) {
return Collections.emptySet();
}
}
private Optional<CurrentWsResponse.Homepage> projectHomepage(DbSession dbSession, UserDto user) {
- Optional<ComponentDto> projectOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orNull());
+ Optional<ComponentDto> projectOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orElse(null));
if (shouldCleanProjectHomepage(projectOptional)) {
cleanUserHomepageInDb(dbSession, user);
return empty();
}
private Optional<CurrentWsResponse.Homepage> applicationAndPortfolioHomepage(DbSession dbSession, UserDto user) {
- Optional<ComponentDto> componentOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orNull());
+ Optional<ComponentDto> componentOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orElse(null));
if (shouldCleanApplicationOrPortfolioHomepage(componentOptional)) {
cleanUserHomepageInDb(dbSession, user);
return empty();
ComponentDto projectDto = null;
if (isNotBlank(projectKey)) {
- Optional<ComponentDto> dtoOptional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orNull());
+ Optional<ComponentDto> dtoOptional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orElse(null));
ComponentDto componentDto = checkFoundWithOptional(dtoOptional, "No project with key '%s'", projectKey);
webhookSupport.checkThatProjectBelongsToOrganization(componentDto, organizationDto, "Project '%s' does not belong to organisation '%s'", projectKey, organizationKey);
webhookSupport.checkPermission(componentDto);
String projectUuid = webhookDto.getProjectUuid();
if (projectUuid != null) {
- Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull());
+ Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null));
ComponentDto componentDto = checkStateWithOptional(optionalDto, "the requested project '%s' was not found", projectUuid);
webhookSupport.checkPermission(componentDto);
deleteWebhook(dbSession, webhookDto);
if (isNotBlank(projectKey)) {
- Optional<ComponentDto> optional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orNull());
+ Optional<ComponentDto> optional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orElse(null));
ComponentDto componentDto = checkFoundWithOptional(optional, "project %s does not exist", projectKey);
webhookSupport.checkPermission(componentDto);
webhookSupport.checkThatProjectBelongsToOrganization(componentDto, organizationDto, "Project '%s' does not belong to organisation '%s'", projectKey, organizationKey);
String projectUuid = webhookDto.getProjectUuid();
if (projectUuid != null) {
- Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull());
+ Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null));
ComponentDto componentDto = checkStateWithOptional(optionalDto, "the requested project '%s' was not found", projectUuid);
webhookSupport.checkPermission(componentDto);
updateWebhook(dbSession, webhookDto, name, url);
import org.sonar.server.project.ProjectLifeCycleListeners;
import org.sonar.server.tester.UserSessionRule;
-import static org.assertj.guava.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
}
private void assertComponentKeyUpdated(String oldKey, String newKey) {
- assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isAbsent();
+ assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isEmpty();
assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
}
- private void assertComponentKeyNotUpdated(String key) {
- assertThat(dbClient.componentDao().selectByKey(dbSession, key)).isPresent();
- }
-
}
import org.sonar.server.tester.UserSessionRule;
import static java.util.Collections.emptyList;
-import static org.assertj.guava.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.sonar.db.component.ComponentTesting.newFileDto;
dbSession.commit();
// Check project key has been updated
- assertThat(db.getDbClient().componentDao().selectByKey(dbSession, project.getDbKey())).isAbsent();
+ assertThat(db.getDbClient().componentDao().selectByKey(dbSession, project.getDbKey())).isEmpty();
assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root")).isNotNull();
// Check file key has been updated
- assertThat(db.getDbClient().componentDao().selectByKey(dbSession, file.getDbKey())).isAbsent();
+ assertThat(db.getDbClient().componentDao().selectByKey(dbSession, file.getDbKey())).isEmpty();
assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/File.xoo")).isNotNull();
assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/InactiveFile.xoo")).isNotNull();
- assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getDbKey())).isAbsent();
+ assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getDbKey())).isEmpty();
- org.assertj.core.api.Assertions.assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
+ assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
}
@Test
assertComponentKeyHasBeenUpdated(file.getDbKey(), "sample:root2:module:src/File.xoo");
// do not index the module but the project
- org.assertj.core.api.Assertions.assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
+ assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
}
@Test
dbSession.commit();
assertComponentKeyHasBeenUpdated(provisionedProject.getDbKey(), "provisionedProject2");
- org.assertj.core.api.Assertions.assertThat(projectIndexers.hasBeenCalled(provisionedProject.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
+ assertThat(projectIndexers.hasBeenCalled(provisionedProject.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
}
@Test
}
private void assertComponentKeyUpdated(String oldKey, String newKey) {
- assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isAbsent();
+ assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isEmpty();
assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
}
}
private void assertComponentKeyHasBeenUpdated(String oldKey, String newKey) {
- assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isAbsent();
+ assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isEmpty();
assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
}
*/
package org.sonar.server.project.ws;
-import com.google.common.base.Optional;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
public void show_source() throws Exception {
String fileKey = "src/Foo.java";
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
- when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+ when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
when(sourceService.getLinesAsHtml(eq(session), eq(file.uuid()), anyInt(), anyInt())).thenReturn(Optional.of(newArrayList(
"/*",
" * Header",
public void show_source_with_from_and_to_params() throws Exception {
String fileKey = "src/Foo.java";
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
- when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+ when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
when(sourceService.getLinesAsHtml(session, file.uuid(), 3, 5)).thenReturn(Optional.of(newArrayList(
" */",
"",
public void show_source_accept_from_less_than_one() throws Exception {
String fileKey = "src/Foo.java";
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
- when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+ when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
when(sourceService.getLinesAsHtml(session, file.uuid(), 1, 5)).thenReturn(Optional.of(newArrayList(
" */",
"",
@Test(expected = ForbiddenException.class)
public void require_code_viewer() throws Exception {
String fileKey = "src/Foo.java";
- when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+ when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
tester.newGetRequest("api/sources", "show").setParam("key", fileKey).execute();
}
}