Search in sources :

Example 1 with ORIGINAL_NAME

use of com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME in project xp by enonic.

the class RestoreContentCommand method updateProperties.

private void updateProperties(final Node node, final boolean isRootContent) {
    final FindNodesByParentResult childrenToRestore = nodeService.findByParent(FindNodesByParentParams.create().size(-1).recursive(true).parentId(node.id()).build());
    childrenToRestore.getNodeIds().forEach(id -> nodeService.update(UpdateNodeParams.create().id(id).editor(toBeEdited -> {
        toBeEdited.data.removeProperties(ARCHIVED_TIME);
        toBeEdited.data.removeProperties(ARCHIVED_BY);
    }).build()));
    if (isRootContent) {
        nodeService.update(UpdateNodeParams.create().id(node.id()).editor(toBeEdited -> {
            toBeEdited.data.removeProperties(ORIGINAL_PARENT_PATH);
            toBeEdited.data.removeProperties(ORIGINAL_NAME);
            toBeEdited.data.removeProperties(ARCHIVED_TIME);
            toBeEdited.data.removeProperties(ARCHIVED_BY);
        }).build());
    }
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) MoveNodeException(com.enonic.xp.node.MoveNodeException) ContentConstants(com.enonic.xp.content.ContentConstants) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Node(com.enonic.xp.node.Node) ORIGINAL_PARENT_PATH(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_PARENT_PATH) ORIGINAL_NAME(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME) RestoreContentParams(com.enonic.xp.archive.RestoreContentParams) ContentId(com.enonic.xp.content.ContentId) RestoreContentException(com.enonic.xp.archive.RestoreContentException) ContextAccessor(com.enonic.xp.context.ContextAccessor) EnumSet(java.util.EnumSet) Property(com.enonic.xp.data.Property) ContentAccessException(com.enonic.xp.content.ContentAccessException) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) ContentInheritType(com.enonic.xp.content.ContentInheritType) NodePath(com.enonic.xp.node.NodePath) ARCHIVED_BY(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_BY) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeId(com.enonic.xp.node.NodeId) MoveNodeListener(com.enonic.xp.node.MoveNodeListener) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeName(com.enonic.xp.node.NodeName) RestoreContentListener(com.enonic.xp.archive.RestoreContentListener) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeAccessException(com.enonic.xp.node.NodeAccessException) Preconditions(com.google.common.base.Preconditions) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) ARCHIVED_TIME(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_TIME) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Example 2 with ORIGINAL_NAME

use of com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME in project xp by enonic.

the class ArchiveContentCommand method updateProperties.

private Node updateProperties(final NodeId nodeId) {
    final FindNodesByParentResult childrenToArchive = nodeService.findByParent(FindNodesByParentParams.create().size(-1).recursive(true).parentId(nodeId).build());
    final Instant now = Instant.now();
    final String archivedBy = getCurrentUser().getKey().toString();
    childrenToArchive.getNodeIds().forEach(id -> nodeService.update(UpdateNodeParams.create().id(id).editor(toBeEdited -> {
        toBeEdited.data.setInstant(ARCHIVED_TIME, now);
        toBeEdited.data.setString(ARCHIVED_BY, archivedBy);
    }).build()));
    return nodeService.update(UpdateNodeParams.create().id(nodeId).editor(toBeEdited -> {
        toBeEdited.data.setString(ORIGINAL_PARENT_PATH, ContentNodeHelper.translateNodePathToContentPath(toBeEdited.source.parentPath()).toString());
        toBeEdited.data.setString(ORIGINAL_NAME, toBeEdited.source.name().toString());
        toBeEdited.data.setInstant(ARCHIVED_TIME, now);
        toBeEdited.data.setString(ARCHIVED_BY, archivedBy);
    }).build());
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) MoveNodeException(com.enonic.xp.node.MoveNodeException) ContentConstants(com.enonic.xp.content.ContentConstants) Node(com.enonic.xp.node.Node) ORIGINAL_PARENT_PATH(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_PARENT_PATH) ArchiveContentException(com.enonic.xp.archive.ArchiveContentException) ArchiveContentListener(com.enonic.xp.archive.ArchiveContentListener) ORIGINAL_NAME(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME) ArchiveContentsResult(com.enonic.xp.archive.ArchiveContentsResult) ContextAccessor(com.enonic.xp.context.ContextAccessor) EnumSet(java.util.EnumSet) User(com.enonic.xp.security.User) ContentAccessException(com.enonic.xp.content.ContentAccessException) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) ContentInheritType(com.enonic.xp.content.ContentInheritType) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) NodePath(com.enonic.xp.node.NodePath) ARCHIVED_BY(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_BY) Instant(java.time.Instant) ZoneId(java.time.ZoneId) NodeId(com.enonic.xp.node.NodeId) MoveNodeListener(com.enonic.xp.node.MoveNodeListener) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeName(com.enonic.xp.node.NodeName) ContentIds(com.enonic.xp.content.ContentIds) DateTimeFormatter(java.time.format.DateTimeFormatter) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeAccessException(com.enonic.xp.node.NodeAccessException) Preconditions(com.google.common.base.Preconditions) ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) ARCHIVED_TIME(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_TIME) Instant(java.time.Instant) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Aggregations

ArchiveConstants (com.enonic.xp.archive.ArchiveConstants)2 ContentAccessException (com.enonic.xp.content.ContentAccessException)2 ContentConstants (com.enonic.xp.content.ContentConstants)2 ContentInheritType (com.enonic.xp.content.ContentInheritType)2 ARCHIVED_BY (com.enonic.xp.content.ContentPropertyNames.ARCHIVED_BY)2 ARCHIVED_TIME (com.enonic.xp.content.ContentPropertyNames.ARCHIVED_TIME)2 ORIGINAL_NAME (com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME)2 ORIGINAL_PARENT_PATH (com.enonic.xp.content.ContentPropertyNames.ORIGINAL_PARENT_PATH)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)2 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)2 MoveNodeException (com.enonic.xp.node.MoveNodeException)2 MoveNodeListener (com.enonic.xp.node.MoveNodeListener)2 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)2 Node (com.enonic.xp.node.Node)2 NodeAccessException (com.enonic.xp.node.NodeAccessException)2 NodeId (com.enonic.xp.node.NodeId)2 NodeName (com.enonic.xp.node.NodeName)2 NodePath (com.enonic.xp.node.NodePath)2 RefreshMode (com.enonic.xp.node.RefreshMode)2