Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 16795 improve savepublish 2 (#16819)
* #16252 format source. Introduce format checker on build. Alter style … (#16288) * #16252 format source. Introduce format checker on build. Alter style files * #16252 remove unwanted file * #16252 remove unwanted file * Updating commit reference for src/main/enterprise * try different location for checkstyle.xml * Revert "#16252 format source. Introduce format checker on build. Alter style … (#16288)" (#16291) This reverts commit 05f9082. * Updating commit reference for src/main/enterprise * #16795 adding new stuff to avoid reindex on some api call and WF * #16795 Minor refactoring * #16795 Adding the support for include all dependencies * #16795 ignoring some logs * #16795 moving code to a constants * #16795 coded the feedback
- Loading branch information
1 parent
ff66cbf
commit c6d21e5
Showing
10 changed files
with
262 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
233 changes: 82 additions & 151 deletions
233
dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package com.dotcms.util; | ||
|
||
import org.apache.log4j.Level; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.dotcms.util; | ||
|
||
/** | ||
* Encapsulates Thread Local context information | ||
* @author jsanca | ||
*/ | ||
public class ThreadContext { | ||
|
||
// by default the api will reindex, set to false if do not want to reindex in an api call. | ||
private boolean reindex = true; | ||
|
||
// when the reindex happens later, the api call can set this to true in order to tell at the end of the thread process to do reindex including dependencies | ||
private boolean includeDependencies = false; | ||
|
||
public boolean isReindex() { | ||
return reindex; | ||
} | ||
|
||
public void setReindex(boolean reindex) { | ||
this.reindex = reindex; | ||
} | ||
|
||
public boolean isIncludeDependencies() { | ||
return includeDependencies; | ||
} | ||
|
||
public void setIncludeDependencies(boolean includeDependencies) { | ||
this.includeDependencies = includeDependencies; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
dotCMS/src/main/java/com/dotcms/util/ThreadContextUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.dotcms.util; | ||
|
||
import com.dotmarketing.exception.DotDataException; | ||
import com.dotmarketing.exception.DotRuntimeException; | ||
import com.dotmarketing.exception.DotSecurityException; | ||
import com.dotmarketing.util.UtilMethods; | ||
|
||
/** | ||
* Thread Context Util provides methods to handle reindex stuff and other thread local context things | ||
* @author jsancas | ||
*/ | ||
public class ThreadContextUtil { | ||
|
||
private static ThreadLocal<ThreadContext> contextLocal = new ThreadLocal<>(); | ||
|
||
/** | ||
* Get the context from the current thread | ||
* @return {@link ThreadContext} | ||
*/ | ||
public static ThreadContext getOrCreateContext() { | ||
|
||
return UtilMethods.get(contextLocal.get(), ()-> { | ||
|
||
final ThreadContext context = new ThreadContext(); | ||
contextLocal.set(context); | ||
return context; | ||
}); | ||
} | ||
|
||
|
||
/** | ||
* Return true if the current thread is config to reindex things in the api calls, otherwise false. | ||
* @return Boolean | ||
*/ | ||
public static boolean isReindex () { | ||
|
||
final ThreadContext context = getOrCreateContext(); | ||
return context.isReindex(); | ||
} | ||
|
||
/** | ||
* Executes the delegate if the reindex is set to true for the current thread | ||
* @param delegate | ||
* @throws DotSecurityException | ||
* @throws DotDataException | ||
*/ | ||
public static void ifReindex (final VoidDelegate delegate) throws DotSecurityException, DotDataException { | ||
|
||
if (isReindex()) { | ||
|
||
delegate.execute(); | ||
} | ||
} | ||
|
||
/** | ||
* Executes the delegate if the reindex is set to true for the current thread | ||
* @param delegate | ||
* @throws DotSecurityException | ||
* @throws DotDataException | ||
*/ | ||
public static void ifReindex (final VoidDelegate delegate, final boolean includeDependencies) throws DotSecurityException, DotDataException { | ||
|
||
if (isReindex()) { | ||
|
||
delegate.execute(); | ||
} else { | ||
|
||
getOrCreateContext().setIncludeDependencies(includeDependencies); | ||
} | ||
} | ||
|
||
/** | ||
* Wrap a void method into not reindex call | ||
* @param delegate {@link VoidDelegate} | ||
* @throws Exception | ||
*/ | ||
public static void wrapVoidNoReindex (final VoidDelegate delegate) { | ||
|
||
final ThreadContext threadContext = getOrCreateContext(); | ||
final boolean reindex = threadContext.isReindex(); | ||
|
||
try { | ||
|
||
threadContext.setReindex(false); | ||
delegate.execute(); | ||
} catch(Throwable e) { | ||
|
||
throw new DotRuntimeException(e); | ||
} finally { | ||
|
||
threadContext.setReindex(reindex); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Wrap a return method into not reindex call | ||
* @param delegate {@link VoidDelegate} | ||
* @throws Exception | ||
*/ | ||
public static <T> T wrapReturnNoReindex (final ReturnableDelegate<T> delegate) { | ||
|
||
final ThreadContext threadContext = getOrCreateContext(); | ||
final boolean reindex = threadContext.isReindex(); | ||
|
||
try { | ||
|
||
threadContext.setReindex(false); | ||
return delegate.execute(); | ||
} catch(Throwable e) { | ||
|
||
throw new DotRuntimeException(e); | ||
} finally { | ||
|
||
threadContext.setReindex(reindex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters