Search in sources :

Example 1 with RepositoryNotFoundException

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

the class NodeServiceImpl method verifyRepositoryExists.

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

Example 2 with RepositoryNotFoundException

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

the class RepositoryServiceImpl method doCreateBranch.

private Repository doCreateBranch(final CreateBranchParams createBranchParams, 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 already exists, throws an exception
    final Branch newBranch = createBranchParams.getBranch();
    if (previousRepository.getBranches().contains(newBranch)) {
        throw new BranchAlreadyExistException(newBranch);
    }
    // If the root node does not exist, creates it
    if (getRootNode(previousRepository.getId(), newBranch) == null) {
        pushRootNode(previousRepository, newBranch);
        RefreshCommand.create().indexServiceInternal(this.indexServiceInternal).refreshMode(RefreshMode.ALL).build().execute();
    }
    // Updates the repository entry
    return repositoryEntryService.addBranchToRepositoryEntry(repositoryId, newBranch);
}
Also used : Branch(com.enonic.xp.branch.Branch) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException)

Example 3 with RepositoryNotFoundException

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

the class RepositoryServiceImpl method doUpdateRepository.

private Repository doUpdateRepository(final UpdateRepositoryParams updateRepositoryParams, Repository previousRepository) {
    RepositoryId repositoryId = updateRepositoryParams.getRepositoryId();
    previousRepository = previousRepository == null ? repositoryEntryService.getRepositoryEntry(repositoryId) : previousRepository;
    if (previousRepository == null) {
        throw new RepositoryNotFoundException(repositoryId);
    }
    final EditableRepository editableRepository = new EditableRepository(previousRepository);
    updateRepositoryParams.getEditor().accept(editableRepository);
    UpdateRepositoryEntryParams params = UpdateRepositoryEntryParams.create().repositoryId(repositoryId).repositoryData(editableRepository.data).attachments(ImmutableList.copyOf(editableRepository.binaryAttachments)).build();
    return repositoryEntryService.updateRepositoryEntry(params);
}
Also used : RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) RepositoryId(com.enonic.xp.repository.RepositoryId) EditableRepository(com.enonic.xp.repository.EditableRepository)

Example 4 with RepositoryNotFoundException

use of com.enonic.xp.repository.RepositoryNotFoundException 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 5 with RepositoryNotFoundException

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

the class RepositoryServiceImpl method getBinary.

@Override
public ByteSource getBinary(final RepositoryId repositoryId, final BinaryReference binaryReference) {
    requireAdminRole();
    Repository repository = repositoryEntryService.getRepositoryEntry(repositoryId);
    if (repository == null) {
        throw new RepositoryNotFoundException(repositoryId);
    }
    final AttachedBinary attachedBinary = repository.getAttachments().getByBinaryReference(binaryReference);
    return attachedBinary == null ? null : repositoryEntryService.getBinary(attachedBinary);
}
Also used : EditableRepository(com.enonic.xp.repository.EditableRepository) Repository(com.enonic.xp.repository.Repository) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Aggregations

RepositoryNotFoundException (com.enonic.xp.repository.RepositoryNotFoundException)6 Repository (com.enonic.xp.repository.Repository)3 RepositoryId (com.enonic.xp.repository.RepositoryId)3 Branch (com.enonic.xp.branch.Branch)2 BranchNotFoundException (com.enonic.xp.repository.BranchNotFoundException)2 EditableRepository (com.enonic.xp.repository.EditableRepository)2 AttachedBinary (com.enonic.xp.node.AttachedBinary)1