@@ -23,15 +23,15 @@ import com.google.common.annotations.VisibleForTesting; | |||
import java.util.Arrays; | |||
import org.sonar.api.utils.MessageException; | |||
public class RatingGrid { | |||
class RatingGrid { | |||
private final double[] gridValues; | |||
public RatingGrid(double[] gridValues) { | |||
RatingGrid(double[] gridValues) { | |||
this.gridValues = Arrays.copyOf(gridValues, gridValues.length); | |||
} | |||
public Rating getRatingForDensity(double density) { | |||
Rating getRatingForDensity(double density) { | |||
for (Rating rating : Rating.values()) { | |||
double lowerBound = getGradeLowerBound(rating); | |||
if (density >= lowerBound) { | |||
@@ -53,7 +53,7 @@ public class RatingGrid { | |||
return gridValues; | |||
} | |||
public enum Rating { | |||
enum Rating { | |||
E(5), | |||
D(4), | |||
C(3), | |||
@@ -69,15 +69,6 @@ public class RatingGrid { | |||
public int getIndex() { | |||
return index; | |||
} | |||
public static Rating createForIndex(int index) { | |||
for (Rating rating : values()) { | |||
if (rating.getIndex() == index) { | |||
return rating; | |||
} | |||
} | |||
throw new IllegalArgumentException("A maintainability rating must be in the range [1..5]."); | |||
} | |||
} | |||
} |
@@ -30,9 +30,9 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.server.user.UserSession; | |||
import static org.sonar.api.user.UserGroupValidation.GROUP_NAME_MAX_LENGTH; | |||
import static org.sonar.db.MyBatis.closeQuietly; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.DESCRIPTION_MAX_LENGTH; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.NAME_MAX_LENGTH; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.PARAM_DESCRIPTION; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.PARAM_NAME; | |||
@@ -59,7 +59,7 @@ public class CreateAction implements UserGroupsWsAction { | |||
action.createParam(PARAM_NAME) | |||
.setDescription(String.format("Name for the new group. A group name cannot be larger than %d characters and must be unique. " + | |||
"The value 'anyone' (whatever the case) is reserved and cannot be used.", NAME_MAX_LENGTH)) | |||
"The value 'anyone' (whatever the case) is reserved and cannot be used.", GROUP_NAME_MAX_LENGTH)) | |||
.setExampleValue("sonar-users") | |||
.setRequired(true); | |||
@@ -32,9 +32,9 @@ import org.sonar.db.user.GroupDto; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.user.UserSession; | |||
import static org.sonar.api.user.UserGroupValidation.GROUP_NAME_MAX_LENGTH; | |||
import static org.sonar.db.MyBatis.closeQuietly; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.DESCRIPTION_MAX_LENGTH; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.NAME_MAX_LENGTH; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.PARAM_DESCRIPTION; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.PARAM_ID; | |||
import static org.sonar.server.usergroups.ws.UserGroupUpdater.PARAM_NAME; | |||
@@ -67,7 +67,7 @@ public class UpdateAction implements UserGroupsWsAction { | |||
action.createParam(PARAM_NAME) | |||
.setDescription(String.format("New name for the group. A group name cannot be larger than %d characters and must be unique. " + | |||
"The value 'anyone' (whatever the case) is reserved and cannot be used.", NAME_MAX_LENGTH)) | |||
"The value 'anyone' (whatever the case) is reserved and cannot be used.", GROUP_NAME_MAX_LENGTH)) | |||
.setExampleValue("sonar-users"); | |||
action.createParam(PARAM_DESCRIPTION) |
@@ -20,7 +20,6 @@ | |||
package org.sonar.server.usergroups.ws; | |||
import com.google.common.base.Preconditions; | |||
import org.sonar.api.security.DefaultGroups; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.user.UserGroupValidation; | |||
import org.sonar.api.utils.text.JsonWriter; | |||
@@ -39,7 +38,6 @@ public class UserGroupUpdater { | |||
// Database column size should be 500 (since migration #353), | |||
// but on some instances, column size is still 255, | |||
// hence the validation is done with 255 | |||
static final int NAME_MAX_LENGTH = 255; | |||
static final int DESCRIPTION_MAX_LENGTH = 200; | |||
private final DbClient dbClient; | |||
@@ -52,15 +50,6 @@ public class UserGroupUpdater { | |||
UserGroupValidation.validateGroupName(name); | |||
} | |||
private static void checkNameLength(String name) { | |||
Preconditions.checkArgument(!name.isEmpty(), "Name cannot be empty"); | |||
Preconditions.checkArgument(name.length() <= NAME_MAX_LENGTH, String.format("Name cannot be longer than %d characters", NAME_MAX_LENGTH)); | |||
} | |||
private static void checkNameNotAnyone(String name) { | |||
Preconditions.checkArgument(!DefaultGroups.isAnyone(name), String.format("Name '%s' is reserved (regardless of case)", DefaultGroups.ANYONE)); | |||
} | |||
protected void checkNameIsUnique(String name, DbSession session) { | |||
// There is no database constraint on column groups.name | |||
// because MySQL cannot create a unique index |
@@ -56,7 +56,7 @@ public class ResourceDao extends AbstractDao { | |||
} | |||
@CheckForNull | |||
private ResourceDto selectResource(ResourceQuery query, DbSession session) { | |||
private static ResourceDto selectResource(ResourceQuery query, DbSession session) { | |||
List<ResourceDto> resources = getResources(query, session); | |||
if (!resources.isEmpty()) { | |||
return resources.get(0); |
@@ -26,7 +26,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; | |||
public class UserGroupValidation { | |||
private static final int GROUP_NAME_MAX_LENGTH = 255; | |||
public static final int GROUP_NAME_MAX_LENGTH = 255; | |||
private UserGroupValidation() { | |||
// Only static methods |