Skip to content

Commit

Permalink
Adjust callback to be more robust for multi-user
Browse files Browse the repository at this point in the history
  • Loading branch information
cetra3 committed Nov 5, 2015
1 parent 9b31dbe commit d0c2569
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions repo/src/main/java/com/parashift/onlyoffice/CallBack.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.parashift.onlyoffice;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
Expand All @@ -16,6 +18,7 @@
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -31,6 +34,9 @@ public class CallBack extends AbstractWebScript {
@Autowired
LockService lockService;

@Resource(name = "policyBehaviourFilter")
BehaviourFilter behaviourFilter;

@Autowired
ContentService contentService;

Expand All @@ -55,13 +61,18 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
lockService.unlock(nodeRef);
break;
case 1:
logger.debug("Document open for editing, locking document");
lockService.lock(nodeRef, LockType.WRITE_LOCK);
if(lockService.getLockStatus(nodeRef).equals(LockStatus.NO_LOCK)) {
logger.debug("Document open for editing, locking document");
behaviourFilter.disableBehaviour(nodeRef);
lockService.lock(nodeRef, LockType.WRITE_LOCK);
} else {
logger.debug("Document already locked, another user has entered/exited");
}
break;
case 2:
logger.debug("Document Updated, changing content");
updateNode(nodeRef, callBackJSon.getString("url"));
lockService.unlock(nodeRef);
updateNode(nodeRef, callBackJSon.getString("url"));
break;
case 3:
logger.error("Onlyoffice has reported that saving the document has failed");
Expand Down

0 comments on commit d0c2569

Please sign in to comment.