Skip to content

Commit

Permalink
Remove deprecated source code #557
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Oct 11, 2023
1 parent 11139ef commit ee4a6a9
Show file tree
Hide file tree
Showing 40 changed files with 474 additions and 901 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public interface Constants
{
String CONTENT_ID_FIELD = "__contentId";

String GUILLOTINE_LOCAL_CTX = "__guillotineLocalContext";

String GUILLOTINE_TARGET_REPO_CTX = "__targetRepository";

String GUILLOTINE_TARGET_BRANCH_CTX = "__targetBranch";
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/enonic/app/guillotine/graphql/GraphQLApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,11 @@ private void generateGuillotineApi( GraphQLTypesRegister typesRegister )
typesRegister.addCreationCallback( "Query", guillotineQueryCreationCallback );

typesRegister.addResolver( "Query", "guillotine", environment -> {
final Map<String, Object> sourceMap = new HashMap<>();

sourceMap.put( Constants.GUILLOTINE_TARGET_REPO_CTX, environment.getArgument( "repo" ) );
sourceMap.put( Constants.GUILLOTINE_TARGET_BRANCH_CTX, environment.getArgument( "branch" ) );
sourceMap.put( Constants.GUILLOTINE_TARGET_SITE_CTX, environment.getArgument( "siteKey" ) );

final Map<String, Object> localContext = environment.getLocalContext();
localContext.put( Constants.GUILLOTINE_LOCAL_CTX, sourceMap );

localContext.put( Constants.GUILLOTINE_TARGET_REPO_CTX, environment.getArgument( "repo" ) );
localContext.put( Constants.GUILLOTINE_TARGET_BRANCH_CTX, environment.getArgument( "branch" ) );
localContext.put( Constants.GUILLOTINE_TARGET_SITE_CTX, environment.getArgument( "siteKey" ) );

return new Object();
} );
Expand All @@ -208,13 +205,13 @@ private void generateGuillotineApi( GraphQLTypesRegister typesRegister )
context.getTypeResolvers().forEach( typesRegister::addTypeResolver );
}

public Object execute( GraphQLSchema graphQLSchema, String query, ScriptValue variables, ScriptValue queryContext )
public Object execute( GraphQLSchema graphQLSchema, String query, ScriptValue variables )
{
GraphQL graphQL = GraphQL.newGraphQL( graphQLSchema ).build();

ExecutionInput executionInput =
ExecutionInput.newExecutionInput().query( query ).variables( extractValue( variables ) ).graphQLContext(
extractValue( queryContext ) ).localContext( new HashMap<String, Object>() ).build();
ExecutionInput.newExecutionInput().query( query ).variables( extractValue( variables ) ).localContext(
new HashMap<String, Object>() ).build();

return new ExecutionResultMapper( graphQL.execute( executionInput ) );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.enonic.app.guillotine.graphql;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import graphql.schema.DataFetcher;
Expand All @@ -19,8 +21,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 @@ -36,42 +36,21 @@ public class GuillotineContext

private final ConcurrentMap<String, TypeResolver> typeResolvers = new ConcurrentHashMap<>();

private final CopyOnWriteArrayList<String> applications;
private final ImmutableList<String> applications;

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.applications = ImmutableList.<String>builder().addAll( builder.applications ).build();
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 @@ -158,9 +137,7 @@ public static Builder create()
public static final class Builder
{

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

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

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

Expand All @@ -178,15 +155,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 @@ -27,7 +27,7 @@ public Map<String, Object> execute( String key, DataFetchingEnvironment environm

private Map<String, Object> doExecute( String key )
{
if ( key == null )
if ( key == null || key.isEmpty() )
{
return 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
Loading

0 comments on commit ee4a6a9

Please sign in to comment.