use of com.enonic.xp.core.impl.content.serializer.ContentDataSerializer in project xp by enonic.
the class ContentOutboundDependenciesIdsResolverTest method setUp.
@BeforeEach
public void setUp() throws Exception {
this.contentService = Mockito.mock(ContentService.class);
this.contentDataSerializer = Mockito.mock(ContentDataSerializer.class);
this.resolver = new ContentOutboundDependenciesIdsResolver(contentService, contentDataSerializer);
}
use of com.enonic.xp.core.impl.content.serializer.ContentDataSerializer in project xp by enonic.
the class ContentNodeTranslatorTest method setUp.
@BeforeEach
public void setUp() throws Exception {
this.nodeService = Mockito.mock(NodeService.class);
final PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
final LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
final PageDescriptorService pageDescriptorService = Mockito.mock(PageDescriptorService.class);
final ContentDataSerializer contentDataSerializer = ContentDataSerializer.create().layoutDescriptorService(layoutDescriptorService).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).build();
this.contentNodeTranslator = new ContentNodeTranslator(nodeService, contentDataSerializer);
}
use of com.enonic.xp.core.impl.content.serializer.ContentDataSerializer 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);
}
Aggregations