use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.
the class DeleteContentCommand method doExecute.
private DeleteContentsResult doExecute() {
this.nodeService.refresh(RefreshMode.ALL);
final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(this.params.getContentPath());
final Node nodeToDelete = this.nodeService.getByPath(nodePath);
if (nodeToDelete == null) {
throw new ContentNotFoundException(this.params.getContentPath(), ContextAccessor.current().getBranch());
}
if (!params.isDeleteOnline()) {
final NodeIds draftChildren = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(nodeToDelete.id()).recursive(true).build()).getNodeIds();
final boolean anyChildIsMovedIn = nodeService.compare(draftChildren, ContentConstants.BRANCH_MASTER).getComparisons().stream().anyMatch(nodeComparison -> {
final boolean moved = CompareStatus.MOVED.equals(nodeComparison.getCompareStatus());
return moved && !nodeComparison.getTargetPath().asAbsolute().toString().startsWith(nodePath.asAbsolute().toString());
});
if (anyChildIsMovedIn) {
throw new RuntimeException(String.format("Cannot make content tree pending delete for [%s], at least one published child is moved in from outside.", nodeToDelete.id()));
}
}
final DeleteContentsResult deletedContents = doDeleteContent(nodeToDelete.id());
this.nodeService.refresh(RefreshMode.ALL);
return deletedContents;
}
use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.
the class DeleteContentHandlerTest method deleteById_notFound.
@Test
public void deleteById_notFound() throws Exception {
final ContentId id = ContentId.from("123456");
Mockito.when(this.contentService.getById(Mockito.any())).thenThrow(new ContentNotFoundException(id, null));
runFunction("/test/DeleteContentHandlerTest.js", "deleteById_notFound");
}
use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.
the class GetContentHandlerTest method getById_notFound.
@Test
public void getById_notFound() throws Exception {
final ContentId id = ContentId.from("123456");
Mockito.when(this.contentService.getById(id)).thenThrow(new ContentNotFoundException(id, null));
runFunction("/test/GetContentHandlerTest.js", "getById_notFound");
}
use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.
the class GetContentHandlerTest method getByPath_notFound.
@Test
public void getByPath_notFound() throws Exception {
final ContentPath path = ContentPath.from("/a/b/mycontent");
Mockito.when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, null));
runFunction("/test/GetContentHandlerTest.js", "getByPath_notFound");
}
use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.
the class SetPermissionsHandlerTest method testContentNotFoundById.
@Test
public void testContentNotFoundById() throws Exception {
Mockito.when(this.contentService.getByPath(Mockito.any())).thenThrow(new ContentNotFoundException(ContentId.from("ee70f5d0-025c-4fbd-a835-5e50ff7b76ba"), Branch.from("draft")));
SecurityService securityService = Mockito.mock(SecurityService.class);
addService(SecurityService.class, securityService);
final Optional<? extends Principal> value = Optional.of(User.ANONYMOUS);
Mockito.<Optional<? extends Principal>>when(securityService.getPrincipal(Mockito.any(PrincipalKey.class))).thenReturn(value);
runFunction("/test/SetPermissionsHandlerTest.js", "setPermissionsNotFoundById");
}
Aggregations