Skip to content

Commit

Permalink
CAUSEWAY-3636: fixes name of config prop; fixes injection on bootstra…
Browse files Browse the repository at this point in the history
…p...

... need to use Provider<QueryResultsCache>
  • Loading branch information
danhaywood committed Nov 13, 2023
1 parent ce3ca48 commit 6da0b4d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3446,9 +3446,9 @@ public enum PersistPolicy {
@Data
public static class LayoutLoaders {

private final GitHub gitHub = new GitHub();
private final Github github = new Github();
@Data
public static class GitHub {
public static class Github {

/**
* eg <code>apache/causeway-app-simpleapp</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class CausewayModuleExtLayoutLoadersGithub {
@Bean(name = "GithubSearch")
public RestTemplate restTemplateForGithubSearch(final CausewayConfiguration causewayConfiguration) {

val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getApiKey();
val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getApiKey();

return new RestTemplateBuilder()
.rootUri("https://api.github.com")
Expand All @@ -108,8 +108,8 @@ public RestTemplate restTemplateForGithubSearch(final CausewayConfiguration caus
@Bean(name = "GithubContent")
public RestTemplate restTemplateForGithubContent(final CausewayConfiguration causewayConfiguration) {

val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getApiKey();
val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getRepository();
val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getApiKey();
val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getRepository();

return new RestTemplateBuilder()
.rootUri(String.format("https://api.github.com/repos/%s", repo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class ActionDomainEvent extends LayoutLoadersGitHubMenu.ActionDomainEvent
}

boolean isConfigured() {
val layoutLoadersGitHub = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub();
val layoutLoadersGitHub = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub();
return layoutLoadersGitHub.getRepository() != null &&
layoutLoadersGitHub.getApiKey() != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.annotation.Priority;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import org.apache.causeway.extensions.layoutloaders.github.menu.LayoutLoadersGitHubMenu;

Expand Down Expand Up @@ -57,28 +58,28 @@ public class LayoutResourceLoaderFromGithub implements LayoutResourceLoader {
final RestTemplate restTemplateForContent;
final CausewayConfiguration causewayConfiguration;
final LayoutLoadersGitHubMenu layoutLoadersGitHubMenu;
final QueryResultsCache queryResultsCache;
final Provider<QueryResultsCache> queryResultsCacheProvider;

@Inject
public LayoutResourceLoaderFromGithub(
final @Qualifier("GithubSearch") RestTemplate restTemplateForSearch,
final @Qualifier("GithubContent") RestTemplate restTemplateForContent,
final CausewayConfiguration causewayConfiguration,
final LayoutLoadersGitHubMenu layoutLoadersGitHubMenu,
final QueryResultsCache queryResultsCache) {
final Provider<QueryResultsCache> queryResultsCacheProvider) {
this.restTemplateForSearch = restTemplateForSearch;
this.restTemplateForContent = restTemplateForContent;
this.causewayConfiguration = causewayConfiguration;
this.layoutLoadersGitHubMenu = layoutLoadersGitHubMenu;
this.queryResultsCache = queryResultsCache;
this.queryResultsCacheProvider = queryResultsCacheProvider;
}

@Override
public Try<LayoutResource> tryLoadLayoutResource(
final @NonNull Class<?> type,
final @NonNull String candidateResourceName) {
return layoutLoadersGitHubMenu.isEnabled()
? queryResultsCache.execute(() -> tryLoadLayoutResource(candidateResourceName),
? queryResultsCacheProvider.get().execute(() -> tryLoadLayoutResource(candidateResourceName),
getClass(), "tryLoadLayoutResource", candidateResourceName)
: Try.empty();
}
Expand All @@ -95,7 +96,7 @@ private Try<LayoutResource> tryLoadLayoutResource(final String candidateResource
private Try<String> search(final @NonNull String candidateResourceName) {

try {
val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getRepository();
val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getRepository();
val searchParams = new HashMap<String, String>();
searchParams.put("q", String.format("%s+in:path+repo:%s", candidateResourceName, repo));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void preconditions() {
void setup() {

val causewayConfiguration = new CausewayConfiguration(null);
causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().setApiKey(getApiKey());
causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().setRepository("apache/causeway-app-simpleapp");
causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().setApiKey(getApiKey());
causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().setRepository("apache/causeway-app-simpleapp");

val module = new CausewayModuleExtLayoutLoadersGithub();
val restTemplateForSearch = module.restTemplateForGithubSearch(causewayConfiguration);
Expand All @@ -46,7 +46,7 @@ void setup() {
layoutLoaderMenu.new enableDynamicLayoutLoading().act();
Assertions.assertThat(layoutLoaderMenu.isEnabled()).isTrue();

loader = new LayoutResourceLoaderFromGithub(restTemplateForSearch, restTemplateForContent, causewayConfiguration, layoutLoaderMenu, queryResultsCache);
loader = new LayoutResourceLoaderFromGithub(restTemplateForSearch, restTemplateForContent, causewayConfiguration, layoutLoaderMenu, () -> queryResultsCache);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.http

0 comments on commit 6da0b4d

Please sign in to comment.