Search in sources :

Example 51 with ContentId

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

the class ContentAuditLogSupportImpl method doUndoPendingDelete.

private void doUndoPendingDelete(final UndoPendingDeleteContentParams params, final Contents contents, final Context rootContext) {
    if (params.getContentIds() == null) {
        return;
    }
    final PropertyTree data = new PropertyTree();
    final PropertySet paramsSet = data.addSet("params");
    paramsSet.addString("target", nullToNull(params.getTarget()));
    paramsSet.addStrings("contentIds", params.getContentIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    addContents(data.getRoot(), contents, "result");
    log("system.content.delete", data, contents.getIds(), rootContext);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ContentId(com.enonic.xp.content.ContentId)

Example 52 with ContentId

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

the class ContentAuditLogSupportImpl method doReprocess.

private void doReprocess(final Content content, final Context rootContext) {
    final ContentId contentId = content.getId();
    final PropertyTree data = new PropertyTree();
    final PropertySet paramsSet = data.addSet("params");
    final PropertySet resultSet = data.addSet("result");
    paramsSet.addString("contentId", nullToNull(contentId));
    addContent(resultSet, content);
    log("system.content.reprocess", data, contentId, rootContext);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ContentId(com.enonic.xp.content.ContentId)

Example 53 with ContentId

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

the class ContentNodeTranslator method doTranslate.

private Content doTranslate(final Node node, final boolean hasChildren, final boolean allowAltRootPath) {
    final ContentId contentId = ContentId.from(node.id().toString());
    if (!allowAltRootPath && !(node.path().toString().startsWith(ContentNodeHelper.getContentRoot().toString() + "/") || node.path().equals(ContentNodeHelper.getContentRoot()))) {
        throw new ContentNotFoundException(contentId, ContextAccessor.current().getBranch(), ContentNodeHelper.getContentRoot());
    }
    final ContentPath parentContentPath = getParent(node.path());
    final Content.Builder<?> builder = contentDataSerializer.fromData(node.data().getRoot());
    builder.id(contentId).parentPath(parentContentPath).name(node.name().toString()).childOrder(node.getChildOrder()).permissions(node.getPermissions()).inheritPermissions(node.inheritsPermissions()).hasChildren(hasChildren).contentState(ContentState.from(node.getNodeState().value())).manualOrderValue(node.getManualOrderValue());
    final boolean isRoot = NodePath.ROOT.equals(node.parentPath());
    if (isRoot) {
        builder.root();
    }
    return builder.build();
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Example 54 with ContentId

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

the class GetNearestSiteCommandTest method get_nearest_site_content_is_site.

@Test
public void get_nearest_site_content_is_site() throws Exception {
    final Node node = Node.create().id(NodeId.from("test")).name("myContent").parentPath(ContentConstants.CONTENT_ROOT_PATH).build();
    final ContentId contentId = ContentId.from("aaa");
    final Site site = Site.create().path("/mycontent").id(contentId).build();
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(node);
    Mockito.when(this.translator.fromNode(node, true)).thenReturn(site);
    assertEquals(site, createCommand(contentId).execute());
}
Also used : Site(com.enonic.xp.site.Site) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 55 with ContentId

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

the class GetNearestSiteCommandTest method get_nearest_site_parent_is_site.

@Test
public void get_nearest_site_parent_is_site() throws Exception {
    final ContentId contentId = ContentId.from("aaa");
    final Node node = Node.create().id(NodeId.from("test")).name("myContent").parentPath(ContentConstants.CONTENT_ROOT_PATH).build();
    final Content content = Content.create().id(contentId).name("name").parentPath(ContentPath.from("/aaa")).build();
    final Site parent = Site.create().path("/mycontent").id(ContentId.from("bbb")).build();
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(node);
    Mockito.when(this.nodeService.getByPath(Mockito.isA(NodePath.class))).thenReturn(node);
    Mockito.when(this.translator.fromNode(node, true)).thenReturn(content, parent);
    assertEquals(parent, createCommand(contentId).execute());
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Aggregations

ContentId (com.enonic.xp.content.ContentId)83 Content (com.enonic.xp.content.Content)34 Test (org.junit.jupiter.api.Test)33 PropertyTree (com.enonic.xp.data.PropertyTree)16 ContentPath (com.enonic.xp.content.ContentPath)14 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentIds (com.enonic.xp.content.ContentIds)11 PropertySet (com.enonic.xp.data.PropertySet)10 NodeId (com.enonic.xp.node.NodeId)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ContentInheritType (com.enonic.xp.content.ContentInheritType)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)7 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)6 Context (com.enonic.xp.context.Context)6 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)5 Node (com.enonic.xp.node.Node)5 Branch (com.enonic.xp.branch.Branch)4 ContentConstants (com.enonic.xp.content.ContentConstants)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4