Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated source code #557 #596

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import graphql.schema.TypeResolver;

import com.enonic.xp.macro.MacroDescriptor;
import com.enonic.xp.portal.PortalRequest;
import com.enonic.xp.portal.PortalRequestAccessor;

public class GuillotineContext
{
Expand All @@ -40,38 +38,17 @@ public class GuillotineContext

private final ImmutableMap<String, MacroDescriptor> macroDecorators;

private final CopyOnWriteArrayList<String> allowPaths;

private GuillotineContext( final Builder builder )
{
this.applications = builder.applications;
this.allowPaths = builder.allowPaths;
this.macroDecorators = ImmutableMap.<String, MacroDescriptor>builder().putAll( builder.macroDecorators ).build();
}

public boolean isGlobalMode()
{
if ( options.containsKey( "__globalModeOn" ) )
{
return options.get( "__globalModeOn" ) == null || (boolean) options.get( "__globalModeOn" );
}

PortalRequest portalRequest = PortalRequestAccessor.get();
boolean globalModeOn = portalRequest.getSite() == null;
options.put( "__globalModeOn", globalModeOn );
return globalModeOn;
}

public List<String> getApplications()
{
return applications;
}

public List<String> getAllowPaths()
{
return allowPaths;
}

public Map<String, MacroDescriptor> getMacroDecorators()
{
return macroDecorators;
Expand Down Expand Up @@ -160,8 +137,6 @@ public static final class Builder

private final CopyOnWriteArrayList<String> applications = new CopyOnWriteArrayList<>();

private final CopyOnWriteArrayList<String> allowPaths = new CopyOnWriteArrayList<>();

private final Map<String, MacroDescriptor> macroDecorators = new HashMap<>();

public Builder()
Expand All @@ -178,15 +153,6 @@ public Builder addApplications( final List<String> applications )
return this;
}

public Builder addAllowPaths( final List<String> allowPaths )
{
if ( allowPaths != null )
{
this.allowPaths.addAll( allowPaths );
}
return this;
}

public Builder addMacroDecorators( final Map<String, MacroDescriptor> macroDecorators )
{
if ( macroDecorators != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public void create()
context.registerType( contentInterface.getName(), contentInterface );

new ConnectionTypeFactory( context ).createConnectionType( contentInterface.getName() );
createQueryContentConnectionType();
createQueryDslContentConnectionType();

GraphQLObjectType untypedContent = newObject( context.uniqueName( "UntypedContent" ), "UntypedContent", List.of( contentInterface ),
Expand All @@ -86,17 +85,6 @@ public void create()
contentTypes.forEach( contentType -> createContentObjectType( contentType, contentInterface ) );
}

private void createQueryContentConnectionType()
{
GraphQLObjectType edgeType = context.getOutputType( "ContentEdge" );

List<GraphQLFieldDefinition> fields = List.of( outputField( "aggregationsAsJson", ExtendedScalars.Json ) );

GraphQLObjectType outputObject = new ConnectionTypeFactory( context ).createConnectionType( "QueryContent", edgeType, fields );

context.registerType( outputObject.getName(), outputObject );
}

private void createQueryDslContentConnectionType()
{
GraphQLObjectType edgeType = context.getOutputType( "ContentEdge" );
Expand Down Expand Up @@ -270,7 +258,7 @@ private List<GraphQLFieldDefinition> getGenericContentFields( String contentType
newArgument( "sort", Scalars.GraphQLString ) ) ) );
result.add( outputField( "permissions", GraphQLTypeReference.typeRef( "Permissions" ) ) );

context.registerDataFetcher( contentType, "_path", new GetContentPathDataFetcher( context, serviceFacade.getContentService() ) );
context.registerDataFetcher( contentType, "_path", new GetContentPathDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( contentType, "contentType",
new ContentTypeDataFetcher( serviceFacade.getMixinService(), serviceFacade.getContentTypeService() ) );
Expand All @@ -283,7 +271,7 @@ private List<GraphQLFieldDefinition> getGenericContentFields( String contentType

context.registerDataFetcher( contentType, "attachments", new GetAttachmentsDataFetcher() );

context.registerDataFetcher( contentType, "parent", new GetContentParentDataFetcher( serviceFacade.getContentService(), context ) );
context.registerDataFetcher( contentType, "parent", new GetContentParentDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( contentType, "owner", new GetContentFieldDataFetcher( "owner" ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.enonic.app.guillotine.graphql.fetchers.GetSiteDataFetcher;
import com.enonic.app.guillotine.graphql.fetchers.GetTypeDataFetcher;
import com.enonic.app.guillotine.graphql.fetchers.GetTypesDataFetcher;
import com.enonic.app.guillotine.graphql.fetchers.QueryConnectionDataFetcher;
import com.enonic.app.guillotine.graphql.fetchers.QueryDataFetcher;
import com.enonic.app.guillotine.graphql.fetchers.QueryDslConnectionDataFetcher;
import com.enonic.app.guillotine.graphql.fetchers.QueryDslDataFetcher;

Expand Down Expand Up @@ -48,31 +46,23 @@ public GraphQLObjectType create()

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

context.registerDataFetcher( headlessCms.getName(), "get",
new GetContentDataFetcher( context, serviceFacade.getContentService() ) );
context.registerDataFetcher( headlessCms.getName(), "get", new GetContentDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "getChildren",
new GetChildrenDataFetcher( context, serviceFacade.getContentService() ) );
new GetChildrenDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "getChildrenConnection",
new GetChildrenConnectionDataFetcher( context, serviceFacade.getContentService() ) );
new GetChildrenConnectionDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "getPermissions",
new GetPermissionsDataFetcher( context, serviceFacade.getContentService() ) );
new GetPermissionsDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "getSite",
new GetSiteDataFetcher( context, serviceFacade.getContentService() ) );
context.registerDataFetcher( headlessCms.getName(), "getSite", new GetSiteDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "query", new QueryDataFetcher( context, serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "queryConnection",
new QueryConnectionDataFetcher( context, serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "queryDsl",
new QueryDslDataFetcher( context, serviceFacade.getContentService() ) );
context.registerDataFetcher( headlessCms.getName(), "queryDsl", new QueryDslDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "queryDslConnection",
new QueryDslConnectionDataFetcher( context, serviceFacade.getContentService() ) );
new QueryDslConnectionDataFetcher( serviceFacade.getContentService() ) );

context.registerDataFetcher( headlessCms.getName(), "getType",
new GetTypeDataFetcher( context, serviceFacade.getContentTypeService() ) );
Expand Down Expand Up @@ -104,21 +94,6 @@ private List<GraphQLFieldDefinition> createHeadlessCMSFields()

fields.add( outputField( "getSite", GraphQLTypeReference.typeRef( "portal_Site" ) ) );

fields.add( outputField( "query", new GraphQLList( contentInterface ),
List.of( newArgument( "query", Scalars.GraphQLString ), newArgument( "offset", Scalars.GraphQLInt ),
newArgument( "first", Scalars.GraphQLInt ), newArgument( "sort", Scalars.GraphQLString ),
newArgument( "contentTypes", new GraphQLList( Scalars.GraphQLString ) ),
newArgument( "filters", new GraphQLList( GraphQLTypeReference.typeRef( "FilterInput" ) ) ) ) ) );

fields.add( outputField( "queryConnection", GraphQLTypeReference.typeRef( "QueryContentConnection" ),
List.of( newArgument( "query", new GraphQLNonNull( Scalars.GraphQLString ) ),
newArgument( "after", Scalars.GraphQLString ), newArgument( "first", Scalars.GraphQLInt ),
newArgument( "sort", Scalars.GraphQLString ),
newArgument( "contentTypes", new GraphQLList( Scalars.GraphQLString ) ),
newArgument( "aggregations",
new GraphQLList( GraphQLTypeReference.typeRef( "AggregationInput" ) ) ),
newArgument( "filters", new GraphQLList( GraphQLTypeReference.typeRef( "FilterInput" ) ) ) ) ) );

fields.add( outputField( "queryDsl", new GraphQLList( contentInterface ),
List.of( newArgument( "query", GraphQLTypeReference.typeRef( "QueryDSLInput" ) ),
newArgument( "offset", Scalars.GraphQLInt ), newArgument( "first", Scalars.GraphQLInt ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ public void create()
createValueCountAggregationInputType();
createAggregationInputType();

createExistsFilterInputType();
createNotExistsFilterInputType();
createHasValueFilterInputType();
createIdsFilterInputType();
createBooleanFilterInputType();
createFilterInputType();

createDslExpressionValueInputType();
createTermExpressionDslInputType();
createLikeDslExpressionInputType();
Expand Down Expand Up @@ -249,79 +242,6 @@ private void createAggregationInputType()
context.registerType( inputObject.getName(), inputObject );
}

private void createExistsFilterInputType()
{
List<GraphQLInputObjectField> fields = new ArrayList<>();

fields.add( inputField( "field", new GraphQLNonNull( Scalars.GraphQLString ) ) );

GraphQLInputObjectType inputObject = newInputObject( context.uniqueName( "ExistsFilterInput" ), "ExistsFilter input type", fields );
context.registerType( inputObject.getName(), inputObject );
}

private void createNotExistsFilterInputType()
{
List<GraphQLInputObjectField> fields = new ArrayList<>();

fields.add( inputField( "field", new GraphQLNonNull( Scalars.GraphQLString ) ) );

GraphQLInputObjectType inputObject =
newInputObject( context.uniqueName( "NotExistsFilterInput" ), "NotExistsFilter input type", fields );
context.registerType( inputObject.getName(), inputObject );
}

private void createHasValueFilterInputType()
{
List<GraphQLInputObjectField> fields = new ArrayList<>();

fields.add( inputField( "field", new GraphQLNonNull( Scalars.GraphQLString ) ) );
fields.add( inputField( "stringValues", new GraphQLList( Scalars.GraphQLString ) ) );
fields.add( inputField( "intValues", new GraphQLList( Scalars.GraphQLInt ) ) );
fields.add( inputField( "floatValues", new GraphQLList( Scalars.GraphQLFloat ) ) );
fields.add( inputField( "booleanValues", new GraphQLList( Scalars.GraphQLBoolean ) ) );

GraphQLInputObjectType inputObject =
newInputObject( context.uniqueName( "HasValueFilterInput" ), "HasValueFilter input type", fields );
context.registerType( inputObject.getName(), inputObject );
}

private void createIdsFilterInputType()
{
List<GraphQLInputObjectField> fields = new ArrayList<>();

fields.add( inputField( "values", new GraphQLList( Scalars.GraphQLString ) ) );

GraphQLInputObjectType inputObject = newInputObject( context.uniqueName( "IdsFilterInput" ), "IdsFilter input type", fields );
context.registerType( inputObject.getName(), inputObject );
}

private void createBooleanFilterInputType()
{
List<GraphQLInputObjectField> fields = new ArrayList<>();

fields.add( inputField( "must", new GraphQLList( GraphQLTypeReference.typeRef( "FilterInput" ) ) ) );
fields.add( inputField( "mustNot", new GraphQLList( GraphQLTypeReference.typeRef( "FilterInput" ) ) ) );
fields.add( inputField( "should", new GraphQLList( GraphQLTypeReference.typeRef( "FilterInput" ) ) ) );

GraphQLInputObjectType inputObject =
newInputObject( context.uniqueName( "BooleanFilterInput" ), "BooleanFilter input type", fields );
context.registerType( inputObject.getName(), inputObject );
}

private void createFilterInputType()
{
List<GraphQLInputObjectField> fields = new ArrayList<>();

fields.add( inputField( "boolean", GraphQLTypeReference.typeRef( "BooleanFilterInput" ) ) );
fields.add( inputField( "exists", GraphQLTypeReference.typeRef( "ExistsFilterInput" ) ) );
fields.add( inputField( "notExists", GraphQLTypeReference.typeRef( "NotExistsFilterInput" ) ) );
fields.add( inputField( "hasValue", GraphQLTypeReference.typeRef( "HasValueFilterInput" ) ) );
fields.add( inputField( "ids", GraphQLTypeReference.typeRef( "IdsFilterInput" ) ) );

GraphQLInputObjectType inputObject = newInputObject( context.uniqueName( "FilterInput" ), "Filter input type", fields );
context.registerType( inputObject.getName(), inputObject );
}

private void createDslExpressionValueInputType()
{
List<GraphQLInputObjectField> fields = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;

import com.enonic.app.guillotine.graphql.ContentSerializer;
import com.enonic.app.guillotine.graphql.GuillotineContext;
import com.enonic.app.guillotine.graphql.commands.GetContentCommand;
import com.enonic.app.guillotine.graphql.helper.GuillotineLocalContextHelper;
import com.enonic.app.guillotine.graphql.helper.SecurityHelper;
Expand All @@ -16,70 +14,52 @@
import com.enonic.xp.content.ContentService;
import com.enonic.xp.context.ContextAccessor;
import com.enonic.xp.context.ContextBuilder;
import com.enonic.xp.portal.PortalRequest;
import com.enonic.xp.portal.PortalRequestAccessor;
import com.enonic.xp.site.Site;

public abstract class BaseContentDataFetcher
implements DataFetcher<Object>
{
private final static Pattern SITE_KEY_PATTERN = Pattern.compile( "\\$\\{site\\}" );

protected final GuillotineContext context;

protected final ContentService contentService;

public BaseContentDataFetcher( final GuillotineContext context, final ContentService contentService )
public BaseContentDataFetcher( final ContentService contentService )
{
this.context = context;
this.contentService = contentService;
}

protected Map<String, Object> getContent( DataFetchingEnvironment environment, boolean returnRootContent )
{
PortalRequest portalRequest = PortalRequestAccessor.get();

String siteKey = GuillotineLocalContextHelper.getSiteKey( environment );

String argumentKey = environment.getArgument( "key" );

if ( argumentKey != null )
{
String key = argumentKey;

Site site = portalRequest.getSite();

if ( context.isGlobalMode() && !siteKey.isEmpty() )
if ( !siteKey.isEmpty() )
{
site = getSiteByKey( siteKey );
}
if ( site != null )
{
key = argumentKey.replaceAll( SITE_KEY_PATTERN.pattern(), site.getPath().toString() );
}
if ( SITE_KEY_PATTERN.matcher( key ).find() )
{
return null;
Site site = getSiteByKey( siteKey );
if ( site != null )
{
key = argumentKey.replaceAll( SITE_KEY_PATTERN.pattern(), site.getPath().toString() );
}
}

return getContentByKey( key, returnRootContent, environment );
}
else
{
if ( context.isGlobalMode() )
if ( !siteKey.isEmpty() )
{
if ( !siteKey.isEmpty() )
{
return getContentByKey( siteKey, returnRootContent, environment );
}
if ( returnRootContent )
{
return ContextBuilder.from( ContextAccessor.current() ).build().callWith(
() -> new GetContentCommand( contentService ).execute( "/", environment ) );
}
return getContentByKey( siteKey, returnRootContent, environment );

Check warning on line 54 in src/main/java/com/enonic/app/guillotine/graphql/fetchers/BaseContentDataFetcher.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/enonic/app/guillotine/graphql/fetchers/BaseContentDataFetcher.java#L54

Added line #L54 was not covered by tests
}
if ( returnRootContent )
{
return ContextBuilder.from( ContextAccessor.current() ).build().callWith(
() -> new GetContentCommand( contentService ).execute( "/", environment ) );

Check warning on line 59 in src/main/java/com/enonic/app/guillotine/graphql/fetchers/BaseContentDataFetcher.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/enonic/app/guillotine/graphql/fetchers/BaseContentDataFetcher.java#L58-L59

Added lines #L58 - L59 were not covered by tests
}
return ContentSerializer.serialize( portalRequest.getContent() );
}
return null;

Check warning on line 62 in src/main/java/com/enonic/app/guillotine/graphql/fetchers/BaseContentDataFetcher.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/enonic/app/guillotine/graphql/fetchers/BaseContentDataFetcher.java#L62

Added line #L62 was not covered by tests
}

private Site getSiteByKey( String siteKey )
Expand All @@ -98,6 +78,6 @@
return null;
}

return SecurityHelper.filterForbiddenContent( contentAsMap, context );
return SecurityHelper.filterForbiddenContent( contentAsMap );
}
}
Loading