mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
java-spring: users for mentions, gson to jackson, rename documentManager to segregated documentManagerExts
This commit is contained in:
@ -18,15 +18,18 @@
|
||||
|
||||
package com.onlyoffice.integration.controllers;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.onlyoffice.integration.Action;
|
||||
import com.onlyoffice.integration.entities.User;
|
||||
import com.onlyoffice.integration.controllers.objects.UserForMention;
|
||||
import com.onlyoffice.integration.entities.enums.Language;
|
||||
import com.onlyoffice.integration.entities.enums.Type;
|
||||
import com.onlyoffice.integration.entities.filemodel.File;
|
||||
import com.onlyoffice.integration.entities.filemodel.FileModel;
|
||||
import com.onlyoffice.integration.services.EditorServices;
|
||||
import com.onlyoffice.integration.services.UserServices;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentManager;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentTokenManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -48,6 +51,9 @@ public class EditorController {
|
||||
@Autowired
|
||||
private DocumentManager documentManager;
|
||||
|
||||
@Autowired
|
||||
private DocumentTokenManager documentTokenManager;
|
||||
|
||||
@Autowired
|
||||
private UserServices userService;
|
||||
|
||||
@ -61,7 +67,7 @@ public class EditorController {
|
||||
@RequestParam(value = "actionLink", required = false) String actionLink,
|
||||
@CookieValue(value = "uid") String uid,
|
||||
@CookieValue(value = "ulang") String lang,
|
||||
Model model){
|
||||
Model model) throws JsonProcessingException {
|
||||
Action action = Action.edit;
|
||||
Type type = Type.desktop;
|
||||
Language language = Language.en;
|
||||
@ -76,7 +82,7 @@ public class EditorController {
|
||||
|
||||
User user = optionalUser.get();
|
||||
|
||||
File file = editorService.createConfiguration(user, fileName, actionLink, action, language, type);
|
||||
FileModel fileModel = editorService.createConfiguration(user, fileName, actionLink, action, language, type);
|
||||
|
||||
Map<String, Object> dataInsertImage = new HashMap<>();
|
||||
dataInsertImage.put("fileType", "png");
|
||||
@ -90,26 +96,31 @@ public class EditorController {
|
||||
dataMailMergeRecipients.put("fileType", "csv");
|
||||
dataMailMergeRecipients.put("url", documentManager.getServerUrl(true) + "/csv");
|
||||
|
||||
//TODO: Implementation
|
||||
List<Map<String, Object>> usersForMentions = new ArrayList<>();
|
||||
|
||||
if(documentManager.tokenEnabled()){
|
||||
file.generateToken();
|
||||
dataInsertImage.put("token", documentManager.createToken(dataInsertImage));
|
||||
dataCompareFile.put("token", documentManager.createToken(dataInsertImage));
|
||||
dataMailMergeRecipients.put("token", documentManager.createToken(dataMailMergeRecipients));
|
||||
List<UserForMention> usersForMentions=new ArrayList<>();
|
||||
if(uid!=null && !uid.equals("uid-0")) {
|
||||
List<User> list = userService.findAll();
|
||||
for (User u : list) {
|
||||
if (!u.getName().equals("anonymous")) {
|
||||
usersForMentions.add(new UserForMention(u.getName(), u.getEmail()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Get rid of GSON
|
||||
Gson gson = new Gson();
|
||||
if(documentTokenManager.tokenEnabled()){
|
||||
fileModel.generateToken();
|
||||
dataInsertImage.put("token", documentTokenManager.createToken(dataInsertImage));
|
||||
dataCompareFile.put("token", documentTokenManager.createToken(dataInsertImage));
|
||||
dataMailMergeRecipients.put("token", documentTokenManager.createToken(dataMailMergeRecipients));
|
||||
}
|
||||
|
||||
model.addAttribute("model", file);
|
||||
ObjectMapper objectMapper=new ObjectMapper();
|
||||
|
||||
model.addAttribute("model", fileModel);
|
||||
model.addAttribute("docserviceApiUrl",docserviceSite + docserviceApiUrl);
|
||||
model.addAttribute("dataInsertImage", gson.toJson(dataInsertImage).substring(1, gson.toJson(dataInsertImage).length()-1));
|
||||
model.addAttribute("dataCompareFile", gson.toJson(dataCompareFile));
|
||||
model.addAttribute("dataMailMergeRecipients", gson.toJson(dataMailMergeRecipients));
|
||||
model.addAttribute("dataInsertImage", objectMapper.writeValueAsString(dataInsertImage).substring(1, objectMapper.writeValueAsString(dataInsertImage).length()-1));
|
||||
model.addAttribute("dataCompareFile", objectMapper.writeValueAsString(dataCompareFile));
|
||||
model.addAttribute("dataMailMergeRecipients", objectMapper.writeValueAsString(dataMailMergeRecipients));
|
||||
model.addAttribute("usersForMentions", usersForMentions);
|
||||
|
||||
return "editor.html";
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package com.onlyoffice.integration.controllers;
|
||||
import com.onlyoffice.integration.serializer.FilterState;
|
||||
import com.onlyoffice.integration.entities.*;
|
||||
import com.onlyoffice.integration.services.UserServices;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentManagerExts;
|
||||
import com.onlyoffice.integration.util.fileUtilities.FileUtility;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -39,6 +40,8 @@ public class IndexController {
|
||||
@Autowired
|
||||
private DocumentManager documentManager;
|
||||
|
||||
@Autowired
|
||||
private DocumentManagerExts documentManagerExts;
|
||||
@Autowired
|
||||
private FileUtility fileUtility;
|
||||
|
||||
@ -106,7 +109,7 @@ public class IndexController {
|
||||
).collect(Collectors.toList());
|
||||
|
||||
List<Boolean> filesEditable = Arrays.stream(files).map(
|
||||
file -> documentManager.getEditedExts().contains(fileUtility.getFileExtension(file.getName()))
|
||||
file -> documentManagerExts.getEditedExts().contains(fileUtility.getFileExtension(file.getName()))
|
||||
).collect(Collectors.toList());
|
||||
|
||||
List<User> users = userService.findAll();
|
||||
@ -127,8 +130,8 @@ public class IndexController {
|
||||
public HashMap<String, String> configParameters(){
|
||||
HashMap<String, String> configuration = new HashMap<>();
|
||||
|
||||
configuration.put("ConverExtList", String.join(",",documentManager.getConvertExts()));
|
||||
configuration.put("EditedExtList", String.join(",",documentManager.getEditedExts()));
|
||||
configuration.put("ConverExtList", String.join(",",documentManagerExts.getConvertExts()));
|
||||
configuration.put("EditedExtList", String.join(",",documentManagerExts.getEditedExts()));
|
||||
configuration.put("UrlConverter", urlConverter);
|
||||
configuration.put("UrlEditor", urlEditor);
|
||||
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.onlyoffice.integration.controllers.objects;
|
||||
|
||||
public class UserForMention {
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
public UserForMention(String name,String email){
|
||||
this.email=email;
|
||||
this.name=name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,9 @@
|
||||
|
||||
package com.onlyoffice.integration.entities.filemodel;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.onlyoffice.integration.Action;
|
||||
@ -27,6 +30,7 @@ import com.onlyoffice.integration.entities.enums.Language;
|
||||
import com.onlyoffice.integration.entities.enums.Mode;
|
||||
import com.onlyoffice.integration.entities.enums.ToolbarDocked;
|
||||
import com.onlyoffice.integration.entities.enums.Type;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentManagerExts;
|
||||
import com.onlyoffice.integration.util.fileUtilities.FileUtility;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -46,6 +50,8 @@ public class EditorConfig {
|
||||
@Autowired
|
||||
private DocumentManager documentManager;
|
||||
|
||||
@Autowired
|
||||
private DocumentManagerExts documentManagerExts;
|
||||
@Autowired
|
||||
private FileUtility fileUtility;
|
||||
|
||||
@ -65,12 +71,16 @@ public class EditorConfig {
|
||||
Language lang,
|
||||
Type type){
|
||||
if (actionData != null) {
|
||||
Gson gson = new Gson();
|
||||
this.actionLink = gson.fromJson(actionData, new TypeToken<HashMap<String, Object>>() { }.getType());
|
||||
ObjectMapper om=new ObjectMapper();
|
||||
try {
|
||||
this.actionLink = om.readValue(actionData, (JavaType) new TypeToken<HashMap<String, Object>>() { }.getType());
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.callbackUrl = documentManager.getCallback(fileName);
|
||||
this.lang = lang;
|
||||
Boolean canEdit = documentManager.getEditedExts().contains(fileUtility.getFileExtension(fileName));
|
||||
Boolean canEdit = documentManagerExts.getEditedExts().contains(fileUtility.getFileExtension(fileName));
|
||||
this.customization = applicationContext.getBean(Customization.class);
|
||||
this.customization.setSubmitForm(canEdit && (action.equals(Action.edit) || action.equals(Action.fillForms)));
|
||||
this.mode = canEdit && !action.equals(Action.view) ? Mode.edit : Mode.view;
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2021
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package com.onlyoffice.integration.util.documentManagers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2021
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package com.onlyoffice.integration.util.documentManagers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2021
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package com.onlyoffice.integration.util.documentManagers;
|
||||
|
||||
import org.primeframework.jwt.Signer;
|
||||
|
||||
@ -18,8 +18,10 @@
|
||||
|
||||
package com.onlyoffice.integration.util.serviceConverter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentManager;
|
||||
import com.onlyoffice.integration.util.documentManagers.DocumentTokenManager;
|
||||
import com.onlyoffice.integration.util.fileUtilities.FileUtility;
|
||||
import com.onlyoffice.integration.util.objects.ConvertBody;
|
||||
import org.json.simple.JSONObject;
|
||||
@ -44,6 +46,9 @@ public class ServiceConverterImpl implements ServiceConverter
|
||||
@Autowired
|
||||
private DocumentManager documentManager;
|
||||
|
||||
@Autowired
|
||||
private DocumentTokenManager documentTokenManager;
|
||||
|
||||
@Autowired
|
||||
private FileUtility fileUtility;
|
||||
|
||||
@ -69,8 +74,13 @@ public class ServiceConverterImpl implements ServiceConverter
|
||||
}
|
||||
|
||||
private String postToServer(ConvertBody body, String headerToken){
|
||||
Gson gson = new Gson();
|
||||
String bodyString = gson.toJson(body);
|
||||
ObjectMapper objectMapper=new ObjectMapper();
|
||||
String bodyString= null;
|
||||
try {
|
||||
bodyString = objectMapper.writeValueAsString(body);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
URL url = null;
|
||||
java.net.HttpURLConnection connection = null;
|
||||
InputStream response = null;
|
||||
@ -87,7 +97,7 @@ public class ServiceConverterImpl implements ServiceConverter
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
connection.setConnectTimeout(convertTimeout);
|
||||
|
||||
if (documentManager.tokenEnabled())
|
||||
if (documentTokenManager.tokenEnabled())
|
||||
{
|
||||
connection.setRequestProperty(documentJwtHeader.equals("") ?
|
||||
"Authorization" : documentJwtHeader, "Bearer " + headerToken);
|
||||
@ -136,7 +146,7 @@ public class ServiceConverterImpl implements ServiceConverter
|
||||
body.setAsync(true);
|
||||
|
||||
String headerToken = "";
|
||||
if (documentManager.tokenEnabled())
|
||||
if (documentTokenManager.tokenEnabled())
|
||||
{
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("url", body.getUrl());
|
||||
@ -149,12 +159,12 @@ public class ServiceConverterImpl implements ServiceConverter
|
||||
map.put("async", body.getAsync());
|
||||
|
||||
// add token to the body if it is enabled
|
||||
String token = documentManager.createToken(map);
|
||||
String token = documentTokenManager.createToken(map);
|
||||
body.setToken(token);
|
||||
|
||||
Map<String, Object> payloadMap = new HashMap<String, Object>();
|
||||
payloadMap.put("payload", map); // create payload object
|
||||
headerToken = documentManager.createToken(payloadMap); // create header token
|
||||
headerToken = documentTokenManager.createToken(payloadMap); // create header token
|
||||
}
|
||||
|
||||
String jsonString = postToServer(body, headerToken);
|
||||
|
||||
@ -122,7 +122,7 @@
|
||||
var histArray = [[${model.GetHistory()}]];
|
||||
var history = histArray[0];
|
||||
var historyData = histArray[1];
|
||||
<!-- String usersForMentions = [[${usersForMentions}]];-->
|
||||
var usersForMentions = [[${usersForMentions}]];
|
||||
|
||||
if (history && historyData) {
|
||||
config.events['onRequestHistory'] = function () {
|
||||
@ -138,19 +138,19 @@
|
||||
};
|
||||
}
|
||||
|
||||
<!-- if(usersForMentions){-->
|
||||
<!-- config.events['onRequestUsers'] = function () {-->
|
||||
<!-- docEditor.setUsers({-->
|
||||
<!-- "users": usersForMentions-->
|
||||
<!-- });-->
|
||||
<!-- };-->
|
||||
<!-- config.events['onRequestSendNotify'] = function (event) {-->
|
||||
<!-- var actionLink = JSON.stringify(event.data.actionLink);-->
|
||||
<!-- console.log("onRequestSendNotify:");-->
|
||||
<!-- console.log(event.data);-->
|
||||
<!-- console.log("Link to comment: " + replaceActionLink(location.href, actionLink));-->
|
||||
<!-- };-->
|
||||
<!-- }-->
|
||||
if(usersForMentions){
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({
|
||||
"users": usersForMentions
|
||||
});
|
||||
};
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
var actionLink = JSON.stringify(event.data.actionLink);
|
||||
console.log("onRequestSendNotify:");
|
||||
console.log(event.data);
|
||||
console.log("Link to comment: " + replaceActionLink(location.href, actionLink));
|
||||
};
|
||||
}
|
||||
|
||||
var сonnectEditor = function () {
|
||||
docEditor = new DocsAPI.DocEditor("iframeEditor", config);
|
||||
|
||||
Reference in New Issue
Block a user