Search in sources :

Example 1 with MappingRuleDao

use of org.folio.dao.MappingRuleDao in project mod-source-record-manager by folio-org.

the class MappingRuleCache method loadMappingRules.

private CompletableFuture<Optional<JsonObject>> loadMappingRules(MappingRuleCacheKey key, Executor executor, MappingRuleDao mappingRuleDao) {
    CompletableFuture<Optional<JsonObject>> future = new CompletableFuture<>();
    executor.execute(() -> mappingRuleDao.get(key.getRecordType(), key.getTenantId()).map(optional -> optional.isPresent() ? optional : Optional.of(new JsonObject())).onComplete(ar -> {
        if (ar.failed()) {
            LOGGER.error("Failed to load mapping rules for tenant '{}' from data base", key.getTenantId(), ar.cause());
            future.completeExceptionally(ar.cause());
            return;
        }
        future.complete(ar.result());
    }));
    return future;
}
Also used : Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Executor(java.util.concurrent.Executor) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) MappingRuleDao(org.folio.dao.MappingRuleDao) Future(io.vertx.core.Future) AsyncLoadingCache(com.github.benmanes.caffeine.cache.AsyncLoadingCache) Component(org.springframework.stereotype.Component) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) MappingRuleCacheKey(org.folio.services.entity.MappingRuleCacheKey) JsonObject(io.vertx.core.json.JsonObject) LogManager(org.apache.logging.log4j.LogManager) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

AsyncLoadingCache (com.github.benmanes.caffeine.cache.AsyncLoadingCache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Executor (java.util.concurrent.Executor)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MappingRuleDao (org.folio.dao.MappingRuleDao)1 MappingRuleCacheKey (org.folio.services.entity.MappingRuleCacheKey)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1