Search in sources :

Example 6 with PageDescriptorService

use of com.enonic.xp.page.PageDescriptorService in project xp by enonic.

the class AbstractContentSynchronizerTest method setUpContentService.

private void setUpContentService() {
    final Map<String, List<String>> metadata = new HashMap<>();
    metadata.put(HttpHeaders.CONTENT_TYPE, List.of("image/jpg"));
    final ExtractedData extractedData = ExtractedData.create().metadata(metadata).build();
    final BinaryExtractor extractor = mock(BinaryExtractor.class);
    when(extractor.extract(isA(ByteSource.class))).thenReturn(extractedData);
    mediaInfoService = new MediaInfoServiceImpl();
    mediaInfoService.setBinaryExtractor(extractor);
    XDataService xDataService = mock(XDataService.class);
    MixinService mixinService = mock(MixinService.class);
    when(mixinService.inlineFormItems(isA(Form.class))).then(AdditionalAnswers.returnsFirstArg());
    pageDescriptorService = mock(PageDescriptorService.class);
    partDescriptorService = mock(PartDescriptorService.class);
    layoutDescriptorService = mock(LayoutDescriptorService.class);
    contentTypeService = new ContentTypeServiceImpl(null, null, mixinService);
    final ResourceService resourceService = mock(ResourceService.class);
    final SiteServiceImpl siteService = new SiteServiceImpl();
    siteService.setResourceService(resourceService);
    siteService.setMixinService(mixinService);
    final AuditLogService auditLogService = mock(AuditLogService.class);
    final ContentConfig contentConfig = mock(ContentConfig.class);
    final ContentAuditLogSupportImpl contentAuditLogSupport = new ContentAuditLogSupportImpl(contentConfig, new ContentAuditLogExecutorImpl(), auditLogService);
    contentService = new ContentServiceImpl(nodeService, pageDescriptorService, partDescriptorService, layoutDescriptorService);
    contentService.setEventPublisher(eventPublisher);
    contentService.setMediaInfoService(mediaInfoService);
    contentService.setSiteService(siteService);
    contentService.setContentTypeService(contentTypeService);
    contentService.setxDataService(xDataService);
    contentService.setFormDefaultValuesProcessor((form, data) -> {
    });
    contentService.setContentAuditLogSupport(contentAuditLogSupport);
    contentService.initialize(mock(ContentConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) IdProviderKey(com.enonic.xp.security.IdProviderKey) TaskServiceImpl(com.enonic.xp.impl.task.TaskServiceImpl) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) HttpHeaders(com.google.common.net.HttpHeaders) ContextAccessor(com.enonic.xp.context.ContextAccessor) Map(java.util.Map) ContextBuilder(com.enonic.xp.context.ContextBuilder) Bundle(org.osgi.framework.Bundle) SystemConstants(com.enonic.xp.security.SystemConstants) EnumSet(java.util.EnumSet) ProjectPermissionsContextManagerImpl(com.enonic.xp.core.impl.project.ProjectPermissionsContextManagerImpl) Media(com.enonic.xp.content.Media) User(com.enonic.xp.security.User) ContentServiceImpl(com.enonic.xp.core.impl.content.ContentServiceImpl) TaskManagerCleanupScheduler(com.enonic.xp.impl.task.TaskManagerCleanupScheduler) Project(com.enonic.xp.project.Project) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) AdditionalAnswers(org.mockito.AdditionalAnswers) BinaryExtractor(com.enonic.xp.extractor.BinaryExtractor) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteStreams(com.google.common.io.ByteStreams) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) ProjectServiceImpl(com.enonic.xp.core.impl.project.ProjectServiceImpl) MixinService(com.enonic.xp.schema.mixin.MixinService) ContentAuditLogExecutorImpl(com.enonic.xp.core.impl.content.ContentAuditLogExecutorImpl) ContentAuditLogSupportImpl(com.enonic.xp.core.impl.content.ContentAuditLogSupportImpl) SiteServiceImpl(com.enonic.xp.core.impl.site.SiteServiceImpl) Mockito.mock(org.mockito.Mockito.mock) CreateContentParams(com.enonic.xp.content.CreateContentParams) SecurityServiceImpl(com.enonic.xp.core.impl.security.SecurityServiceImpl) ContentConstants(com.enonic.xp.content.ContentConstants) RecurringJob(com.enonic.xp.core.internal.concurrent.RecurringJob) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) MediaInfoServiceImpl(com.enonic.xp.core.impl.media.MediaInfoServiceImpl) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ContentTypeServiceImpl(com.enonic.xp.core.impl.schema.content.ContentTypeServiceImpl) ProjectName(com.enonic.xp.project.ProjectName) AuditLogService(com.enonic.xp.audit.AuditLogService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) XDataService(com.enonic.xp.schema.xdata.XDataService) OsgiSupportMock(com.enonic.xp.core.internal.osgi.OsgiSupportMock) PropertyTree(com.enonic.xp.data.PropertyTree) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) ResourceService(com.enonic.xp.resource.ResourceService) ContentPath(com.enonic.xp.content.ContentPath) ContentInheritType(com.enonic.xp.content.ContentInheritType) NodePath(com.enonic.xp.node.NodePath) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) LocalTaskManagerImpl(com.enonic.xp.impl.task.LocalTaskManagerImpl) Mockito.when(org.mockito.Mockito.when) Form(com.enonic.xp.form.Form) ExtractedData(com.enonic.xp.extractor.ExtractedData) PrincipalKey(com.enonic.xp.security.PrincipalKey) ContentConfig(com.enonic.xp.core.impl.content.ContentConfig) CreateMediaParams(com.enonic.xp.content.CreateMediaParams) NamedTaskFactory(com.enonic.xp.impl.task.script.NamedTaskFactory) InputStream(java.io.InputStream) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) AuditLogService(com.enonic.xp.audit.AuditLogService) MediaInfoServiceImpl(com.enonic.xp.core.impl.media.MediaInfoServiceImpl) ContentAuditLogExecutorImpl(com.enonic.xp.core.impl.content.ContentAuditLogExecutorImpl) HashMap(java.util.HashMap) Form(com.enonic.xp.form.Form) ContentTypeServiceImpl(com.enonic.xp.core.impl.schema.content.ContentTypeServiceImpl) XDataService(com.enonic.xp.schema.xdata.XDataService) ResourceService(com.enonic.xp.resource.ResourceService) SiteServiceImpl(com.enonic.xp.core.impl.site.SiteServiceImpl) MixinService(com.enonic.xp.schema.mixin.MixinService) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) ContentConfig(com.enonic.xp.core.impl.content.ContentConfig) BinaryExtractor(com.enonic.xp.extractor.BinaryExtractor) ExtractedData(com.enonic.xp.extractor.ExtractedData) ContentAuditLogSupportImpl(com.enonic.xp.core.impl.content.ContentAuditLogSupportImpl) ContentServiceImpl(com.enonic.xp.core.impl.content.ContentServiceImpl) ByteSource(com.google.common.io.ByteSource) List(java.util.List)

