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);
}
});
}
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);
}
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);
}
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);
}
});
}
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);
}
Aggregations