-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple APIs in one app #10514
- Loading branch information
1 parent
e8cc38d
commit 5fe9f78
Showing
12 changed files
with
214 additions
and
83 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
13 changes: 13 additions & 0 deletions
13
modules/core/core-api/src/main/java/com/enonic/xp/api/ApiDescriptorService.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,13 @@ | ||
package com.enonic.xp.api; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
import com.enonic.xp.app.ApplicationKey; | ||
import com.enonic.xp.page.DescriptorKey; | ||
|
||
@PublicApi | ||
public interface ApiDescriptorService | ||
{ | ||
ApiDescriptor getByKey( DescriptorKey descriptorKey ); | ||
|
||
ApiDescriptors getByApplication( ApplicationKey applicationKey ); | ||
} |
29 changes: 29 additions & 0 deletions
29
modules/core/core-api/src/main/java/com/enonic/xp/api/ApiDescriptors.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,29 @@ | ||
package com.enonic.xp.api; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.enonic.xp.support.AbstractImmutableEntityList; | ||
|
||
public final class ApiDescriptors | ||
extends AbstractImmutableEntityList<ApiDescriptor> | ||
{ | ||
private ApiDescriptors( final ImmutableList<ApiDescriptor> list ) | ||
{ | ||
super( list ); | ||
} | ||
|
||
public static ApiDescriptors empty() | ||
{ | ||
return new ApiDescriptors( ImmutableList.of() ); | ||
} | ||
|
||
public static ApiDescriptors from( final ApiDescriptor... descriptors ) | ||
{ | ||
return from( ImmutableList.copyOf( descriptors ) ); | ||
} | ||
|
||
public static ApiDescriptors from( final Iterable<ApiDescriptor> descriptors ) | ||
{ | ||
return new ApiDescriptors( ImmutableList.copyOf( descriptors ) ); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...rtal/portal-impl/src/main/java/com/enonic/xp/portal/impl/api/ApiDescriptorKeyLocator.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,36 @@ | ||
package com.enonic.xp.portal.impl.api; | ||
|
||
import java.util.Set; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
|
||
import com.enonic.xp.app.ApplicationKey; | ||
import com.enonic.xp.page.DescriptorKey; | ||
import com.enonic.xp.resource.ResourceService; | ||
|
||
public class ApiDescriptorKeyLocator | ||
{ | ||
private final ResourceService service; | ||
|
||
private final String pattern; | ||
|
||
public ApiDescriptorKeyLocator( final ResourceService service ) | ||
{ | ||
this.service = service; | ||
this.pattern = "^/apis/(api|(?<name>[^/]+)/\\k<name>)\\.(xml|js)$"; | ||
} | ||
|
||
public Set<DescriptorKey> findKeys( final ApplicationKey key ) | ||
{ | ||
return this.service.findFiles( key, this.pattern ) | ||
.stream() | ||
.map( resource -> DescriptorKey.from( key, getNameWithoutExtension( resource.getName() ) ) ) | ||
.collect( ImmutableSet.toImmutableSet() ); | ||
} | ||
|
||
private static String getNameWithoutExtension( final String name ) | ||
{ | ||
final int pos = name.lastIndexOf( '.' ); | ||
return pos > 0 ? name.substring( 0, pos ) : name; | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
.../portal/portal-impl/src/main/java/com/enonic/xp/portal/impl/api/ApiDescriptorService.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
Oops, something went wrong.