Example 7 with PageDescriptorService

use of com.enonic.xp.page.PageDescriptorService in project xp by enonic.

the class UpdateContentCommand method doExecute.

private Content doExecute() {
    final Content contentBeforeChange = getContent(params.getContentId());
    Content editedContent = editContent(params.getEditor(), contentBeforeChange);
    if (params.stopInherit()) {
        if (editedContent.getInherit().contains(ContentInheritType.CONTENT)) {
            nodeService.commit(NodeCommitEntry.create().message("Base inherited version").build(), NodeIds.from(params.getContentId().toString()));
            editedContent.getInherit().remove(ContentInheritType.CONTENT);
        }
        editedContent.getInherit().remove(ContentInheritType.NAME);
    }
    final BinaryReferences removeAttachments = Objects.requireNonNullElseGet(params.getRemoveAttachments(), BinaryReferences::empty);
    if (contentBeforeChange.equals(editedContent) && params.getCreateAttachments() == null && removeAttachments.isEmpty() && !this.params.isClearAttachments()) {
        return contentBeforeChange;
    }
    editedContent = processContent(contentBeforeChange, editedContent);
    validateBlockingChecks(editedContent);
    final ValidationErrors.Builder validationErrorsBuilder = ValidationErrors.create();
    if (!params.isClearAttachments() && contentBeforeChange.getValidationErrors() != null) {
        contentBeforeChange.getValidationErrors().stream().filter(validationError -> validationError instanceof AttachmentValidationError).map(validationError -> (AttachmentValidationError) validationError).filter(validationError -> !removeAttachments.contains(validationError.getAttachment())).forEach(validationErrorsBuilder::add);
    }
    final ValidationErrors validationErrors = ValidateContentDataCommand.create().contentId(editedContent.getId()).data(editedContent.getData()).extraDatas(editedContent.getAllExtraData()).contentTypeName(editedContent.getType()).contentName(editedContent.getName()).displayName(editedContent.getDisplayName()).createAttachments(params.getCreateAttachments()).contentValidators(this.contentValidators).contentTypeService(this.contentTypeService).validationErrorsBuilder(validationErrorsBuilder).build().execute();
    if (params.isRequireValid()) {
        validationErrors.stream().findFirst().ifPresent(validationError -> {
            throw new ContentDataValidationException(validationError.getMessage());
        });
    }
    editedContent = Content.create(editedContent).valid(!validationErrors.hasErrors()).validationErrors(validationErrors).build();
    editedContent = attachThumbnail(editedContent);
    editedContent = setModifiedTime(editedContent);
    final UpdateContentTranslatorParams updateContentTranslatorParams = UpdateContentTranslatorParams.create().editedContent(editedContent).createAttachments(this.params.getCreateAttachments()).removeAttachments(this.params.getRemoveAttachments()).clearAttachments(this.params.isClearAttachments()).modifier(getCurrentUser().getKey()).build();
    final UpdateNodeParams updateNodeParams = UpdateNodeParamsFactory.create(updateContentTranslatorParams).contentTypeService(this.contentTypeService).xDataService(this.xDataService).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
    final Node editedNode = this.nodeService.update(updateNodeParams);
    return translator.fromNode(editedNode, true);
}
Also used : ContentDataValidationException(com.enonic.xp.content.ContentDataValidationException) BinaryReferences(com.enonic.xp.util.BinaryReferences) MediaInfo(com.enonic.xp.media.MediaInfo) Node(com.enonic.xp.node.Node) LoggerFactory(org.slf4j.LoggerFactory) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ValidationErrors(com.enonic.xp.content.ValidationErrors) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ContentEditor(com.enonic.xp.content.ContentEditor) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Thumbnail(com.enonic.xp.icon.Thumbnail) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) Media(com.enonic.xp.content.Media) Logger(org.slf4j.Logger) ContentAccessException(com.enonic.xp.content.ContentAccessException) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) ContentProcessor(com.enonic.xp.content.processor.ContentProcessor) InputTypes(com.enonic.xp.inputtype.InputTypes) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) Instant(java.time.Instant) ContentType(com.enonic.xp.schema.content.ContentType) AttachmentValidationError(com.enonic.xp.content.AttachmentValidationError) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Objects(java.util.Objects) EditableContent(com.enonic.xp.content.EditableContent) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) Site(com.enonic.xp.site.Site) InputValidator(com.enonic.xp.core.impl.content.validate.InputValidator) EditableSite(com.enonic.xp.content.EditableSite) NodeAccessException(com.enonic.xp.node.NodeAccessException) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) Preconditions(com.google.common.base.Preconditions) UpdateContentTranslatorParams(com.enonic.xp.content.UpdateContentTranslatorParams) NodeIds(com.enonic.xp.node.NodeIds) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) UpdateContentTranslatorParams(com.enonic.xp.content.UpdateContentTranslatorParams) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) ContentDataValidationException(com.enonic.xp.content.ContentDataValidationException) BinaryReferences(com.enonic.xp.util.BinaryReferences) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Node(com.enonic.xp.node.Node) AttachmentValidationError(com.enonic.xp.content.AttachmentValidationError)

