Search in sources :

Example 1 with SiteConfigs

use of com.enonic.xp.site.SiteConfigs 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 SiteConfigs

use of com.enonic.xp.site.SiteConfigs in project xp by enonic.

the class SiteConfigProcessorTest method test_site_config_with_html_area.

@Test
public void test_site_config_with_html_area() throws Exception {
    final Form form = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
    final SiteConfigs siteConfigs = SiteConfigs.create().add(SiteConfig.create().application(applicationKey1).config(new PropertyTree()).build()).build();
    final PatternIndexConfigDocument result = processConfigs(siteConfigs, form);
    assertEquals(1, result.getPathIndexConfigs().size());
    assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text1")).getIndexValueProcessors().get(0).getName());
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) SiteConfigs(com.enonic.xp.site.SiteConfigs) Test(org.junit.jupiter.api.Test)

Example 3 with SiteConfigs

use of com.enonic.xp.site.SiteConfigs in project xp by enonic.

the class SiteConfigProcessorTest method test_multiple_site_configs_with_same_path.

@Test
public void test_multiple_site_configs_with_same_path() throws Exception {
    final Form form1 = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
    final Form form2 = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
    final SiteConfigs siteConfigs = SiteConfigs.create().add(SiteConfig.create().application(applicationKey1).config(new PropertyTree()).build()).add(SiteConfig.create().application(applicationKey2).config(new PropertyTree()).build()).build();
    final PatternIndexConfigDocument result = processConfigs(siteConfigs, form1, form2);
    assertEquals(1, result.getPathIndexConfigs().size());
    assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text1")).getIndexValueProcessors().get(0).getName());
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) SiteConfigs(com.enonic.xp.site.SiteConfigs) Test(org.junit.jupiter.api.Test)

Example 4 with SiteConfigs

use of com.enonic.xp.site.SiteConfigs in project xp by enonic.

the class SiteConfigProcessorTest method test_multiple_site_configs_with_html_areas.

@Test
public void test_multiple_site_configs_with_html_areas() throws Exception {
    final Form form1 = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
    final Form form2 = Form.create().addFormItem(Input.create().name("text2").label("text2").inputType(InputTypeName.HTML_AREA).build()).build();
    final SiteConfigs siteConfigs = SiteConfigs.create().add(SiteConfig.create().application(applicationKey1).config(new PropertyTree()).build()).add(SiteConfig.create().application(applicationKey2).config(new PropertyTree()).build()).build();
    final PatternIndexConfigDocument result = processConfigs(siteConfigs, form1, form2);
    assertEquals(2, result.getPathIndexConfigs().size());
    assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text1")).getIndexValueProcessors().get(0).getName());
    assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text2")).getIndexValueProcessors().get(0).getName());
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) SiteConfigs(com.enonic.xp.site.SiteConfigs) Test(org.junit.jupiter.api.Test)

Example 5 with SiteConfigs

use of com.enonic.xp.site.SiteConfigs in project xp by enonic.

the class ProjectAccessSiteProcessor method processUpdate.

@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
    final Site editedSite = (Site) params.getEditedContent();
    final SiteConfigs editedSiteConfigs = editedSite.getSiteConfigs();
    final Site originalSite = (Site) params.getOriginalContent();
    final SiteConfigs originalSiteConfigs = originalSite.getSiteConfigs();
    final Context context = ContextAccessor.current();
    final AuthenticationInfo authenticationInfo = context.getAuthInfo();
    final ProjectName projectName = ProjectName.from(context.getRepositoryId());
    if (!Objects.equals(originalSiteConfigs, editedSiteConfigs)) {
        if (!ProjectAccessHelper.hasAdminAccess(authenticationInfo)) {
            if (ProjectConstants.DEFAULT_PROJECT_NAME.equals(projectName)) {
                throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey());
            } else if (!this.projectPermissionsContextManager.hasAnyProjectRole(authenticationInfo, projectName, Set.of(ProjectRole.OWNER))) {
                throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey(), ProjectRole.OWNER);
            }
        }
    }
    return null;
}
Also used : Site(com.enonic.xp.site.Site) Context(com.enonic.xp.context.Context) ProjectName(com.enonic.xp.project.ProjectName) SiteConfigs(com.enonic.xp.site.SiteConfigs) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Aggregations

SiteConfigs (com.enonic.xp.site.SiteConfigs)6 PropertyTree (com.enonic.xp.data.PropertyTree)4 Form (com.enonic.xp.form.Form)3 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)3 Test (org.junit.jupiter.api.Test)3 SiteConfigsDataSerializer (com.enonic.xp.site.SiteConfigsDataSerializer)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 Context (com.enonic.xp.context.Context)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 ProjectName (com.enonic.xp.project.ProjectName)1 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)1 Site (com.enonic.xp.site.Site)1 SiteConfig (com.enonic.xp.site.SiteConfig)1 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)1