Search in sources :

Example 6 with PartDescriptorService

use of com.enonic.xp.region.PartDescriptorService 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 7 with PartDescriptorService

use of com.enonic.xp.region.PartDescriptorService 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 8 with PartDescriptorService

use of com.enonic.xp.region.PartDescriptorService 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)

Example 9 with PartDescriptorService

use of com.enonic.xp.region.PartDescriptorService in project xp by enonic.

the class PartRendererTest method htmlResponseComponentEditModeNoMethodToHandleReq.

@Test
public void htmlResponseComponentEditModeNoMethodToHandleReq() {
    final PartDescriptor partDescriptor = PartDescriptor.create().displayName("My part component").config(Form.create().build()).key(DescriptorKey.from("module:myPartComponent")).build();
    final ControllerScript controllerScript = new ControllerScript() {

        @Override
        public PortalResponse execute(final PortalRequest portalRequest) {
            return new PortalResponseSerializer(null, HttpStatus.METHOD_NOT_ALLOWED).serialize();
        }

        @Override
        public void onSocketEvent(final WebSocketEvent event) {
        }
    };
    final PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    renderer = new PartRenderer();
    renderer.setPartDescriptorService(partDescriptorService);
    renderer.setControllerScriptFactory(controllerScriptFactory);
    when(partDescriptorService.getByKey(any())).thenReturn(partDescriptor);
    when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
    portalRequest.setMode(RenderMode.EDIT);
    partComponent = PartComponent.create().descriptor("myapp:myPartComponent").descriptor(partDescriptor.getKey()).build();
    // exercise
    portalResponse = renderer.render(partComponent, portalRequest);
    // verify
    String expected = "<div data-portal-component-type=\"part\" data-portal-placeholder=\"true\" data-portal-placeholder-error=\"true\"><span class=\"data-portal-placeholder-error\">No method provided to handle request</span></div>";
    assertEquals(expected, portalResponse.getAsString());
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) WebSocketEvent(com.enonic.xp.web.websocket.WebSocketEvent) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) PartDescriptor(com.enonic.xp.region.PartDescriptor) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 10 with PartDescriptorService

use of com.enonic.xp.region.PartDescriptorService in project xp by enonic.

the class PartRendererTest method nullResponseComponentEditMode.

@Test
public void nullResponseComponentEditMode() {
    final PartDescriptor partDescriptor = PartDescriptor.create().displayName("My part component").config(Form.create().build()).key(DescriptorKey.from("module:myPartComponent")).build();
    final ControllerScript controllerScript = new ControllerScript() {

        @Override
        public PortalResponse execute(final PortalRequest portalRequest) {
            return new PortalResponseSerializer(null).serialize();
        }

        @Override
        public void onSocketEvent(final WebSocketEvent event) {
        }
    };
    final PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    renderer = new PartRenderer();
    renderer.setPartDescriptorService(partDescriptorService);
    renderer.setControllerScriptFactory(controllerScriptFactory);
    when(partDescriptorService.getByKey(any())).thenReturn(partDescriptor);
    when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
    portalRequest.setMode(RenderMode.EDIT);
    partComponent = PartComponent.create().descriptor("myapp:myPartComponent").descriptor(partDescriptor.getKey()).build();
    // exercise
    portalResponse = renderer.render(partComponent, portalRequest);
    // verify
    String expected = "<div data-portal-component-type=\"part\"></div>";
    assertEquals(expected, portalResponse.getAsString());
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) WebSocketEvent(com.enonic.xp.web.websocket.WebSocketEvent) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) PartDescriptor(com.enonic.xp.region.PartDescriptor) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Aggregations

PartDescriptorService (com.enonic.xp.region.PartDescriptorService)12 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)9 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)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 PortalRequest (com.enonic.xp.portal.PortalRequest)3 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)3 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)3 PartDescriptor (com.enonic.xp.region.PartDescriptor)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 WebSocketEvent (com.enonic.xp.web.websocket.WebSocketEvent)3 Test (org.junit.jupiter.api.Test)3 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)2