Search in sources :

Example 21 with ProjectInput

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);
    }
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) ProjectAssert.assertProjectInfo(com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 22 with ProjectInput

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);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 23 with ProjectInput

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);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 24 with ProjectInput

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));
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) ValidationException(com.google.gerrit.server.validators.ValidationException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ProjectCreationValidationListener(com.google.gerrit.server.validators.ProjectCreationValidationListener) Project(com.google.gerrit.reviewdb.client.Project) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

ProjectInput (com.google.gerrit.extensions.api.projects.ProjectInput)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 Test (org.junit.Test)19 Project (com.google.gerrit.reviewdb.client.Project)6 ProjectAssert.assertProjectInfo (com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo)3 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)1 ValidationException (com.google.gerrit.server.validators.ValidationException)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1