Search in sources :

Example 1 with ContentInheritType

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

the class CreatedEventSyncCommand method createImportParams.

private ImportContentParams createImportParams(final ContentToSync content, final ContentPath parentPath, final InsertManualStrategy insertManualStrategy) {
    final BinaryAttachments.Builder builder = BinaryAttachments.create();
    content.getSourceContent().getAttachments().forEach(attachment -> {
        final ByteSource binary = content.getSourceContext().callWith(() -> contentService.getBinary(content.getId(), attachment.getBinaryReference()));
        builder.add(new BinaryAttachment(attachment.getBinaryReference(), binary));
    });
    final ContentPath targetPath = buildNewPath(parentPath, content.getSourceContent().getName());
    final EnumSet<ContentInheritType> inheritTypes = content.getSourceContent().getName().toString().equals(targetPath.getName()) ? EnumSet.allOf(ContentInheritType.class) : EnumSet.complementOf(EnumSet.of(ContentInheritType.NAME));
    return ImportContentParams.create().importContent(content.getSourceContent()).targetPath(targetPath).binaryAttachments(builder.build()).inherit(inheritTypes).originProject(ProjectName.from(content.getSourceContext().getRepositoryId())).importPermissionsOnCreate(false).dryRun(false).insertManualStrategy(insertManualStrategy).build();
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) ByteSource(com.google.common.io.ByteSource) ContentPath(com.enonic.xp.content.ContentPath) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Example 2 with ContentInheritType

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

the class ContentServiceImplTest_restore method restore_inherited.

@Test
public void restore_inherited() {
    final Content content = createContent(ContentPath.ROOT, "content");
    this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
    refresh();
    final ContentId importedId = archiveContext().callWith(() -> this.contentService.importContent(ImportContentParams.create().importContent(content).targetPath(content.getPath()).inherit(EnumSet.allOf(ContentInheritType.class)).build()).getContent().getId());
    this.contentService.restore(RestoreContentParams.create().contentId(importedId).build());
    final Set<ContentInheritType> inherit = this.contentService.getById(importedId).getInherit();
    assertEquals(2, inherit.size());
    assertTrue(inherit.contains(ContentInheritType.SORT));
    assertTrue(inherit.contains(ContentInheritType.NAME));
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentInheritType(com.enonic.xp.content.ContentInheritType) Test(org.junit.jupiter.api.Test)

Example 3 with ContentInheritType

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

the class ContentServiceImplTest_restore method restore_dont_stop_inherited.

@Test
public void restore_dont_stop_inherited() {
    final Content content = createContent(ContentPath.ROOT, "content");
    this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
    refresh();
    final ContentId importedId = archiveContext().callWith(() -> this.contentService.importContent(ImportContentParams.create().importContent(content).targetPath(content.getPath()).inherit(EnumSet.allOf(ContentInheritType.class)).build()).getContent().getId());
    this.contentService.restore(RestoreContentParams.create().contentId(importedId).stopInherit(false).build());
    final Set<ContentInheritType> inherit = this.contentService.getById(importedId).getInherit();
    assertEquals(4, inherit.size());
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentInheritType(com.enonic.xp.content.ContentInheritType) Test(org.junit.jupiter.api.Test)

Example 4 with ContentInheritType

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

the class ResetContentInheritanceCommand method execute.

void execute() {
    final ProjectName sourceProjectName = fetchSourceProjectName(params.getProjectName());
    validateSourceContentExist(sourceProjectName);
    final Context targetContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(params.getProjectName().getRepoId()).branch(ContentConstants.BRANCH_DRAFT).authInfo(createAdminAuthInfo()).build();
    targetContext.runWith(() -> {
        if (contentService.contentExists(params.getContentId())) {
            final Content targetContent = contentService.getById(params.getContentId());
            final Set<ContentInheritType> typesToReset = params.getInherit().stream().filter(contentInheritType -> !targetContent.getInherit().contains(contentInheritType)).collect(Collectors.toSet());
            if (!typesToReset.isEmpty()) {
                final UpdateContentParams updateParams = new UpdateContentParams().contentId(targetContent.getId()).modifier(targetContent.getModifier()).stopInherit(false).editor(edit -> {
                    edit.inherit = processInherit(edit.inherit, typesToReset);
                    edit.workflowInfo = WorkflowInfo.inProgress();
                });
                contentService.update(updateParams);
                syncContent(targetContent.getId(), sourceProjectName, params.getProjectName());
            }
        }
    });
}
Also used : Context(com.enonic.xp.context.Context) ContentService(com.enonic.xp.content.ContentService) User(com.enonic.xp.security.User) ContentConstants(com.enonic.xp.content.ContentConstants) ProjectService(com.enonic.xp.project.ProjectService) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentInheritType(com.enonic.xp.content.ContentInheritType) Set(java.util.Set) Content(com.enonic.xp.content.Content) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Project(com.enonic.xp.project.Project) Collectors(java.util.stream.Collectors) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) ContentId(com.enonic.xp.content.ContentId) Stream(java.util.stream.Stream) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) ContextAccessor(com.enonic.xp.context.ContextAccessor) ProjectName(com.enonic.xp.project.ProjectName) RoleKeys(com.enonic.xp.security.RoleKeys) Preconditions(com.google.common.base.Preconditions) Context(com.enonic.xp.context.Context) ContextBuilder(com.enonic.xp.context.ContextBuilder) EnumSet(java.util.EnumSet) ProjectName(com.enonic.xp.project.ProjectName) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Example 5 with ContentInheritType

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

the class CreateContentCommandTest method mockContentNode.

private void mockContentNode(final String name, final String parentPath, final String language, final EnumSet<ContentInheritType> inherit) {
    final PropertyTree data = new PropertyTree();
    data.setSet(ContentPropertyNames.DATA, new PropertySet());
    data.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
    data.setString(ContentPropertyNames.TYPE, ContentTypeName.folder().toString());
    data.setString(ContentPropertyNames.LANGUAGE, language);
    data.addStrings(ContentPropertyNames.INHERIT, inherit.stream().map(ContentInheritType::name).collect(Collectors.toList()));
    final Node contentNode = Node.create().id(NodeId.from("id1")).name(name).parentPath(NodePath.create(parentPath).build()).data(data).build();
    Mockito.when(nodeService.getByPath(contentNode.path())).thenReturn(contentNode);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Aggregations

ContentInheritType (com.enonic.xp.content.ContentInheritType)6 Content (com.enonic.xp.content.Content)4 ContentId (com.enonic.xp.content.ContentId)3 Test (org.junit.jupiter.api.Test)2 ContentConstants (com.enonic.xp.content.ContentConstants)1 ContentPath (com.enonic.xp.content.ContentPath)1 ContentService (com.enonic.xp.content.ContentService)1 ResetContentInheritParams (com.enonic.xp.content.ResetContentInheritParams)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)1 BinaryAttachments (com.enonic.xp.node.BinaryAttachments)1 Node (com.enonic.xp.node.Node)1 Project (com.enonic.xp.project.Project)1 ProjectName (com.enonic.xp.project.ProjectName)1