Search in sources :

Example 61 with ContentId

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

the class PortalUrlServiceImpl_processHtmlTest method process_unknown_content.

@Test
public void process_unknown_content() {
    when(contentService.getById(isA(ContentId.class))).thenAnswer((params) -> {
        final ContentId id = params.getArgument(0);
        throw new ContentNotFoundException(id, ContextAccessor.current().getBranch());
    });
    // Process an html text containing a link to an unknown content
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"content://123\">Content</a>");
    // Checks that the error 500 page is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/error/404?message=Content+with+id+%5B123%5D+was+not+found+in+branch+%5Bdraft%5D\">Content</a>", processedHtml);
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 62 with ContentId

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

the class UpdateAttachmentsParamsTest method fromBuilder.

@Test
public void fromBuilder() {
    ContentId id = ContentId.from("id-1");
    Attachment attachment = Attachment.create().mimeType("image/jpg").name("MyImage.jpg").build();
    UpdateAttachmentsParams params = UpdateAttachmentsParams.create(id).addAttachments(attachment).build();
    assertEquals(id, params.getContentId());
    assertEquals(1, params.getAttachments().getSize());
    assertEquals(attachment, params.getAttachments().first());
}
Also used : ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 63 with ContentId

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

the class ReprocessContentCommand method reprocessMedia.

private Content reprocessMedia(final Media media) {
    final Attachment source = media.getSourceAttachment();
    if (source == null) {
        return media;
    }
    final ContentId id = media.getId();
    final ByteSource binary = GetBinaryCommand.create(id, source.getBinaryReference(), this).build().execute();
    final UpdateMediaParams updateMediaParams = new UpdateMediaParams().byteSource(binary).mimeType(source.getMimeType()).content(id).name(source.getName());
    return UpdateMediaCommand.create(updateMediaParams, this).mediaInfoService(mediaInfoService).siteService(this.siteService).contentTypeService(this.contentTypeService).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).build().execute();
}
Also used : UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) ByteSource(com.google.common.io.ByteSource) Attachment(com.enonic.xp.attachment.Attachment) ContentId(com.enonic.xp.content.ContentId)

Example 64 with ContentId

use of com.enonic.xp.content.ContentId 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 65 with ContentId

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

the class ResolveContentsToBePublishedCommand method getWorkResult.

private ResolveSyncWorkResult getWorkResult(final ContentId contentId) {
    final NodeIds nodeIds = excludedContentIds != null ? NodeIds.from(excludedContentIds.stream().map(id -> NodeId.from(id.toString())).collect(Collectors.toList())) : NodeIds.empty();
    final boolean includeChildren = excludeChildrenIds == null || !this.excludeChildrenIds.contains(contentId);
    return nodeService.resolveSyncWork(SyncWorkResolverParams.create().includeChildren(includeChildren).includeDependencies(this.includeDependencies).nodeId(NodeId.from(contentId.toString())).excludedNodeIds(nodeIds).branch(this.target).statusesToStopDependenciesSearch(Set.of(CompareStatus.EQUAL)).build());
}
Also used : ContentId(com.enonic.xp.content.ContentId) ResolveSyncWorkResult(com.enonic.xp.node.ResolveSyncWorkResult) ContentIds(com.enonic.xp.content.ContentIds) Set(java.util.Set) Preconditions(com.google.common.base.Preconditions) Collectors(java.util.stream.Collectors) Branch(com.enonic.xp.branch.Branch) NodeIds(com.enonic.xp.node.NodeIds) CompareContentResults(com.enonic.xp.content.CompareContentResults) CompareStatus(com.enonic.xp.content.CompareStatus) NodeId(com.enonic.xp.node.NodeId) SyncWorkResolverParams(com.enonic.xp.node.SyncWorkResolverParams) NodeIds(com.enonic.xp.node.NodeIds)

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