Search in sources :

Example 1 with BinaryService

use of com.enonic.xp.repo.impl.binary.BinaryService in project xp by enonic.

the class CreateNodeCommand_path_integrity_test method create.

@Test
public void create() {
    final int concurrentAttempts = 5;
    final int expectedSuccessfulAttempts = 1;
    final AtomicInteger exceptionCounter = new AtomicInteger();
    CompletableFuture.allOf(IntStream.range(0, concurrentAttempts).mapToObj(i -> CompletableFuture.runAsync(CreateNodeTask.create().binaryService(this.binaryService).storageService(this.storageService).nodeSearchService(this.searchService).indexServiceInternal(this.indexServiceInternal).context(ContextAccessor.current()).build()).exceptionally(throwable -> {
        exceptionCounter.incrementAndGet();
        return null;
    })).toArray(CompletableFuture[]::new)).join();
    assertEquals(concurrentAttempts - expectedSuccessfulAttempts, exceptionCounter.get());
    refresh();
    final FindNodesByQueryResult result = doFindByQuery(NodeQuery.create().path(NodePath.create(NodePath.ROOT, "myNode").build()).build());
    assertEquals(expectedSuccessfulAttempts, result.getTotalHits());
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) NodeStorageService(com.enonic.xp.repo.impl.storage.NodeStorageService) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) NodePath(com.enonic.xp.node.NodePath) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.jupiter.api.Test) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextAccessor(com.enonic.xp.context.ContextAccessor) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) Context(com.enonic.xp.context.Context) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeQuery(com.enonic.xp.node.NodeQuery) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Test(org.junit.jupiter.api.Test)

Example 2 with BinaryService

use of com.enonic.xp.repo.impl.binary.BinaryService in project xp by enonic.

the class DuplicateNodeCommand method updateNodeReferences.

private void updateNodeReferences(final Node node, final NodeReferenceUpdatesHolder nodeReferenceUpdatesHolder) {
    final PropertyTree data = node.data();
    boolean changes = false;
    for (final Property property : node.data().getProperties(ValueTypes.REFERENCE)) {
        final Reference reference = property.getReference();
        if (reference != null && nodeReferenceUpdatesHolder.mustUpdate(reference)) {
            changes = true;
            data.setReference(property.getPath(), nodeReferenceUpdatesHolder.getNewReference(reference));
        }
    }
    if (changes) {
        UpdateNodeCommand.create(this).params(UpdateNodeParams.create().id(node.id()).editor(toBeEdited -> toBeEdited.data = data).build()).binaryService(this.binaryService).build().execute();
    }
    nodeReferencesUpdated(1);
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) Property(com.enonic.xp.data.Property) Nodes(com.enonic.xp.node.Nodes) Logger(org.slf4j.Logger) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) Node(com.enonic.xp.node.Node) LoggerFactory(org.slf4j.LoggerFactory) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) AttachedBinary(com.enonic.xp.node.AttachedBinary) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) InsertManualStrategy(com.enonic.xp.node.InsertManualStrategy) RepositoryId(com.enonic.xp.repository.RepositoryId) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) Reference(com.enonic.xp.util.Reference) ContextAccessor(com.enonic.xp.context.ContextAccessor) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) ValueTypes(com.enonic.xp.data.ValueTypes) Preconditions(com.google.common.base.Preconditions) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Property(com.enonic.xp.data.Property)

Aggregations

ContextAccessor (com.enonic.xp.context.ContextAccessor)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 BinaryService (com.enonic.xp.repo.impl.binary.BinaryService)2 NodeSearchService (com.enonic.xp.repo.impl.search.NodeSearchService)2 Context (com.enonic.xp.context.Context)1 Property (com.enonic.xp.data.Property)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 ValueTypes (com.enonic.xp.data.ValueTypes)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 InsertManualStrategy (com.enonic.xp.node.InsertManualStrategy)1 Node (com.enonic.xp.node.Node)1 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1 NodePath (com.enonic.xp.node.NodePath)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 Nodes (com.enonic.xp.node.Nodes)1