Search in sources :

Example 1 with ContentAlreadyExistsException

use of com.enonic.xp.content.ContentAlreadyExistsException in project xp by enonic.

the class MoveContentCommand method execute.

MoveContentsResult execute() {
    params.validate();
    try {
        final MoveContentsResult movedContents = doExecute();
        this.nodeService.refresh(RefreshMode.ALL);
        return movedContents;
    } catch (MoveNodeException e) {
        throw new MoveContentException(e.getMessage(), ContentPath.from(e.getPath().toString()));
    } catch (NodeAlreadyExistAtPathException e) {
        throw new ContentAlreadyExistsException(ContentPath.from(e.getNode().toString()), e.getRepositoryId(), e.getBranch());
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : MoveNodeException(com.enonic.xp.node.MoveNodeException) NodeAccessException(com.enonic.xp.node.NodeAccessException) MoveContentException(com.enonic.xp.content.MoveContentException) MoveContentsResult(com.enonic.xp.content.MoveContentsResult) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 2 with ContentAlreadyExistsException

use of com.enonic.xp.content.ContentAlreadyExistsException in project xp by enonic.

the class RenameContentCommandTest method test_already_exists.

@Test
void test_already_exists() {
    Node mockNode = Node.create().id(NodeId.from("testId")).build();
    final RepositoryId repositoryId = RepositoryId.from("some.repo");
    final Branch branch = Branch.from("somebranch");
    when(nodeService.rename(isA(RenameNodeParams.class))).thenThrow(new NodeAlreadyExistAtPathException(NodePath.create("/content/mycontent2").build(), repositoryId, branch));
    when(nodeService.getById(mockNode.id())).thenReturn(mockNode);
    final Content content = createContent(true);
    final RenameContentCommand command = createCommand(RenameContentParams.create().contentId(content.getId()).newName(ContentName.from("mycontent2")).build());
    final ContentAlreadyExistsException exception = assertThrows(ContentAlreadyExistsException.class, command::execute);
    assertEquals(branch, exception.getBranch());
    assertEquals(repositoryId, exception.getRepositoryId());
}
Also used : Branch(com.enonic.xp.branch.Branch) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test)

Example 3 with ContentAlreadyExistsException

use of com.enonic.xp.content.ContentAlreadyExistsException in project xp by enonic.

the class CreateContentCommand method doExecute.

private Content doExecute() {
    final ContentType contentType = contentTypeService.getByName(new GetContentTypeParams().contentTypeName(params.getType()));
    validateContentType(contentType);
    formDefaultValuesProcessor.setDefaultValues(contentType.getForm(), params.getData());
    // TODO apply default values to xData
    CreateContentParams processedParams = runContentProcessors(this.params, contentType);
    validateBlockingChecks(processedParams);
    final CreateContentTranslatorParams createContentTranslatorParams = createContentTranslatorParams(processedParams);
    final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(createContentTranslatorParams).contentTypeService(this.contentTypeService).pageDescriptorService(this.pageDescriptorService).xDataService(this.xDataService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
    try {
        final Node createdNode = nodeService.create(createNodeParams);
        if (params.isRefresh()) {
            nodeService.refresh(RefreshMode.SEARCH);
        }
        return translator.fromNode(createdNode, false);
    } catch (NodeAlreadyExistAtPathException e) {
        throw new ContentAlreadyExistsException(ContentPath.from(createContentTranslatorParams.getParent(), createContentTranslatorParams.getName().toString()), e.getRepositoryId(), e.getBranch());
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) NodeAccessException(com.enonic.xp.node.NodeAccessException) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentTranslatorParams(com.enonic.xp.content.CreateContentTranslatorParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Node(com.enonic.xp.node.Node) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 4 with ContentAlreadyExistsException

use of com.enonic.xp.content.ContentAlreadyExistsException in project xp by enonic.

the class CreatedEventSyncCommand method doSync.

private void doSync(final ContentToSync content) {
    try {
        content.getSourceContext().runWith(() -> {
            if (contentService.contentExists(content.getSourceContent().getParentPath())) {
                final ContentId parentId = contentService.getByPath(content.getSourceContent().getParentPath()).getId();
                content.getTargetContext().runWith(() -> {
                    if (content.getSourceContent().getParentPath().isRoot()) {
                        syncRootContent(content);
                    } else if (contentService.contentExists(parentId)) {
                        syncChildContent(parentId, content);
                    }
                });
            }
        });
    } catch (ContentAlreadyExistsException e) {
        LOG.warn("content [{}] already exists.", content.getId());
    }
}
Also used : ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) ContentId(com.enonic.xp.content.ContentId)

Example 5 with ContentAlreadyExistsException

use of com.enonic.xp.content.ContentAlreadyExistsException in project xp by enonic.

the class CreateMediaHandler method doExecute.

@Override
protected Object doExecute() {
    String name = this.name;
    Content result = null;
    final ContentPath parent = this.parentPath != null ? ContentPath.from(this.parentPath) : ContentPath.ROOT;
    while (result == null) {
        final CreateMediaParams params = createParams(name);
        try {
            result = this.contentService.create(params);
        } catch (ContentAlreadyExistsException e) {
            name = generateUniqueContentName(this.idGenerator, parent, this.name);
        }
    }
    return new ContentMapper(result);
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) Content(com.enonic.xp.content.Content) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) ContentMapper(com.enonic.xp.lib.content.mapper.ContentMapper) ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)8 Content (com.enonic.xp.content.Content)3 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)3 Test (org.junit.jupiter.api.Test)3 ContentAccessException (com.enonic.xp.content.ContentAccessException)2 ContentId (com.enonic.xp.content.ContentId)2 ContentPath (com.enonic.xp.content.ContentPath)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 CreateMediaParams (com.enonic.xp.content.CreateMediaParams)2 Node (com.enonic.xp.node.Node)2 NodeAccessException (com.enonic.xp.node.NodeAccessException)2 ContentType (com.enonic.xp.schema.content.ContentType)2 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)2 Branch (com.enonic.xp.branch.Branch)1 CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)1 MoveContentException (com.enonic.xp.content.MoveContentException)1 MoveContentsResult (com.enonic.xp.content.MoveContentsResult)1 Context (com.enonic.xp.context.Context)1 ContentMapper (com.enonic.xp.lib.content.mapper.ContentMapper)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1