Search in sources :

Example 71 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class BranchesCollection method parse.

@Override
public BranchResource parse(ProjectResource parent, IdString id) throws ResourceNotFoundException, IOException, BadRequestException {
    String branchName = id.get();
    if (!branchName.equals(Constants.HEAD)) {
        branchName = RefNames.fullName(branchName);
    }
    List<BranchInfo> branches = list.get().apply(parent);
    for (BranchInfo b : branches) {
        if (branchName.equals(b.ref)) {
            return new BranchResource(parent.getControl(), b);
        }
    }
    throw new ResourceNotFoundException();
}
Also used : BranchInfo(com.google.gerrit.extensions.api.projects.BranchInfo) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 72 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class CommitsCollection method parse.

@Override
public CommitResource parse(ProjectResource parent, IdString id) throws ResourceNotFoundException, IOException {
    ObjectId objectId;
    try {
        objectId = ObjectId.fromString(id.get());
    } catch (IllegalArgumentException e) {
        throw new ResourceNotFoundException(id);
    }
    try (Repository repo = repoManager.openRepository(parent.getNameKey());
        RevWalk rw = new RevWalk(repo)) {
        RevCommit commit = rw.parseCommit(objectId);
        rw.parseBody(commit);
        if (!parent.getControl().canReadCommit(db.get(), repo, commit)) {
            throw new ResourceNotFoundException(id);
        }
        for (int i = 0; i < commit.getParentCount(); i++) {
            rw.parseBody(rw.parseCommit(commit.getParent(i)));
        }
        return new CommitResource(parent, commit);
    } catch (MissingObjectException | IncorrectObjectTypeException e) {
        throw new ResourceNotFoundException(id);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 73 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException 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)

Example 74 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class ListTags method get.

public TagInfo get(ProjectResource resource, IdString id) throws ResourceNotFoundException, IOException {
    try (Repository repo = getRepository(resource.getNameKey());
        RevWalk rw = new RevWalk(repo)) {
        String tagName = id.get();
        if (!tagName.startsWith(Constants.R_TAGS)) {
            tagName = Constants.R_TAGS + tagName;
        }
        Ref ref = repo.getRefDatabase().exactRef(tagName);
        ProjectControl control = resource.getControl();
        if (ref != null && !visibleTags(control, repo, ImmutableMap.of(ref.getName(), ref)).isEmpty()) {
            return createTagInfo(permissionBackend.user(control.getUser()).project(resource.getNameKey()).ref(ref.getName()), ref, rw);
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) IdString(com.google.gerrit.extensions.restapi.IdString) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 75 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class DashboardsCollection method parse.

private DashboardResource parse(ProjectControl ctl, String ref, String path, ProjectControl myCtl) throws ResourceNotFoundException, IOException, AmbiguousObjectException, IncorrectObjectTypeException, ConfigInvalidException {
    String id = ref + ":" + path;
    if (!ref.startsWith(REFS_DASHBOARDS)) {
        ref = REFS_DASHBOARDS + ref;
    }
    if (!Repository.isValidRefName(ref) || !ctl.controlForRef(ref).isVisible()) {
        throw new ResourceNotFoundException(id);
    }
    try (Repository git = gitManager.openRepository(ctl.getProject().getNameKey())) {
        ObjectId objId = git.resolve(ref + ":" + path);
        if (objId == null) {
            throw new ResourceNotFoundException(id);
        }
        BlobBasedConfig cfg = new BlobBasedConfig(null, git, objId);
        return new DashboardResource(myCtl, ref, path, cfg, false);
    } catch (RepositoryNotFoundException e) {
        throw new ResourceNotFoundException(id);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) IdString(com.google.gerrit.extensions.restapi.IdString) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig)

Aggregations

ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)75 IdString (com.google.gerrit.extensions.restapi.IdString)18 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)17 AuthException (com.google.gerrit.extensions.restapi.AuthException)15 Repository (org.eclipse.jgit.lib.Repository)14 Project (com.google.gerrit.reviewdb.client.Project)13 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)12 Account (com.google.gerrit.reviewdb.client.Account)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 RevWalk (org.eclipse.jgit.revwalk.RevWalk)11 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)10 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)10 IOException (java.io.IOException)9 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)9 ObjectId (org.eclipse.jgit.lib.ObjectId)9 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)8 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)8 CurrentUser (com.google.gerrit.server.CurrentUser)7 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)7 ArrayList (java.util.ArrayList)7