Operator operator = criterion.getOperator();
String value = criterion.getValue();
checkArgument(EQ.equals(operator), "Only equals operator is available for quality gate criteria");
- Arrays.stream(Level.values()).filter(level -> level.name().equalsIgnoreCase(value)).findFirst()
+ Level qualityGate = Arrays.stream(Level.values()).filter(level -> level.name().equalsIgnoreCase(value)).findFirst()
.orElseThrow(() -> new IllegalArgumentException(format("Unknown quality gate status : '%s'", value)));
- query.setQualityGateStatus(Level.valueOf(value));
+ query.setQualityGateStatus(qualityGate);
}
private static void processMetricCriterion(Criterion criterion, ProjectMeasuresQuery query) {
public SearchIdResult(SearchResponse response, Function<String, ID> converter) {
this.facets = new Facets(response);
- this.total = response.getHits().totalHits();
+ this.total = response.getHits().getTotalHits();
this.ids = convertToIds(response.getHits(), converter);
}
}
public ComponentTextSearchQuery build() {
- this.queryText = requireNonNull(queryText, "query text cannot be null");
- this.fieldKey = requireNonNull(fieldKey, "field key cannot be null");
- this.fieldName = requireNonNull(fieldName, "field name cannot be null");
- this.recentlyBrowsedKeys = requireNonNull(recentlyBrowsedKeys, "field recentlyBrowsedKeys cannot be null");
- this.favoriteKeys = requireNonNull(favoriteKeys, "field favoriteKeys cannot be null");
+ requireNonNull(queryText, "query text cannot be null");
+ requireNonNull(fieldKey, "field key cannot be null");
+ requireNonNull(fieldName, "field name cannot be null");
+ requireNonNull(recentlyBrowsedKeys, "field recentlyBrowsedKeys cannot be null");
+ requireNonNull(favoriteKeys, "field favoriteKeys cannot be null");
return new ComponentTextSearchQuery(this);
}
}
*/
package org.sonar.server.issue;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
import java.util.Arrays;
import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import static com.google.common.collect.Lists.newArrayList;
return false;
}
// Probably incorrect - comparing Object[] arrays with Arrays.equals
- if (!Arrays.equals(l10nParams, message.l10nParams)) {
- return false;
- }
- if ((text != null) ? !text.equals(message.text) : (message.text != null)) {
- return false;
- }
- return true;
+ return Arrays.equals(l10nParams, message.l10nParams) && ((text != null) ? text.equals(message.text) : (message.text == null));
}
@Override
import org.sonar.server.issue.IssueUpdater;
import org.sonar.server.user.UserSession;
+import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.emptyToNull;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
private final OperationResponseWriter responseWriter;
public AssignAction(System2 system2, UserSession userSession, DbClient dbClient, IssueFinder issueFinder, IssueFieldsSetter issueFieldsSetter, IssueUpdater issueUpdater,
- OperationResponseWriter responseWriter) {
+ OperationResponseWriter responseWriter) {
this.system2 = system2;
this.userSession = userSession;
this.dbClient = dbClient;
ComponentDto project = Optional.ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull())
.orElseThrow(() -> new IllegalStateException(format("Unknown project %s", projectUuid)));
OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, project.getOrganizationUuid())
- .orElseThrow(() -> new IllegalStateException(format("Unknown organization %s", project.getOrganizationUuid())));
- dbClient.organizationMemberDao().select(dbSession, organizationDto.getUuid(), user.getId())
- .orElseThrow(() -> new IllegalArgumentException(format("User '%s' is not member of organization '%s'", user.getLogin(), organizationDto.getKey())));
+ .orElseThrow(() -> new IllegalStateException(format("Unknown organizationMember %s", project.getOrganizationUuid())));
+ checkArgument(dbClient.organizationMemberDao().select(dbSession, organizationDto.getUuid(), user.getId()).isPresent(),
+ "User '%s' is not member of organization '%s'", user.getLogin(), organizationDto.getKey());
}
}
import org.sonar.server.usergroups.ws.GroupWsSupport;
import org.sonarqube.ws.client.permission.PermissionsWsParameters;
-import static java.lang.String.format;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.server.ws.WsUtils.checkFound;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
}
public void checkMembership(DbSession dbSession, OrganizationDto organization, UserId user) {
- dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getId())
- .orElseThrow(() -> new IllegalArgumentException(format("User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey())));
+ checkArgument(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getId()).isPresent(),
+ "User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey());
}
}
import org.sonar.db.user.UserGroupDto;
import org.sonar.server.user.UserSession;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_ID;
}
private void checkMembership(DbSession dbSession, OrganizationDto organization, UserDto user) {
- dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getId())
- .orElseThrow(() -> new IllegalArgumentException(format("User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey())));
+ checkArgument(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getId()).isPresent(),
+ "User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey());
}
}
*/
@Deprecated
public Rule getParent() {
- return template;
+ return getTemplate();
}
/**
*/
@Deprecated
public Rule setParent(Rule parent) {
- this.template = parent;
- return this;
+ return setTemplate(parent);
}
/**
}
public ProjectRepositories addSettings(String moduleKey, Map<String, String> settings) {
- Map<String, String> existingSettings = settingsByModule.get(moduleKey);
- if (existingSettings == null) {
- existingSettings = new HashMap<>();
- settingsByModule.put(moduleKey, existingSettings);
- }
+ Map<String, String> existingSettings = settingsByModule.computeIfAbsent(moduleKey, k -> new HashMap<>());
existingSettings.putAll(settings);
return this;
}
return this;
}
- Map<String, FileData> existingFileDataByPath = fileDataByModuleAndPath.get(moduleKey);
- if (existingFileDataByPath == null) {
- existingFileDataByPath = new HashMap<>();
- fileDataByModuleAndPath.put(moduleKey, existingFileDataByPath);
- }
+ Map<String, FileData> existingFileDataByPath = fileDataByModuleAndPath.computeIfAbsent(moduleKey, k -> new HashMap<>());
existingFileDataByPath.put(path, fileData);
return this;
}