Search in sources :

Example 11 with RepositoryId

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

the class SnapshotServiceImpl method doRestore.

private RestoreResult doRestore(final RestoreParams restoreParams) {
    checkSnapshotRepository();
    final String snapshotName = restoreParams.isLatest() ? determineNameOfLatestSnapshot() : restoreParams.getSnapshotName();
    validateSnapshot(snapshotName);
    final RepositoryId repositoryToRestore = restoreParams.getRepositoryId();
    boolean restoreAll = repositoryToRestore == null;
    final RepositoryIds repositoriesBeforeRestore = restoreAll ? repositoryEntryService.findRepositoryEntryIds() : null;
    this.eventPublisher.publish(RepositoryEvents.restoreInitialized());
    if (restoreAll) {
        LOG.info("Restoring all repositories from snapshot");
    } else {
        LOG.info("Restoring repository {} from snapshot", repositoryToRestore);
    }
    final RestoreResult result = SnapshotRestoreExecutor.create().snapshotName(snapshotName).repositoriesToClose(restoreAll ? repositoriesBeforeRestore : RepositoryIds.from(repositoryToRestore)).repositoriesToRestore(restoreAll ? RepositoryIds.empty() : RepositoryIds.from(repositoryToRestore)).client(this.client).snapshotRepositoryName(SNAPSHOT_REPOSITORY_NAME).indexServiceInternal(this.indexServiceInternal).build().execute();
    if (restoreAll) {
        final RepositoryIds repositoriesAfterRestore = repositoryEntryService.findRepositoryEntryIds();
        repositoriesBeforeRestore.stream().filter(Predicate.not(repositoriesAfterRestore::contains)).forEach(repositoryId -> {
            LOG.info("Deleting repository {} indices missing in snapshot", repositoryId);
            indexServiceInternal.deleteIndices(IndexNameResolver.resolveIndexNames(repositoryId).toArray(String[]::new));
        });
    }
    LOG.info("Snapshot Restore completed");
    this.eventPublisher.publish(RepositoryEvents.restored());
    return result;
}
Also used : RepositoryIds(com.enonic.xp.repository.RepositoryIds) RestoreResult(com.enonic.xp.node.RestoreResult) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 12 with RepositoryId

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

the class IndexServiceImpl method updateIndexSettings.

@Override
public UpdateIndexSettingsResult updateIndexSettings(final UpdateIndexSettingsParams params) {
    final UpdateIndexSettingsResult.Builder result = UpdateIndexSettingsResult.create();
    final UpdateIndexSettings updateIndexSettings = UpdateIndexSettings.from(params.getSettings());
    for (final RepositoryId repositoryId : params.getRepositoryIds()) {
        updateIndexSettings(repositoryId, updateIndexSettings, params.isRequireClosedIndex(), result);
    }
    return result.build();
}
Also used : UpdateIndexSettingsResult(com.enonic.xp.index.UpdateIndexSettingsResult) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 13 with RepositoryId

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

the class DuplicateNodeCommand method attachBinaries.

private void attachBinaries(final Node node, final CreateNodeParams.Builder paramsBuilder) {
    for (final AttachedBinary attachedBinary : node.getAttachedBinaries()) {
        final RepositoryId repositoryId = ContextAccessor.current().getRepositoryId();
        paramsBuilder.attachBinary(attachedBinary.getBinaryReference(), this.binaryService.get(repositoryId, attachedBinary));
    }
}
Also used : RepositoryId(com.enonic.xp.repository.RepositoryId) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 14 with RepositoryId

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

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

the class AbstractNodeEventHandler method createNodeContext.

InternalContext createNodeContext(final Map<Object, Object> map, final InternalContext context) {
    final InternalContext.Builder nodeContext = InternalContext.create(context);
    final RepositoryId repositoryId = getRepositoryId(map);
    if (repositoryId != null) {
        nodeContext.repositoryId(repositoryId);
    }
    final Branch branch = getBranch(map);
    if (branch != null) {
        nodeContext.branch(branch);
    }
    return nodeContext.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Branch(com.enonic.xp.branch.Branch) RepositoryId(com.enonic.xp.repository.RepositoryId)

Aggregations

RepositoryId (com.enonic.xp.repository.RepositoryId)61 Test (org.junit.jupiter.api.Test)21 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Branch (com.enonic.xp.branch.Branch)14 Repository (com.enonic.xp.repository.Repository)11 Node (com.enonic.xp.node.Node)9 ByteSource (com.google.common.io.ByteSource)8 IOException (java.io.IOException)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 Segment (com.enonic.xp.blob.Segment)5 Context (com.enonic.xp.context.Context)5 ContextAccessor (com.enonic.xp.context.ContextAccessor)5 ContextBuilder (com.enonic.xp.context.ContextBuilder)5 BlobKey (com.enonic.xp.blob.BlobKey)4 EventPublisher (com.enonic.xp.event.EventPublisher)4 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)4 Project (com.enonic.xp.project.Project)4 DumpConstants (com.enonic.xp.repo.impl.dump.DumpConstants)4 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)4 RepositoryIds (com.enonic.xp.repository.RepositoryIds)4