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