use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class ContentDataProcessor method process.
public PropertyTree process(final PropertyTree originalData) {
final PropertyTree data = originalData.copy();
if (data.hasProperty(ContentPropertyNames.INHERIT)) {
boolean changed = false;
final ImmutableSet.Builder<String> inheritSet = ImmutableSet.builder();
for (final String value : data.getStrings(ContentPropertyNames.INHERIT)) {
if (!getTypesToProceed().contains(ContentInheritType.valueOf(value))) {
inheritSet.add(value);
} else {
changed = true;
}
}
if (changed) {
data.removeProperties(ContentPropertyNames.INHERIT);
data.addStrings(ContentPropertyNames.INHERIT, inheritSet.build());
}
}
return data;
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class ContentOutboundDependenciesIdsResolver method resolveOutboundDependenciesIds.
private ContentIds resolveOutboundDependenciesIds(final ContentId contentId) {
final Content content = this.contentService.getById(contentId);
final ContentIds.Builder contentIds = ContentIds.create();
final PropertySet contentPageData = new PropertyTree().getRoot();
if (content.getPage() != null) {
contentDataSerializer.toPageData(content.getPage(), contentPageData);
}
final Stream<Property> extraDataDependencies = content.hasExtraData() ? content.getAllExtraData().stream().flatMap(extraData -> extraData.getData().getProperties(ValueTypes.REFERENCE).stream()) : Stream.empty();
Stream.of(content.getData().getProperties(ValueTypes.REFERENCE).stream(), contentPageData.getProperties(ValueTypes.REFERENCE).stream(), extraDataDependencies).flatMap(s -> s).forEach(property -> {
final String value = property.getValue().toString();
if (!contentId.toString().equals(value) && !nullToEmpty(value).isBlank()) {
contentIds.add(ContentId.from(value));
}
});
if (content.getProcessedReferences() != null && content.getProcessedReferences().getSize() > 0) {
contentIds.addAll(content.getProcessedReferences());
}
return contentIds.build();
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class ContentServiceImpl method create.
@Override
public Content create(final CreateContentParams params) {
final Content content = CreateContentCommand.create().nodeService(this.nodeService).contentTypeService(this.contentTypeService).translator(this.translator).eventPublisher(this.eventPublisher).siteService(this.siteService).xDataService(this.xDataService).contentProcessors(this.contentProcessors).contentValidators(this.contentValidators).formDefaultValuesProcessor(this.formDefaultValuesProcessor).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).allowUnsafeAttachmentNames(config.attachments_allowUnsafeNames()).params(params).build().execute();
if (content instanceof Site) {
this.create(CreateContentParams.create().owner(content.getOwner()).displayName(TEMPLATES_FOLDER_DISPLAY_NAME).name(TEMPLATES_FOLDER_NAME).inheritPermissions(true).parent(content.getPath()).type(ContentTypeName.templateFolder()).requireValid(true).contentData(new PropertyTree()).build());
return this.doGetById(content.getId());
}
contentAuditLogSupport.createContent(params, content);
return content;
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class CreateNodeParamsFactory method produce.
public CreateNodeParams produce() {
final PropertyTree contentAsData = contentDataSerializer.toCreateNodeData(params);
final PropertySet extraDataSet = contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.EXTRA_DATA));
final String language = contentAsData.getString(PropertyPath.from(ContentPropertyNames.LANGUAGE));
final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.DATA))).build();
final Page page = contentAsData.hasProperty(COMPONENTS) ? contentDataSerializer.fromPageData(contentAsData.getRoot()) : null;
final ExtraDatas extraData = extraDataSet != null ? contentDataSerializer.fromExtraData(extraDataSet) : null;
final ContentIndexConfigFactory.Builder indexConfigFactoryBuilder = ContentIndexConfigFactory.create().contentTypeName(params.getType()).siteConfigs(siteConfigs).siteService(siteService).xDataService(xDataService).contentTypeService(contentTypeService);
if (page != null) {
indexConfigFactoryBuilder.page(page).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).layoutDescriptorService(layoutDescriptorService);
}
if (extraData != null) {
indexConfigFactoryBuilder.extraDatas(extraData);
}
if (!nullToEmpty(language).isBlank()) {
indexConfigFactoryBuilder.language(language);
}
final IndexConfigDocument indexConfigDocument = indexConfigFactoryBuilder.build().produce();
final CreateNodeParams.Builder builder = CreateNodeParams.create().name(resolveNodeName(params.getName())).parent(ContentNodeHelper.translateContentParentToNodeParentPath(params.getParent())).data(contentAsData).indexConfigDocument(indexConfigDocument).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).childOrder(params.getChildOrder()).nodeType(ContentConstants.CONTENT_NODE_COLLECTION);
for (final CreateAttachment attachment : params.getCreateAttachments()) {
builder.attachBinary(attachment.getBinaryReference(), attachment.getByteSource());
}
return builder.build();
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class CreateMediaCommand method doExecute.
private Content doExecute() {
final MediaInfo mediaInfo = mediaInfoService.parseMediaInfo(params.getByteSource());
if ((params.getMimeType() == null || isBinaryContentType(params.getMimeType())) && mediaInfo.getMediaType() != null) {
params.mimeType(mediaInfo.getMediaType());
}
Preconditions.checkNotNull(params.getMimeType(), "Unable to resolve media type");
final ContentTypeName resolvedTypeFromMimeType = ContentTypeFromMimeTypeResolver.resolve(params.getMimeType());
final ContentTypeName type = resolvedTypeFromMimeType != null ? resolvedTypeFromMimeType : isExecutableContentType(params.getMimeType(), params.getName()) ? ContentTypeName.executableMedia() : ContentTypeName.unknownMedia();
final PropertyTree data = new PropertyTree();
new MediaFormDataBuilder().type(type).attachment(params.getName()).focalX(params.getFocalX()).focalY(params.getFocalY()).caption(params.getCaption()).artist(params.getArtist()).copyright(params.getCopyright()).tags(params.getTags()).build(data);
final CreateAttachment mediaAttachment = CreateAttachment.create().name(params.getName()).mimeType(params.getMimeType()).label("source").byteSource(params.getByteSource()).text(type.isTextualMedia() ? mediaInfo.getTextContent() : "").build();
final CreateContentParams createContentParams = CreateContentParams.create().name(params.getName()).parent(params.getParent()).requireValid(true).type(type).displayName(trimExtension(params.getName())).contentData(data).createAttachments(CreateAttachments.from(mediaAttachment)).inheritPermissions(true).build();
final CreateContentCommand createCommand = CreateContentCommand.create(this).mediaInfo(mediaInfo).params(createContentParams).siteService(this.siteService).xDataService(this.xDataService).formDefaultValuesProcessor(this.formDefaultValuesProcessor).pageDescriptorService(this.pageDescriptorService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).allowUnsafeAttachmentNames(this.allowUnsafeAttachmentNames).build();
return createCommand.execute();
}
Aggregations