Tobias Jeger pushed to branch feature/visual-editing-psp1-CHANNELMGR-915 at 
cms-community / hippo-addon-channel-manager


Commits:
fd579cd7 by Tobias Jeger at 2016-10-15T15:30:04+02:00
CHANNELMGR-915 Update error handling logic

- - - - -


1 changed file:

- 
content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java


Changes:

=====================================
content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java
=====================================
--- 
a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java
+++ 
b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java
@@ -81,11 +81,14 @@ public class DocumentsServiceImpl implements 
DocumentsService {
         final DocumentType docType = getDocumentType(handle);
 
         WorkflowUtils.getDocumentVariantNode(handle, 
WorkflowUtils.Variant.DRAFT)
-                .ifPresent(draft -> writeFields(document, draft, docType));
-
-        // TODO what about problems writing to the repository?
-
-        persistChangesAndKeepEditing(session, workflow);
+                .ifPresent(draft -> {
+                    if (writeFields(document, draft, docType)) {
+                        cancelPendingChanges(session);
+                        // TODO: tell the caller that the operation failed. 
Throw new kind of exception?
+                    } else {
+                        persistChangesAndKeepEditing(session, workflow);
+                    }
+                });
     }
 
     @Override
@@ -139,6 +142,7 @@ public class DocumentsServiceImpl implements 
DocumentsService {
         }
     }
 
+    // TODO: how to communicate about write errors...?
     private boolean writeFields(final Document document, final Node variant, 
final DocumentType docType) {
         int errors = 0;
         final Map<String, Object> valueMap = document.getFields();
@@ -148,6 +152,14 @@ public class DocumentsServiceImpl implements 
DocumentsService {
         return errors > 0;
     }
 
+    private void cancelPendingChanges(final Session session) {
+        try {
+            session.refresh(false);
+        } catch(RepositoryException e) {
+            log.warn("Problem cancelling pending changes", e);
+        }
+    }
+
     private void persistChangesAndKeepEditing(final Session session, final 
EditableWorkflow workflow) {
         try {
             session.save();



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

Reply via email to