}
private void validateParameters() throws ProjectCreationFailedException {
if (createProjectArgs.getProjectName() == null
|| createProjectArgs.getProjectName().isEmpty()) {
throw new ProjectCreationFailedException("Project name is required");
}
if (createProjectArgs.getProjectName().endsWith(Constants.DOT_GIT_EXT)) {
createProjectArgs.setProjectName(createProjectArgs.getProjectName()
.substring(
0,
createProjectArgs.getProjectName().length()
- Constants.DOT_GIT_EXT.length()));
}
if (!currentUser.getCapabilities().canCreateProject()) {
throw new ProjectCreationFailedException(String.format(
"%s does not have \"Create Project\" capability.",
currentUser.getUserName()));
}
if (createProjectArgs.ownerIds == null
|| createProjectArgs.ownerIds.isEmpty()) {
createProjectArgs.ownerIds =
new ArrayList<AccountGroup.UUID>(projectOwnerGroups);
}
List<String> transformedBranches = new ArrayList<String>();
if (createProjectArgs.branch == null ||
createProjectArgs.branch.isEmpty()) {
createProjectArgs.branch = Collections.singletonList(Constants.MASTER);
}
for (String branch : createProjectArgs.branch) {
while (branch.startsWith("/")) {
branch = branch.substring(1);
}
if (!branch.startsWith(Constants.R_HEADS)) {
branch = Constants.R_HEADS + branch;
}
if (!Repository.isValidRefName(branch)) {
throw new ProjectCreationFailedException(String.format(
"Branch \"%s\" is not a valid name.", branch));
}
if (!transformedBranches.contains(branch)) {
transformedBranches.add(branch);
}