From 702b7b13efec6d6a01a891e835987c396d233853 Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Thu, 27 Mar 2008 09:58:39 +0000 Subject: [PATCH] Offline edit fixes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8600 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/bean/coci/EditOfflineDialog.java | 17 +++++++ .../web/bean/coci/EditOnlineDialog.java | 45 ++++++++++++++----- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/source/java/org/alfresco/web/bean/coci/EditOfflineDialog.java b/source/java/org/alfresco/web/bean/coci/EditOfflineDialog.java index eccdefa76a..ef72d511c5 100644 --- a/source/java/org/alfresco/web/bean/coci/EditOfflineDialog.java +++ b/source/java/org/alfresco/web/bean/coci/EditOfflineDialog.java @@ -30,12 +30,14 @@ import java.util.Map; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; +import javax.transaction.UserTransaction; import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.DownloadContentServlet; import org.alfresco.web.bean.repository.Node; +import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.users.UserPreferencesBean; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.UIActionLink; @@ -44,6 +46,8 @@ import org.apache.commons.logging.LogFactory; public class EditOfflineDialog extends CheckinCheckoutDialog { + private static final long serialVersionUID = -4848508258494238150L; + public static final String OFFLINE_EDITING = "offlineEditing"; public static final String CLOSE = "close"; public static final String MSG_ERROR_CHECKOUT = "error_checkout"; @@ -130,17 +134,25 @@ public class EditOfflineDialog extends CheckinCheckoutDialog */ private void checkoutFile(Node node) { + UserTransaction tx = null; + FacesContext context = FacesContext.getCurrentInstance(); + if (node != null) { try { + tx = Repository.getUserTransaction(context, false); + tx.begin(); + if (logger.isDebugEnabled()) logger.debug("Trying to checkout content node Id: " + node.getId()); NodeRef workingCopyRef = null; + // checkout the content to the current space workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef()); getNodeService().setProperty(workingCopyRef, ContentModel.PROP_WORKING_COPY_MODE, OFFLINE_EDITING); + // set the working copy Node instance Node workingCopy = new Node(workingCopyRef); property.setWorkingDocument(workingCopy); @@ -153,9 +165,14 @@ public class EditOfflineDialog extends CheckinCheckoutDialog workingCopy.getProperties().put("url", url); workingCopy.getProperties().put("fileType32", Utils.getFileTypeImage(workingCopy.getName(), false)); + + // commit the transaction + tx.commit(); } catch (Throwable err) { + try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} + Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_CHECKOUT) + err.getMessage(), err); diff --git a/source/java/org/alfresco/web/bean/coci/EditOnlineDialog.java b/source/java/org/alfresco/web/bean/coci/EditOnlineDialog.java index cc479e341d..4ef0102149 100644 --- a/source/java/org/alfresco/web/bean/coci/EditOnlineDialog.java +++ b/source/java/org/alfresco/web/bean/coci/EditOnlineDialog.java @@ -28,11 +28,15 @@ import java.util.Map; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; +import javax.transaction.UserTransaction; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Node; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.UIActionLink; /** @@ -162,20 +166,39 @@ public class EditOnlineDialog extends CCCheckoutFileDialog Node node = property.getDocument(); if (node != null) { - // if current content is already working copy then we don't checkout - if (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false) + UserTransaction tx = null; + FacesContext context = FacesContext.getCurrentInstance(); + + try { - // if checkout is successful, then checkoutFile sets property workingDocument - checkoutFile(FacesContext.getCurrentInstance(), null); - - Node workingCopyNode = property.getWorkingDocument(); - - if (workingCopyNode != null) + tx = Repository.getUserTransaction(context, false); + tx.begin(); + + // if current content is already working copy then we don't checkout + if (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false) { - // set working copy node as document for editing - property.setDocument(workingCopyNode); - getNodeService().setProperty(workingCopyNode.getNodeRef(), ContentModel.PROP_WORKING_COPY_MODE, ONLINE_EDITING); + // if checkout is successful, then checkoutFile sets property workingDocument + checkoutFile(FacesContext.getCurrentInstance(), null); + + Node workingCopyNode = property.getWorkingDocument(); + + if (workingCopyNode != null) + { + // set working copy node as document for editing + property.setDocument(workingCopyNode); + getNodeService().setProperty(workingCopyNode.getNodeRef(), ContentModel.PROP_WORKING_COPY_MODE, ONLINE_EDITING); + } } + + // commit the transaction + tx.commit(); + } + catch (Throwable err) + { + try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} + + Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), + MSG_ERROR_CHECKOUT) + err.getMessage(), err); } } }