-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee4a6a9
commit b567b1a
Showing
21 changed files
with
406 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 0 additions & 65 deletions
65
src/main/java/com/enonic/app/guillotine/graphql/fetchers/GetContentPathDataFetcher.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/enonic/app/guillotine/graphql/fetchers/SitePathResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.enonic.app.guillotine.graphql.fetchers; | ||
|
||
import com.enonic.xp.content.ContentId; | ||
import com.enonic.xp.content.ContentNotFoundException; | ||
import com.enonic.xp.content.ContentPath; | ||
import com.enonic.xp.content.ContentService; | ||
|
||
class SitePathResolver | ||
{ | ||
private final ContentService contentService; | ||
|
||
SitePathResolver( final ContentService contentService ) | ||
{ | ||
this.contentService = contentService; | ||
} | ||
Check warning on line 15 in src/main/java/com/enonic/app/guillotine/graphql/fetchers/SitePathResolver.java Codecov / codecov/patchsrc/main/java/com/enonic/app/guillotine/graphql/fetchers/SitePathResolver.java#L13-L15
|
||
|
||
ContentPath resolve( final String siteKey ) | ||
{ | ||
if ( siteKey == null || siteKey.isEmpty() ) | ||
{ | ||
return null; | ||
} | ||
try | ||
{ | ||
if ( siteKey.startsWith( "/" ) ) | ||
{ | ||
return contentService.getByPath( ContentPath.from( siteKey ) ).getPath(); | ||
} | ||
else | ||
{ | ||
return contentService.getById( ContentId.from( siteKey ) ).getPath(); | ||
} | ||
} | ||
catch ( ContentNotFoundException e ) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/enonic/app/guillotine/graphql/helper/ParamsUrHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.enonic.app.guillotine.graphql.helper; | ||
|
||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.Multimap; | ||
import com.google.common.net.UrlEscapers; | ||
|
||
public class ParamsUrHelper | ||
{ | ||
public static void resolveParams( final Multimap<String, String> holder, final Object originalParams ) | ||
{ | ||
if ( originalParams instanceof Map ) | ||
{ | ||
for ( Map.Entry<String, Object> entry : ( (Map<String, Object>) originalParams ).entrySet() ) | ||
{ | ||
applyParam( holder, entry.getKey(), entry.getValue() ); | ||
} | ||
} | ||
} | ||
|
||
public static void appendParams( final StringBuilder str, final Collection<Map.Entry<String, String>> params ) | ||
{ | ||
if ( params == null || params.isEmpty() ) | ||
{ | ||
return; | ||
} | ||
str.append( "?" ); | ||
final Iterator<Map.Entry<String, String>> it = params.iterator(); | ||
appendParam( str, it.next() ); | ||
while ( it.hasNext() ) | ||
{ | ||
str.append( "&" ); | ||
appendParam( str, it.next() ); | ||
} | ||
} | ||
|
||
private static void applyParam( final Multimap<String, String> holder, final String key, final Object value ) | ||
{ | ||
if ( value instanceof Iterable ) | ||
{ | ||
applyParam( holder, key, (Iterable) value ); | ||
} | ||
else | ||
{ | ||
holder.put( key, Objects.toString( value, null ) ); | ||
} | ||
} | ||
|
||
private static void applyParam( final Multimap<String, String> holder, final String key, final Iterable values ) | ||
{ | ||
for ( final Object value : values ) | ||
{ | ||
holder.put( key, Objects.toString( value, null ) ); | ||
} | ||
} | ||
|
||
|
||
private static void appendParam( final StringBuilder str, final Map.Entry<String, String> param ) | ||
{ | ||
final String value = param.getValue(); | ||
str.append( urlEncode( param.getKey() ) ); | ||
if ( value != null ) | ||
{ | ||
str.append( "=" ).append( urlEncode( value ) ); | ||
} | ||
} | ||
|
||
private static String urlEncode( final String value ) | ||
{ | ||
return UrlEscapers.urlFormParameterEscaper().escape( value ); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/com/enonic/app/guillotine/graphql/GetMediaContentGraphQLIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.enonic.app.guillotine.graphql; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import graphql.schema.GraphQLSchema; | ||
|
||
import com.enonic.app.guillotine.graphql.helper.CastHelper; | ||
import com.enonic.xp.content.ContentId; | ||
import com.enonic.xp.portal.url.AttachmentUrlParams; | ||
|
||
import static com.enonic.app.guillotine.graphql.ResourceHelper.readGraphQLQuery; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class GetMediaContentGraphQLIntegrationTest | ||
extends BaseGraphQLIntegrationTest | ||
{ | ||
@Override | ||
protected void initialize() | ||
throws Exception | ||
{ | ||
super.initialize(); | ||
} | ||
|
||
@Test | ||
public void testMediaAndAttachmentUrls() | ||
{ | ||
when( serviceFacade.getPortalUrlService().attachmentUrl( any( AttachmentUrlParams.class ) ) ).thenReturn( "url?a=1&b=2&b=3&c" ); | ||
when( contentService.getById( ContentId.from( "contentId" ) ) ).thenReturn( ContentFixtures.createMediaContent() ); | ||
|
||
GraphQLSchema graphQLSchema = getBean().createSchema(); | ||
|
||
Map<String, Object> result = executeQuery( graphQLSchema, readGraphQLQuery( "graphql/getMediaContent.graphql" ) ); | ||
|
||
assertFalse( result.containsKey( "errors" ) ); | ||
assertTrue( result.containsKey( "data" ) ); | ||
|
||
Map<String, Object> attachmentUrlField = CastHelper.cast( getFieldFromGuillotine( result, "attachmentUrl" ) ); | ||
assertEquals( "url?a=1&b=2&b=3&c", attachmentUrlField.get( "mediaUrl" ) ); | ||
} | ||
|
||
@Test | ||
public void testDownloadAttachmentUrl() | ||
{ | ||
when( serviceFacade.getPortalUrlService().attachmentUrl( any( AttachmentUrlParams.class ) ) ).thenReturn( "url?download" ); | ||
when( contentService.getById( ContentId.from( "contentId" ) ) ).thenReturn( ContentFixtures.createMediaContent() ); | ||
|
||
GraphQLSchema graphQLSchema = getBean().createSchema(); | ||
|
||
Map<String, Object> result = executeQuery( graphQLSchema, readGraphQLQuery( "graphql/getMediaContent.graphql" ) ); | ||
|
||
assertFalse( result.containsKey( "errors" ) ); | ||
assertTrue( result.containsKey( "data" ) ); | ||
|
||
Map<String, Object> downloadAttachmentUrlField = CastHelper.cast( getFieldFromGuillotine( result, "downloadAttachmentUrl" ) ); | ||
assertEquals( "url?download", downloadAttachmentUrlField.get( "mediaUrl" ) ); | ||
} | ||
} |
Oops, something went wrong.