3333import org .osgi .service .metatype .annotations .AttributeDefinition ;
3434import org .osgi .service .metatype .annotations .Designate ;
3535import org .osgi .service .metatype .annotations .ObjectClassDefinition ;
36+ import org .slf4j .Logger ;
37+ import org .slf4j .LoggerFactory ;
3638
3739@ Component (
3840 immediate = true ,
@@ -43,6 +45,8 @@ public class Executor implements EventListener {
4345
4446 public static final String LOCK_DIR = "executor" ;
4547
48+ private static final Logger LOG = LoggerFactory .getLogger (Executor .class );
49+
4650 @ ObjectClassDefinition (name = "AEM Content Manager - Code Executor" )
4751 public @interface Config {
4852
@@ -278,10 +282,8 @@ private void handleNotifications(ContextualExecution execution) {
278282 ? "✅"
279283 : (execution .getStatus () == ExecutionStatus .FAILED ? "❌" : "⚠️" ));
280284 templateVars .put ("statusHere" , execution .getStatus () == ExecutionStatus .SUCCEEDED ? "" : "@here" );
281- TemplateFormatter templateFormatter =
282- execution .getContext ().getCodeContext ().getFormatter ().getTemplate ();
283- String title = StringUtils .trim (templateFormatter .renderString (config .notificationTitle (), templateVars ));
284- String text = StringUtils .trim (templateFormatter .renderString (config .notificationText (), templateVars ));
285+ String title = StringUtils .trim (formatTemplate (config .notificationTitle (), templateVars ));
286+ String text = StringUtils .trim (formatTemplate (config .notificationText (), templateVars ));
285287
286288 Map <String , Object > fields = new LinkedHashMap <>();
287289 fields .put ("Status" , execution .getStatus ().name ().toLowerCase ());
@@ -372,4 +374,13 @@ private void useLocker(ResourceResolverFactory resolverFactory, Consumer<Locker>
372374 private void useHistory (ResourceResolverFactory resolverFactory , Consumer <ExecutionHistory > consumer ) {
373375 ResolverUtils .useContentResolver (resolverFactory , null , r -> consumer .accept (new ExecutionHistory (r )));
374376 }
377+
378+ private String formatTemplate (String template , Map <String , Object > vars ) {
379+ try {
380+ return new TemplateFormatter ().renderString (template , vars );
381+ } catch (Exception e ) {
382+ LOG .warn ("Cannot format template '{}'!" , template , e );
383+ return template ;
384+ }
385+ }
375386}
0 commit comments