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);
}
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());
}
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();
}
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());
}
}
});
}
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());
}
Aggregations