Search in sources :

Example 1 with BranchNotFoundException

use of com.enonic.xp.repository.BranchNotFoundException in project xp by enonic.

the class NodeServiceImpl method verifyBranchExists.

private void verifyBranchExists(Branch branch) {
    NodeHelper.runAsAdmin(() -> {
        final RepositoryId repoId = ContextAccessor.current().getRepositoryId();
        final Repository repository = this.repositoryService.get(repoId);
        if (repository == null) {
            throw new RepositoryNotFoundException(repoId);
        }
        if (!repository.getBranches().contains(branch)) {
            throw new BranchNotFoundException(branch);
        }
    });
}
Also used : Repository(com.enonic.xp.repository.Repository) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 2 with BranchNotFoundException

use of com.enonic.xp.repository.BranchNotFoundException in project xp by enonic.

the class RepositoryServiceImpl method doDeleteBranch.

private Repository doDeleteBranch(final DeleteBranchParams params, final RepositoryId repositoryId, Repository previousRepository) {
    // If the repository entry does not exist, throws an exception
    previousRepository = previousRepository == null ? repositoryEntryService.getRepositoryEntry(repositoryId) : previousRepository;
    if (previousRepository == null) {
        throw new RepositoryNotFoundException(repositoryId);
    }
    // If the branch does not exist, throws an exception
    final Branch branch = params.getBranch();
    if (!previousRepository.getBranches().contains(branch)) {
        throw new BranchNotFoundException(branch);
    }
    // If the root node exists, deletes it
    if (getRootNode(previousRepository.getId(), branch) != null) {
        deleteRootNode(branch);
    }
    // Updates the repository entry
    return repositoryEntryService.removeBranchFromRepositoryEntry(repositoryId, branch);
}
Also used : Branch(com.enonic.xp.branch.Branch) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException)

Aggregations

BranchNotFoundException (com.enonic.xp.repository.BranchNotFoundException)2 RepositoryNotFoundException (com.enonic.xp.repository.RepositoryNotFoundException)2 Branch (com.enonic.xp.branch.Branch)1 Repository (com.enonic.xp.repository.Repository)1 RepositoryId (com.enonic.xp.repository.RepositoryId)1