Example 8 with PageDescriptorService

use of com.enonic.xp.page.PageDescriptorService in project xp by enonic.

the class UpdateNodeParamsFactory method toNodeEditor.

private NodeEditor toNodeEditor(final UpdateContentTranslatorParams params) {
    final Content content = params.getEditedContent();
    final PropertyTree nodeData = contentDataSerializer.toUpdateNodeData(params);
    final ContentIndexConfigFactory indexConfigFactory = ContentIndexConfigFactory.create().contentTypeService(contentTypeService).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).layoutDescriptorService(layoutDescriptorService).siteService(this.siteService).xDataService(this.xDataService).contentTypeName(content.getType()).page(content.getPage()).siteConfigs(content.isSite() ? ((Site) content).getSiteConfigs() : null).extraDatas(content.getAllExtraData()).language(content.getLanguage() != null ? content.getLanguage().getLanguage() : null).build();
    return editableNode -> {
        editableNode.indexConfigDocument = indexConfigFactory.produce();
        editableNode.data = nodeData;
        editableNode.manualOrderValue = content.getManualOrderValue();
        editableNode.permissions = content.getPermissions();
        editableNode.inheritPermissions = content.inheritsPermissions();
    };
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) SiteService(com.enonic.xp.site.SiteService) Content(com.enonic.xp.content.Content) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) Site(com.enonic.xp.site.Site) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) Preconditions(com.google.common.base.Preconditions) ContentIndexConfigFactory(com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory) UpdateContentTranslatorParams(com.enonic.xp.content.UpdateContentTranslatorParams) NodeEditor(com.enonic.xp.node.NodeEditor) XDataService(com.enonic.xp.schema.xdata.XDataService) PropertyTree(com.enonic.xp.data.PropertyTree) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIndexConfigFactory(com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)

