use of com.enonic.xp.site.SiteConfigsDataSerializer 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.site.SiteConfigsDataSerializer in project xp by enonic.
the class ValidateContentDataCommandTest method testSiteConfigTextRegexpPasses.
@Test
public void testSiteConfigTextRegexpPasses() {
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.site()).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
PropertyTree rootDataSet = new PropertyTree();
PropertyTree siteConfigDataSet = new PropertyTree();
siteConfigDataSet.setString("textInput-1", "1234");
SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapp")).config(siteConfigDataSet).build();
new SiteConfigsDataSerializer().toProperties(SiteConfigs.from(siteConfig), rootDataSet.getRoot());
Mockito.when(siteService.getDescriptor(Mockito.isA(ApplicationKey.class))).thenReturn(createSiteDescriptor());
// exercise
final ValidationErrors result = executeValidation(rootDataSet, ContentTypeName.site());
assertFalse(result.hasErrors());
}
use of com.enonic.xp.site.SiteConfigsDataSerializer in project xp by enonic.
the class ValidateContentDataCommandTest method testSiteConfigTextRegexpFailure.
@Test
public void testSiteConfigTextRegexpFailure() {
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.site()).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
PropertyTree rootDataSet = new PropertyTree();
PropertyTree siteConfigDataSet = new PropertyTree();
siteConfigDataSet.setString("textInput-1", "test");
SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapp")).config(siteConfigDataSet).build();
new SiteConfigsDataSerializer().toProperties(SiteConfigs.from(siteConfig), rootDataSet.getRoot());
Mockito.when(siteService.getDescriptor(Mockito.isA(ApplicationKey.class))).thenReturn(createSiteDescriptor());
// exercise
final ValidationErrors result = executeValidation(rootDataSet, ContentTypeName.site());
assertThat(result.stream()).hasSize(1);
}
use of com.enonic.xp.site.SiteConfigsDataSerializer in project xp by enonic.
the class SiteConfigsValidator method validate.
@Override
public void validate(final ContentValidatorParams params, final ValidationErrors.Builder validationErrorsBuilder) {
final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(params.getData().getRoot()).build();
for (final SiteConfig siteConfig : siteConfigs) {
final ApplicationKey applicationKey = siteConfig.getApplicationKey();
final SiteDescriptor siteDescriptor = siteService.getDescriptor(applicationKey);
if (siteDescriptor != null) {
OccurrenceValidator.validate(siteDescriptor.getForm(), siteConfig.getConfig().getRoot(), validationErrorsBuilder);
try {
InputValidator.create().form(siteDescriptor.getForm()).inputTypeResolver(InputTypes.BUILTIN).build().validate(siteConfig.getConfig());
} catch (final Exception e) {
validationErrorsBuilder.add(ValidationError.generalError(ValidationErrorCode.from(ApplicationKey.SYSTEM, "cms.validation.siteConfigInvalid")).args(siteConfig.getApplicationKey()).build());
}
}
}
}
use of com.enonic.xp.site.SiteConfigsDataSerializer in project xp by enonic.
the class MacroInstructionTest method createSite.
private Site createSite(final String id, final String name, final String contentTypeName) {
PropertyTree rootDataSet = new PropertyTree();
SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapp")).config(new PropertyTree()).build();
new SiteConfigsDataSerializer().toProperties(SiteConfigs.from(siteConfig), rootDataSet.getRoot());
return Site.create().id(ContentId.from(id)).path(ContentPath.from(name)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName)).data(rootDataSet).build();
}
Aggregations