use of com.enonic.xp.region.LayoutDescriptorService in project xp by enonic.
the class RenameContentCommandTest method setUp.
@BeforeEach
void setUp() {
this.contentTypeService = mock(ContentTypeService.class);
this.contentService = mock(ContentService.class);
this.nodeService = mock(NodeService.class);
this.eventPublisher = mock(EventPublisher.class);
this.translator = mock(ContentNodeTranslator.class);
this.xDataService = mock(XDataService.class);
this.pageDescriptorService = mock(PageDescriptorService.class);
this.partDescriptorService = mock(PartDescriptorService.class);
this.layoutDescriptorService = mock(LayoutDescriptorService.class);
this.contentDataSerializer = ContentDataSerializer.create().layoutDescriptorService(layoutDescriptorService).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).build();
final ContentType contentType = ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build();
when(contentTypeService.getByName(isA(GetContentTypeParams.class))).thenReturn(contentType);
mockNode = Node.create().id(NodeId.from("testId")).build();
when(nodeService.rename(isA(RenameNodeParams.class))).thenReturn(mockNode);
when(nodeService.getById(mockNode.id())).thenReturn(mockNode);
}
use of com.enonic.xp.region.LayoutDescriptorService 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);
}
use of com.enonic.xp.region.LayoutDescriptorService 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();
};
}
use of com.enonic.xp.region.LayoutDescriptorService 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);
}
use of com.enonic.xp.region.LayoutDescriptorService in project xp by enonic.
the class LayoutRendererTest method htmlResponseComponentEditMode.
@Test
public void htmlResponseComponentEditMode() {
final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().displayName("My layout component").config(Form.create().build()).key(DescriptorKey.from("module:myLayoutComponent")).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("left").build()).add(RegionDescriptor.create().name("right").build()).build()).build();
final ControllerScript controllerScript = new ControllerScript() {
@Override
public PortalResponse execute(final PortalRequest portalRequest) {
return PortalResponse.create().body("<div class=\"row\"><div data-portal-region=\"left\" class=\"col-left\"></div><div data-portal-region=\"right\" class=\"col-right\"></div></div>").contentType(MediaType.HTML_UTF_8).status(HttpStatus.OK).build();
}
@Override
public void onSocketEvent(final WebSocketEvent event) {
}
};
final LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
renderer = new LayoutRenderer();
renderer.setLayoutDescriptorService(layoutDescriptorService);
renderer.setControllerScriptFactory(controllerScriptFactory);
when(layoutDescriptorService.getByKey(any())).thenReturn(layoutDescriptor);
when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
portalRequest.setMode(RenderMode.EDIT);
layoutComponent = LayoutComponent.create().descriptor("myapp:myLayoutComponent").descriptor(layoutDescriptor.getKey()).build();
// exercise
portalResponse = renderer.render(layoutComponent, portalRequest);
// verify
String expected = "<div data-portal-component-type=\"layout\" class=\"row\"><div data-portal-region=\"left\" class=\"col-left\"></div><div data-portal-region=\"right\" class=\"col-right\"></div></div>";
assertEquals(expected, portalResponse.getAsString());
}
Aggregations