Skip to content
Snippets Groups Projects
Commit baffcea4 authored by uhensler's avatar uhensler
Browse files

OO-4009: Versioning of with OnlyOffice edited files

parent 182e884d
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ public interface OnlyOfficeService { ...@@ -43,7 +43,7 @@ public interface OnlyOfficeService {
boolean canUpdateContent(VFSLeaf vfsLeaf, Identity identity, String documentKey); boolean canUpdateContent(VFSLeaf vfsLeaf, Identity identity, String documentKey);
boolean updateContent(VFSLeaf vfsLeaf, Identity identity, String url); boolean updateContent(VFSLeaf vfsLeaf, Identity identity, String url, boolean versionControlled);
boolean isLockNeeded(Mode mode); boolean isLockNeeded(Mode mode);
......
...@@ -102,12 +102,10 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService { ...@@ -102,12 +102,10 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService {
} }
@Override @Override
public boolean updateContent(VFSLeaf vfsLeaf, Identity identity, String url) { public boolean updateContent(VFSLeaf vfsLeaf, Identity identity, String url, boolean versionControlled) {
boolean updated = false; boolean updated = false;
try (InputStream in = new URL(url).openStream()) { try (InputStream in = new URL(url).openStream()) {
//TODO uh versionCntrolled if(versionControlled && vfsLeaf.canVersion() == VFSConstants.YES) {
if(//access.isVersionControlled() &&
vfsLeaf.canVersion() == VFSConstants.YES) {
updated = vfsRepositoryService.addVersion(vfsLeaf, identity, "OnlyOffice", in); updated = vfsRepositoryService.addVersion(vfsLeaf, identity, "OnlyOffice", in);
} else { } else {
updated = VFSManager.copyContent(in, vfsLeaf); updated = VFSManager.copyContent(in, vfsLeaf);
......
...@@ -33,6 +33,7 @@ import javax.ws.rs.POST; ...@@ -33,6 +33,7 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
...@@ -72,6 +73,7 @@ public class OnlyOfficeWebService { ...@@ -72,6 +73,7 @@ public class OnlyOfficeWebService {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response postCallback( public Response postCallback(
@PathParam("fileId") String fileId, @PathParam("fileId") String fileId,
@QueryParam("versionControlled") boolean versionControlled,
CallbackVO callbackVO, CallbackVO callbackVO,
@Context HttpHeaders httpHeaders) { @Context HttpHeaders httpHeaders) {
log.debug("OnlyOffice REST post callback request for File ID: " + fileId); log.debug("OnlyOffice REST post callback request for File ID: " + fileId);
...@@ -91,6 +93,7 @@ public class OnlyOfficeWebService { ...@@ -91,6 +93,7 @@ public class OnlyOfficeWebService {
CallbackStatus status = CallbackStatus.valueOf(callbackVO.getStatus()); CallbackStatus status = CallbackStatus.valueOf(callbackVO.getStatus());
switch(status) { switch(status) {
case Editing: case Editing:
// If a document is opened in view mode, ONLYOFFICE does not send an editing callback and therefore the document won't be locked.
responseVO = lock(fileId, callbackVO); responseVO = lock(fileId, callbackVO);
break; break;
case ClosedWithoutChanges: case ClosedWithoutChanges:
...@@ -104,7 +107,7 @@ public class OnlyOfficeWebService { ...@@ -104,7 +107,7 @@ public class OnlyOfficeWebService {
break; break;
case MustSave: case MustSave:
case MustForceSave: case MustForceSave:
responseVO = updateContent(fileId, callbackVO); responseVO = updateContent(fileId, callbackVO, versionControlled);
break; break;
case ErrorCorrupted: case ErrorCorrupted:
log.warn("ONLYOFFICE has reported that saving the document has failed. File ID: " + fileId); log.warn("ONLYOFFICE has reported that saving the document has failed. File ID: " + fileId);
...@@ -152,6 +155,9 @@ public class OnlyOfficeWebService { ...@@ -152,6 +155,9 @@ public class OnlyOfficeWebService {
VFSLeaf vfsLeaf = onlyOfficeService.getVfsLeaf(fileId); VFSLeaf vfsLeaf = onlyOfficeService.getVfsLeaf(fileId);
if (vfsLeaf == null) return error(); if (vfsLeaf == null) return error();
// Every user which opens the document sets a lock, i.e. adds a new token to the lock.
// Because we are not able to get the LockInfo at that place, we do not unlock for every user who closes the document.
// We let all lock (tokens) until the last user closes the document and then we remove the lock and all its tokens.
boolean lastUser = callbackVO.getUsers() == null || callbackVO.getUsers().length == 0; boolean lastUser = callbackVO.getUsers() == null || callbackVO.getUsers().length == 0;
if (lastUser) { if (lastUser) {
onlyOfficeService.unlock(vfsLeaf); onlyOfficeService.unlock(vfsLeaf);
...@@ -159,7 +165,7 @@ public class OnlyOfficeWebService { ...@@ -159,7 +165,7 @@ public class OnlyOfficeWebService {
return success(); return success();
} }
private CallbackResponseVO updateContent(String fileId, CallbackVO callbackVO) { private CallbackResponseVO updateContent(String fileId, CallbackVO callbackVO, boolean versionControlled) {
String IdentityId = callbackVO.getUsers()[0]; String IdentityId = callbackVO.getUsers()[0];
Identity identity = onlyOfficeService.getIdentity(IdentityId); Identity identity = onlyOfficeService.getIdentity(IdentityId);
if (identity == null) return error(); if (identity == null) return error();
...@@ -172,7 +178,7 @@ public class OnlyOfficeWebService { ...@@ -172,7 +178,7 @@ public class OnlyOfficeWebService {
log.debug("ONLYOFFICE has no right to update file. File ID: " + fileId + ", identity: " + IdentityId); log.debug("ONLYOFFICE has no right to update file. File ID: " + fileId + ", identity: " + IdentityId);
return error(); return error();
} }
boolean updated = onlyOfficeService.updateContent(vfsLeaf, identity, callbackVO.getUrl()); boolean updated = onlyOfficeService.updateContent(vfsLeaf, identity, callbackVO.getUrl(), versionControlled);
onlyOfficeService.unlock(vfsLeaf); onlyOfficeService.unlock(vfsLeaf);
return updated? success(): error(); return updated? success(): error();
} }
......
...@@ -48,7 +48,8 @@ public class ApiConfigBuilder { ...@@ -48,7 +48,8 @@ public class ApiConfigBuilder {
private final VFSMetadata vfsMetadata; private final VFSMetadata vfsMetadata;
private final Identity identity; private final Identity identity;
private boolean edit; private boolean edit = true;
private boolean versionControlled = false;
private static ObjectMapper mapper = new ObjectMapper(); private static ObjectMapper mapper = new ObjectMapper();
...@@ -78,6 +79,17 @@ public class ApiConfigBuilder { ...@@ -78,6 +79,17 @@ public class ApiConfigBuilder {
return this; return this;
} }
/**
* Default: false
*
* @param versionControlled
* @return
*/
public ApiConfigBuilder withVersionControlled(boolean versionControlled) {
this.versionControlled = versionControlled;
return this;
}
public ApiConfig build() { public ApiConfig build() {
String fileName = vfsMetadata.getFilename(); String fileName = vfsMetadata.getFilename();
...@@ -151,6 +163,9 @@ public class ApiConfigBuilder { ...@@ -151,6 +163,9 @@ public class ApiConfigBuilder {
private String getCallbackUrl() { private String getCallbackUrl() {
StringBuilder fileUrl = getFileUrl(); StringBuilder fileUrl = getFileUrl();
fileUrl.append("callback"); fileUrl.append("callback");
if (versionControlled) {
fileUrl.append("?versionControlled=true");
}
return fileUrl.toString(); return fileUrl.toString();
} }
......
...@@ -76,6 +76,7 @@ public class OnlyOfficeEditorController extends BasicController { ...@@ -76,6 +76,7 @@ public class OnlyOfficeEditorController extends BasicController {
} else { } else {
String apiConfig = ApiConfigBuilder.builder(vfsMetadata, getIdentity()) String apiConfig = ApiConfigBuilder.builder(vfsMetadata, getIdentity())
.withEdit(Mode.EDIT.equals(secCallback.getMode())) .withEdit(Mode.EDIT.equals(secCallback.getMode()))
.withVersionControlled(secCallback.isVersionControlled())
.buildJson(); .buildJson();
log.debug("OnlyOffice ApiConfig: " + apiConfig); log.debug("OnlyOffice ApiConfig: " + apiConfig);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment