Mathijs den Burger pushed to branch master at cms-community / hippo-cms

Commits:
c4ca121d by Mathijs den Burger at 2016-09-14T12:51:41+02:00
CMS-10444 Only execute workflow in setMode() when available

The setMode() implementation obtains or commits an editable instance
of the document when the mode is set to 'edit'. However, obtaining
or committing an editable instance is not always possible (e.g. when
a publication request is pending).

We now check whether a workflow method is available (via the workflow
hints) before actually invoking it. The actual mode is only changed
when the workflow call succeeds to keep the behavior the same
(super.setMode() was not called when the workflow method failed).

- - - - -


1 changed file:

- 
workflow/frontend/src/main/java/org/hippoecm/frontend/editor/HippostdPublishableEditor.java


Changes:

=====================================
workflow/frontend/src/main/java/org/hippoecm/frontend/editor/HippostdPublishableEditor.java
=====================================
--- 
a/workflow/frontend/src/main/java/org/hippoecm/frontend/editor/HippostdPublishableEditor.java
+++ 
b/workflow/frontend/src/main/java/org/hippoecm/frontend/editor/HippostdPublishableEditor.java
@@ -1,15 +1,15 @@
 /*
- *  Copyright 2008-2013 Hippo B.V. (http://www.onehippo.com)
+ * Copyright 2008-2016 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.
- *  You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- *       http://www.apache.org/licenses/LICENSE-2.0
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
@@ -198,19 +198,9 @@ public class HippostdPublishableEditor extends 
AbstractCmsEditor<Node> implement
                 postClose(contexts);
 
                 try {
-                    if (mode == Mode.EDIT || getMode() == Mode.EDIT) {
-                        switch (mode) {
-                            case EDIT:
-                                workflow.obtainEditableInstance();
-                                break;
-                            case VIEW:
-                            case COMPARE:
-                                workflow.commitEditableInstance();
-                                break;
-                        }
+                    if (executeWorkflowForMode(mode, workflow)) {
+                        super.setMode(mode);
                     }
-                    super.setMode(mode);
-
                 } finally {
                     start();
                 }
@@ -226,6 +216,32 @@ public class HippostdPublishableEditor extends 
AbstractCmsEditor<Node> implement
         }
     }
 
+    private boolean executeWorkflowForMode(final Mode mode, final 
EditableWorkflow workflow) throws RepositoryException, RemoteException, 
WorkflowException {
+        if (mode == Mode.EDIT || getMode() == Mode.EDIT) {
+            switch (mode) {
+                case EDIT:
+                    if (!isWorkflowMethodAvailable(workflow, 
"obtainEditableInstance")) {
+                        return false;
+                    }
+                    workflow.obtainEditableInstance();
+                    break;
+                case VIEW:
+                case COMPARE:
+                    if (!isWorkflowMethodAvailable(workflow, 
"commitEditableInstance")) {
+                        return false;
+                    }
+                    workflow.commitEditableInstance();
+                    break;
+            }
+        }
+        return true;
+    }
+
+    private static boolean isWorkflowMethodAvailable(Workflow workflow, String 
methodName) throws RepositoryException, RemoteException, WorkflowException {
+        Serializable hint = workflow.hints().get(methodName);
+        return hint == null || Boolean.parseBoolean(hint.toString());
+    }
+
     public void onEvent(EventIterator events) {
         this.modified = true;
     }



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-cms/commit/c4ca121d9d92adf46159b761e5f7bbb14dfdbcab
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to