You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ju...@apache.org on 2019/10/09 07:39:12 UTC
[fineract-cn-async] 06/33: Add null checks for tenant identifier
This is an automated email from the ASF dual-hosted git repository.
juhan pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-async.git
commit 25dd7affcb0fb36f7fefa8420c48e7eba83b57af
Author: Mark <ma...@gmail.com>
AuthorDate: Wed Apr 19 14:36:20 2017 +0200
Add null checks for tenant identifier
---
.../mifos/core/async/core/DelegatingTenantContextCallable.java | 9 ++++++++-
.../mifos/core/async/core/DelegatingTenantContextExecutor.java | 10 ++++++++--
.../mifos/core/async/core/DelegatingTenantContextRunnable.java | 9 ++++++++-
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/main/java/io/mifos/core/async/core/DelegatingTenantContextCallable.java b/src/main/java/io/mifos/core/async/core/DelegatingTenantContextCallable.java
index d473b24..139c1ff 100644
--- a/src/main/java/io/mifos/core/async/core/DelegatingTenantContextCallable.java
+++ b/src/main/java/io/mifos/core/async/core/DelegatingTenantContextCallable.java
@@ -9,6 +9,11 @@ public class DelegatingTenantContextCallable<V> implements Callable<V> {
private final Callable<V> delegate;
private final String tenantIdentifier;
+ DelegatingTenantContextCallable(Callable<V> delegate) {
+ this.delegate = delegate;
+ this.tenantIdentifier = null;
+ }
+
DelegatingTenantContextCallable(final Callable<V> delegate, final String tenantIdentifier) {
super();
this.delegate = delegate;
@@ -19,7 +24,9 @@ public class DelegatingTenantContextCallable<V> implements Callable<V> {
public V call() throws Exception {
try {
TenantContextHolder.clear();
- TenantContextHolder.setIdentifier(this.tenantIdentifier);
+ if(this.tenantIdentifier != null) {
+ TenantContextHolder.setIdentifier(this.tenantIdentifier);
+ }
return this.delegate.call();
} finally {
TenantContextHolder.clear();
diff --git a/src/main/java/io/mifos/core/async/core/DelegatingTenantContextExecutor.java b/src/main/java/io/mifos/core/async/core/DelegatingTenantContextExecutor.java
index 67e6322..1061822 100644
--- a/src/main/java/io/mifos/core/async/core/DelegatingTenantContextExecutor.java
+++ b/src/main/java/io/mifos/core/async/core/DelegatingTenantContextExecutor.java
@@ -41,10 +41,16 @@ public class DelegatingTenantContextExecutor implements AsyncTaskExecutor {
}
private Runnable wrap(final Runnable task) {
- return new DelegatingTenantContextRunnable(task, TenantContextHolder.checkedGetIdentifier());
+ if(TenantContextHolder.identifier().isPresent()) {
+ return new DelegatingTenantContextRunnable(task, TenantContextHolder.checkedGetIdentifier());
+ }
+ return new DelegatingTenantContextRunnable(task);
}
private <T> Callable<T> wrap(final Callable<T> task) {
- return new DelegatingTenantContextCallable<>(task, TenantContextHolder.checkedGetIdentifier());
+ if(TenantContextHolder.identifier().isPresent()) {
+ return new DelegatingTenantContextCallable<>(task, TenantContextHolder.checkedGetIdentifier());
+ }
+ return new DelegatingTenantContextCallable<>(task);
}
}
diff --git a/src/main/java/io/mifos/core/async/core/DelegatingTenantContextRunnable.java b/src/main/java/io/mifos/core/async/core/DelegatingTenantContextRunnable.java
index e0471d1..37d8ba6 100644
--- a/src/main/java/io/mifos/core/async/core/DelegatingTenantContextRunnable.java
+++ b/src/main/java/io/mifos/core/async/core/DelegatingTenantContextRunnable.java
@@ -7,6 +7,11 @@ public class DelegatingTenantContextRunnable implements Runnable {
private final Runnable delegate;
private final String tenantIdentifier;
+ DelegatingTenantContextRunnable(final Runnable delegate) {
+ this.delegate = delegate;
+ this.tenantIdentifier = null;
+ }
+
DelegatingTenantContextRunnable(final Runnable delegate, final String tenantIdentifier) {
super();
this.delegate = delegate;
@@ -17,7 +22,9 @@ public class DelegatingTenantContextRunnable implements Runnable {
public void run() {
try {
TenantContextHolder.clear();
- TenantContextHolder.setIdentifier(this.tenantIdentifier);
+ if(this.tenantIdentifier != null) {
+ TenantContextHolder.setIdentifier(this.tenantIdentifier);
+ }
this.delegate.run();
} finally {
TenantContextHolder.clear();