Search in sources :

Example 1 with SiteConfigsDataSerializer

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();
}
Also used : SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) Page(com.enonic.xp.page.Page) SiteConfigs(com.enonic.xp.site.SiteConfigs) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ExtraDatas(com.enonic.xp.content.ExtraDatas) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) ContentIndexConfigFactory(com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)

Example 2 with SiteConfigsDataSerializer

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());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ApplicationKey(com.enonic.xp.app.ApplicationKey) ContentType(com.enonic.xp.schema.content.ContentType) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) ValidationErrors(com.enonic.xp.content.ValidationErrors) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig) Test(org.junit.jupiter.api.Test)

Example 3 with SiteConfigsDataSerializer

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ApplicationKey(com.enonic.xp.app.ApplicationKey) ContentType(com.enonic.xp.schema.content.ContentType) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) ValidationErrors(com.enonic.xp.content.ValidationErrors) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig) Test(org.junit.jupiter.api.Test)

Example 4 with SiteConfigsDataSerializer

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());
            }
        }
    }
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) SiteConfig(com.enonic.xp.site.SiteConfig) SiteConfigs(com.enonic.xp.site.SiteConfigs)

Example 5 with SiteConfigsDataSerializer

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();
}
Also used : SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig)

Aggregations

SiteConfigsDataSerializer (com.enonic.xp.site.SiteConfigsDataSerializer)5 PropertyTree (com.enonic.xp.data.PropertyTree)4 SiteConfig (com.enonic.xp.site.SiteConfig)4 ApplicationKey (com.enonic.xp.app.ApplicationKey)3 ValidationErrors (com.enonic.xp.content.ValidationErrors)2 ContentType (com.enonic.xp.schema.content.ContentType)2 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)2 SiteConfigs (com.enonic.xp.site.SiteConfigs)2 Test (org.junit.jupiter.api.Test)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 ContentIndexConfigFactory (com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)1 PropertySet (com.enonic.xp.data.PropertySet)1 IndexConfigDocument (com.enonic.xp.index.IndexConfigDocument)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 Page (com.enonic.xp.page.Page)1 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)1