-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide Project via injection (#672)
* Provide project via injection * Move projectmodule to ctp package * Move provider logic to provider class * Move project related classes to same package * Move application loader to application.conf where it belongs * Disable sunrise modules for tests * Provide i18n module to simple Play app for tests * Fix test issue with missing modules * Move localization classes back to package * Add documentation * Test static constructor projectContext
- Loading branch information
Showing
30 changed files
with
291 additions
and
187 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
25 changes: 25 additions & 0 deletions
25
common/app/com/commercetools/sunrise/ctp/client/SphereClientModule.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,25 @@ | ||
package com.commercetools.sunrise.ctp.client; | ||
|
||
import com.commercetools.sunrise.framework.controllers.metrics.SimpleMetricsSphereClientProvider; | ||
import com.google.inject.AbstractModule; | ||
import io.sphere.sdk.client.SphereClient; | ||
import io.sphere.sdk.client.SphereClientConfig; | ||
|
||
import javax.inject.Singleton; | ||
|
||
/** | ||
* Module that allows to inject a {@link SphereClient} and its configuration. | ||
*/ | ||
public final class SphereClientModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
bind(SphereClientConfig.class) | ||
.toProvider(SphereClientConfigProvider.class) | ||
.in(Singleton.class); | ||
|
||
bind(SphereClient.class) | ||
.toProvider(SimpleMetricsSphereClientProvider.class) | ||
.in(Singleton.class); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
common/app/com/commercetools/sunrise/ctp/project/ProjectModule.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,19 @@ | ||
package com.commercetools.sunrise.ctp.project; | ||
|
||
import com.google.inject.AbstractModule; | ||
import io.sphere.sdk.projects.Project; | ||
|
||
import javax.inject.Singleton; | ||
|
||
/** | ||
* Module that allows to inject a commercetools {@link Project}. | ||
*/ | ||
public final class ProjectModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
bind(Project.class) | ||
.toProvider(ProjectProvider.class) | ||
.in(Singleton.class); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
common/app/com/commercetools/sunrise/ctp/project/ProjectProvider.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,31 @@ | ||
package com.commercetools.sunrise.ctp.project; | ||
|
||
import io.sphere.sdk.client.SphereClient; | ||
import io.sphere.sdk.client.SphereRequest; | ||
import io.sphere.sdk.projects.Project; | ||
import io.sphere.sdk.projects.queries.ProjectGet; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import java.time.Duration; | ||
|
||
import static io.sphere.sdk.client.SphereClientUtils.blockingWait; | ||
|
||
/** | ||
* Provides the commercetools {@link Project} associated with the injected {@link SphereClient}. | ||
*/ | ||
public final class ProjectProvider implements Provider<Project> { | ||
|
||
private final SphereClient sphereClient; | ||
|
||
@Inject | ||
ProjectProvider(final SphereClient sphereClient) { | ||
this.sphereClient = sphereClient; | ||
} | ||
|
||
@Override | ||
public Project get() { | ||
final SphereRequest<Project> request = ProjectGet.of(); | ||
return blockingWait(sphereClient.execute(request), Duration.ofSeconds(30)); | ||
} | ||
} |
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
6 changes: 1 addition & 5 deletions
6
common/app/com/commercetools/sunrise/framework/injection/SunriseModule.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
7 changes: 6 additions & 1 deletion
7
common/app/com/commercetools/sunrise/framework/localization/CountryFromSessionProvider.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
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.