Search in sources :

Example 1 with Repository

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

the class RepositoriesJson method create.

public static RepositoriesJson create(final Repositories repositories) {
    final RepositoriesJson json = new RepositoriesJson();
    json.repositories = new ArrayList<>();
    for (final Repository repo : repositories) {
        json.repositories.add(RepositoryJson.create(repo));
    }
    return json;
}
Also used : Repository(com.enonic.xp.repository.Repository)

Example 2 with Repository

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

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

the class RepositoryEntryServiceImpl method updateRepositoryNode.

private Repository updateRepositoryNode(final UpdateNodeParams updateNodeParams) {
    final Node updatedNode = createContext().callWith(() -> UpdateNodeCommand.create().params(updateNodeParams).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).binaryService(this.binaryService).build().execute());
    eventPublisher.publish(NodeEvents.updated(updatedNode));
    refresh();
    Repository repository = RepositoryNodeTranslator.toRepository(updatedNode);
    eventPublisher.publish(RepositoryEvents.updated(repository.getId()));
    return repository;
}
Also used : Repository(com.enonic.xp.repository.Repository) Node(com.enonic.xp.node.Node)

Example 4 with Repository

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

the class RepositoryServiceImpl method doCreateRepo.

private Repository doCreateRepo(final CreateRepositoryParams params) {
    final RepositoryId repositoryId = params.getRepositoryId();
    final boolean repoAlreadyInitialized = this.nodeRepositoryService.isInitialized(repositoryId);
    if (repoAlreadyInitialized) {
        throw new RepositoryAlreadyExistException(repositoryId);
    }
    this.nodeRepositoryService.create(params);
    createRootNode(params);
    final Repository repository = createRepositoryObject(params);
    repositoryEntryService.createRepositoryEntry(repository);
    return repository;
}
Also used : EditableRepository(com.enonic.xp.repository.EditableRepository) Repository(com.enonic.xp.repository.Repository) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 5 with Repository

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

the class VersionTableVacuumCommand method doProcessRepository.

private void doProcessRepository(final Repository repository) {
    int counter = 0;
    NodeVersionId lastVersionId = null;
    NodeVersionQuery query = createQuery(lastVersionId);
    NodeVersionQueryResult versionsResult = nodeService.findVersions(query);
    long hits = versionsResult.getHits();
    final long totalHits = versionsResult.getTotalHits();
    if (listener != null) {
        listener.stepBegin(repository.getId().toString(), totalHits);
    }
    while (hits > 0) {
        final List<NodeVersionId> versionsToDelete = new ArrayList<>();
        final Set<BlobKey> nodeBlobToCheckSet = new HashSet<>();
        final Set<BlobKey> binaryBlobToCheckSet = new HashSet<>();
        final NodeVersionsMetadata versions = versionsResult.getNodeVersionsMetadata();
        for (NodeVersionMetadata version : versions) {
            final boolean toDelete = processVersion(repository, version);
            if (toDelete) {
                result.deleted();
                versionsToDelete.add(version.getNodeVersionId());
                nodeBlobToCheckSet.add(version.getNodeVersionKey().getNodeBlobKey());
                binaryBlobToCheckSet.addAll(version.getBinaryBlobKeys().getSet());
            } else {
                result.inUse();
            }
            lastVersionId = version.getNodeVersionId();
            counter++;
        }
        versionService.delete(versionsToDelete, InternalContext.from(ContextAccessor.current()));
        nodeBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.NODE_BLOB_KEY)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.NODE_SEGMENT_LEVEL, blobKey));
        binaryBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.BINARY_BLOB_KEYS)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.BINARY_SEGMENT_LEVEL, blobKey));
        query = createQuery(lastVersionId);
        versionsResult = nodeService.findVersions(query);
        hits = versionsResult.getHits();
    }
    if (listener != null) {
        listener.processed(counter);
    }
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) IsBlobUsedByVersionCommand(com.enonic.xp.repo.impl.vacuum.blob.IsBlobUsedByVersionCommand) RepositoryService(com.enonic.xp.repository.RepositoryService) Node(com.enonic.xp.node.Node) VersionService(com.enonic.xp.repo.impl.version.VersionService) LoggerFactory(org.slf4j.LoggerFactory) NodeConstants(com.enonic.xp.repo.impl.node.NodeConstants) Segment(com.enonic.xp.blob.Segment) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) BlobKey(com.enonic.xp.blob.BlobKey) Branch(com.enonic.xp.branch.Branch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentLevel(com.enonic.xp.blob.SegmentLevel) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) BlobStore(com.enonic.xp.blob.BlobStore) NodeService(com.enonic.xp.node.NodeService) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) ContextBuilder(com.enonic.xp.context.ContextBuilder) RangeFilter(com.enonic.xp.query.filter.RangeFilter) VersionIndexPath(com.enonic.xp.repo.impl.version.VersionIndexPath) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Logger(org.slf4j.Logger) IndexPath(com.enonic.xp.index.IndexPath) RepositorySegmentUtils(com.enonic.xp.repository.RepositorySegmentUtils) InternalContext(com.enonic.xp.repo.impl.InternalContext) Set(java.util.Set) ValueFactory(com.enonic.xp.data.ValueFactory) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) VacuumListener(com.enonic.xp.vacuum.VacuumListener) OrderExpr(com.enonic.xp.query.expr.OrderExpr) List(java.util.List) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) VacuumTaskParams(com.enonic.xp.repo.impl.vacuum.VacuumTaskParams) Repository(com.enonic.xp.repository.Repository) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) ArrayList(java.util.ArrayList) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) BlobKey(com.enonic.xp.blob.BlobKey) HashSet(java.util.HashSet)

Aggregations

Repository (com.enonic.xp.repository.Repository)40 Test (org.junit.jupiter.api.Test)21 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)15 RepositoryId (com.enonic.xp.repository.RepositoryId)10 Node (com.enonic.xp.node.Node)9 Branch (com.enonic.xp.branch.Branch)8 PropertyTree (com.enonic.xp.data.PropertyTree)7 Context (com.enonic.xp.context.Context)6 FindNodesByMultiRepoQueryResult (com.enonic.xp.node.FindNodesByMultiRepoQueryResult)5 MultiRepoNodeQuery (com.enonic.xp.node.MultiRepoNodeQuery)5 NodeQuery (com.enonic.xp.node.NodeQuery)5 SearchTargets (com.enonic.xp.node.SearchTargets)5 ContextAccessor (com.enonic.xp.context.ContextAccessor)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 CreateRepositoryParams (com.enonic.xp.repository.CreateRepositoryParams)4 RepositoryService (com.enonic.xp.repository.RepositoryService)4 SystemLoadResult (com.enonic.xp.dump.SystemLoadResult)3 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)3 NodeService (com.enonic.xp.node.NodeService)3 Project (com.enonic.xp.project.Project)3