Offline edit fixes

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8600 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2008-03-27 09:58:39 +00:00
parent 0cbd2dce3f
commit 702b7b13ef
2 changed files with 51 additions and 11 deletions

View File

@@ -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);

View File

@@ -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,6 +166,14 @@ public class EditOnlineDialog extends CCCheckoutFileDialog
Node node = property.getDocument();
if (node != null)
{
UserTransaction tx = null;
FacesContext context = FacesContext.getCurrentInstance();
try
{
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)
{
@@ -177,6 +189,17 @@ public class EditOnlineDialog extends CCCheckoutFileDialog
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);
}
}
}