mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -30,12 +30,14 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.faces.event.ActionEvent;
|
import javax.faces.event.ActionEvent;
|
||||||
|
import javax.transaction.UserTransaction;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.web.app.Application;
|
import org.alfresco.web.app.Application;
|
||||||
import org.alfresco.web.app.servlet.DownloadContentServlet;
|
import org.alfresco.web.app.servlet.DownloadContentServlet;
|
||||||
import org.alfresco.web.bean.repository.Node;
|
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.bean.users.UserPreferencesBean;
|
||||||
import org.alfresco.web.ui.common.Utils;
|
import org.alfresco.web.ui.common.Utils;
|
||||||
import org.alfresco.web.ui.common.component.UIActionLink;
|
import org.alfresco.web.ui.common.component.UIActionLink;
|
||||||
@@ -44,6 +46,8 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
|
|
||||||
public class EditOfflineDialog extends CheckinCheckoutDialog
|
public class EditOfflineDialog extends CheckinCheckoutDialog
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = -4848508258494238150L;
|
||||||
|
|
||||||
public static final String OFFLINE_EDITING = "offlineEditing";
|
public static final String OFFLINE_EDITING = "offlineEditing";
|
||||||
public static final String CLOSE = "close";
|
public static final String CLOSE = "close";
|
||||||
public static final String MSG_ERROR_CHECKOUT = "error_checkout";
|
public static final String MSG_ERROR_CHECKOUT = "error_checkout";
|
||||||
@@ -130,17 +134,25 @@ public class EditOfflineDialog extends CheckinCheckoutDialog
|
|||||||
*/
|
*/
|
||||||
private void checkoutFile(Node node)
|
private void checkoutFile(Node node)
|
||||||
{
|
{
|
||||||
|
UserTransaction tx = null;
|
||||||
|
FacesContext context = FacesContext.getCurrentInstance();
|
||||||
|
|
||||||
if (node != null)
|
if (node != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
tx = Repository.getUserTransaction(context, false);
|
||||||
|
tx.begin();
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("Trying to checkout content node Id: " + node.getId());
|
logger.debug("Trying to checkout content node Id: " + node.getId());
|
||||||
NodeRef workingCopyRef = null;
|
NodeRef workingCopyRef = null;
|
||||||
|
|
||||||
// checkout the content to the current space
|
// checkout the content to the current space
|
||||||
workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef());
|
workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef());
|
||||||
getNodeService().setProperty(workingCopyRef, ContentModel.PROP_WORKING_COPY_MODE,
|
getNodeService().setProperty(workingCopyRef, ContentModel.PROP_WORKING_COPY_MODE,
|
||||||
OFFLINE_EDITING);
|
OFFLINE_EDITING);
|
||||||
|
|
||||||
// set the working copy Node instance
|
// set the working copy Node instance
|
||||||
Node workingCopy = new Node(workingCopyRef);
|
Node workingCopy = new Node(workingCopyRef);
|
||||||
property.setWorkingDocument(workingCopy);
|
property.setWorkingDocument(workingCopy);
|
||||||
@@ -153,9 +165,14 @@ public class EditOfflineDialog extends CheckinCheckoutDialog
|
|||||||
workingCopy.getProperties().put("url", url);
|
workingCopy.getProperties().put("url", url);
|
||||||
workingCopy.getProperties().put("fileType32",
|
workingCopy.getProperties().put("fileType32",
|
||||||
Utils.getFileTypeImage(workingCopy.getName(), false));
|
Utils.getFileTypeImage(workingCopy.getName(), false));
|
||||||
|
|
||||||
|
// commit the transaction
|
||||||
|
tx.commit();
|
||||||
}
|
}
|
||||||
catch (Throwable err)
|
catch (Throwable err)
|
||||||
{
|
{
|
||||||
|
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
|
||||||
|
|
||||||
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(),
|
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(),
|
||||||
MSG_ERROR_CHECKOUT)
|
MSG_ERROR_CHECKOUT)
|
||||||
+ err.getMessage(), err);
|
+ err.getMessage(), err);
|
||||||
|
@@ -28,11 +28,15 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.faces.event.ActionEvent;
|
import javax.faces.event.ActionEvent;
|
||||||
|
import javax.transaction.UserTransaction;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
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.Node;
|
||||||
|
import org.alfresco.web.bean.repository.Repository;
|
||||||
|
import org.alfresco.web.ui.common.Utils;
|
||||||
import org.alfresco.web.ui.common.component.UIActionLink;
|
import org.alfresco.web.ui.common.component.UIActionLink;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,20 +166,39 @@ public class EditOnlineDialog extends CCCheckoutFileDialog
|
|||||||
Node node = property.getDocument();
|
Node node = property.getDocument();
|
||||||
if (node != null)
|
if (node != null)
|
||||||
{
|
{
|
||||||
// if current content is already working copy then we don't checkout
|
UserTransaction tx = null;
|
||||||
if (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false)
|
FacesContext context = FacesContext.getCurrentInstance();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// if checkout is successful, then checkoutFile sets property workingDocument
|
tx = Repository.getUserTransaction(context, false);
|
||||||
checkoutFile(FacesContext.getCurrentInstance(), null);
|
tx.begin();
|
||||||
|
|
||||||
Node workingCopyNode = property.getWorkingDocument();
|
// if current content is already working copy then we don't checkout
|
||||||
|
if (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false)
|
||||||
if (workingCopyNode != null)
|
|
||||||
{
|
{
|
||||||
// set working copy node as document for editing
|
// if checkout is successful, then checkoutFile sets property workingDocument
|
||||||
property.setDocument(workingCopyNode);
|
checkoutFile(FacesContext.getCurrentInstance(), null);
|
||||||
getNodeService().setProperty(workingCopyNode.getNodeRef(), ContentModel.PROP_WORKING_COPY_MODE, ONLINE_EDITING);
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user