Skip to content

Commit

Permalink
XData mixins must be filtered #802
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Mar 19, 2024
1 parent 484643e commit 24ecdc7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ private void createComponentType()

private void createComponentDataConfigType( String componentType )
{
String componentDataConfigTypeName = componentType + "ComponentDataConfig";
String componentDataConfigTypeName = context.uniqueName( componentType + "ComponentDataConfig" );

List<GraphQLFieldDefinition> componentFields = new ArrayList<>();

context.getApplications().forEach( applicationKey -> {
String componentApplicationConfigTypeName =
componentType + "_" + StringNormalizer.create( applicationKey ) + "_ComponentDataApplicationConfig";
String componentApplicationConfigTypeName =
context.uniqueName( componentType + "_" + StringNormalizer.create( applicationKey ) + "_ComponentDataApplicationConfig" );

List<ComponentDescriptor> descriptors =
serviceFacade.getComponentDescriptorService().getComponentDescriptors( componentType, applicationKey );
Expand All @@ -210,18 +210,18 @@ private void createComponentDataConfigType( String componentType )
descriptors.forEach( descriptor -> {
String descriptorName = StringNormalizer.create( descriptor.getName() );

String componentApplicationDescriptorTypeName =
componentType + "_" + StringNormalizer.create( applicationKey ) + "_" + descriptorName;
String componentApplicationDescriptorTypeName =
context.uniqueName( componentType + "_" + StringNormalizer.create( applicationKey ) + "_" + descriptorName );

List<GraphQLFieldDefinition> descriptorConfigTypeFields =
createFormItemFields( descriptor.getConfig().getFormItems(), componentApplicationDescriptorTypeName );

if ( !descriptorConfigTypeFields.isEmpty() )
{
GraphQLObjectType descriptorConfigType = newObject( context.uniqueName( componentApplicationDescriptorTypeName ),
componentType + " component application config for application ['" +
applicationKey + "'] and descriptor ['" + descriptor.getName() +
"']", descriptorConfigTypeFields );
GraphQLObjectType descriptorConfigType = newObject( componentApplicationDescriptorTypeName,
componentType + " component application config for application ['" +
applicationKey + "'] and descriptor ['" + descriptor.getName() +
"']", descriptorConfigTypeFields );

context.registerType( descriptorConfigType.getName(), descriptorConfigType );

Expand All @@ -237,10 +237,9 @@ private void createComponentDataConfigType( String componentType )

if ( !componentApplicationTypeFields.isEmpty() )
{
GraphQLObjectType componentApplicationConfigType = newObject( context.uniqueName( componentApplicationConfigTypeName ),
componentType +
" component application config for application ['" +
applicationKey + "']", componentApplicationTypeFields );
String description = componentType + " component application config for application ['" + applicationKey + "']";
GraphQLObjectType componentApplicationConfigType =
newObject( componentApplicationConfigTypeName, description, componentApplicationTypeFields );

GraphQLFieldDefinition componentTypeField =
outputField( StringNormalizer.create( applicationKey ), componentApplicationConfigType );
Expand All @@ -253,8 +252,8 @@ private void createComponentDataConfigType( String componentType )

if ( !componentFields.isEmpty() )
{
GraphQLObjectType componentDataType =
newObject( context.uniqueName( componentDataConfigTypeName ), componentType + " component config.", componentFields );
GraphQLObjectType componentDataType =
newObject( componentDataConfigTypeName, componentType + " component config.", componentFields );

context.registerType( componentDataType.getName(), componentDataType );
}
Expand All @@ -264,7 +263,7 @@ private List<GraphQLFieldDefinition> createFormItemFields( FormItems formItems,
{
List<GraphQLFieldDefinition> resultFields = new ArrayList<>();

FormItemTypesHelper.getFilteredFormItems( formItems ).forEach( formItem -> {
FormItemTypesHelper.getFilteredComponentFormItems( formItems ).forEach( formItem -> {
String fieldName = StringNormalizer.create( formItem.getName() );

GraphQLOutputType formItemObject = (GraphQLOutputType) formItemTypesFactory.generateFormItemObject( typeName, formItem );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.enonic.app.guillotine.graphql.helper.CastHelper;
import com.enonic.app.guillotine.graphql.helper.StringNormalizer;

import static com.enonic.app.guillotine.graphql.helper.FormItemTypesHelper.getFilteredFormItems;
import static com.enonic.app.guillotine.graphql.helper.FormItemTypesHelper.getFilteredComponentFormItems;
import static com.enonic.app.guillotine.graphql.helper.GraphQLHelper.newObject;
import static com.enonic.app.guillotine.graphql.helper.GraphQLHelper.outputField;

Expand Down Expand Up @@ -53,12 +53,12 @@ private void createMacroConfigType()
String macroTypeName =
"Macro_" + StringNormalizer.create( macroDescriptor.getKey().getApplicationKey().getName() ) + "_" + descriptorName;

String macroDataConfigTypeName = macroTypeName + "_DataConfig";
String macroDataConfigTypeName = context.uniqueName( macroTypeName + "_DataConfig" );

List<GraphQLFieldDefinition> macroDataConfigFields = new ArrayList<>();
macroDataConfigFields.add( outputField( "body", Scalars.GraphQLString ) );

getFilteredFormItems( macroDescriptor.getForm().getFormItems() ).forEach( formItem -> {
getFilteredComponentFormItems( macroDescriptor.getForm().getFormItems() ).forEach( formItem -> {
String fieldName = StringNormalizer.create( formItem.getName() );

GraphQLOutputType formItemObject =
Expand All @@ -73,10 +73,11 @@ private void createMacroConfigType()
macroDataConfigFields.add( field );
} );

GraphQLObjectType macroDataConfigType = newObject( context.uniqueName( macroDataConfigTypeName ),
"Macro descriptor data config for application ['" +
macroDescriptor.getKey().getApplicationKey() + "'] and descriptor ['" +
descriptorName + "']", macroDataConfigFields );
String description =
"Macro descriptor data config for application ['" + macroDescriptor.getKey().getApplicationKey() + "'] and descriptor ['" +
descriptorName + "']";

GraphQLObjectType macroDataConfigType = newObject( macroDataConfigTypeName, description, macroDataConfigFields );

context.registerType( macroDataConfigType.getName(), macroDataConfigType );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ public XDataTypesFactory( final GuillotineContext context, final ServiceFacade s

public void create()
{
String extraDataTypeName = "ExtraData";
String extraDataTypeName = context.uniqueName( "ExtraData" );

List<GraphQLFieldDefinition> xDataTypeFields = new ArrayList<>();

getApplicationsKeys().forEach( applicationKey -> {
String xDataApplicationConfigTypeName = "XData_" + StringNormalizer.create( applicationKey ) + "_ApplicationConfig";
String xDataApplicationConfigTypeName =
context.uniqueName( "XData_" + StringNormalizer.create( applicationKey ) + "_ApplicationConfig" );

XDatas extraData = serviceFacade.getComponentDescriptorService().getExtraData( applicationKey );

Expand All @@ -58,17 +59,17 @@ public void create()

String xDataTypeName = "XData_" + StringNormalizer.create( applicationKey ) + "_" + descriptorName;

String xDataConfigTypeName = xDataTypeName + "_DataConfig";
String xDataConfigTypeName = context.uniqueName( xDataTypeName + "_DataConfig" );

List<GraphQLFieldDefinition> xDataConfigFields =
createFormItemFields( xData.getForm().getFormItems(), xDataConfigTypeName );

if ( !xDataConfigFields.isEmpty() )
{
GraphQLObjectType xDataConfigType = newObject( context.uniqueName( xDataConfigTypeName ),
"Extra data config for application ['" + applicationKey +
"}'] and descriptor ['" + xData.getName().getLocalName() + "']",
xDataConfigFields );
GraphQLObjectType xDataConfigType = newObject( xDataConfigTypeName,
"Extra data config for application ['" + applicationKey +
"}'] and descriptor ['" + xData.getName().getLocalName() + "']",
xDataConfigFields );

context.registerType( xDataConfigType.getName(), xDataConfigType );

Expand All @@ -82,9 +83,9 @@ public void create()

if ( !xDataApplicationTypeFields.isEmpty() )
{
GraphQLObjectType applicationConfigType = newObject( context.uniqueName( xDataApplicationConfigTypeName ),
"XDataApplicationConfig for application ['" + applicationKey +
"']", xDataApplicationTypeFields );
GraphQLObjectType applicationConfigType =
newObject( xDataApplicationConfigTypeName, "XDataApplicationConfig for application ['" + applicationKey + "']",
xDataApplicationTypeFields );

GraphQLFieldDefinition xDataTypeField = outputField( StringNormalizer.create( applicationKey ), applicationConfigType );
xDataTypeFields.add( xDataTypeField );
Expand All @@ -97,7 +98,7 @@ public void create()

if ( !xDataTypeFields.isEmpty() )
{
GraphQLObjectType extraDataType = newObject( context.uniqueName( extraDataTypeName ), "Extra data.", xDataTypeFields );
GraphQLObjectType extraDataType = newObject( extraDataTypeName, "Extra data.", xDataTypeFields );

context.registerType( extraDataType.getName(), extraDataType );
}
Expand All @@ -107,7 +108,7 @@ private List<GraphQLFieldDefinition> createFormItemFields( FormItems formItems,
{
List<GraphQLFieldDefinition> xDataConfigFields = new ArrayList<>();

FormItemTypesHelper.getFilteredFormItems( formItems ).forEach( formItem -> {
FormItemTypesHelper.getFilteredComponentFormItems( formItems ).forEach( formItem -> {
String fieldName = StringNormalizer.create( formItem.getName() );

GraphQLOutputType formItemObject = (GraphQLOutputType) formItemTypesFactory.generateFormItemObject( typeName, formItem );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,42 @@
import com.enonic.xp.form.FormItemSet;
import com.enonic.xp.form.FormItems;
import com.enonic.xp.form.FormOptionSet;
import com.enonic.xp.form.InlineMixin;
import com.enonic.xp.form.Input;
import com.enonic.xp.form.Layout;
import com.enonic.xp.form.Occurrences;
import com.enonic.xp.inputtype.InputTypeName;

public class FormItemTypesHelper
{

public static List<FormItem> getFilteredComponentFormItems( FormItems formItems )
{
List<FormItem> result = new ArrayList<>();
for ( FormItem formItem : formItems )
{
if ( formItem instanceof FormItemSet && !( (FormItemSet) formItem ).getFormItems().iterator().hasNext() )
{
continue;
}
if ( formItem instanceof InlineMixin )
{
continue;
}
if ( formItem instanceof Layout )
{
result.addAll( getFilteredFormItems( ( (FieldSet) formItem ).getFormItems() ) );
continue;
}
if ( formItem instanceof Input && ( (Input) formItem ).getInputType().equals( InputTypeName.SITE_CONFIGURATOR ) )
{
continue;
}
result.add( formItem );
}
return result;
}

public static List<FormItem> getFilteredFormItems( FormItems formItems )
{
List<FormItem> result = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private void serializeExtraData( final MapGenerator gen, final Iterable<ExtraDat
for ( final ExtraData extraData : extraDatas )
{
gen.map( extraData.getName().getLocalName() );
gen.value( Constants.CONTENT_ID_FIELD, content.getId().toString() );
new PropertyTreeMapper( extraData.getData(), content.getId().toString() ).serialize( gen );
gen.end();
}
Expand Down

0 comments on commit 24ecdc7

Please sign in to comment.