use of no.cantara.docsite.cache.CacheStore in project SourceCodePortal by Cantara.
the class Application method initialize.
public static Application initialize(DynamicConfiguration configuration, int port) {
String host = configuration.evaluateToString("http.host");
CacheStore cacheStore = CacheInitializer.initialize(configuration);
ExecutorService executorService = ExecutorService.create();
ScheduledExecutorService scheduledExecutorService = ScheduledExecutorService.create(configuration, executorService, cacheStore);
RepositoryConfigLoader configLoader = new RepositoryConfigLoader(configuration, cacheStore);
ApplicationController applicationController = new ApplicationController(configuration.evaluateToString("http.cors.allow.origin"), configuration.evaluateToString("http.cors.allow.header"), configuration.evaluateToBoolean("http.cors.allow.origin.test"), port, configuration, executorService, scheduledExecutorService, cacheStore);
return new Application(configuration, host, port, executorService, scheduledExecutorService, cacheStore, configLoader, applicationController);
}
use of no.cantara.docsite.cache.CacheStore in project SourceCodePortal by Cantara.
the class GitHubPageServiceTest method testName.
@Ignore
// (enabled = false)
@Test
public void testName() {
ExecutorService executorService = ExecutorService.create();
executorService.start();
DynamicConfiguration configuration = configuration();
CacheStore cacheStore = cacheStore(configuration);
RepositoryConfigLoader loader = new RepositoryConfigLoader(configuration, cacheStore);
loader.load();
cacheStore.getRepositories().forEach(rg -> {
// TODO lookup CacheGroupKey for CacheKey and pass that to worker task
// TODO use CacheGroupKey for pages
// executorService.queue(new FetchPageTask(configuration, executorService, cacheStore, rg.getKey(), rg.getValue().readmeURL));
LOG.trace("{} - {}", rg.getKey(), rg.getValue().apiReadmeURL.getExternalURL());
// cacheStore.getReadmeContents().get(cacheStore.getCacheKeys().get(rg.getKey().asCacheKey()));
});
executorService.shutdown();
}
use of no.cantara.docsite.cache.CacheStore in project SourceCodePortal by Cantara.
the class ScmRepositoryServiceTest method testRepositoryService.
@Ignore
@Test
public void testRepositoryService() {
DynamicConfiguration configuration = configuration();
CacheStore cacheStore = cacheStore(configuration);
RepositoryConfigLoader loader = new RepositoryConfigLoader(configuration, cacheStore);
cacheStore.getRepositoryConfig().getConfig().repos.forEach((k, v) -> {
LOG.trace("configRepo: {}", v);
});
loader.load();
ScmRepositoryService service = new ScmRepositoryService(cacheStore);
service.keySet().forEach(k -> {
// LOG.trace("key: {}", k);
});
// service.sortedEntrySet().entrySet().forEach(entry -> {
// LOG.trace("group: {} -- count: {}", entry.getKey().groupId, entry.getValue().size());
// entry.getValue().forEach(scmRepository -> {
// LOG.trace(" {}", scmRepository.cacheRepositoryKey.repoName );
// });
// });
service.groupedRepositories().forEach((k, v) -> {
if (k.isGroup()) {
LOG.trace("isGroup: {}", k.groupId);
v.forEach(r -> {
LOG.trace(" {}", r);
// LOG.trace(" {}", r.cacheRepositoryKey.repoName);
});
}
});
}
use of no.cantara.docsite.cache.CacheStore in project SourceCodePortal by Cantara.
the class CommitsHandler method handleRequest.
@Override
public boolean handleRequest(DynamicConfiguration configuration, CacheStore cacheStore, ResourceContext resourceContext, WebContext webContext, HttpServerExchange exchange) {
try {
Map<String, Object> templateVariables = new HashMap<>();
if (resourceContext.getTuples().size() > 2) {
return false;
}
boolean renderAll = (resourceContext.getTuples().size() == 1 && resourceContext.getLast().get().id == null);
ScmCommitRevisionService commitRevisionService = new ScmCommitRevisionService(cacheStore);
if (renderAll) {
Map<CacheShaKey, ScmCommitRevision> commitRevisions = commitRevisionService.entrySet();
templateVariables.put("commitRevisions", new GroupByDateIterator(new ArrayList<>(commitRevisions.values())));
templateVariables.put("displayName", String.format("All %s repos", cacheStore.getRepositoryConfig().getOrganization(RepoConfig.ScmProvider.GITHUB)));
} else {
boolean renderGroupOrRepo = resourceContext.getTuples().size() == 1;
String organization = cacheStore.getRepositoryConfig().getOrganization(RepoConfig.ScmProvider.GITHUB);
String groupIdOrRepoName = (renderGroupOrRepo ? resourceContext.getLast().get().id : resourceContext.getFirst().get().id);
String branchOrNull = (renderGroupOrRepo ? null : resourceContext.getLast().get().resource);
templateVariables.put("displayName", groupIdOrRepoName);
String groupIdIfRenderRepo = null;
if (!renderGroupOrRepo) {
CacheRepositoryKey cacheRepositoryKey = commitRevisionService.getCacheRepositoryKey(CacheKey.of(organization, groupIdOrRepoName, branchOrNull));
if (cacheRepositoryKey != null) {
groupIdIfRenderRepo = cacheRepositoryKey.groupId;
}
}
Map<CacheShaKey, ScmCommitRevision> commitRevisionMap = new LinkedHashMap<>();
Map<CacheShaKey, ScmCommitRevision> cacheStoreCommitsMap = new LinkedHashMap<>();
{
Cache<CacheShaKey, ScmCommitRevision> cacheStoreCommits = cacheStore.getCommits();
cacheStoreCommits.iterator().forEachRemaining(a -> cacheStoreCommitsMap.put(a.getKey(), a.getValue()));
}
// for (Map.Entry<CacheShaKey, ScmCommitRevision> entry : cacheStoreCommitsMap.entrySet()) {
for (Cache.Entry<CacheShaKey, ScmCommitRevision> entry : cacheStore.getCommits()) {
// for (Map.Entry<CacheShaKey, ScmCommitRevision> entry : commitRevisionService.entrySet().entrySet()) {
CacheShaKey key = entry.getKey();
ScmCommitRevision value = entry.getValue();
// group view
if (renderGroupOrRepo && key.compareToUsingGroupId(organization, groupIdOrRepoName)) {
commitRevisionMap.put(key, value);
// repo view
} else if (!renderGroupOrRepo && key.compareToUsingRepoName(organization, groupIdOrRepoName, branchOrNull, groupIdIfRenderRepo)) {
commitRevisionMap.put(key, value);
}
}
LOG.trace("CommitRevisions-size: {}", commitRevisionMap.size());
Map<CacheShaKey, ScmCommitRevision> sortedMap = sortByValue(commitRevisionMap);
GroupByDateIterator groupByDateIterator = new GroupByDateIterator(new ArrayList<>(sortedMap.values()));
templateVariables.put("commitRevisions", groupByDateIterator);
}
if (ThymeleafViewEngineProcessor.processView(exchange, cacheStore, webContext.asTemplateResource(), templateVariables)) {
return true;
}
return false;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
use of no.cantara.docsite.cache.CacheStore in project SourceCodePortal by Cantara.
the class RepositoryConfigLoaderTest method testRepositoryConfig.
@Test(enabled = false)
public void testRepositoryConfig() throws Exception {
ExecutorService executorService = ExecutorService.create();
executorService.start();
DynamicConfiguration configuration = configuration();
CacheStore cacheStore = cacheStore(configuration);
RepositoryConfigLoader service = new RepositoryConfigLoader(configuration, cacheStore);
service.load();
assertTrue(cacheStore.getRepositoryGroupsByGroupId("SourceCodePortal-t").size() > 1);
assertTrue(cacheStore.getRepositoryGroupsByGroupId("Whydah-t").size() > 15);
LOG.trace(JsonbFactory.prettyPrint(cacheStore.getConfiguredRepositories()));
}
Aggregations