Search in sources :

Example 1 with CacheStore

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);
}
Also used : ScheduledExecutorService(no.cantara.docsite.executor.ScheduledExecutorService) ApplicationController(no.cantara.docsite.controller.ApplicationController) ScheduledExecutorService(no.cantara.docsite.executor.ScheduledExecutorService) ExecutorService(no.cantara.docsite.executor.ExecutorService) CacheStore(no.cantara.docsite.cache.CacheStore) RepositoryConfigLoader(no.cantara.docsite.domain.config.RepositoryConfigLoader)

Example 2 with CacheStore

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();
}
Also used : DynamicConfiguration(no.ssb.config.DynamicConfiguration) StoreBasedDynamicConfiguration(no.ssb.config.StoreBasedDynamicConfiguration) ExecutorService(no.cantara.docsite.executor.ExecutorService) CacheStore(no.cantara.docsite.cache.CacheStore) RepositoryConfigLoader(no.cantara.docsite.domain.config.RepositoryConfigLoader) Ignore(org.testng.annotations.Ignore) RepositoryConfigLoaderTest(no.cantara.docsite.domain.config.RepositoryConfigLoaderTest) Test(org.testng.annotations.Test)

Example 3 with CacheStore

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);
            });
        }
    });
}
Also used : DynamicConfiguration(no.ssb.config.DynamicConfiguration) StoreBasedDynamicConfiguration(no.ssb.config.StoreBasedDynamicConfiguration) CacheStore(no.cantara.docsite.cache.CacheStore) RepositoryConfigLoader(no.cantara.docsite.domain.config.RepositoryConfigLoader) Ignore(org.testng.annotations.Ignore) Test(org.testng.annotations.Test)

Example 4 with CacheStore

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;
    }
}
Also used : RepoConfig(no.cantara.docsite.domain.config.RepoConfig) WebHandler(no.cantara.docsite.web.WebHandler) CacheRepositoryKey(no.cantara.docsite.cache.CacheRepositoryKey) HttpServerExchange(io.undertow.server.HttpServerExchange) LoggerFactory(org.slf4j.LoggerFactory) WebContext(no.cantara.docsite.web.WebContext) HashMap(java.util.HashMap) CacheKey(no.cantara.docsite.cache.CacheKey) CacheShaKey(no.cantara.docsite.cache.CacheShaKey) ScmCommitRevision(no.cantara.docsite.domain.scm.ScmCommitRevision) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ResourceContext(no.cantara.docsite.web.ResourceContext) DynamicConfiguration(no.ssb.config.DynamicConfiguration) Map(java.util.Map) Cache(javax.cache.Cache) GroupByDateIterator(no.cantara.docsite.domain.scm.GroupByDateIterator) LinkedList(java.util.LinkedList) ScmCommitRevisionService(no.cantara.docsite.domain.scm.ScmCommitRevisionService) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ThymeleafViewEngineProcessor(no.cantara.docsite.web.ThymeleafViewEngineProcessor) List(java.util.List) CacheStore(no.cantara.docsite.cache.CacheStore) Collections(java.util.Collections) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CacheShaKey(no.cantara.docsite.cache.CacheShaKey) GroupByDateIterator(no.cantara.docsite.domain.scm.GroupByDateIterator) LinkedHashMap(java.util.LinkedHashMap) CacheRepositoryKey(no.cantara.docsite.cache.CacheRepositoryKey) ScmCommitRevisionService(no.cantara.docsite.domain.scm.ScmCommitRevisionService) ScmCommitRevision(no.cantara.docsite.domain.scm.ScmCommitRevision) Cache(javax.cache.Cache)

Example 5 with CacheStore

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()));
}
Also used : DynamicConfiguration(no.ssb.config.DynamicConfiguration) StoreBasedDynamicConfiguration(no.ssb.config.StoreBasedDynamicConfiguration) ExecutorService(no.cantara.docsite.executor.ExecutorService) CacheStore(no.cantara.docsite.cache.CacheStore) Test(org.testng.annotations.Test)

Aggregations

CacheStore (no.cantara.docsite.cache.CacheStore)7 DynamicConfiguration (no.ssb.config.DynamicConfiguration)5 Test (org.testng.annotations.Test)5 StoreBasedDynamicConfiguration (no.ssb.config.StoreBasedDynamicConfiguration)4 RepositoryConfigLoader (no.cantara.docsite.domain.config.RepositoryConfigLoader)3 ExecutorService (no.cantara.docsite.executor.ExecutorService)3 LinkedHashMap (java.util.LinkedHashMap)2 CacheRepositoryKey (no.cantara.docsite.cache.CacheRepositoryKey)2 CacheShaKey (no.cantara.docsite.cache.CacheShaKey)2 Ignore (org.testng.annotations.Ignore)2 HttpServerExchange (io.undertow.server.HttpServerExchange)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1