Michiel Eggermont pushed to branch feature/projectdocs at cms-community / 
hippo-repository


Commits:
8045f48c by Michiel Eggermont at 2018-01-16T15:55:34+01:00
REPO-1907 Get action from args when method is triggerAction

We introduced DocumentWorkflow#triggerAction() and implemented it in the
DocumentWorkflowImpl.As a consequence when this new method is used the
WorkflowInvocationHandler invokes the triggerAction method while the
actual action is contained in the args array. After invocation of the
method an event is published. The published event does however not
contain the action that was actually performed, but only the method.

I fixed this by explicity checking the method name for "triggerAction"
and then finding the corresponding Action in the args. If an action
exists it will be set on the event.

- - - - -


1 changed file:

- engine/src/main/java/org/hippoecm/repository/impl/WorkflowLogger.java


Changes:

=====================================
engine/src/main/java/org/hippoecm/repository/impl/WorkflowLogger.java
=====================================
--- a/engine/src/main/java/org/hippoecm/repository/impl/WorkflowLogger.java
+++ b/engine/src/main/java/org/hippoecm/repository/impl/WorkflowLogger.java
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2012-2014 Hippo B.V. (http://www.onehippo.com)
+ *  Copyright 2012-2018 Hippo B.V. (http://www.onehippo.com)
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,12 +16,15 @@
 package org.hippoecm.repository.impl;
 
 import java.util.Arrays;
+import java.util.Optional;
+import java.util.stream.Stream;
 
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.hippoecm.repository.api.ActionAware;
 import org.hippoecm.repository.api.Document;
 import org.hippoecm.repository.api.HippoNodeType;
 import org.hippoecm.repository.api.HippoWorkspace;
@@ -66,11 +69,24 @@ public class WorkflowLogger {
             if (arguments != null) {
                 event.arguments(Arrays.asList(arguments));
             }
+            getAction(methodName, args)
+                    .ifPresent(event::action);
             eventBus.post(event);
         }
 
     }
 
+    private Optional<String> getAction(final String methodName, final Object[] 
args) {
+        if ("triggerAction".equals(methodName) && args != null && args.length 
> 0) {
+            return Stream.of(args)
+                    .filter(ActionAware.class::isInstance)
+                    .map(ActionAware.class::cast)
+                    .map(ActionAware::getAction)
+                    .findFirst();
+        }
+        return Optional.empty();
+    }
+
     private Boolean isSystemUser(String userName) {
         try {
             final SecurityService securityService = ((HippoWorkspace) 
session.getWorkspace()).getSecurityService();



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-repository/commit/8045f48c4c8500be74824ac4c776b11e150d10a5

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-repository/commit/8045f48c4c8500be74824ac4c776b11e150d10a5
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to