use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class CreateProjectIT method createProjectWithCapability.
@Test
public void createProjectWithCapability() throws Exception {
allowGlobalCapabilities(SystemGroupBackend.REGISTERED_USERS, GlobalCapability.CREATE_PROJECT);
try {
setApiUser(user);
ProjectInput in = new ProjectInput();
in.name = name("newProject");
ProjectInfo p = gApi.projects().create(in).get();
assertThat(p.name).isEqualTo(in.name);
} finally {
removeGlobalCapabilities(SystemGroupBackend.REGISTERED_USERS, GlobalCapability.CREATE_PROJECT);
}
}
use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class CreateProjectIT method createProjectWithoutCapability_Forbidden.
@Test
public void createProjectWithoutCapability_Forbidden() throws Exception {
setApiUser(user);
ProjectInput in = new ProjectInput();
in.name = name("newProject");
assertCreateFails(in, AuthException.class);
}
use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class CreateProjectIT method createProjectWhenProjectAlreadyExists_Conflict.
@Test
public void createProjectWhenProjectAlreadyExists_Conflict() throws Exception {
ProjectInput in = new ProjectInput();
in.name = allProjects.get();
assertCreateFails(in, ResourceConflictException.class);
}
use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class CreateProject method apply.
@Override
public Response<ProjectInfo> apply(TopLevelResource resource, ProjectInput input) throws BadRequestException, UnprocessableEntityException, ResourceConflictException, ResourceNotFoundException, IOException, ConfigInvalidException, PermissionBackendException {
if (input == null) {
input = new ProjectInput();
}
if (input.name != null && !name.equals(input.name)) {
throw new BadRequestException("name must match URL");
}
CreateProjectArgs args = new CreateProjectArgs();
args.setProjectName(ProjectUtil.stripGitSuffix(name));
String parentName = MoreObjects.firstNonNull(Strings.emptyToNull(input.parent), allProjects.get());
args.newParent = projectsCollection.get().parse(parentName, false).getControl();
args.createEmptyCommit = input.createEmptyCommit;
args.permissionsOnly = input.permissionsOnly;
args.projectDescription = Strings.emptyToNull(input.description);
args.submitType = input.submitType;
args.branch = normalizeBranchNames(input.branches);
if (input.owners == null || input.owners.isEmpty()) {
args.ownerIds = new ArrayList<>(projectOwnerGroups.create(args.getProject()).get());
} else {
args.ownerIds = Lists.newArrayListWithCapacity(input.owners.size());
for (String owner : input.owners) {
args.ownerIds.add(groupsCollection.get().parse(owner).getGroupUUID());
}
}
args.contributorAgreements = MoreObjects.firstNonNull(input.useContributorAgreements, InheritableBoolean.INHERIT);
args.signedOffBy = MoreObjects.firstNonNull(input.useSignedOffBy, InheritableBoolean.INHERIT);
args.contentMerge = input.submitType == SubmitType.FAST_FORWARD_ONLY ? InheritableBoolean.FALSE : MoreObjects.firstNonNull(input.useContentMerge, InheritableBoolean.INHERIT);
args.newChangeForAllNotInTarget = MoreObjects.firstNonNull(input.createNewChangeForAllNotInTarget, InheritableBoolean.INHERIT);
args.changeIdRequired = MoreObjects.firstNonNull(input.requireChangeId, InheritableBoolean.INHERIT);
try {
args.maxObjectSizeLimit = ProjectConfig.validMaxObjectSizeLimit(input.maxObjectSizeLimit);
} catch (ConfigInvalidException e) {
throw new BadRequestException(e.getMessage());
}
for (ProjectCreationValidationListener l : projectCreationValidationListeners) {
try {
l.validateNewProject(args);
} catch (ValidationException e) {
throw new ResourceConflictException(e.getMessage(), e);
}
}
Project p = createProject(args);
if (input.pluginConfigValues != null) {
try {
ProjectControl projectControl = projectControlFactory.controlFor(p.getNameKey(), identifiedUser.get());
ConfigInput in = new ConfigInput();
in.pluginConfigValues = input.pluginConfigValues;
putConfig.get().apply(projectControl, in);
} catch (NoSuchProjectException e) {
throw new ResourceNotFoundException(p.getName());
}
}
return Response.created(json.format(p));
}
Aggregations