use of com.nexblocks.authguard.service.model.Entity in project AuthGuard by AuthGuard.
the class IdempotencyServiceImpl method performOperation.
@Override
public <T extends Entity> CompletableFuture<T> performOperation(final Supplier<T> operation, final String idempotentKey, final String entityType) {
return findByKeyAndEntityType(idempotentKey, entityType).thenApplyAsync(record -> {
if (record.isPresent()) {
throw new IdempotencyException(record.get());
}
return operation.get();
}).thenApply(result -> {
final IdempotentRecordBO record = IdempotentRecordBO.builder().id(ID.generate()).entityId(result.getId()).entityType(result.getEntityType()).idempotentKey(idempotentKey).build();
// we don't have to wait for this to finish
CompletableFuture.runAsync(() -> create(record));
return result;
});
}
use of com.nexblocks.authguard.service.model.Entity in project AuthGuard by AuthGuard.
the class PersistenceService method create.
public BO create(final BO entity) {
final OffsetDateTime now = OffsetDateTime.now();
final DO mappedDo = boToDo.apply(entity);
mappedDo.setId(ID.generate());
mappedDo.setDeleted(false);
mappedDo.setCreatedAt(now);
mappedDo.setLastModified(now);
return repository.save(mappedDo).thenApply(persisted -> {
final BO persistedBo = doToBo.apply(persisted);
messageBus.publish(channel, Messages.created(persistedBo));
return persistedBo;
}).join();
}
use of com.nexblocks.authguard.service.model.Entity in project AuthGuard by AuthGuard.
the class PersistenceService method update.
public Optional<BO> update(final BO entity) {
final OffsetDateTime now = OffsetDateTime.now();
final DO mappedDo = boToDo.apply(entity);
mappedDo.setLastModified(now);
return repository.update(mappedDo).thenApply(opt -> {
final Optional<BO> boOpt = opt.map(doToBo);
boOpt.ifPresent(bo -> messageBus.publish(channel, Messages.updated(bo)));
return boOpt;
}).join();
}
Aggregations