Example 9 with PageDescriptorService

use of com.enonic.xp.page.PageDescriptorService in project xp by enonic.

the class HtmlAreaContentProcessorTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.siteService = Mockito.mock(SiteService.class);
    this.xDataService = Mockito.mock(XDataService.class);
    this.contentTypeService = Mockito.mock(ContentTypeService.class);
    this.pageDescriptorService = Mockito.mock(PageDescriptorService.class);
    this.partDescriptorService = Mockito.mock(PartDescriptorService.class);
    this.layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
    contentTypeName = ContentTypeName.from("myContentType");
    final GetContentTypeParams params = GetContentTypeParams.from(contentTypeName);
    contentType = ContentType.create().name(contentTypeName).superType(ContentTypeName.folder()).form(Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build()).build();
    final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(contentType).build();
    Mockito.when(contentTypeService.getByName(params)).thenReturn(contentType);
    Mockito.when(xDataService.getByNames(Mockito.isA(XDataNames.class))).thenReturn(XDatas.empty());
    htmlAreaContentProcessor = new HtmlAreaContentProcessor();
    htmlAreaContentProcessor.setContentTypeService(contentTypeService);
    htmlAreaContentProcessor.setSiteService(siteService);
    htmlAreaContentProcessor.setXDataService(xDataService);
    htmlAreaContentProcessor.setPageDescriptorService(pageDescriptorService);
    htmlAreaContentProcessor.setPartDescriptorService(partDescriptorService);
    htmlAreaContentProcessor.setLayoutDescriptorService(layoutDescriptorService);
    result = htmlAreaContentProcessor.processUpdate(processUpdateParams);
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) SiteService(com.enonic.xp.site.SiteService) XDataNames(com.enonic.xp.schema.xdata.XDataNames) XDataService(com.enonic.xp.schema.xdata.XDataService) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

PageDescriptorService (com.enonic.xp.page.PageDescriptorService)9 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)9 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)9 XDataService (com.enonic.xp.schema.xdata.XDataService)5 Content (com.enonic.xp.content.Content)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ContentDataSerializer (com.enonic.xp.core.impl.content.serializer.ContentDataSerializer)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 ContentType (com.enonic.xp.schema.content.ContentType)3 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)3 ContentTypeService (com.enonic.xp.schema.content.ContentTypeService)3 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)3 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2 AuditLogService (com.enonic.xp.audit.AuditLogService)2 ContentConstants (com.enonic.xp.content.ContentConstants)2 ContentInheritType (com.enonic.xp.content.ContentInheritType)2 ContentPath (com.enonic.xp.content.ContentPath)2 ContentPublishInfo (com.enonic.xp.content.ContentPublishInfo)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2