ソースを参照

最新onlyoffice后端

wangqiong 2 年 前
コミット
7c9681b236
共有100 個のファイルを変更した782 個の追加6039 個の削除を含む
  1. 33
    0
      .gitignore
  2. 127
    201
      LICENSE
  3. 313
    224
      README.md
  4. 0
    0
      file/8c969104e32f4efc9d83946ad5108ce2
  5. バイナリ
      file/a0f59131619d430fb72a146ca2477ff6.docx
  6. バイナリ
      jpg/QQ截图20230805221213.jpg
  7. バイナリ
      jpg/docx-pdf.jpg
  8. バイナリ
      jpg/edit.jpg
  9. バイナリ
      jpg/editppt.jpg
  10. バイナリ
      jpg/editxlsx.jpg
  11. バイナリ
      jpg/f.jpg
  12. バイナリ
      jpg/view.jpg
  13. バイナリ
      jpg/viewppt.jpg
  14. バイナリ
      jpg/viewxls.jpg
  15. バイナリ
      jpg/xlsx2pdf.jpg
  16. 3
    0
      plugins/externallistener/README.md
  17. 25
    0
      plugins/externallistener/config.json
  18. 28
    0
      plugins/externallistener/index.html
  19. バイナリ
      plugins/externallistener/resources/img/icon.png
  20. バイナリ
      plugins/externallistener/resources/img/icon@2x.png
  21. 103
    0
      plugins/externallistener/scripts/code.js
  22. 3
    0
      plugins/externallistener/translations/langs.json
  23. 3
    0
      plugins/externallistener/translations/zh-CN.json
  24. 144
    109
      pom.xml
  25. 0
    115
      src/main/java/com/onlyoffice/integration/ExampleData.java
  26. 0
    32
      src/main/java/com/onlyoffice/integration/IntegrationApplication.java
  27. 0
    87
      src/main/java/com/onlyoffice/integration/IntegrationConfiguration.java
  28. 0
    239
      src/main/java/com/onlyoffice/integration/controllers/EditorController.java
  29. 0
    624
      src/main/java/com/onlyoffice/integration/controllers/FileController.java
  30. 0
    147
      src/main/java/com/onlyoffice/integration/controllers/IndexController.java
  31. 0
    32
      src/main/java/com/onlyoffice/integration/documentserver/callbacks/Callback.java
  32. 0
    50
      src/main/java/com/onlyoffice/integration/documentserver/callbacks/CallbackHandler.java
  33. 0
    35
      src/main/java/com/onlyoffice/integration/documentserver/callbacks/Status.java
  34. 0
    59
      src/main/java/com/onlyoffice/integration/documentserver/callbacks/implementations/EditCallback.java
  35. 0
    50
      src/main/java/com/onlyoffice/integration/documentserver/callbacks/implementations/ForcesaveCallback.java
  36. 0
    50
      src/main/java/com/onlyoffice/integration/documentserver/callbacks/implementations/SaveCallback.java
  37. 0
    28
      src/main/java/com/onlyoffice/integration/documentserver/managers/callback/CallbackManager.java
  38. 0
    333
      src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java
  39. 0
    246
      src/main/java/com/onlyoffice/integration/documentserver/managers/document/DefaultDocumentManager.java
  40. 0
    42
      src/main/java/com/onlyoffice/integration/documentserver/managers/document/DocumentManager.java
  41. 0
    183
      src/main/java/com/onlyoffice/integration/documentserver/managers/history/DefaultHistoryManager.java
  42. 0
    26
      src/main/java/com/onlyoffice/integration/documentserver/managers/history/HistoryManager.java
  43. 0
    135
      src/main/java/com/onlyoffice/integration/documentserver/managers/jwt/DefaultJwtManager.java
  44. 0
    33
      src/main/java/com/onlyoffice/integration/documentserver/managers/jwt/JwtManager.java
  45. 0
    70
      src/main/java/com/onlyoffice/integration/documentserver/managers/template/SampleTemplateManager.java
  46. 0
    28
      src/main/java/com/onlyoffice/integration/documentserver/managers/template/TemplateManager.java
  47. 0
    24
      src/main/java/com/onlyoffice/integration/documentserver/models/AbstractModel.java
  48. 0
    53
      src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Customization.java
  49. 0
    40
      src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Embedded.java
  50. 0
    48
      src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Goback.java
  51. 0
    45
      src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Info.java
  52. 0
    38
      src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Logo.java
  53. 0
    32
      src/main/java/com/onlyoffice/integration/documentserver/models/enums/Action.java
  54. 0
    48
      src/main/java/com/onlyoffice/integration/documentserver/models/enums/ConvertErrorType.java
  55. 0
    25
      src/main/java/com/onlyoffice/integration/documentserver/models/enums/DocumentType.java
  56. 0
    24
      src/main/java/com/onlyoffice/integration/documentserver/models/enums/Mode.java
  57. 0
    24
      src/main/java/com/onlyoffice/integration/documentserver/models/enums/ToolbarDocked.java
  58. 0
    25
      src/main/java/com/onlyoffice/integration/documentserver/models/enums/Type.java
  59. 0
    41
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/CommentGroup.java
  60. 0
    49
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/Document.java
  61. 0
    59
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/EditorConfig.java
  62. 0
    44
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/FileModel.java
  63. 0
    55
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/Permission.java
  64. 0
    42
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/ReferenceData.java
  65. 0
    32
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/Template.java
  66. 0
    42
      src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/User.java
  67. 0
    23
      src/main/java/com/onlyoffice/integration/documentserver/serializers/FilterState.java
  68. 0
    38
      src/main/java/com/onlyoffice/integration/documentserver/serializers/SerializerFilter.java
  69. 0
    42
      src/main/java/com/onlyoffice/integration/documentserver/storage/FileStorageMutator.java
  70. 0
    31
      src/main/java/com/onlyoffice/integration/documentserver/storage/FileStoragePathBuilder.java
  71. 0
    392
      src/main/java/com/onlyoffice/integration/documentserver/storage/LocalFileStorage.java
  72. 0
    33
      src/main/java/com/onlyoffice/integration/documentserver/util/Constants.java
  73. 0
    36
      src/main/java/com/onlyoffice/integration/documentserver/util/Misc.java
  74. 0
    78
      src/main/java/com/onlyoffice/integration/documentserver/util/SSLUtils.java
  75. 0
    203
      src/main/java/com/onlyoffice/integration/documentserver/util/file/DefaultFileUtility.java
  76. 0
    41
      src/main/java/com/onlyoffice/integration/documentserver/util/file/FileUtility.java
  77. 0
    267
      src/main/java/com/onlyoffice/integration/documentserver/util/service/DefaultServiceConverter.java
  78. 0
    34
      src/main/java/com/onlyoffice/integration/documentserver/util/service/ServiceConverter.java
  79. 0
    33
      src/main/java/com/onlyoffice/integration/dto/Action.java
  80. 0
    31
      src/main/java/com/onlyoffice/integration/dto/ChangesHistory.java
  81. 0
    31
      src/main/java/com/onlyoffice/integration/dto/ChangesUser.java
  82. 0
    40
      src/main/java/com/onlyoffice/integration/dto/Convert.java
  83. 0
    33
      src/main/java/com/onlyoffice/integration/dto/ConvertedData.java
  84. 0
    36
      src/main/java/com/onlyoffice/integration/dto/Converter.java
  85. 0
    40
      src/main/java/com/onlyoffice/integration/dto/History.java
  86. 0
    31
      src/main/java/com/onlyoffice/integration/dto/Mentions.java
  87. 0
    46
      src/main/java/com/onlyoffice/integration/dto/Track.java
  88. 0
    41
      src/main/java/com/onlyoffice/integration/entities/AbstractEntity.java
  89. 0
    39
      src/main/java/com/onlyoffice/integration/entities/Group.java
  90. 0
    56
      src/main/java/com/onlyoffice/integration/entities/Permission.java
  91. 0
    48
      src/main/java/com/onlyoffice/integration/entities/User.java
  92. 0
    58
      src/main/java/com/onlyoffice/integration/mappers/AbstractMapper.java
  93. 0
    27
      src/main/java/com/onlyoffice/integration/mappers/Mapper.java
  94. 0
    69
      src/main/java/com/onlyoffice/integration/mappers/PermissionsMapper.java
  95. 0
    53
      src/main/java/com/onlyoffice/integration/mappers/UsersMapper.java
  96. 0
    28
      src/main/java/com/onlyoffice/integration/repositories/GroupRepository.java
  97. 0
    25
      src/main/java/com/onlyoffice/integration/repositories/PermissionRepository.java
  98. 0
    25
      src/main/java/com/onlyoffice/integration/repositories/UserRepository.java
  99. 0
    63
      src/main/java/com/onlyoffice/integration/services/GroupServices.java
  100. 0
    0
      src/main/java/com/onlyoffice/integration/services/PermissionServices.java

+ 33
- 0
.gitignore ファイルの表示

@@ -0,0 +1,33 @@
1
+HELP.md
2
+target/
3
+!.mvn/wrapper/maven-wrapper.jar
4
+!**/src/main/**/target/
5
+!**/src/test/**/target/
6
+
7
+### STS ###
8
+.apt_generated
9
+.classpath
10
+.factorypath
11
+.project
12
+.settings
13
+.springBeans
14
+.sts4-cache
15
+
16
+### IntelliJ IDEA ###
17
+.idea
18
+*.iws
19
+*.iml
20
+*.ipr
21
+
22
+### NetBeans ###
23
+/nbproject/private/
24
+/nbbuild/
25
+/dist/
26
+/nbdist/
27
+/.nb-gradle/
28
+build/
29
+!**/src/main/**/build/
30
+!**/src/test/**/build/
31
+
32
+### VS Code ###
33
+.vscode/

+ 127
- 201
LICENSE ファイルの表示

@@ -1,201 +1,127 @@
1
-                                 Apache License
2
-                           Version 2.0, January 2004
3
-                        http://www.apache.org/licenses/
4
-
5
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
-   1. Definitions.
8
-
9
-      "License" shall mean the terms and conditions for use, reproduction,
10
-      and distribution as defined by Sections 1 through 9 of this document.
11
-
12
-      "Licensor" shall mean the copyright owner or entity authorized by
13
-      the copyright owner that is granting the License.
14
-
15
-      "Legal Entity" shall mean the union of the acting entity and all
16
-      other entities that control, are controlled by, or are under common
17
-      control with that entity. For the purposes of this definition,
18
-      "control" means (i) the power, direct or indirect, to cause the
19
-      direction or management of such entity, whether by contract or
20
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
-      outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
-      "You" (or "Your") shall mean an individual or Legal Entity
24
-      exercising permissions granted by this License.
25
-
26
-      "Source" form shall mean the preferred form for making modifications,
27
-      including but not limited to software source code, documentation
28
-      source, and configuration files.
29
-
30
-      "Object" form shall mean any form resulting from mechanical
31
-      transformation or translation of a Source form, including but
32
-      not limited to compiled object code, generated documentation,
33
-      and conversions to other media types.
34
-
35
-      "Work" shall mean the work of authorship, whether in Source or
36
-      Object form, made available under the License, as indicated by a
37
-      copyright notice that is included in or attached to the work
38
-      (an example is provided in the Appendix below).
39
-
40
-      "Derivative Works" shall mean any work, whether in Source or Object
41
-      form, that is based on (or derived from) the Work and for which the
42
-      editorial revisions, annotations, elaborations, or other modifications
43
-      represent, as a whole, an original work of authorship. For the purposes
44
-      of this License, Derivative Works shall not include works that remain
45
-      separable from, or merely link (or bind by name) to the interfaces of,
46
-      the Work and Derivative Works thereof.
47
-
48
-      "Contribution" shall mean any work of authorship, including
49
-      the original version of the Work and any modifications or additions
50
-      to that Work or Derivative Works thereof, that is intentionally
51
-      submitted to Licensor for inclusion in the Work by the copyright owner
52
-      or by an individual or Legal Entity authorized to submit on behalf of
53
-      the copyright owner. For the purposes of this definition, "submitted"
54
-      means any form of electronic, verbal, or written communication sent
55
-      to the Licensor or its representatives, including but not limited to
56
-      communication on electronic mailing lists, source code control systems,
57
-      and issue tracking systems that are managed by, or on behalf of, the
58
-      Licensor for the purpose of discussing and improving the Work, but
59
-      excluding communication that is conspicuously marked or otherwise
60
-      designated in writing by the copyright owner as "Not a Contribution."
61
-
62
-      "Contributor" shall mean Licensor and any individual or Legal Entity
63
-      on behalf of whom a Contribution has been received by Licensor and
64
-      subsequently incorporated within the Work.
65
-
66
-   2. Grant of Copyright License. Subject to the terms and conditions of
67
-      this License, each Contributor hereby grants to You a perpetual,
68
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
-      copyright license to reproduce, prepare Derivative Works of,
70
-      publicly display, publicly perform, sublicense, and distribute the
71
-      Work and such Derivative Works in Source or Object form.
72
-
73
-   3. Grant of Patent License. Subject to the terms and conditions of
74
-      this License, each Contributor hereby grants to You a perpetual,
75
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
-      (except as stated in this section) patent license to make, have made,
77
-      use, offer to sell, sell, import, and otherwise transfer the Work,
78
-      where such license applies only to those patent claims licensable
79
-      by such Contributor that are necessarily infringed by their
80
-      Contribution(s) alone or by combination of their Contribution(s)
81
-      with the Work to which such Contribution(s) was submitted. If You
82
-      institute patent litigation against any entity (including a
83
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
84
-      or a Contribution incorporated within the Work constitutes direct
85
-      or contributory patent infringement, then any patent licenses
86
-      granted to You under this License for that Work shall terminate
87
-      as of the date such litigation is filed.
88
-
89
-   4. Redistribution. You may reproduce and distribute copies of the
90
-      Work or Derivative Works thereof in any medium, with or without
91
-      modifications, and in Source or Object form, provided that You
92
-      meet the following conditions:
93
-
94
-      (a) You must give any other recipients of the Work or
95
-          Derivative Works a copy of this License; and
96
-
97
-      (b) You must cause any modified files to carry prominent notices
98
-          stating that You changed the files; and
99
-
100
-      (c) You must retain, in the Source form of any Derivative Works
101
-          that You distribute, all copyright, patent, trademark, and
102
-          attribution notices from the Source form of the Work,
103
-          excluding those notices that do not pertain to any part of
104
-          the Derivative Works; and
105
-
106
-      (d) If the Work includes a "NOTICE" text file as part of its
107
-          distribution, then any Derivative Works that You distribute must
108
-          include a readable copy of the attribution notices contained
109
-          within such NOTICE file, excluding those notices that do not
110
-          pertain to any part of the Derivative Works, in at least one
111
-          of the following places: within a NOTICE text file distributed
112
-          as part of the Derivative Works; within the Source form or
113
-          documentation, if provided along with the Derivative Works; or,
114
-          within a display generated by the Derivative Works, if and
115
-          wherever such third-party notices normally appear. The contents
116
-          of the NOTICE file are for informational purposes only and
117
-          do not modify the License. You may add Your own attribution
118
-          notices within Derivative Works that You distribute, alongside
119
-          or as an addendum to the NOTICE text from the Work, provided
120
-          that such additional attribution notices cannot be construed
121
-          as modifying the License.
122
-
123
-      You may add Your own copyright statement to Your modifications and
124
-      may provide additional or different license terms and conditions
125
-      for use, reproduction, or distribution of Your modifications, or
126
-      for any such Derivative Works as a whole, provided Your use,
127
-      reproduction, and distribution of the Work otherwise complies with
128
-      the conditions stated in this License.
129
-
130
-   5. Submission of Contributions. Unless You explicitly state otherwise,
131
-      any Contribution intentionally submitted for inclusion in the Work
132
-      by You to the Licensor shall be under the terms and conditions of
133
-      this License, without any additional terms or conditions.
134
-      Notwithstanding the above, nothing herein shall supersede or modify
135
-      the terms of any separate license agreement you may have executed
136
-      with Licensor regarding such Contributions.
137
-
138
-   6. Trademarks. This License does not grant permission to use the trade
139
-      names, trademarks, service marks, or product names of the Licensor,
140
-      except as required for reasonable and customary use in describing the
141
-      origin of the Work and reproducing the content of the NOTICE file.
142
-
143
-   7. Disclaimer of Warranty. Unless required by applicable law or
144
-      agreed to in writing, Licensor provides the Work (and each
145
-      Contributor provides its Contributions) on an "AS IS" BASIS,
146
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
-      implied, including, without limitation, any warranties or conditions
148
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
-      PARTICULAR PURPOSE. You are solely responsible for determining the
150
-      appropriateness of using or redistributing the Work and assume any
151
-      risks associated with Your exercise of permissions under this License.
152
-
153
-   8. Limitation of Liability. In no event and under no legal theory,
154
-      whether in tort (including negligence), contract, or otherwise,
155
-      unless required by applicable law (such as deliberate and grossly
156
-      negligent acts) or agreed to in writing, shall any Contributor be
157
-      liable to You for damages, including any direct, indirect, special,
158
-      incidental, or consequential damages of any character arising as a
159
-      result of this License or out of the use or inability to use the
160
-      Work (including but not limited to damages for loss of goodwill,
161
-      work stoppage, computer failure or malfunction, or any and all
162
-      other commercial damages or losses), even if such Contributor
163
-      has been advised of the possibility of such damages.
164
-
165
-   9. Accepting Warranty or Additional Liability. While redistributing
166
-      the Work or Derivative Works thereof, You may choose to offer,
167
-      and charge a fee for, acceptance of support, warranty, indemnity,
168
-      or other liability obligations and/or rights consistent with this
169
-      License. However, in accepting such obligations, You may act only
170
-      on Your own behalf and on Your sole responsibility, not on behalf
171
-      of any other Contributor, and only if You agree to indemnify,
172
-      defend, and hold each Contributor harmless for any liability
173
-      incurred by, or claims asserted against, such Contributor by reason
174
-      of your accepting any such warranty or additional liability.
175
-
176
-   END OF TERMS AND CONDITIONS
177
-
178
-   APPENDIX: How to apply the Apache License to your work.
179
-
180
-      To apply the Apache License to your work, attach the following
181
-      boilerplate notice, with the fields enclosed by brackets "[]"
182
-      replaced with your own identifying information. (Don't include
183
-      the brackets!)  The text should be enclosed in the appropriate
184
-      comment syntax for the file format. We also recommend that a
185
-      file or class name and description of purpose be included on the
186
-      same "printed page" as the copyright notice for easier
187
-      identification within third-party archives.
188
-
189
-   Copyright [yyyy] [name of copyright owner]
190
-
191
-   Licensed under the Apache License, Version 2.0 (the "License");
192
-   you may not use this file except in compliance with the License.
193
-   You may obtain a copy of the License at
194
-
195
-       http://www.apache.org/licenses/LICENSE-2.0
196
-
197
-   Unless required by applicable law or agreed to in writing, software
198
-   distributed under the License is distributed on an "AS IS" BASIS,
199
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
-   See the License for the specific language governing permissions and
201
-   limitations under the License.
1
+                     木兰宽松许可证, 第2版
2
+
3
+   木兰宽松许可证, 第2版 
4
+   2020年1月 http://license.coscl.org.cn/MulanPSL2
5
+
6
+
7
+   您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
8
+
9
+   0. 定义
10
+
11
+      “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
12
+
13
+      “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
14
+
15
+      “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
16
+
17
+      “法人实体”是指提交贡献的机构及其“关联实体”。
18
+
19
+      “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
20
+
21
+   1. 授予版权许可
22
+
23
+      每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
24
+
25
+   2. 授予专利许可
26
+
27
+      每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
28
+
29
+   3. 无商标许可
30
+
31
+      “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
32
+
33
+   4. 分发限制
34
+
35
+      您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
36
+
37
+   5. 免责声明与责任限制
38
+
39
+      “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 
40
+
41
+   6. 语言
42
+      “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
43
+
44
+   条款结束 
45
+
46
+   如何将木兰宽松许可证,第2版,应用到您的软件
47
+   
48
+   如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
49
+
50
+      1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
51
+
52
+      2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
53
+
54
+      3, 请将如下声明文本放入每个源文件的头部注释中。
55
+
56
+   Copyright (c) [Year] [name of copyright holder]
57
+   [Software Name] is licensed under Mulan PSL v2.
58
+   You can use this software according to the terms and conditions of the Mulan PSL v2. 
59
+   You may obtain a copy of Mulan PSL v2 at:
60
+            http://license.coscl.org.cn/MulanPSL2 
61
+   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
62
+   See the Mulan PSL v2 for more details.  
63
+
64
+
65
+                     Mulan Permissive Software License,Version 2
66
+
67
+   Mulan Permissive Software License,Version 2 (Mulan PSL v2)
68
+   January 2020 http://license.coscl.org.cn/MulanPSL2
69
+
70
+   Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: 
71
+   
72
+   0. Definition
73
+   
74
+      Software means the program and related documents which are licensed under this License and comprise all Contribution(s). 
75
+   
76
+      Contribution means the copyrightable work licensed by a particular Contributor under this License.
77
+   
78
+      Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
79
+   
80
+      Legal Entity means the entity making a Contribution and all its Affiliates.
81
+   
82
+      Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
83
+
84
+   1. Grant of Copyright License
85
+
86
+      Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
87
+
88
+   2. Grant of Patent License 
89
+
90
+      Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
91
+
92
+   3. No Trademark License
93
+
94
+      No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
95
+
96
+   4. Distribution Restriction
97
+
98
+      You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
99
+
100
+   5. Disclaimer of Warranty and Limitation of Liability
101
+
102
+      THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
103
+
104
+   6. Language
105
+
106
+      THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
107
+
108
+   END OF THE TERMS AND CONDITIONS
109
+
110
+   How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
111
+
112
+      To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
113
+
114
+      i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; 
115
+
116
+      ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
117
+
118
+      iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
119
+
120
+
121
+   Copyright (c) [Year] [name of copyright holder]
122
+   [Software Name] is licensed under Mulan PSL v2.
123
+   You can use this software according to the terms and conditions of the Mulan PSL v2. 
124
+   You may obtain a copy of Mulan PSL v2 at:
125
+               http://license.coscl.org.cn/MulanPSL2 
126
+   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
127
+   See the Mulan PSL v2 for more details.  

+ 313
- 224
README.md ファイルの表示

@@ -1,247 +1,336 @@
1
-## Overview
2
-
3
-This example will help you integrate ONLYOFFICE Docs into your web application written in Java 
4
-with Spring Boot.
5
-
6
-Spring Boot has a lot of functionality, but its most significant features are: dependency management, 
7
-auto-configuration, and built-in servlet containers.
8
-
9
-**Please note**: It is intended for testing purposes and demonstrating functionality of the editors. Do NOT use this integration example on your own server without proper code modifications! In case you enabled the test example, disable it before going for production.
10
-
11
-## For Windows
12
-
13
-### Step 1. Install ONLYOFFICE Docs
14
-
15
-Download and install ONLYOFFICE Docs (packaged as Document Server).
16
-
17
-See the detailed guide to learn how to install Document Server [for Windows](https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx). 
18
-
19
-### Step 2. Download the Java code for the editors integration
20
-
21
-Download the [Java-Spring example](https://api.onlyoffice.com/editors/demopreview) from our site.
22
-
23
-To connect the editors to your website, specify the path to the editors installation, server port and the path to the storage folder in the *\src\main\resources\application.properties* file:
24
-
25
-```
26
- files.storage=
27
- server.port=port
28
- files.docservice.url.site=https://documentserver/
29
-```
30
-
31
-where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path. For example, *D:\\\\folder*. Please note that on Windows OS the double backslash must be used as a separator.
32
-
33
-If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) it the *\src\main\resources\editor.html* file.
34
-
35
-### Step 3. Install the prerequisites
36
-To run the Java example code, install the Java version 11 appropriate for your OS and framework  **Apache Maven**:
37
-
38
-* Java (download from [the Oracle official website](https://www.oracle.com/ru/java/technologies/javase-jdk11-downloads.html));
39
-* Apache Maven (download from [the official website](https://maven.apache.org/download.cgi)).
40
-
41
-### Step 4. Set environment variables
42
-
43
-1. After you have installed Java on Windows, set the **JAVA_HOME** environment variable to point to the Java installation directory.
44
-
45
-	Find out where Java is installed. If you didn't change the path during installation, it will be something like this:
46
-
47
-	```
48
-	C:\Program Files\Java\jdk11
49
-	```
50
-
51
-	In **Windows 7** right click **My Computer** and select **Properties**, then click **Advanced**.
52
-
53
-	In **Windows 8** go to **Control Panel** -> **System** -> **Advanced System Settings**.
54
-
55
-	Click the **Environment Variables** button.
56
-
57
-	Under **System Variables**, click **New**.
58
-
59
-	In the **Variable Name** field, enter **JAVA_HOME** if you installed the **JDK** (Java Development Kit) or **JRE_HOME** if you installed the **JRE** (Java Runtime Environment).
60
-
61
-	In the **Variable Value** field, enter your **JDK** or **JRE** installation path, for example C:\Program Files\Java\jdk11.
62
-
63
-	Check if the variable created successfully by **echo** command in the **Command Prompt**:
64
-
65
-	```
66
-	echo %JAVA_HOME%
67
-	```
68
-
69
-2. Set the **MAVEN_HOME** environment variable:
70
-
71
-    Unzip the downloaded archive with the maven to any directory, it will be something like this:
72
-
73
-    ```
74
-    C:\apache-maven-3.8.1
75
-   ```
76
-    In **Windows 7** right click **My Computer** and select **Properties**, then click **Advanced**.
77
-
78
-	In **Windows 8** go to **Control Panel** -> **System** -> **Advanced System Settings**.
79
-
80
-	Click the **Environment Variables** button.
81
-
82
-	Under **System Variables**, click **New**.
83
-
84
-	In the **Variable Name** field, enter **MAVEN_HOME**.
85
-
86
-	In the **Variable Value** field, enter your **JDK** or **JRE** installation path, for example C:\apache-maven-3.8.1.
87
-
88
-	Add C:\apache-maven-3.8.1\bin to the PATH system variable:
89
-	In system variables, find PATH, clicks on the Edit... button. In “Edit environment variable” dialog, clicks on the New button and add this C:\apache-maven-3.8.1\bin
90
-
91
-	Check if the variable created successfully by **echo** command in the **Command Prompt**:
92
-
93
-	```
94
-	echo %MAVEN_HOME%
95
-	```
96
-
97
-
98
-### Step 5. Start application with Maven
99
-
100
-1. Open the console and go the java-spring folder using the **cd** command, for example:
101
-	```
102
-	cd C:\Program Files\document-server-integration\web\documentserver-example\java-spring
103
-	```
104
-2. In the open console enter the following commands:
105
-	```
106
-	mvn clean
107
-	mvn package
108
-	mvn spring-boot:run
109
-	```
110
-3. Open your browser using **server.address** and **server.port**:
111
- 
112
-     ```
113
-     http://server.address:server.port/
114
-     ```
115
-
116
-### Step 6. Check accessibility
117
-
118
- In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files. 
119
-
120
-Make sure that the Document Server has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files.
121
-
122
-## For Linux
123
-### Step 1. Install ONLYOFFICE Docs
124
-
125
-Download and install ONLYOFFICE Docs (packaged as Document Server). 
126
-
127
-See the detailed guide to learn how to install Document Server [for Linux](https://helpcenter.onlyoffice.com/installation/docs-developer-install-ubuntu.aspx). 
128
-
129
-### Step 2. Install the prerequisites and run the website with the editors
130
-
131
-1. Install **Java**:
132
-
133
-    ```
134
-    sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java11-installer
135
-    ```
136
-
137
-2. Download the archive with the Java-Spring example and unpack the archive or clone git repository:
138
-
139
-    a) archive with Java-Spring:
140
-
141
-    ```
142
-    wget https://api.onlyoffice.com/app_data/editor/Java%20Spring%20Example.zip
143
-    ```
144
-    
145
-    ```
146
-    unzip Java\ Spring\ Example.zip
147
-    ```
148
-    b) git repository:
149
-    ```
150
-    git clone https://github.com/ONLYOFFICE/document-server-integration.git
151
-    ```
152
-
153
-
154
-3. Change the current directory for the project directory:
155
-
156
-    a) from archive
157
-
158
-    ```
159
-   cd Java\ Spring\ Example/
160
-   ```
161
-   b) from git repository 
162
-    ```
163
-    cd document-server-integration/web/documentserver-example/java-spring
164
-    ```
165
-4. Edit the *application.properties* configuration file. Specify the name of your local server with the ONLYOFFICE Document Server installed.
166
-
167
-    ```
168
-    nano src/main/resources/application.properties
169
-    ```
170
-
171
-	Edit the following lines:
172 1
 
2
+# Spring-Boot-onlyOffice(集成onlyOffice服务)
3
+
4
+springboot集成onlyOffice的实现。在参考网络上的资料结合自身实际情况总结,让集成oo方便快捷。 封装了oo服务的API和统一了配置。
5
+- 在线编辑,查看,转换
6
+
7
+
8
+* onlyOffice.yml配置文件
9
+* 如果解决了你地方问题,请给个 **star** 
10
+-----------------------------------
11
+# 对外使用的java类 —— OnlyServiceAPI
12
+## 核心方法
13
+
14
+<table>
15
+    <thead>
16
+        <tr>
17
+            <th>方法名称</th>
18
+            <th>参数</th>
19
+            <th>参数说明</th>
20
+            <th>返回值</th>
21
+        </tr>
22
+    </thead>
23
+    <tbody>
24
+        <tr>
25
+            <td rowspan="3">openDocument()</td>
26
+            <td> Map&lt;String,Object&gt; map</td>
27
+            <td> 文件数据信息<br>
28
+                {<br>
29
+                    必填 fileId<br>
30
+                    必填 fileName<br>
31
+                    必填 fileType<br>
32
+                    必填 fileSize<br>
33
+                    可用携带其它值<br>
34
+                }
35
+            </td>
36
+            <td rowspan="3">
37
+                <pre>
38
+{
39
+"editorConfig": {
40
+    "mode": "edit",
41
+    "customization": {
42
+        "feedback": {
43
+            "visible": false
44
+        },
45
+        "help": false,
46
+        "goback": {
47
+            "blank": false
48
+        },
49
+        "macros": false,
50
+        "autosave": false,
51
+        "comments": false,
52
+        "review": {},
53
+        "hideRightMenu": true,
54
+        "anonymous": {
55
+            "request": false
56
+        },
57
+        "forcesave": true,
58
+        "logo": {},
59
+        "hideNotes": true
60
+    },
61
+    "plugins": {
62
+        "pluginsData": [],
63
+        "autostart": []
64
+    },
65
+    "callbackUrl": "http://172.31.240.1:9090/onlyOffice/save",
66
+    "lang": "zh-CN",
67
+    "user": {
68
+        "name": "TongHuic7bba5",
69
+        "id": "c7bba5"
70
+    }
71
+  },
72
+"docServiceApiUrl": "http://172.31.240.1:8886/web-apps/apps/api/documents/api.js",
73
+"documentType": "word",
74
+"document": {
75
+    "permissions": {
76
+        "edit": true,
77
+        "chat": false,
78
+        "review": false
79
+    },
80
+    "title": "fdfs.docx",
81
+    "fileType": "docx",
82
+    "key": "63f560ec03a94654b10cd4fdeebec05a",
83
+    "url": "http://172.31.240.1:9090/download/09cee8767dd3476280fa865bacfaf213",
84
+    "info": {
85
+        "sharingSettings": [{
86
+            "isLink": true,
87
+            "permissions": ["Full Access"],
88
+            "user": "TongHuic7bba5"
89
+        }],
90
+        "created": "2023-08-05 21:38:25"
91
+    }
92
+},
93
+"type": "desktop",
94
+"token": ""
95
+}</pre>
96
+            </td>
97
+        </tr>
98
+        <tr>
99
+            <td>String mode</td>
100
+            <td>打开方式  <br>edit<br>view</td>
101
+        </tr>
102
+        <tr>
103
+            <td>boolean collaborativeEditing</td>
104
+            <td>是否协同编辑</td>
105
+        </tr>
106
+        <tr>
107
+            <td>handlerStatus()</td>
108
+            <td>JSONObject jsonObject</td>
109
+            <td>onlyOffice 回调传来的值。<br>https://api.onlyoffice.com/editors/callback</td>
110
+            <td></td>
111
+        </tr>
112
+        <tr>
113
+            <td rowspan="2">save():触发保存回调。</td>
114
+            <td>String key</td>
115
+            <td>是openDocument()返回值中的key</td>
116
+            <td rowspan="2">String : 提示信息</td>
117
+        </tr>
118
+        <tr>   
119
+            <td>String userId</td>
120
+            <td>用户Id</td>
121
+        </tr>
122
+        <tr>
123
+            <td rowspan="5">converted()</td>
124
+            <td>String filetype</td>
125
+            <td>文件类型</td>
126
+            <td rowspan="5">转换后的文件下载地址</td>
127
+        </tr>
128
+        <tr>
129
+            <td>String fileId</td>
130
+            <td>文件Id</td>
131
+        </tr>
132
+        <tr>
133
+            <td>String outputtype</td>
134
+            <td>转化类型</td>
135
+        </tr>
136
+        <tr>
137
+            <td>String title</td>
138
+            <td>转换后的文件名称</td>
139
+        </tr>
140
+        <tr>
141
+            <td>String password</td>
142
+            <td>文档密码</td>
143
+        </tr>
144
+    </tbody>
145
+</table>
146
+
147
+**注意:**
148
+ * 外部触发保存操作,save()方法。
149
+ * `autosave`/`forcesave` 参数为默认值时有效
150
+ * 修改文件后,没有执行回调方法。在点击保存后执行回调
151
+
152
+![](jpg/f.jpg)
153
+
154
+
155
+快速使用
156
+-----------------------------------
157
+
158
+- 必须的依赖
159
+
160
+``` pom
161
+    <dependency>
162
+        <groupId>org.springframework.boot</groupId>
163
+        <artifactId>spring-boot-starter-data-redis</artifactId>
164
+    </dependency>
165
+    <dependency>
166
+        <groupId>org.projectlombok</groupId>
167
+        <artifactId>lombok</artifactId>
168
+        <optional>true</optional>
169
+    </dependency>
170
+    <dependency>
171
+        <groupId>com.alibaba</groupId>
172
+        <artifactId>fastjson</artifactId>
173
+        <version>2.0.25</version>
174
+    </dependency>
175
+    <dependency>
176
+        <groupId>cn.hutool</groupId>
177
+        <artifactId>hutool-all</artifactId>
178
+        <version>5.8.16</version>
179
+    </dependency>
180
+    <dependency>
181
+        <groupId>com.inversoft</groupId>
182
+        <artifactId>prime-jwt</artifactId>
183
+        <version>1.3.1</version>
184
+    </dependency>
185
+    <dependency>
186
+        <groupId>org.apache.commons</groupId>
187
+        <artifactId>commons-pool2</artifactId>
188
+    </dependency>
189
+``` 
190
+
191
+- 定义关键接口(oo服务回调使用) `重要`
192
+  
193
+    1.保存接口
173 194
     ```
174
-    files.storage=
175
-    server.port=port
176
-    files.docservice.url.site=https://documentserver/
195
+        参考:demo/controller/IndexController.saveFile()
196
+        对应配置文件参数:oo.call-back-url
197
+        回调状态
198
+          0 - 找不到具有密钥标识符的文档
199
+          1 - 正在编辑文档(打开文件回调)
200
+          2 - 文档已准备好保存
201
+          3 - 发生文档保存错误
202
+          4 - 不作任何更改就关闭文档(关闭回调)
203
+          6 - 正在编辑文档,但保存当前文档状态(保存回调)
204
+          7 - 强制保存文档时发生错误
177 205
     ```
178 206
 
179
-	where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path.
180
-   
181
-
182
-5. Install **Maven**:
183
-
207
+    2.下载文件地址
184 208
     ```
185
-    sudo apt-get install maven
209
+        参考:demo/controller/IndexController.download()
210
+        对应配置文件参数:oo.download-file
211
+        对应openDocument()方法返回值中的 document.url
212
+        打开文件后oo服务要下载对应的文件
186 213
     ```
187
-    
188
-6. Build:
189
-
214
+- 实现SaveFileProcessor类
190 215
     ```
191
-    mvn package
216
+    参考:demo.service.DemoService
192 217
     ```
218
+    <table>
219
+        <thead>
220
+            <tr>   
221
+                <th> 方法名称 </th>
222
+                <th> 方法说明 </th>
223
+                <th> 参数 </th>
224
+                <th> 参数说明 </th>
225
+                <th> 返回值 </th>
226
+            </tr>
227
+        </thead>
228
+        <tbody>
229
+            <tr>
230
+                <td rowspan="3">saveBeforeInitialization()</td>
231
+                <td rowspan="3">保存前置方法</td>
232
+                <td>Map&lt;String, Object&gt; map</td>
233
+                <td>在openDocument()方法中传入的文件数据信息</td>
234
+                <td rowspan="3"></td>
235
+            </tr>
236
+            <tr>
237
+                <td>byte[] bytes</td>
238
+                <td>文件二进制数据</td>
239
+            </tr>
240
+            <tr>
241
+                <td>String fileExtension</td>
242
+                <td>文件后缀</td>
243
+            </tr>
244
+            <tr>
245
+                <td rowspan="4">save()</td>
246
+                <td rowspan="4">保存方法,实现自己的保存逻辑</td>
247
+                <td>Map&lt;String, Object&gt; map</td>
248
+                <td>在openDocument()方法中传入的文件数据信息</td>
249
+                <td rowspan="4">Map&lt;String, Object&gt; 更新内存中的信息</td>
250
+            </tr>
251
+            <tr>
252
+                <td>byte[] bytes</td>
253
+                <td>文件二进制数据</td>
254
+            </tr>
255
+            <tr>
256
+                <td>byte[] changes</td>
257
+                <td>当前文件和保存之前文件的区别。changes.zip</td>
258
+            </tr>
259
+            <tr>
260
+                <td>String key</td>
261
+                <td>是openDocument()返回值中的key</td>
262
+            </tr>
263
+            <tr>
264
+                <td rowspan="3">saveAfterInitialization()</td>
265
+                <td rowspan="3">保存后置方法</td>
266
+                <td>Map&lt;String, Object&gt; map</td>
267
+                <td>在openDocument()方法中传入的文件数据信息</td>
268
+                <td rowspan="3"></td>
269
+            </tr>
270
+            <tr>
271
+                <td>byte[] bytes</td>
272
+                <td>文件二进制数据</td>
273
+            </tr>
274
+            <tr>
275
+                <td>String fileExtension</td>
276
+                <td>文件后缀</td>
277
+            </tr>
278
+        </tbody>
279
+    </table>
280
+
281
+
282
+## 更新记录
283
+
284
+- [x] 修复关闭文件后快速再次打开该文件后,保存时报错的bug 2023/11/10
285
+- [x] 修复内存文件信息在保存后没有修改的bug 2023/10/23
286
+- [x] 实现和编辑器的数据通信 2023/9/9 (更新链接)
287
+  https://blog.xenosp.cn/posts/87468caf/
288
+- [x] 修复文件转pdf时只有第一页的bug 2023/8/13
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+-----------------------------------
297
+
298
+
299
+# 页面集成
300
+### html
301
+```
302
+参考 onlyOffice.html
303
+style.js 中的openDocument()
304
+```
305
+### vue
306
+```
307
+参考 onlyOffice.vue
308
+```
309
+-----------------------------------
193 310
 
194
- 7. Start Java-Spring example:
195
-     ```
196
-     ./mvnw spring-boot:run
197
-     ```
198
- 8. Open your browser using **server.address** and **server.port**:
199
-
200
-     ```
201
-     http://server.address:server.port/
202
-     ```
203
-  
311
+![](jpg/QQ截图20230805221213.jpg)
312
+### 编辑
204 313
 
205
-### Step 3. Check accessibility
314
+![](jpg/edit.jpg)
315
+![](jpg/editxlsx.jpg)
316
+![](jpg/editppt.jpg)
317
+### 查看
206 318
 
207
-In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files. 
319
+![](jpg/view.jpg)
320
+![](jpg/viewxls.jpg)
321
+![](jpg/viewppt.jpg)
322
+### 文件转换
323
+![](jpg/docx-pdf.jpg)
324
+![](jpg/xlsx2pdf.jpg)
208 325
 
209
-Make sure that the Document Server has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files.
210 326
 
211
-##  For Docker
212 327
 
213
-1. Edit the *application.properties* configuration file. Specify the name of your local server with the ONLYOFFICE Document Server installed ([installation instructions](https://helpcenter.onlyoffice.com/installation/docs-developer-install-docker.aspx)).
214 328
 
215
-	```
216
-	nano src/main/resources/application.properties
217
-	```
218
-	
219
-2. Edit the following lines:
220 329
 
221
-   ```
222
-   files.storage=
223
-   server.port=port
224
-   files.docservice.url.site=https://documentserver/
225
-   ```
226 330
 
227
-    where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path.
228 331
 
229
-3. Run the next command in the java example directory:
230 332
 
231
-	```
232
-	docker-compose up
233
-	```
234
-4. Open your browser using **server.address** and **server.port**:
235 333
 
236
-      ```
237
-      http://server.address:server.port/
238
-      ```
239 334
 
240
-## Important security info
241 335
 
242
-Please keep in mind the following security aspects when you are using test examples:
243 336
 
244
-* There is no protection of the storage from unauthorized access since there is no need for authorization.
245
-* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
246
-* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
247
-* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.

+ 0
- 0
file/8c969104e32f4efc9d83946ad5108ce2 ファイルの表示


バイナリ
file/a0f59131619d430fb72a146ca2477ff6.docx ファイルの表示


バイナリ
jpg/QQ截图20230805221213.jpg ファイルの表示


バイナリ
jpg/docx-pdf.jpg ファイルの表示


バイナリ
jpg/edit.jpg ファイルの表示


バイナリ
jpg/editppt.jpg ファイルの表示


バイナリ
jpg/editxlsx.jpg ファイルの表示


バイナリ
jpg/f.jpg ファイルの表示


バイナリ
jpg/view.jpg ファイルの表示


バイナリ
jpg/viewppt.jpg ファイルの表示


バイナリ
jpg/viewxls.jpg ファイルの表示


バイナリ
jpg/xlsx2pdf.jpg ファイルの表示


+ 3
- 0
plugins/externallistener/README.md ファイルの表示

@@ -0,0 +1,3 @@
1
+## Overview
2
+
3
+(Linux服务器安装好)把当前文件夹放到路径: /var/www/onlyoffice/documentserver/sdkjs-plugins

+ 25
- 0
plugins/externallistener/config.json ファイルの表示

@@ -0,0 +1,25 @@
1
+{
2
+    "name"       : "Listener",
3
+    "guid"       : "asc.{A8705DEE-7544-4C33-B3D5-168406D92F72}",
4
+    "baseUrl"    : "",
5
+    "variations" : [
6
+        {
7
+            "description"         : "Listener",
8
+            "url"                 : "index.html",
9
+            "icons"               : ["resources/img/icon.png", "resources/img/icon@2x.png"],
10
+            "isViewer"            : false,
11
+            "EditorsSupport"      : ["word", "cell", "slide"],
12
+            "isVisual"            : false,
13
+            "isModal"             : true,
14
+            "isInsideMode"        : false,
15
+            "isSystem"            : true,
16
+            "initDataType"        : "none",
17
+            "initData"            : "",
18
+            "isUpdateOleOnResize" : true,
19
+            "buttons"             : [],
20
+            "events"              : [
21
+                "onExternalPluginMessage"
22
+            ]
23
+        }
24
+    ]
25
+}

+ 28
- 0
plugins/externallistener/index.html ファイルの表示

@@ -0,0 +1,28 @@
1
+<!--
2
+ (c) Copyright Ascensio System SIA 2020
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+     http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ -->
16
+<!DOCTYPE html>
17
+<html>
18
+<head>
19
+    <meta charset="UTF-8" />
20
+    <title>Listener</title>
21
+    <script type="text/javascript" src="../v1/plugins.js"></script>
22
+    <script type="text/javascript" src="../v1/plugins-ui.js"></script>
23
+    <link rel="stylesheet" href="../v1/plugins.css">
24
+    <script type="text/javascript" src="scripts/code.js"></script>
25
+</head>
26
+<body>
27
+</body>
28
+</html>

バイナリ
plugins/externallistener/resources/img/icon.png ファイルの表示


バイナリ
plugins/externallistener/resources/img/icon@2x.png ファイルの表示


+ 103
- 0
plugins/externallistener/scripts/code.js ファイルの表示

@@ -0,0 +1,103 @@
1
+/**
2
+ *
3
+ * (c) Copyright Ascensio System SIA 2020
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ *     http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+(function(window, undefined){
19
+
20
+	window.Asc.plugin.init = function() {
21
+		console.log("插件初始化")
22
+
23
+		// none
24
+		window.parent.Common.Gateway.on('internalcommand', function(data){
25
+			console.log(data); // 接受到123参数console.log(data.data); // 接受到321参数
26
+			var data_ = data.data
27
+			switch (data.command){
28
+				case "insertText":
29
+					let text = "${"+data_.text+"}"
30
+					window.Asc.plugin.executeMethod ("PasteText", [text]);
31
+					if(window.Asc.plugin.info.editorType == 'cell'){
32
+						CorrectText('insertText')
33
+					}
34
+					break;
35
+				case 'getText':
36
+					CorrectText('getText')
37
+					break
38
+			}
39
+		});
40
+
41
+		var _info = window.Asc.plugin.info;
42
+		var userName =_info.userName
43
+		var userId = _info.userId
44
+
45
+		function CorrectText (command) {
46
+			let data = {
47
+				command:command,
48
+				text:""
49
+			}
50
+			switch (window.Asc.plugin.info.editorType) {
51
+				case 'word':
52
+				case 'slide': {
53
+					window.Asc.plugin.executeMethod ("GetSelectedText", [{"Numbering": false, "Math": false, "TableCellSeparator": '\n', "ParaSeparator": '\n', "TabSymbol": String.fromCharCode(9)}], function (e) {
54
+						let text = e.trim()
55
+						data.text = text
56
+						window.parent.parent.postMessage(JSON.stringify(data),'*');
57
+					});
58
+					break;
59
+				}
60
+				case 'cell': {
61
+					Asc.scope.command = command;
62
+					window.Asc.plugin.callCommand (function () {
63
+						var oWorksheet = Api.GetActiveSheet();
64
+						var oActiveCell = oWorksheet.GetActiveCell();
65
+						let str = oActiveCell.Text
66
+						if(str.indexOf("${") != -1){
67
+							str = str.substring(2,str.length-1)
68
+						}
69
+						let data = {
70
+							command:Asc.scope.command,
71
+							sheetName:oWorksheet.Name,
72
+							text:str,
73
+							x:oActiveCell.Row,
74
+							y:oActiveCell.Col
75
+						}
76
+
77
+						localStorage.setItem('dataInfo', JSON.stringify(data))
78
+					}, false,false,function(){
79
+						window.parent.parent.postMessage(localStorage.getItem('dataInfo'),'*');
80
+						localStorage.removeItem('dataInfo')
81
+					});
82
+					/*		window.Asc.plugin.executeMethod ("GetSelectedText", [{"Numbering": false, "Math": false, "TableCellSeparator": '\n', "ParaSeparator": '\n', "TabSymbol": String.fromCharCode(9)}], function (e) {
83
+                                let text = e.trim()
84
+                                console.log(text)
85
+                                data.text = text
86
+                                if (text == '') {
87
+                                    text = text.replace (/\t/g, '\n');
88
+                                    window.parent.parent.postMessage(JSON.stringify(data),'*');
89
+                                }
90
+                                else {
91
+
92
+                                }
93
+                            });*/
94
+					break;
95
+				}
96
+			}
97
+		}
98
+	};
99
+
100
+	window.Asc.plugin.button = function(id) {
101
+	};
102
+
103
+})(window, undefined);

+ 3
- 0
plugins/externallistener/translations/langs.json ファイルの表示

@@ -0,0 +1,3 @@
1
+[
2
+	"zh-CN"
3
+]

+ 3
- 0
plugins/externallistener/translations/zh-CN.json ファイルの表示

@@ -0,0 +1,3 @@
1
+{
2
+
3
+}

+ 144
- 109
pom.xml ファイルの表示

@@ -1,112 +1,147 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
-	<modelVersion>4.0.0</modelVersion>
5
-	<parent>
6
-		<groupId>org.springframework.boot</groupId>
7
-		<artifactId>spring-boot-starter-parent</artifactId>
8
-		<version>2.5.1</version>
9
-		<relativePath/> <!-- lookup parent from repository -->
10
-	</parent>
11
-	<groupId>com.onlyoffice</groupId>
12
-	<artifactId>integration</artifactId>
13
-	<version>1.0</version>
14
-	<name>Java Spring Integration Example</name>
15
-	<description>ONLYOFFICE Java Spring Integration</description>
16
-	<properties>
17
-		<java.version>11</java.version>
18
-	</properties>
19
-	<dependencies>
20
-		<dependency>
21
-			<groupId>org.springframework.boot</groupId>
22
-			<artifactId>spring-boot-starter-web</artifactId>
23
-		</dependency>
24
-		<dependency>
25
-			<groupId>org.springframework.boot</groupId>
26
-			<artifactId>spring-boot-devtools</artifactId>
27
-			<optional>true</optional>
28
-		</dependency>
29
-		<dependency>
30
-			<groupId>org.springframework.boot</groupId>
31
-			<artifactId>spring-boot-starter-thymeleaf</artifactId>
32
-			<version>2.5.1</version>
33
-		</dependency>
34
-		<dependency>
35
-			<groupId>org.springframework.boot</groupId>
36
-			<artifactId>spring-boot-starter-data-jpa</artifactId>
37
-		</dependency>
38
-		<dependency>
39
-			<groupId>com.h2database</groupId>
40
-			<artifactId>h2</artifactId>
41
-			<scope>runtime</scope>
42
-		</dependency>
43
-		<dependency>
44
-			<groupId>com.googlecode.json-simple</groupId>
45
-			<artifactId>json-simple</artifactId>
46
-			<version>1.1</version>
47
-		</dependency>
48
-		<dependency>
49
-			<groupId>com.google.code.gson</groupId>
50
-			<artifactId>gson</artifactId>
51
-			<version>2.8.9</version>
52
-		</dependency>
53
-		<dependency>
54
-			<groupId>com.inversoft</groupId>
55
-			<artifactId>prime-jwt</artifactId>
56
-			<version>1.3.1</version>
57
-		</dependency>
58
-		<dependency>
59
-			<groupId>org.projectlombok</groupId>
60
-			<artifactId>lombok</artifactId>
61
-			<version>1.18.20</version>
62
-			<scope>provided</scope>
63
-		</dependency>
64
-		<dependency>
65
-			<groupId>com.fasterxml.jackson.core</groupId>
66
-			<artifactId>jackson-core</artifactId>
67
-			<version>2.13.4</version>
68
-		</dependency>
69
-		<dependency>
70
-			<groupId>com.fasterxml.jackson.core</groupId>
71
-			<artifactId>jackson-databind</artifactId>
72
-			<version>2.13.4.2</version>
73
-		</dependency>
74
-		<dependency>
75
-			<groupId>org.modelmapper</groupId>
76
-			<artifactId>modelmapper</artifactId>
77
-			<version>2.4.2</version>
78
-		</dependency>
79
-	</dependencies>
80
-	<build>
81
-		<plugins>
82
-			<plugin>
83
-				<groupId>org.springframework.boot</groupId>
84
-				<artifactId>spring-boot-maven-plugin</artifactId>
85
-			</plugin>
86
-			<plugin>
87
-				<groupId>org.apache.maven.plugins</groupId>
88
-				<artifactId>maven-checkstyle-plugin</artifactId>
89
-				<version>3.2.0</version>
90
-				<executions>
91
-					<execution>
92
-						<id>validate</id>
93
-						<phase>validate</phase>
94
-						<configuration>
95
-							<configLocation>checkstyle.xml</configLocation>
96
-							<failsOnError>true</failsOnError>
97
-							<failOnViolation>true</failOnViolation>
98
-							<logViolationsToConsole>true</logViolationsToConsole>
99
-							<violationSeverity>warning</violationSeverity>
100
-							<consoleOutput>true</consoleOutput>
101
-							<includeTestSourceDirectory>true
102
-							</includeTestSourceDirectory>
103
-						</configuration>
104
-						<goals>
105
-							<goal>check</goal>
106
-						</goals>
107
-					</execution>
108
-				</executions>
109
-			</plugin>
110
-		</plugins>
111
-	</build>
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+    <modelVersion>4.0.0</modelVersion>
5
+    <parent>
6
+        <groupId>org.springframework.boot</groupId>
7
+        <artifactId>spring-boot-starter-parent</artifactId>
8
+        <version>2.6.6</version>
9
+        <relativePath/> <!-- lookup parent from repository -->
10
+    </parent>
11
+    <groupId>com.oo</groupId>
12
+    <artifactId>Spring-Boot-onlyOffice</artifactId>
13
+    <version>0.0.1-SNAPSHOT</version>
14
+    <name>Spring-Boot-onlyOffice</name>
15
+    <description>Demo project for Spring Boot</description>
16
+    <properties>
17
+        <java.version>1.8</java.version>
18
+    </properties>
19
+    <dependencies>
20
+        <dependency>
21
+            <groupId>org.springframework.boot</groupId>
22
+            <artifactId>spring-boot-starter-thymeleaf</artifactId>
23
+        </dependency>
24
+        <dependency>
25
+            <groupId>org.springframework.boot</groupId>
26
+            <artifactId>spring-boot-starter-web</artifactId>
27
+        </dependency>
28
+
29
+        <dependency>
30
+            <groupId>org.springframework.boot</groupId>
31
+            <artifactId>spring-boot-devtools</artifactId>
32
+            <optional>true</optional>
33
+        </dependency>
34
+        <dependency>
35
+            <groupId>org.projectlombok</groupId>
36
+            <artifactId>lombok</artifactId>
37
+            <optional>true</optional>
38
+        </dependency>
39
+        <dependency>
40
+            <groupId>org.springframework.boot</groupId>
41
+            <artifactId>spring-boot-starter-test</artifactId>
42
+            <scope>test</scope>
43
+        </dependency>
44
+        <dependency>
45
+            <groupId>com.baomidou</groupId>
46
+            <artifactId>mybatis-plus-boot-starter</artifactId>
47
+            <version>3.5.1</version>
48
+        </dependency>
49
+        <dependency>
50
+            <groupId>com.baomidou</groupId>
51
+            <artifactId>mybatis-plus-generator</artifactId>
52
+            <version>3.5.1</version>
53
+        </dependency>
54
+        <dependency>
55
+            <groupId>com.alibaba</groupId>
56
+            <artifactId>druid-spring-boot-starter</artifactId>
57
+            <version>1.1.22</version>
58
+        </dependency>
59
+        <dependency>
60
+            <groupId>mysql</groupId>
61
+            <artifactId>mysql-connector-java</artifactId>
62
+            <version>8.0.17</version>
63
+        </dependency>
64
+        <dependency>
65
+            <groupId>com.alibaba</groupId>
66
+            <artifactId>fastjson</artifactId>
67
+            <version>2.0.25</version>
68
+        </dependency>
69
+        <dependency>
70
+            <groupId>cn.hutool</groupId>
71
+            <artifactId>hutool-all</artifactId>
72
+            <version>5.8.16</version>
73
+        </dependency>
74
+        <dependency>
75
+            <groupId>com.inversoft</groupId>
76
+            <artifactId>prime-jwt</artifactId>
77
+            <version>1.3.1</version>
78
+        </dependency>
79
+        <dependency>
80
+            <groupId>org.apache.commons</groupId>
81
+            <artifactId>commons-pool2</artifactId>
82
+        </dependency>
83
+        <dependency>
84
+            <groupId>org.springframework.boot</groupId>
85
+            <artifactId>spring-boot-starter-data-redis</artifactId>
86
+        </dependency>
87
+        <dependency>
88
+            <groupId>commons-fileupload</groupId>
89
+            <artifactId>commons-fileupload</artifactId>
90
+            <version>1.4</version>
91
+        </dependency>
92
+    </dependencies>
93
+
94
+    <build>
95
+        <plugins>
96
+            <plugin>
97
+                <groupId>org.springframework.boot</groupId>
98
+                <artifactId>spring-boot-maven-plugin</artifactId>
99
+                <configuration>
100
+                    <excludes>
101
+                        <exclude>
102
+                            <groupId>org.projectlombok</groupId>
103
+                            <artifactId>lombok</artifactId>
104
+                        </exclude>
105
+                    </excludes>
106
+                </configuration>
107
+            </plugin>
108
+        </plugins>
109
+    </build>
110
+    <repositories>
111
+        <repository>
112
+            <id>spring-milestones</id>
113
+            <name>Spring Milestones</name>
114
+            <url>https://repo.spring.io/milestone</url>
115
+            <snapshots>
116
+                <enabled>false</enabled>
117
+            </snapshots>
118
+        </repository>
119
+        <repository>
120
+            <id>spring-snapshots</id>
121
+            <name>Spring Snapshots</name>
122
+            <url>https://repo.spring.io/snapshot</url>
123
+            <releases>
124
+                <enabled>false</enabled>
125
+            </releases>
126
+        </repository>
127
+    </repositories>
128
+    <pluginRepositories>
129
+        <pluginRepository>
130
+            <id>spring-milestones</id>
131
+            <name>Spring Milestones</name>
132
+            <url>https://repo.spring.io/milestone</url>
133
+            <snapshots>
134
+                <enabled>false</enabled>
135
+            </snapshots>
136
+        </pluginRepository>
137
+        <pluginRepository>
138
+            <id>spring-snapshots</id>
139
+            <name>Spring Snapshots</name>
140
+            <url>https://repo.spring.io/snapshot</url>
141
+            <releases>
142
+                <enabled>false</enabled>
143
+            </releases>
144
+        </pluginRepository>
145
+    </pluginRepositories>
146
+
112 147
 </project>

+ 0
- 115
src/main/java/com/onlyoffice/integration/ExampleData.java ファイルの表示

@@ -1,115 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration;
20
-
21
-import com.onlyoffice.integration.documentserver.serializers.FilterState;
22
-import com.onlyoffice.integration.services.UserServices;
23
-import org.springframework.beans.factory.annotation.Autowired;
24
-import org.springframework.stereotype.Component;
25
-
26
-import javax.annotation.PostConstruct;
27
-import java.util.ArrayList;
28
-import java.util.List;
29
-
30
-@Component
31
-public class ExampleData {
32
-    @Autowired
33
-    private UserServices userService;
34
-    @PostConstruct
35
-    public void init() {
36
-        // the description for user 0
37
-        List<String> descriptionUserZero = List.of(
38
-                "The name is requested when the editor is opened",
39
-                "Doesn’t belong to any group",
40
-                "Can review all the changes",
41
-                "Can perform all actions with comments",
42
-                "The file favorite state is undefined",
43
-                "Can't mention others in comments",
44
-                "Can't create new files from the editor",
45
-                "Can’t see anyone’s information",
46
-                "Can't rename files from the editor",
47
-                "Can't view chat",
48
-                "Can't protect file",
49
-                "View file without collaboration"
50
-        );
51
-
52
-        // the description for user 1
53
-        List<String> descriptionUserFirst = List.of(
54
-                "File author by default",
55
-                "He doesn’t belong to any of the groups",
56
-                "He can review all the changes",
57
-                "He can do everything with the comments",
58
-                "The file favorite state is undefined",
59
-                "Can create a file from a template with data from the editor",
60
-                "Can see the information about all users",
61
-                "Can view chat"
62
-        );
63
-
64
-        // the description for user 2
65
-        List<String> descriptionUserSecond = List.of(
66
-                "He belongs to Group2",
67
-                "He can review only his own changes or the changes made by the users who don’t belong"
68
-                        + " to any of the groups",
69
-                "He can view every comment, edit his comments and the comments left by the users "
70
-                        + "who don't belong to any of the groups and remove only his comments",
71
-                "This file is favorite",
72
-                "Can create a file from an editor",
73
-                "Can see the information about users from Group2 and users who don’t belong to any group",
74
-                "Can view chat"
75
-        );
76
-
77
-        // the description for user 3
78
-        List<String> descriptionUserThird = List.of(
79
-                "He belongs to Group3",
80
-                "He can review only the changes made by the users from Group2",
81
-                "He can view the comments left by the users from Group2 and Group3 and edit the comments left by "
82
-                        + "the users from Group2",
83
-                "This file isn’t favorite",
84
-                "He can’t copy data from the file into the clipboard",
85
-                "He can’t download the file",
86
-                "He can’t print the file",
87
-                "Can create a file from an editor",
88
-                "Can see the information about Group2 users",
89
-                "Can view chat"
90
-        );
91
-
92
-        // create user 1 with the specified parameters
93
-        userService.createUser("John Smith", "smith@example.com", descriptionUserFirst,
94
-                "", List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
95
-                List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
96
-                List.of(FilterState.NULL.toString()), null, true, true);
97
-
98
-        // create user 2 with the specified parameters
99
-        userService.createUser("Mark Pottato", "pottato@example.com", descriptionUserSecond,
100
-                "group-2", List.of("", "group-2"), List.of(FilterState.NULL.toString()),
101
-                List.of("group-2", ""), List.of("group-2"), List.of("group-2", ""), true, true,
102
-                true);
103
-
104
-        // create user 3 with the specified parameters
105
-        userService.createUser("Hamish Mitchell", "mitchell@example.com", descriptionUserThird,
106
-                "group-3", List.of("group-2"), List.of("group-2", "group-3"), List.of("group-2"),
107
-                new ArrayList<>(), List.of("group-2"), false, true, true);
108
-
109
-        // create user 0 with the specified parameters
110
-        userService.createUser("Anonymous", null, descriptionUserZero, "",
111
-                List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
112
-                List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
113
-                new ArrayList<>(), null, false, false);
114
-    }
115
-}

+ 0
- 32
src/main/java/com/onlyoffice/integration/IntegrationApplication.java ファイルの表示

@@ -1,32 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration;
20
-
21
-import org.springframework.boot.SpringApplication;
22
-import org.springframework.boot.autoconfigure.SpringBootApplication;
23
-
24
-@SpringBootApplication
25
-public class IntegrationApplication {
26
-
27
-    // run the SpringApplication from the IntagrationApplication with the specified parameters
28
-    public static void main(final String[] args) {
29
-        SpringApplication.run(IntegrationApplication.class, args);
30
-    }
31
-
32
-}

+ 0
- 87
src/main/java/com/onlyoffice/integration/IntegrationConfiguration.java ファイルの表示

@@ -1,87 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration;
20
-
21
-import com.fasterxml.jackson.databind.ObjectMapper;
22
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
23
-import org.json.simple.parser.JSONParser;
24
-import org.modelmapper.ModelMapper;
25
-import org.modelmapper.convention.MatchingStrategies;
26
-import org.springframework.beans.factory.annotation.Autowired;
27
-import org.springframework.beans.factory.annotation.Value;
28
-import org.springframework.context.annotation.Bean;
29
-import org.springframework.context.annotation.Configuration;
30
-
31
-import javax.annotation.PostConstruct;
32
-
33
-import com.onlyoffice.integration.documentserver.util.SSLUtils;
34
-
35
-@Configuration
36
-public class IntegrationConfiguration {
37
-
38
-    @Value("${files.storage}")
39
-    private String storageAddress;
40
-
41
-    @Value("${files.docservice.verify-peer-off}")
42
-    private String verifyPerrOff;
43
-
44
-    @Autowired
45
-    private FileStoragePathBuilder storagePathBuilder;
46
-
47
-    @Autowired
48
-    private SSLUtils ssl;
49
-
50
-    @Bean
51
-    public ModelMapper mapper() {  // create the model mapper
52
-        ModelMapper mapper = new ModelMapper();
53
-        mapper.getConfiguration()  // get the mapper configuration and set new parameters to it
54
-                .setMatchingStrategy(MatchingStrategies.STRICT)  // specify the STRICT matching strategy
55
-                .setFieldMatchingEnabled(true)  // define if the field matching is enabled or not
56
-                .setSkipNullEnabled(true)  // define if null value will be skipped or not
57
-                .setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE);  /* specify
58
-                 the PRIVATE field access level */
59
-        return mapper;
60
-    }
61
-
62
-    @Bean
63
-    public JSONParser jsonParser() {  // create JSON parser
64
-        return new JSONParser();
65
-    }
66
-
67
-    @PostConstruct
68
-    public void init() {  // initialize the storage path builder
69
-        storagePathBuilder.configure(storageAddress.isBlank() ? null : storageAddress);
70
-        if (!verifyPerrOff.isEmpty()) {
71
-            try {
72
-                if (verifyPerrOff.equals("true")) {
73
-                    ssl.turnOffSslChecking(); //the certificate will be ignored
74
-                } else {
75
-                    ssl.turnOnSslChecking(); //the certificate will be verified
76
-                }
77
-            } catch (Exception e) {
78
-                e.printStackTrace();
79
-            }
80
-        }
81
-    }
82
-
83
-    @Bean
84
-    public ObjectMapper objectMapper() {  // create the object mapper
85
-        return new ObjectMapper();
86
-    }
87
-}

+ 0
- 239
src/main/java/com/onlyoffice/integration/controllers/EditorController.java ファイルの表示

@@ -1,239 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.controllers;
20
-
21
-import com.fasterxml.jackson.core.JsonProcessingException;
22
-import com.fasterxml.jackson.databind.ObjectMapper;
23
-import com.onlyoffice.integration.documentserver.managers.history.HistoryManager;
24
-import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
25
-import com.onlyoffice.integration.documentserver.models.enums.Action;
26
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
27
-import com.onlyoffice.integration.entities.User;
28
-import com.onlyoffice.integration.dto.Mentions;
29
-import com.onlyoffice.integration.documentserver.models.enums.Type;
30
-import com.onlyoffice.integration.documentserver.models.filemodel.FileModel;
31
-import com.onlyoffice.integration.services.UserServices;
32
-import com.onlyoffice.integration.services.configurers.FileConfigurer;
33
-import com.onlyoffice.integration.services.configurers.wrappers.DefaultFileWrapper;
34
-import lombok.SneakyThrows;
35
-import org.springframework.beans.factory.annotation.Autowired;
36
-import org.springframework.beans.factory.annotation.Value;
37
-import org.springframework.stereotype.Controller;
38
-import org.springframework.ui.Model;
39
-import org.springframework.web.bind.annotation.CookieValue;
40
-import org.springframework.web.bind.annotation.CrossOrigin;
41
-import org.springframework.web.bind.annotation.GetMapping;
42
-import org.springframework.web.bind.annotation.RequestParam;
43
-
44
-import java.util.ArrayList;
45
-import java.util.Arrays;
46
-import java.util.HashMap;
47
-import java.util.List;
48
-import java.util.Locale;
49
-import java.util.Map;
50
-import java.util.Optional;
51
-
52
-import static com.onlyoffice.integration.documentserver.util.Constants.ANONYMOUS_USER_ID;
53
-
54
-@CrossOrigin("*")
55
-@Controller
56
-public class EditorController {
57
-
58
-    @Value("${files.docservice.url.site}")
59
-    private String docserviceSite;
60
-
61
-    @Value("${files.docservice.url.api}")
62
-    private String docserviceApiUrl;
63
-
64
-    @Value("${files.docservice.languages}")
65
-    private String langs;
66
-
67
-    @Autowired
68
-    private FileStoragePathBuilder storagePathBuilder;
69
-
70
-    @Autowired
71
-    private JwtManager jwtManager;
72
-
73
-    @Autowired
74
-    private UserServices userService;
75
-
76
-    @Autowired
77
-    private HistoryManager historyManager;
78
-
79
-    @Autowired
80
-    private ObjectMapper objectMapper;
81
-
82
-    @Autowired
83
-    private FileConfigurer<DefaultFileWrapper> fileConfigurer;
84
-
85
-    @GetMapping(path = "${url.editor}")
86
-    // process request to open the editor page
87
-    public String index(@RequestParam("fileName") final String fileName,
88
-                        @RequestParam(value = "action", required = false) final String actionParam,
89
-                        @RequestParam(value = "type", required = false) final String typeParam,
90
-                        @RequestParam(value = "actionLink", required = false) final String actionLink,
91
-                        @RequestParam(value = "directUrl", required = false,
92
-                                defaultValue = "false") final Boolean directUrl,
93
-                        @CookieValue(value = "uid") final String uid,
94
-                        @CookieValue(value = "ulang") final String lang,
95
-                        final Model model) throws JsonProcessingException {
96
-        Action action = Action.edit;
97
-        Type type = Type.desktop;
98
-        Locale locale = new Locale("en");
99
-
100
-        if (actionParam != null) {
101
-            action = Action.valueOf(actionParam);
102
-        }
103
-        if (typeParam != null) {
104
-            type = Type.valueOf(typeParam);
105
-        }
106
-
107
-        List<String> langsAndKeys = Arrays.asList(langs.split("\\|"));
108
-        for (String langAndKey : langsAndKeys) {
109
-            String[] couple = langAndKey.split(":");
110
-            if (couple[0].equals(lang)) {
111
-                String[] langAndCountry = couple[0].split("-");
112
-                locale = new Locale(langAndCountry[0], langAndCountry.length > 1 ? langAndCountry[1] : "");
113
-            }
114
-        }
115
-
116
-        Optional<User> optionalUser = userService.findUserById(Integer.parseInt(uid));
117
-
118
-        // if the user is not present, return the ONLYOFFICE start page
119
-        if (!optionalUser.isPresent()) {
120
-            return "index.html";
121
-        }
122
-
123
-        User user = optionalUser.get();
124
-
125
-        // get file model with the default file parameters
126
-        FileModel fileModel = fileConfigurer.getFileModel(
127
-                DefaultFileWrapper
128
-                        .builder()
129
-                        .fileName(fileName)
130
-                        .type(type)
131
-                        .lang(locale.toLanguageTag())
132
-                        .action(action)
133
-                        .user(user)
134
-                        .actionData(actionLink)
135
-                        .isEnableDirectUrl(directUrl)
136
-                        .build()
137
-        );
138
-
139
-        // add attributes to the specified model
140
-        // add file model with the default parameters to the original model
141
-        model.addAttribute("model", fileModel);
142
-
143
-        // get file history and add it to the model
144
-        model.addAttribute("fileHistory", historyManager.getHistory(fileModel.getDocument()));
145
-
146
-        // create the document service api URL and add it to the model
147
-        model.addAttribute("docserviceApiUrl", docserviceSite + docserviceApiUrl);
148
-
149
-        // get an image and add it to the model
150
-        model.addAttribute("dataInsertImage",  getInsertImage(directUrl));
151
-
152
-        // get a document for comparison and add it to the model
153
-        model.addAttribute("dataCompareFile",  getCompareFile(directUrl));
154
-
155
-        // get recipients data for mail merging and add it to the model
156
-        model.addAttribute("dataMailMergeRecipients", getMailMerge(directUrl));
157
-
158
-        // get user data for mentions and add it to the model
159
-        model.addAttribute("usersForMentions", getUserMentions(uid));
160
-        return "editor.html";
161
-    }
162
-
163
-    private List<Mentions> getUserMentions(final String uid) {  // get user data for mentions
164
-        List<Mentions> usersForMentions = new ArrayList<>();
165
-        if (uid != null && !uid.equals("4")) {
166
-            List<User> list = userService.findAll();
167
-            for (User u : list) {
168
-                if (u.getId() != Integer.parseInt(uid) && u.getId() != ANONYMOUS_USER_ID) {
169
-
170
-                    // user data includes user names and emails
171
-                    usersForMentions.add(new Mentions(u.getName(), u.getEmail()));
172
-                }
173
-            }
174
-        }
175
-
176
-        return usersForMentions;
177
-    }
178
-
179
-    @SneakyThrows
180
-    private String getInsertImage(final Boolean directUrl) {  // get an image that will be inserted into the document
181
-        Map<String, Object> dataInsertImage = new HashMap<>();
182
-        dataInsertImage.put("fileType", "png");
183
-        dataInsertImage.put("url", storagePathBuilder.getServerUrl(true) + "/css/img/logo.png");
184
-        if (directUrl) {
185
-            dataInsertImage.put("directUrl", storagePathBuilder
186
-                    .getServerUrl(false) + "/css/img/logo.png");
187
-        }
188
-
189
-        // check if the document token is enabled
190
-        if (jwtManager.tokenEnabled()) {
191
-
192
-            // create token from the dataInsertImage object
193
-            dataInsertImage.put("token", jwtManager.createToken(dataInsertImage));
194
-        }
195
-
196
-        return objectMapper.writeValueAsString(dataInsertImage)
197
-                .substring(1, objectMapper.writeValueAsString(dataInsertImage).length() - 1);
198
-    }
199
-
200
-    // get a document that will be compared with the current document
201
-    @SneakyThrows
202
-    private String getCompareFile(final Boolean directUrl) {
203
-        Map<String, Object> dataCompareFile = new HashMap<>();
204
-        dataCompareFile.put("fileType", "docx");
205
-        dataCompareFile.put("url", storagePathBuilder.getServerUrl(true) + "/assets?name=sample.docx");
206
-        if (directUrl) {
207
-            dataCompareFile.put("directUrl", storagePathBuilder
208
-                    .getServerUrl(false) + "/assets?name=sample.docx");
209
-        }
210
-
211
-        // check if the document token is enabled
212
-        if (jwtManager.tokenEnabled()) {
213
-
214
-            // create token from the dataCompareFile object
215
-            dataCompareFile.put("token", jwtManager.createToken(dataCompareFile));
216
-        }
217
-
218
-        return objectMapper.writeValueAsString(dataCompareFile);
219
-    }
220
-
221
-    @SneakyThrows
222
-    private String getMailMerge(final Boolean directUrl) {
223
-        Map<String, Object> dataMailMergeRecipients = new HashMap<>();  // get recipients data for mail merging
224
-        dataMailMergeRecipients.put("fileType", "csv");
225
-        dataMailMergeRecipients.put("url", storagePathBuilder.getServerUrl(true) + "/csv");
226
-        if (directUrl) {
227
-            dataMailMergeRecipients.put("directUrl", storagePathBuilder.getServerUrl(false) + "/csv");
228
-        }
229
-
230
-        // check if the document token is enabled
231
-        if (jwtManager.tokenEnabled()) {
232
-
233
-            // create token from the dataMailMergeRecipients object
234
-            dataMailMergeRecipients.put("token", jwtManager.createToken(dataMailMergeRecipients));
235
-        }
236
-
237
-        return objectMapper.writeValueAsString(dataMailMergeRecipients);
238
-    }
239
-}

+ 0
- 624
src/main/java/com/onlyoffice/integration/controllers/FileController.java ファイルの表示

@@ -1,624 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.controllers;
20
-
21
-import com.fasterxml.jackson.databind.ObjectMapper;
22
-import com.google.gson.Gson;
23
-import com.google.gson.GsonBuilder;
24
-import com.onlyoffice.integration.documentserver.callbacks.CallbackHandler;
25
-import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
26
-import com.onlyoffice.integration.documentserver.storage.FileStorageMutator;
27
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
28
-import com.onlyoffice.integration.dto.Converter;
29
-import com.onlyoffice.integration.dto.ConvertedData;
30
-import com.onlyoffice.integration.dto.Track;
31
-import com.onlyoffice.integration.entities.User;
32
-import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
33
-import com.onlyoffice.integration.services.UserServices;
34
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
35
-import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
36
-import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
37
-import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
38
-
39
-import org.json.simple.JSONArray;
40
-import org.json.simple.JSONObject;
41
-import org.json.simple.parser.JSONParser;
42
-import org.springframework.beans.factory.annotation.Autowired;
43
-import org.springframework.beans.factory.annotation.Value;
44
-import org.springframework.core.io.Resource;
45
-import org.springframework.http.HttpHeaders;
46
-import org.springframework.http.MediaType;
47
-import org.springframework.http.ResponseEntity;
48
-import org.springframework.stereotype.Controller;
49
-import org.springframework.ui.Model;
50
-import org.springframework.web.bind.annotation.CookieValue;
51
-import org.springframework.web.bind.annotation.CrossOrigin;
52
-import org.springframework.web.bind.annotation.GetMapping;
53
-import org.springframework.web.bind.annotation.PostMapping;
54
-import org.springframework.web.bind.annotation.PutMapping;
55
-import org.springframework.web.bind.annotation.RequestBody;
56
-import org.springframework.web.bind.annotation.RequestParam;
57
-import org.springframework.web.bind.annotation.ResponseBody;
58
-import org.springframework.web.multipart.MultipartFile;
59
-
60
-import javax.servlet.http.HttpServletRequest;
61
-import java.io.File;
62
-import java.io.FileInputStream;
63
-import java.io.FileWriter;
64
-import java.io.IOException;
65
-import java.io.InputStream;
66
-import java.net.InetAddress;
67
-import java.net.URL;
68
-import java.net.URLEncoder;
69
-import java.nio.charset.StandardCharsets;
70
-import java.nio.file.Files;
71
-import java.nio.file.Path;
72
-import java.nio.file.Paths;
73
-import java.text.SimpleDateFormat;
74
-import java.util.ArrayList;
75
-import java.util.Date;
76
-import java.util.HashMap;
77
-import java.util.LinkedHashMap;
78
-import java.util.Map;
79
-import java.util.Optional;
80
-
81
-@CrossOrigin("*")
82
-@Controller
83
-public class FileController {
84
-
85
-    @Value("${files.docservice.header}")
86
-    private String documentJwtHeader;
87
-
88
-    @Value("${filesize-max}")
89
-    private String filesizeMax;
90
-
91
-    @Value("${files.docservice.url.site}")
92
-    private String docserviceUrlSite;
93
-
94
-    @Value("${files.docservice.url.command}")
95
-    private String docserviceUrlCommand;
96
-
97
-    @Autowired
98
-    private FileUtility fileUtility;
99
-    @Autowired
100
-    private DocumentManager documentManager;
101
-    @Autowired
102
-    private JwtManager jwtManager;
103
-    @Autowired
104
-    private FileStorageMutator storageMutator;
105
-    @Autowired
106
-    private FileStoragePathBuilder storagePathBuilder;
107
-    @Autowired
108
-    private UserServices userService;
109
-    @Autowired
110
-    private CallbackHandler callbackHandler;
111
-    @Autowired
112
-    private ObjectMapper objectMapper;
113
-    @Autowired
114
-    private ServiceConverter serviceConverter;
115
-    @Autowired
116
-    private CallbackManager callbackManager;
117
-
118
-    // create user metadata
119
-    private String createUserMetadata(final String uid, final String fullFileName) {
120
-        Optional<User> optionalUser = userService.findUserById(Integer.parseInt(uid));  // find a user by their ID
121
-        String documentType = fileUtility.getDocumentType(fullFileName).toString().toLowerCase();  // get document type
122
-        if (optionalUser.isPresent()) {
123
-            User user = optionalUser.get();
124
-            storageMutator.createMeta(fullFileName,  // create meta information with the user ID and name specified
125
-                    String.valueOf(user.getId()), user.getName());
126
-        }
127
-        return "{ \"filename\": \"" + fullFileName + "\", \"documentType\": \"" + documentType + "\" }";
128
-    }
129
-
130
-    // download data from the specified file
131
-    private ResponseEntity<Resource> downloadFile(final String fileName) {
132
-        Resource resource = storageMutator.loadFileAsResource(fileName);  // load the specified file as a resource
133
-        String contentType = "application/octet-stream";
134
-
135
-        // create a response with the content type, header and body with the file data
136
-        return ResponseEntity.ok()
137
-                .contentType(MediaType.parseMediaType(contentType))
138
-                .header(HttpHeaders.CONTENT_DISPOSITION,
139
-                        "attachment; filename=\"" + resource.getFilename() + "\"")
140
-                .body(resource);
141
-    }
142
-
143
-    // download data from the specified history file
144
-    private ResponseEntity<Resource> downloadFileHistory(final String fileName,
145
-                                                         final String version,
146
-                                                         final String file) {
147
-
148
-        // load the specified file as a resource
149
-        Resource resource = storageMutator.loadFileAsResourceHistory(fileName, version, file);
150
-        String contentType = "application/octet-stream";
151
-
152
-        // create a response with the content type, header and body with the file data
153
-        return ResponseEntity.ok()
154
-                .contentType(MediaType.parseMediaType(contentType))
155
-                .header(HttpHeaders.CONTENT_DISPOSITION,
156
-                        "attachment; filename=\"" + resource.getFilename() + "\"")
157
-                .body(resource);
158
-    }
159
-
160
-    @PostMapping("/upload")
161
-    @ResponseBody
162
-    public String upload(@RequestParam("file") final MultipartFile file,  // upload a file
163
-                             @CookieValue("uid") final String uid) {
164
-        try {
165
-            String fullFileName = file.getOriginalFilename();  // get file name
166
-            String fileExtension = fileUtility.getFileExtension(fullFileName);  // get file extension
167
-            long fileSize = file.getSize();  // get file size
168
-            byte[] bytes = file.getBytes();  // get file in bytes
169
-
170
-            // check if the file size exceeds the maximum file size or is less than 0
171
-            if (fileUtility.getMaxFileSize() < fileSize || fileSize <= 0) {
172
-                return "{ \"error\": \"File size is incorrect\"}";  // if so, write an error message to the response
173
-            }
174
-
175
-            // check if file extension is supported by the editor
176
-            if (!fileUtility.getFileExts().contains(fileExtension)) {
177
-
178
-                // if not, write an error message to the response
179
-                return "{ \"error\": \"File type is not supported\"}";
180
-            }
181
-
182
-            String fileNamePath = storageMutator.updateFile(fullFileName, bytes);  // update a file
183
-            if (fileNamePath.isBlank()) {
184
-                throw new IOException("Could not update a file");  // if the file cannot be updated, an error occurs
185
-            }
186
-
187
-            fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath) + fileExtension;  // get full file name
188
-
189
-            return createUserMetadata(uid, fullFileName);  // create user metadata and return it
190
-        } catch (Exception e) {
191
-            e.printStackTrace();
192
-        }
193
-
194
-        // if the operation of file uploading is unsuccessful, an error occurs
195
-        return "{ \"error\": \"Something went wrong when uploading the file.\"}";
196
-    }
197
-
198
-    @PostMapping(path = "${url.converter}")
199
-    @ResponseBody
200
-    public String convert(@RequestBody final Converter body,  // convert a file
201
-                          @CookieValue("uid") final String uid, @CookieValue("ulang") final String lang) {
202
-        // get file name
203
-        String fileName = body.getFileName();
204
-
205
-        // get URL for downloading a file with the specified name
206
-        String fileUri = documentManager.getDownloadUrl(fileName, true);
207
-
208
-        // get file password if it exists
209
-        String filePass = body.getFilePass() != null ? body.getFilePass() : null;
210
-
211
-        // get file extension
212
-        String fileExt = fileUtility.getFileExtension(fileName);
213
-
214
-        // get document type (word, cell or slide)
215
-        DocumentType type = fileUtility.getDocumentType(fileName);
216
-
217
-        // convert to .ooxml
218
-        String internalFileExt = "ooxml";
219
-
220
-        try {
221
-            // check if the file with such an extension can be converted
222
-            if (fileUtility.getConvertExts().contains(fileExt)) {
223
-                String key = serviceConverter.generateRevisionId(fileUri);  // generate document key
224
-                ConvertedData response = serviceConverter  // get the URL to the converted file
225
-                        .getConvertedData(fileUri, fileExt, internalFileExt, key, filePass, true, lang);
226
-
227
-                String newFileUri = response.getUri();
228
-                String newFileType = "." + response.getFileType();
229
-
230
-                if (newFileUri.isEmpty()) {
231
-                    return "{ \"step\" : \"0\", \"filename\" : \"" + fileName + "\"}";
232
-                }
233
-
234
-                /* get a file name of an internal file extension with an index if the file
235
-                 with such a name already exists */
236
-                String nameWithInternalExt = fileUtility.getFileNameWithoutExtension(fileName) + newFileType;
237
-                String correctedName = documentManager.getCorrectName(nameWithInternalExt);
238
-
239
-                URL url = new URL(newFileUri);
240
-                java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
241
-                InputStream stream = connection.getInputStream();  // get input stream of the converted file
242
-
243
-                if (stream == null) {
244
-                    connection.disconnect();
245
-                    throw new RuntimeException("Input stream is null");
246
-                }
247
-
248
-                // remove source file
249
-                storageMutator.deleteFile(fileName);
250
-
251
-                // create the converted file with input stream
252
-                storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(correctedName)), stream);
253
-                fileName = correctedName;
254
-            }
255
-
256
-            // create meta information about the converted file with the user ID and name specified
257
-            return createUserMetadata(uid, fileName);
258
-        } catch (Exception e) {
259
-            e.printStackTrace();
260
-        }
261
-        // if the operation of file converting is unsuccessful, an error occurs
262
-        return "{ \"error\": \"" + "The file can't be converted.\"}";
263
-    }
264
-
265
-    @PostMapping("/delete")
266
-    @ResponseBody
267
-    public String delete(@RequestBody final Converter body) {  // delete a file
268
-        try {
269
-            String fullFileName = fileUtility.getFileName(body.getFileName());  // get full file name
270
-
271
-            // delete a file from the storage and return the status of this operation (true or false)
272
-            boolean fileSuccess = storageMutator.deleteFile(fullFileName);
273
-
274
-            // delete file history and return the status of this operation (true or false)
275
-            boolean historySuccess = storageMutator.deleteFileHistory(fullFileName);
276
-
277
-            return "{ \"success\": \"" + (fileSuccess && historySuccess) + "\"}";
278
-        } catch (Exception e) {
279
-            // if the operation of file deleting is unsuccessful, an error occurs
280
-            return "{ \"error\": \"" + e.getMessage() + "\"}";
281
-        }
282
-    }
283
-
284
-    @GetMapping("/downloadhistory")
285
-    public ResponseEntity<Resource> downloadHistory(final HttpServletRequest request, // download a file
286
-                                             @RequestParam("fileName") final String fileName,
287
-                                             @RequestParam("ver") final String version,
288
-                                             @RequestParam("file") final String file) { // history file
289
-        try {
290
-            // check if a token is enabled or not
291
-            if (jwtManager.tokenEnabled() && jwtManager.tokenUseForRequest()) {
292
-                String header = request.getHeader(documentJwtHeader == null  // get the document JWT header
293
-                        || documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
294
-                if (header != null && !header.isEmpty()) {
295
-                    String token = header
296
-                            .replace("Bearer ", "");  // token is the header without the Bearer prefix
297
-                    jwtManager.readToken(token);  // read the token
298
-                } else {
299
-                    return null;
300
-                }
301
-            }
302
-            return downloadFileHistory(fileName, version, file);  // download data from the specified file
303
-        } catch (Exception e) {
304
-            return null;
305
-        }
306
-    }
307
-
308
-    @GetMapping(path = "${url.download}")
309
-    public ResponseEntity<Resource> download(final HttpServletRequest request,  // download a file
310
-                                             @RequestParam("fileName") final String fileName,
311
-                                             @RequestParam(value = "userAddress", required = false)
312
-                                                 final String userAddress) {
313
-        try {
314
-            // check if a token is enabled or not
315
-            if (jwtManager.tokenEnabled() && userAddress != null && jwtManager.tokenUseForRequest()) {
316
-                String header = request.getHeader(documentJwtHeader == null // get the document JWT header
317
-                        || documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
318
-                if (header != null && !header.isEmpty()) {
319
-                    String token = header
320
-                            .replace("Bearer ", "");  // token is the header without the Bearer prefix
321
-                    jwtManager.readToken(token);  // read the token
322
-                } else {
323
-                    return null;
324
-                }
325
-            }
326
-            return downloadFile(fileName);  // download data from the specified file
327
-        } catch (Exception e) {
328
-            return null;
329
-        }
330
-    }
331
-
332
-    @GetMapping("/create")
333
-    public String create(@RequestParam("fileExt")
334
-                             final String fileExt, // create a sample file of the specified extension
335
-                         @RequestParam(value = "sample", required = false) final Optional<Boolean> isSample,
336
-                         @CookieValue(value = "uid", required = false) final String uid,
337
-                         final Model model) {
338
-        // specify if the sample data exists or not
339
-        Boolean sampleData = (isSample.isPresent() && !isSample.isEmpty()) && isSample.get();
340
-        if (fileExt != null) {
341
-            try {
342
-                Optional<User> user = userService.findUserById(Integer.parseInt(uid));  // find a user by their ID
343
-                if (!user.isPresent()) {
344
-                    // if the user with the specified ID doesn't exist, an error occurs
345
-                    throw new RuntimeException("Could not fine any user with id = " + uid);
346
-                }
347
-                String fileName = documentManager.createDemo(fileExt,
348
-                        sampleData,
349
-                        uid,
350
-                        user.get().getName());  // create a demo document with the sample data
351
-                if (fileName.isBlank() || fileName == null) {
352
-                    throw new RuntimeException("You must have forgotten to add asset files");
353
-                }
354
-                return "redirect:editor?fileName=" + URLEncoder
355
-                        .encode(fileName, StandardCharsets.UTF_8);  // redirect the request
356
-            } catch (Exception ex) {
357
-                model.addAttribute("error", ex.getMessage());
358
-                return "error.html";
359
-            }
360
-        }
361
-        return "redirect:/";
362
-    }
363
-
364
-    @GetMapping("/assets")
365
-    public ResponseEntity<Resource> assets(@RequestParam("name")
366
-                                               final String name) {  // get sample files from the assests
367
-        String fileName = Path.of("assets", "document-templates", "sample", fileUtility.getFileName(name)).toString();
368
-        return downloadFile(fileName);
369
-    }
370
-
371
-    @GetMapping("/csv")
372
-    public ResponseEntity<Resource> csv() {  // download a csv file
373
-        String fileName = Path.of("assets", "document-templates", "sample", "csv.csv").toString();
374
-        return downloadFile(fileName);
375
-    }
376
-
377
-    @GetMapping("/files")
378
-    @ResponseBody
379
-    public ArrayList<Map<String, Object>> files(@RequestParam(value = "fileId", required = false)
380
-                                                    final String fileId) {  // get files information
381
-        return fileId == null ? documentManager.getFilesInfo() : documentManager.getFilesInfo(fileId);
382
-    }
383
-
384
-    @PostMapping(path = "${url.track}")
385
-    @ResponseBody
386
-    public String track(final HttpServletRequest request,  // track file changes
387
-                        @RequestParam("fileName") final String fileName,
388
-                        @RequestParam("userAddress") final String userAddress,
389
-                        @RequestBody final Track body) {
390
-        Track track;
391
-        try {
392
-            String bodyString = objectMapper
393
-                    .writeValueAsString(body);  // write the request body to the object mapper as a string
394
-            String header = request.getHeader(documentJwtHeader == null  // get the request header
395
-                    || documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
396
-
397
-            if (bodyString.isEmpty()) {  // if the request body is empty, an error occurs
398
-                throw new RuntimeException("{\"error\":1,\"message\":\"Request payload is empty\"}");
399
-            }
400
-
401
-            JSONObject bodyCheck = jwtManager.parseBody(bodyString, header);  // parse the request body
402
-            track = objectMapper.readValue(bodyCheck.toJSONString(), Track.class);  // read the request body
403
-        } catch (Exception e) {
404
-            e.printStackTrace();
405
-            return e.getMessage();
406
-        }
407
-
408
-        int error = callbackHandler.handle(track, fileName);
409
-
410
-        return "{\"error\":" + error + "}";
411
-    }
412
-
413
-    @PostMapping("/saveas")
414
-    @ResponseBody
415
-    public String saveAs(@RequestBody final JSONObject body, @CookieValue("uid") final String uid) {
416
-        String title = (String) body.get("title");
417
-        String saveAsFileUrl = (String) body.get("url");
418
-
419
-        try {
420
-            String fileName = documentManager.getCorrectName(title);
421
-            String curExt = fileUtility.getFileExtension(fileName);
422
-
423
-            if (!fileUtility.getFileExts().contains(curExt)) {
424
-                return "{\"error\":\"File type is not supported\"}";
425
-            }
426
-
427
-            URL url = new URL(saveAsFileUrl);
428
-            java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
429
-            InputStream stream = connection.getInputStream();
430
-
431
-            if (Integer.parseInt(filesizeMax) < stream.available() || stream.available() <= 0) {
432
-                return "{\"error\":\"File size is incorrect\"}";
433
-            }
434
-            storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(fileName)), stream);
435
-            createUserMetadata(uid, fileName);
436
-
437
-            return "{\"file\":  \"" + fileName + "\"}";
438
-        } catch (IOException e) {
439
-            e.printStackTrace();
440
-            return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
441
-        }
442
-    }
443
-
444
-    @PostMapping("/rename")
445
-    @ResponseBody
446
-    public String rename(@RequestBody final JSONObject body) {
447
-        String newfilename = (String) body.get("newfilename");
448
-        String dockey = (String) body.get("dockey");
449
-        String origExt = "." + (String) body.get("ext");
450
-        String curExt = newfilename;
451
-
452
-        if (newfilename.indexOf(".") != -1) {
453
-            curExt = (String) fileUtility.getFileExtension(newfilename);
454
-        }
455
-
456
-        if (origExt.compareTo(curExt) != 0) {
457
-            newfilename += origExt;
458
-        }
459
-
460
-        HashMap<String, String> meta = new HashMap<>();
461
-        meta.put("title", newfilename);
462
-
463
-        try {
464
-            callbackManager.commandRequest("meta", dockey, meta);
465
-            return "result ok";
466
-        } catch (Exception e) {
467
-            e.printStackTrace();
468
-            return e.getMessage();
469
-        }
470
-    }
471
-
472
-    @PostMapping("/reference")
473
-    @ResponseBody
474
-    public String reference(@RequestBody final JSONObject body) {
475
-        try {
476
-            JSONParser parser = new JSONParser();
477
-            Gson gson = new GsonBuilder().disableHtmlEscaping().create();
478
-
479
-            String userAddress = "";
480
-            String fileName = "";
481
-
482
-            if (body.containsKey("referenceData")) {
483
-                LinkedHashMap referenceDataObj = (LinkedHashMap) body.get("referenceData");
484
-                String instanceId = (String) referenceDataObj.get("instanceId");
485
-
486
-                if (instanceId.equals(storagePathBuilder.getServerUrl(false))) {
487
-                    JSONObject fileKey = (JSONObject) parser.parse((String) referenceDataObj.get("fileKey"));
488
-                    userAddress = (String) fileKey.get("userAddress");
489
-                    if (userAddress.equals(InetAddress.getLocalHost().getHostAddress())) {
490
-                        fileName = (String) fileKey.get("fileName");
491
-                    }
492
-                }
493
-            }
494
-
495
-
496
-            if (fileName.equals("")) {
497
-                try {
498
-                    String path = (String) body.get("path");
499
-                    path = fileUtility.getFileName(path);
500
-                    File f = new File(storagePathBuilder.getFileLocation(path));
501
-                    if (f.exists()) {
502
-                        fileName = path;
503
-                    }
504
-                } catch (Exception e) {
505
-                    return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
506
-                }
507
-            }
508
-
509
-            if (fileName.equals("")) {
510
-                return "{ \"error\": \"File not found\"}";
511
-            }
512
-
513
-            boolean directUrl = (boolean) body.get("directUrl");
514
-
515
-            HashMap<String, Object> fileKey = new HashMap<>();
516
-            fileKey.put("fileName", fileName);
517
-            fileKey.put("userAddress", InetAddress.getLocalHost().getHostAddress());
518
-
519
-            HashMap<String, Object> referenceData = new HashMap<>();
520
-            referenceData.put("instanceId", storagePathBuilder.getServerUrl(true));
521
-            referenceData.put("fileKey", gson.toJson(fileKey));
522
-
523
-            HashMap<String, Object> data = new HashMap<>();
524
-            data.put("fileType", fileUtility.getFileExtension(fileName).replace(".", ""));
525
-            data.put("url", documentManager.getDownloadUrl(fileName, true));
526
-            data.put("directUrl", directUrl ? documentManager.getDownloadUrl(fileName, false) : null);
527
-            data.put("referenceData", referenceData);
528
-            data.put("path", fileName);
529
-
530
-            if (jwtManager.tokenEnabled()) {
531
-                String token = jwtManager.createToken(data);
532
-                data.put("token", token);
533
-            }
534
-            return gson.toJson(data);
535
-        } catch (Exception e) {
536
-            e.printStackTrace();
537
-            return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
538
-        }
539
-    }
540
-
541
-    @PutMapping("/restore")
542
-    @ResponseBody
543
-    public String restore(@RequestBody final JSONObject body) {
544
-        try {
545
-            String sourceBasename = (String) body.get("fileName");
546
-            Integer version = (Integer) body.get("version");
547
-            String userID = (String) body.get("userId");
548
-
549
-            String sourceStringFile = storagePathBuilder.getFileLocation(sourceBasename);
550
-            File sourceFile = new File(sourceStringFile);
551
-            Path sourcePathFile = sourceFile.toPath();
552
-            String historyDirectory = storagePathBuilder.getHistoryDir(sourcePathFile.toString());
553
-
554
-            Integer bumpedVersion = storagePathBuilder.getFileVersion(historyDirectory, false);
555
-            String bumpedVersionStringDirectory = documentManager.versionDir(historyDirectory, bumpedVersion, true);
556
-            File bumpedVersionDirectory = new File(bumpedVersionStringDirectory);
557
-            if (!bumpedVersionDirectory.exists()) {
558
-                bumpedVersionDirectory.mkdir();
559
-            }
560
-
561
-            Path bumpedKeyPathFile = Paths.get(bumpedVersionStringDirectory, "key.txt");
562
-            String bumpedKeyStringFile = bumpedKeyPathFile.toString();
563
-            File bumpedKeyFile = new File(bumpedKeyStringFile);
564
-            String bumpedKey = serviceConverter.generateRevisionId(
565
-                storagePathBuilder.getStorageLocation()
566
-                + "/"
567
-                + sourceBasename
568
-                + "/"
569
-                + Long.toString(sourceFile.lastModified())
570
-            );
571
-            FileWriter bumpedKeyFileWriter = new FileWriter(bumpedKeyFile);
572
-            bumpedKeyFileWriter.write(bumpedKey);
573
-            bumpedKeyFileWriter.close();
574
-
575
-            Integer userInnerID = Integer.parseInt(userID.replace("uid-", ""));
576
-            User user = userService.findUserById(userInnerID).get();
577
-
578
-            Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json");
579
-            String bumpedChangesStringFile = bumpedChangesPathFile.toString();
580
-            File bumpedChangesFile = new File(bumpedChangesStringFile);
581
-            JSONObject bumpedChangesUser = new JSONObject();
582
-            // Don't add the `uid-` prefix.
583
-            // https://github.com/ONLYOFFICE/document-server-integration/issues/437#issuecomment-1663526562
584
-            bumpedChangesUser.put("id", user.getId());
585
-            bumpedChangesUser.put("name", user.getName());
586
-            JSONObject bumpedChangesChangesItem = new JSONObject();
587
-            bumpedChangesChangesItem.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
588
-            bumpedChangesChangesItem.put("user", bumpedChangesUser);
589
-            JSONArray bumpedChangesChanges = new JSONArray();
590
-            bumpedChangesChanges.add(bumpedChangesChangesItem);
591
-            JSONObject bumpedChanges = new JSONObject();
592
-            bumpedChanges.put("serverVersion", null);
593
-            bumpedChanges.put("changes", bumpedChangesChanges);
594
-            String bumpedChangesContent = bumpedChanges.toJSONString();
595
-            FileWriter bumpedChangesFileWriter = new FileWriter(bumpedChangesFile);
596
-            bumpedChangesFileWriter.write(bumpedChangesContent);
597
-            bumpedChangesFileWriter.close();
598
-
599
-            String sourceExtension = fileUtility.getFileExtension(sourceBasename);
600
-            String previousBasename = "prev" + sourceExtension;
601
-
602
-            Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename);
603
-            Files.move(sourcePathFile, bumpedFile);
604
-
605
-            String recoveryVersionStringDirectory = documentManager.versionDir(historyDirectory, version, true);
606
-            Path recoveryPathFile = Paths.get(recoveryVersionStringDirectory, previousBasename);
607
-            String recoveryStringFile = recoveryPathFile.toString();
608
-            FileInputStream recoveryStream = new FileInputStream(recoveryStringFile);
609
-            storageMutator.createFile(sourcePathFile, recoveryStream);
610
-            recoveryStream.close();
611
-
612
-            JSONObject responseBody = new JSONObject();
613
-            responseBody.put("error", null);
614
-            responseBody.put("success", true);
615
-            return responseBody.toJSONString();
616
-        } catch (Exception error) {
617
-            error.printStackTrace();
618
-            JSONObject responseBody = new JSONObject();
619
-            responseBody.put("error", error.getMessage());
620
-            responseBody.put("success", false);
621
-            return responseBody.toJSONString();
622
-        }
623
-    }
624
-}

+ 0
- 147
src/main/java/com/onlyoffice/integration/controllers/IndexController.java ファイルの表示

@@ -1,147 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.controllers;
20
-
21
-import com.onlyoffice.integration.documentserver.storage.FileStorageMutator;
22
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
23
-import com.onlyoffice.integration.documentserver.util.Misc;
24
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
25
-import com.onlyoffice.integration.entities.User;
26
-import com.onlyoffice.integration.services.UserServices;
27
-import org.springframework.beans.factory.annotation.Autowired;
28
-import org.springframework.beans.factory.annotation.Value;
29
-import org.springframework.stereotype.Controller;
30
-import org.springframework.ui.Model;
31
-import org.springframework.web.bind.annotation.CrossOrigin;
32
-import org.springframework.web.bind.annotation.GetMapping;
33
-import org.springframework.web.bind.annotation.PostMapping;
34
-import org.springframework.web.bind.annotation.RequestParam;
35
-import org.springframework.web.bind.annotation.ResponseBody;
36
-
37
-import java.util.ArrayList;
38
-import java.util.Arrays;
39
-import java.util.HashMap;
40
-import java.util.LinkedHashMap;
41
-import java.util.List;
42
-import java.util.Map;
43
-import java.util.stream.Collectors;
44
-
45
-@CrossOrigin("*")
46
-@Controller
47
-public class IndexController {
48
-
49
-    @Autowired
50
-    private FileStorageMutator storageMutator;
51
-
52
-    @Autowired
53
-    private FileStoragePathBuilder storagePathBuilder;
54
-
55
-    @Autowired
56
-    private FileUtility fileUtility;
57
-
58
-    @Autowired
59
-    private Misc mistUtility;
60
-
61
-    @Autowired
62
-    private UserServices userService;
63
-
64
-    @Value("${files.docservice.url.site}")
65
-    private String docserviceSite;
66
-
67
-    @Value("${files.docservice.url.preloader}")
68
-    private String docservicePreloader;
69
-
70
-    @Value("${url.converter}")
71
-    private String urlConverter;
72
-
73
-    @Value("${url.editor}")
74
-    private String urlEditor;
75
-
76
-    @Value("${files.docservice.languages}")
77
-    private String langs;
78
-
79
-    @GetMapping("${url.index}")
80
-    public String index(@RequestParam(value = "directUrl", required = false) final Boolean directUrl,
81
-                        final Model model) {
82
-        java.io.File[] files = storageMutator.getStoredFiles();  // get all the stored files from the storage
83
-        List<String> docTypes = new ArrayList<>();
84
-        List<Boolean> filesEditable = new ArrayList<>();
85
-        List<String> versions = new ArrayList<>();
86
-        List<Boolean> isFillFormDoc = new ArrayList<>();
87
-        List<String> langsAndKeys = Arrays.asList(langs.split("\\|"));
88
-
89
-        Map<String, String> languages = new LinkedHashMap<>();
90
-
91
-        langsAndKeys.forEach((str) -> {
92
-            String[] couple = str.split(":");
93
-            languages.put(couple[0], couple[1]);
94
-        });
95
-
96
-        List<User> users = userService.findAll();  // get a list of all the users
97
-
98
-        String tooltip = users.stream()  // get the tooltip with the user descriptions
99
-                .map(user -> mistUtility.convertUserDescriptions(user.getName(),
100
-                        user.getDescriptions()))  // convert user descriptions to the specified format
101
-                .collect(Collectors.joining());
102
-
103
-        for (java.io.File file:files) {  // run through all the files
104
-            String fileName = file.getName();  // get file name
105
-            docTypes.add(fileUtility
106
-                    .getDocumentType(fileName)
107
-                    .toString()
108
-                    .toLowerCase());  // add a document type of each file to the list
109
-            filesEditable.add(fileUtility.getEditedExts()
110
-                    .contains(fileUtility.getFileExtension(fileName)));  // specify if a file is editable or not
111
-            versions.add(" [" + storagePathBuilder.
112
-                    getFileVersion(fileName, true) + "]");  // add a file version to the list
113
-            isFillFormDoc.add(fileUtility.getFillExts().contains(fileUtility.getFileExtension(fileName)));
114
-        }
115
-
116
-        // add all the parameters to the model
117
-        model.addAttribute("isFillFormDoc", isFillFormDoc);
118
-        model.addAttribute("versions", versions);
119
-        model.addAttribute("files", files);
120
-        model.addAttribute("docTypes", docTypes);
121
-        model.addAttribute("filesEditable", filesEditable);
122
-        model.addAttribute("datadocs", docserviceSite + docservicePreloader);
123
-        model.addAttribute("tooltip", tooltip);
124
-        model.addAttribute("users", users);
125
-        model.addAttribute("languages", languages);
126
-        model.addAttribute("directUrl", directUrl);
127
-
128
-        return "index.html";
129
-    }
130
-
131
-    @PostMapping("/config")
132
-    @ResponseBody
133
-    public HashMap<String, String> configParameters() {  // get configuration parameters
134
-        HashMap<String, String> configuration = new HashMap<>();
135
-
136
-        configuration.put("FillExtList", String.join(",", fileUtility
137
-                .getFillExts()));  // put a list of the extensions that can be filled to config
138
-        configuration.put("ConverExtList", String.join(",", fileUtility
139
-                .getConvertExts()));  // put a list of the extensions that can be converted to config
140
-        configuration.put("EditedExtList", String.join(",", fileUtility
141
-                .getEditedExts()));  // put a list of the extensions that can be edited to config
142
-        configuration.put("UrlConverter", urlConverter);
143
-        configuration.put("UrlEditor", urlEditor);
144
-
145
-        return configuration;
146
-    }
147
-}

+ 0
- 32
src/main/java/com/onlyoffice/integration/documentserver/callbacks/Callback.java ファイルの表示

@@ -1,32 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.callbacks;
20
-
21
-import com.onlyoffice.integration.dto.Track;
22
-import org.springframework.beans.factory.annotation.Autowired;
23
-
24
-// specify the callback handler functions
25
-public interface Callback {
26
-    int handle(Track body, String fileName);  // handle the callback
27
-    int getStatus();  // get document status
28
-    @Autowired
29
-    default void selfRegistration(CallbackHandler callbackHandler) {  // register a callback handler
30
-        callbackHandler.register(getStatus(), this);
31
-    }
32
-}

+ 0
- 50
src/main/java/com/onlyoffice/integration/documentserver/callbacks/CallbackHandler.java ファイルの表示

@@ -1,50 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.callbacks;
20
-
21
-import com.onlyoffice.integration.dto.Track;
22
-import org.slf4j.Logger;
23
-import org.slf4j.LoggerFactory;
24
-import org.springframework.stereotype.Service;
25
-
26
-import java.util.HashMap;
27
-import java.util.Map;
28
-
29
-@Service
30
-public class CallbackHandler {
31
-
32
-    private Logger logger = LoggerFactory.getLogger(CallbackHandler.class);
33
-
34
-    private Map<Integer, Callback> callbackHandlers = new HashMap<>();
35
-
36
-    public void register(final int code, final Callback callback) {  // register a callback handler
37
-        callbackHandlers.put(code, callback);
38
-    }
39
-
40
-    public int handle(final Track body, final String fileName) {  // handle a callback
41
-        Callback callback = callbackHandlers.get(body.getStatus());
42
-        if (callback == null) {
43
-            logger.warn("Callback status " + body.getStatus() + " is not supported yet");
44
-           return 0;
45
-        }
46
-
47
-        int result = callback.handle(body, fileName);
48
-        return result;
49
-    }
50
-}

+ 0
- 35
src/main/java/com/onlyoffice/integration/documentserver/callbacks/Status.java ファイルの表示

@@ -1,35 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.callbacks;
20
-
21
-// document status
22
-public enum Status {
23
-    EDITING(1),  // 1 - document is being edited
24
-    SAVE(2),  // 2 - document is ready for saving
25
-    CORRUPTED(3),  // 3 - document saving error has occurred
26
-    MUST_FORCE_SAVE(6),  // 6 - document is being edited, but the current document state is saved
27
-    CORRUPTED_FORCE_SAVE(7);  // 7 - error has occurred while force saving the document
28
-    private int code;
29
-    Status(final int codeParam) {
30
-        this.code = codeParam;
31
-    }
32
-    public int getCode() {  // get document status
33
-        return this.code;
34
-    }
35
-}

+ 0
- 59
src/main/java/com/onlyoffice/integration/documentserver/callbacks/implementations/EditCallback.java ファイルの表示

@@ -1,59 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.callbacks.implementations;
20
-
21
-import com.onlyoffice.integration.documentserver.callbacks.Callback;
22
-import com.onlyoffice.integration.documentserver.callbacks.Status;
23
-import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
24
-import com.onlyoffice.integration.dto.Action;
25
-import com.onlyoffice.integration.dto.Track;
26
-import org.springframework.beans.factory.annotation.Autowired;
27
-import org.springframework.stereotype.Component;
28
-
29
-@Component
30
-public class EditCallback implements Callback {
31
-    @Autowired
32
-    private CallbackManager callbackManager;
33
-    @Override
34
-    public int handle(final Track body,
35
-                      final String fileName) {  // handle the callback when the document is being edited
36
-        int result = 0;
37
-        Action action =  body.getActions().get(0);  // get the user ID who is editing the document
38
-        if (action.getType().equals(com.onlyoffice.integration.documentserver.models.enums
39
-                .Action.edit)) {  // if this value is not equal to the user ID
40
-            String user =  action.getUserid();  // get user ID
41
-            if (!body.getUsers().contains(user)) {  // if this user is not specified in the body
42
-                String key = body.getKey();  // get document key
43
-                try {
44
-                    // create a command request to forcibly save the document being edited without closing it
45
-                    callbackManager.commandRequest("forcesave", key, null);
46
-                } catch (Exception e) {
47
-                    e.printStackTrace();
48
-                    result = 1;
49
-                }
50
-            }
51
-        }
52
-        return result;
53
-    }
54
-
55
-    @Override
56
-    public int getStatus() {  // get document status
57
-        return Status.EDITING.getCode();  // return status 1 - document is being edited
58
-    }
59
-}

+ 0
- 50
src/main/java/com/onlyoffice/integration/documentserver/callbacks/implementations/ForcesaveCallback.java ファイルの表示

@@ -1,50 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.callbacks.implementations;
20
-
21
-import com.onlyoffice.integration.documentserver.callbacks.Callback;
22
-import com.onlyoffice.integration.documentserver.callbacks.Status;
23
-import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
24
-import com.onlyoffice.integration.dto.Track;
25
-import org.springframework.beans.factory.annotation.Autowired;
26
-import org.springframework.stereotype.Component;
27
-
28
-@Component
29
-public class ForcesaveCallback implements Callback {
30
-    @Autowired
31
-    private CallbackManager callbackManager;
32
-    @Override
33
-    public int handle(final Track body,
34
-                      final String fileName) {  // handle the callback when the force saving request is performed
35
-        int result = 0;
36
-        try {
37
-            callbackManager.processForceSave(body, fileName);  // file force saving process
38
-        } catch (Exception ex) {
39
-            ex.printStackTrace();
40
-            result = 1;
41
-        }
42
-        return result;
43
-    }
44
-
45
-    @Override
46
-    public int getStatus() {  // get document status
47
-        // return status 6 - document is being edited, but the current document state is saved
48
-        return Status.MUST_FORCE_SAVE.getCode();
49
-    }
50
-}

+ 0
- 50
src/main/java/com/onlyoffice/integration/documentserver/callbacks/implementations/SaveCallback.java ファイルの表示

@@ -1,50 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.callbacks.implementations;
20
-
21
-import com.onlyoffice.integration.documentserver.callbacks.Callback;
22
-import com.onlyoffice.integration.documentserver.callbacks.Status;
23
-import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
24
-import com.onlyoffice.integration.dto.Track;
25
-import org.springframework.beans.factory.annotation.Autowired;
26
-import org.springframework.stereotype.Component;
27
-
28
-@Component
29
-public class SaveCallback implements Callback {
30
-    @Autowired
31
-    private CallbackManager callbackManager;
32
-    @Override
33
-    public int handle(final Track body,
34
-                      final String fileName) {  // handle the callback when the saving request is performed
35
-        int result = 0;
36
-        try {
37
-            callbackManager.processSave(body, fileName);  // file saving process
38
-        } catch (Exception ex) {
39
-            ex.printStackTrace();
40
-            result = 1;
41
-        }
42
-
43
-        return result;
44
-    }
45
-
46
-    @Override
47
-    public int getStatus() {  // get document status
48
-        return Status.SAVE.getCode();  // return status 2 - document is ready for saving
49
-    }
50
-}

+ 0
- 28
src/main/java/com/onlyoffice/integration/documentserver/managers/callback/CallbackManager.java ファイルの表示

@@ -1,28 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.callback;
20
-
21
-import com.onlyoffice.integration.dto.Track;
22
-import java.util.HashMap;
23
-
24
-public interface CallbackManager {  // specify the callback manager functions
25
-    void processSave(Track body, String fileName);  // file saving process
26
-    void commandRequest(String method, String key, HashMap meta);  // create a command request
27
-    void processForceSave(Track body, String fileName);  // file force saving process
28
-}

+ 0
- 333
src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java ファイルの表示

@@ -1,333 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.callback;
20
-
21
-import com.fasterxml.jackson.databind.ObjectMapper;
22
-import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
23
-import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
24
-import com.onlyoffice.integration.documentserver.storage.FileStorageMutator;
25
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
26
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
27
-import com.onlyoffice.integration.dto.Action;
28
-import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
29
-import com.onlyoffice.integration.dto.Track;
30
-import lombok.SneakyThrows;
31
-import org.json.simple.JSONObject;
32
-import org.springframework.beans.factory.annotation.Autowired;
33
-import org.springframework.beans.factory.annotation.Value;
34
-import org.springframework.context.annotation.Primary;
35
-import org.springframework.http.HttpStatus;
36
-import org.springframework.stereotype.Component;
37
-
38
-import java.io.ByteArrayInputStream;
39
-import java.io.File;
40
-import java.io.InputStream;
41
-import java.io.OutputStream;
42
-import java.net.URL;
43
-import java.nio.charset.StandardCharsets;
44
-import java.nio.file.Path;
45
-import java.nio.file.Paths;
46
-import java.util.HashMap;
47
-import java.util.List;
48
-import java.util.Map;
49
-
50
-import static com.onlyoffice.integration.documentserver.util.Constants.FILE_SAVE_TIMEOUT;
51
-
52
-// todo: Refactoring
53
-@Component
54
-@Primary
55
-public class DefaultCallbackManager implements CallbackManager {
56
-
57
-    @Value("${files.docservice.url.site}")
58
-    private String docserviceUrlSite;
59
-    @Value("${files.docservice.url.command}")
60
-    private String docserviceUrlCommand;
61
-    @Value("${files.docservice.header}")
62
-    private String documentJwtHeader;
63
-
64
-    @Autowired
65
-    private DocumentManager documentManager;
66
-    @Autowired
67
-    private JwtManager jwtManager;
68
-    @Autowired
69
-    private FileUtility fileUtility;
70
-    @Autowired
71
-    private FileStorageMutator storageMutator;
72
-    @Autowired
73
-    private FileStoragePathBuilder storagePathBuilder;
74
-    @Autowired
75
-    private ObjectMapper objectMapper;
76
-    @Autowired
77
-    private ServiceConverter serviceConverter;
78
-
79
-    // download file from url
80
-    @SneakyThrows
81
-    private byte[] getDownloadFile(final String url) {
82
-        if (url == null || url.isEmpty()) {
83
-            throw new RuntimeException("Url argument is not specified");  // URL isn't specified
84
-        }
85
-
86
-        URL uri = new URL(url);
87
-        java.net.HttpURLConnection connection = (java.net.HttpURLConnection) uri.openConnection();
88
-        connection.setConnectTimeout(FILE_SAVE_TIMEOUT);
89
-        InputStream stream = connection.getInputStream();  // get input stream of the file information from the URL
90
-
91
-        int statusCode = connection.getResponseCode();
92
-        if (statusCode != HttpStatus.OK.value()) {  // checking status code
93
-            connection.disconnect();
94
-            throw new RuntimeException("Document editing service returned status: " + statusCode);
95
-        }
96
-
97
-        if (stream == null) {
98
-            connection.disconnect();
99
-            throw new RuntimeException("Input stream is null");
100
-        }
101
-
102
-        return stream.readAllBytes();
103
-    }
104
-
105
-    // file saving
106
-    @SneakyThrows
107
-    private void saveFile(final byte[] byteArray, final Path path) {
108
-        if (path == null) {
109
-            throw new RuntimeException("Path argument is not specified");  // file isn't specified
110
-        }
111
-        // update a file or create a new one
112
-        storageMutator.createOrUpdateFile(path, new ByteArrayInputStream(byteArray));
113
-    }
114
-
115
-    @Override
116
-    @SneakyThrows
117
-    public void processSave(final Track body, final String fileName) {  // file saving process
118
-        String downloadUri = body.getUrl();
119
-        String changesUri = body.getChangesurl();
120
-        String key = body.getKey();
121
-        String newFileName = fileName;
122
-
123
-        String curExt = fileUtility.getFileExtension(fileName);  // get current file extension
124
-        String downloadExt = "." + body.getFiletype(); // get an extension of the downloaded file
125
-
126
-        // todo: Refactoring
127
-        // convert downloaded file to the file with the current extension if these extensions aren't equal
128
-        if (!curExt.equals(downloadExt)) {
129
-            try {
130
-                String newFileUri = serviceConverter
131
-                        .getConvertedData(downloadUri, downloadExt, curExt,
132
-                                serviceConverter.generateRevisionId(downloadUri), null, false,
133
-                                null).getUri();  // convert a file and get URL to a new file
134
-                if (newFileUri.isEmpty()) {
135
-                    newFileName = documentManager
136
-                            .getCorrectName(fileUtility.getFileNameWithoutExtension(fileName)
137
-                                    + downloadExt);  // get the correct file name if it already exists
138
-                } else {
139
-                    downloadUri = newFileUri;
140
-                }
141
-            } catch (Exception e) {
142
-                newFileName = documentManager
143
-                        .getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + downloadExt);
144
-            }
145
-        }
146
-
147
-        byte[] byteArrayFile = getDownloadFile(downloadUri);  // download document file
148
-
149
-        String storagePath = storagePathBuilder.getFileLocation(newFileName);  // get the path to a new file
150
-        Path lastVersion = Paths.get(storagePathBuilder
151
-                .getFileLocation(fileName));  // get the path to the last file version
152
-
153
-        if (lastVersion.toFile().exists()) {  // if the last file version exists
154
-            Path histDir = Paths.get(storagePathBuilder.getHistoryDir(storagePath));  // get the history directory
155
-            storageMutator.createDirectory(histDir);  // and create it
156
-
157
-            String versionDir = documentManager
158
-                    .versionDir(histDir.toAbsolutePath().toString(),  // get the file version directory
159
-                    storagePathBuilder
160
-                            .getFileVersion(histDir.toAbsolutePath().toString(), false), true);
161
-
162
-            Path ver = Paths.get(versionDir);
163
-            Path toSave = Paths.get(storagePath);
164
-
165
-            storageMutator.createDirectory(ver);  // create the file version directory
166
-
167
-            lastVersion.toFile().renameTo(new File(versionDir + File.separator + "prev" + curExt));
168
-
169
-            saveFile(byteArrayFile, toSave); // save document file
170
-
171
-            byte[] byteArrayChanges = getDownloadFile(changesUri); // download file changes
172
-            saveFile(byteArrayChanges, Path
173
-                    .of(versionDir + File.separator + "diff.zip")); // save file changes to the diff.zip archive
174
-
175
-            JSONObject jsonChanges = new JSONObject();  // create a json object for document changes
176
-            jsonChanges.put("changes", body.getHistory().getChanges());  // put the changes to the json object
177
-            jsonChanges.put("serverVersion", body.getHistory()
178
-                    .getServerVersion());  // put the server version to the json object
179
-            String history = objectMapper.writeValueAsString(jsonChanges);
180
-
181
-            if (history == null && body.getHistory() != null) {
182
-                history = objectMapper.writeValueAsString(body.getHistory());
183
-            }
184
-
185
-            if (history != null && !history.isEmpty()) {
186
-                // write the history changes to the changes.json file
187
-                storageMutator.writeToFile(versionDir + File.separator + "changes.json", history);
188
-            }
189
-
190
-            // write the key value to the key.txt file
191
-            storageMutator.writeToFile(versionDir + File.separator + "key.txt", key);
192
-
193
-            // get the path to the forcesaved file version and remove it
194
-            storageMutator.deleteFile(storagePathBuilder.getForcesavePath(newFileName, false));
195
-        }
196
-    }
197
-
198
-    // todo: Replace (String method) with (Enum method)
199
-    @SneakyThrows
200
-    public void commandRequest(final String method,
201
-                               final String key,
202
-                               final HashMap meta) {  // create a command request
203
-        String documentCommandUrl = docserviceUrlSite + docserviceUrlCommand;
204
-
205
-        URL url = new URL(documentCommandUrl);
206
-        java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
207
-
208
-        HashMap<String, Object> params = new HashMap<String, Object>();
209
-        params.put("c", method);
210
-        params.put("key", key);
211
-
212
-        if (meta != null) {
213
-            params.put("meta", meta);
214
-        }
215
-
216
-        String headerToken;
217
-        // check if a secret key to generate token exists or not
218
-        if (jwtManager.tokenEnabled() && jwtManager.tokenUseForRequest()) {
219
-            Map<String, Object> payloadMap = new HashMap<>();
220
-            payloadMap.put("payload", params);
221
-            headerToken = jwtManager.createToken(payloadMap);  // encode a payload object into a header token
222
-
223
-            // add a header Authorization with a header token and Authorization prefix in it
224
-            connection.setRequestProperty(documentJwtHeader.equals("")
225
-                    ? "Authorization" : documentJwtHeader, "Bearer " + headerToken);
226
-
227
-            String token = jwtManager.createToken(params);  // encode a payload object into a body token
228
-            params.put("token", token);
229
-        }
230
-
231
-        String bodyString = objectMapper.writeValueAsString(params);
232
-
233
-        byte[] bodyByte = bodyString.getBytes(StandardCharsets.UTF_8);
234
-
235
-        connection.setRequestMethod("POST");  // set the request method
236
-        connection
237
-                .setRequestProperty("Content-Type", "application/json; charset=UTF-8");  // set the Content-Type header
238
-        connection.setDoOutput(true);  // set the doOutput field to true
239
-        connection.connect();
240
-
241
-        try (OutputStream os = connection.getOutputStream()) {
242
-            os.write(bodyByte);  // write bytes to the output stream
243
-        }
244
-
245
-        InputStream stream = connection.getInputStream();  // get input stream
246
-
247
-        if (stream == null) {
248
-            throw new RuntimeException("Could not get an answer");
249
-        }
250
-
251
-        String jsonString = serviceConverter.convertStreamToString(stream);  // convert stream to json string
252
-        connection.disconnect();
253
-
254
-        JSONObject response = serviceConverter.convertStringToJSON(jsonString);  // convert json string to json object
255
-        // todo: Add errors ENUM
256
-        String responseCode = response.get("error").toString();
257
-        switch (responseCode) {
258
-            case "0":
259
-            case "4":
260
-                break;
261
-            default:
262
-                throw new RuntimeException(response.toJSONString());
263
-            }
264
-        }
265
-
266
-    @SneakyThrows
267
-    public void processForceSave(final Track body, final String fileNameParam) {  // file force saving process
268
-
269
-        String downloadUri = body.getUrl();
270
-        String fileName = fileNameParam;
271
-
272
-        String curExt = fileUtility.getFileExtension(fileName);  // get current file extension
273
-        String downloadExt = "." + body.getFiletype();  // get an extension of the downloaded file
274
-
275
-        Boolean newFileName = false;
276
-
277
-        // convert downloaded file to the file with the current extension if these extensions aren't equal
278
-        // todo: Extract function
279
-        if (!curExt.equals(downloadExt)) {
280
-            try {
281
-                // convert file and get URL to a new file
282
-                String newFileUri = serviceConverter
283
-                        .getConvertedData(downloadUri, downloadExt, curExt, serviceConverter
284
-                                .generateRevisionId(downloadUri), null, false, null).getUri();
285
-                if (newFileUri.isEmpty()) {
286
-                    newFileName = true;
287
-                } else {
288
-                    downloadUri = newFileUri;
289
-                }
290
-            } catch (Exception e) {
291
-                newFileName = true;
292
-            }
293
-        }
294
-
295
-        byte[] byteArrayFile = getDownloadFile(downloadUri);  // download document file
296
-        String forcesavePath = "";
297
-
298
-        // todo: Use ENUMS
299
-        // todo: Pointless toString conversion
300
-        boolean isSubmitForm = body.getForcesavetype().toString().equals("3");
301
-
302
-        // todo: Extract function
303
-        if (isSubmitForm) {  // if the form is submitted
304
-            if (newFileName) {
305
-                // get the correct file name if it already exists
306
-                fileName = documentManager
307
-                        .getCorrectName(fileUtility
308
-                                .getFileNameWithoutExtension(fileName) + "-form" + downloadExt);
309
-            } else {
310
-                fileName = documentManager
311
-                        .getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + "-form" + curExt);
312
-            }
313
-            forcesavePath = storagePathBuilder.getFileLocation(fileName);  // create forcesave path if it doesn't exist
314
-            List<Action> actions =  body.getActions();
315
-            Action action = actions.get(0);
316
-            String user = action.getUserid();  // get the user ID
317
-            // create meta data for the forcesaved file
318
-            storageMutator.createMeta(fileName, user, "Filling Form");
319
-        } else {
320
-            if (newFileName) {
321
-                fileName = documentManager
322
-                        .getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + downloadExt);
323
-            }
324
-
325
-            forcesavePath = storagePathBuilder.getForcesavePath(fileName, false);
326
-            if (forcesavePath.isEmpty()) {
327
-                forcesavePath = storagePathBuilder.getForcesavePath(fileName, true);
328
-            }
329
-        }
330
-
331
-        saveFile(byteArrayFile, Path.of(forcesavePath));
332
-    }
333
-}

+ 0
- 246
src/main/java/com/onlyoffice/integration/documentserver/managers/document/DefaultDocumentManager.java ファイルの表示

@@ -1,246 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.document;
20
-
21
-import com.onlyoffice.integration.documentserver.storage.FileStorageMutator;
22
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
23
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
24
-import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
25
-import org.springframework.beans.factory.annotation.Autowired;
26
-import org.springframework.beans.factory.annotation.Value;
27
-import org.springframework.context.annotation.Primary;
28
-import org.springframework.stereotype.Component;
29
-
30
-import java.io.File;
31
-import java.io.InputStream;
32
-import java.io.UnsupportedEncodingException;
33
-import java.math.BigDecimal;
34
-import java.math.RoundingMode;
35
-import java.net.InetAddress;
36
-import java.net.URLEncoder;
37
-import java.net.UnknownHostException;
38
-import java.nio.file.Files;
39
-import java.nio.file.Path;
40
-import java.nio.file.Paths;
41
-import java.util.ArrayList;
42
-import java.util.Date;
43
-import java.util.LinkedHashMap;
44
-import java.util.Map;
45
-
46
-import static com.onlyoffice.integration.documentserver.util.Constants.KILOBYTE_SIZE;
47
-
48
-@Component
49
-@Primary
50
-public class DefaultDocumentManager implements DocumentManager {
51
-
52
-    @Value("${files.storage.folder}")
53
-    private String storageFolder;
54
-    @Value("${files.storage}")
55
-    private String filesStorage;
56
-    @Value("${url.track}")
57
-    private String trackUrl;
58
-    @Value("${url.download}")
59
-    private String downloadUrl;
60
-
61
-    @Autowired
62
-    private FileStorageMutator storageMutator;
63
-    @Autowired
64
-    private FileStoragePathBuilder storagePathBuilder;
65
-    @Autowired
66
-    private FileUtility fileUtility;
67
-    @Autowired
68
-    private ServiceConverter serviceConverter;
69
-
70
-    // get URL to the created file
71
-    public String getCreateUrl(final String fileName, final Boolean sample) {
72
-        String fileExt = fileUtility.getFileExtension(fileName).replace(".", "");
73
-        String url = storagePathBuilder.getServerUrl(true)
74
-                + "/create?fileExt=" + fileExt + "&sample=" + sample;
75
-        return url;
76
-    }
77
-
78
-    // get a file name with an index if the file with such a name already exists
79
-    public String getCorrectName(final String fileName) {
80
-        String baseName = fileUtility.getFileNameWithoutExtension(fileName);  // get file name without extension
81
-        String ext = fileUtility.getFileExtension(fileName);  // get file extension
82
-        String name = baseName + ext;  // create a full file name
83
-
84
-        Path path = Paths.get(storagePathBuilder.getFileLocation(name));
85
-
86
-        // run through all the files with such a name in the storage directory
87
-        for (int i = 1; Files.exists(path); i++) {
88
-            name = baseName + " (" + i + ")" + ext;  // and add an index to the base name
89
-            path = Paths.get(storagePathBuilder.getFileLocation(name));
90
-        }
91
-
92
-        return name;
93
-    }
94
-
95
-    // get file URL
96
-    public String getFileUri(final String fileName, final Boolean forDocumentServer) {
97
-        try {
98
-            String serverPath = storagePathBuilder.getServerUrl(forDocumentServer);  // get server URL
99
-            String hostAddress = storagePathBuilder.getStorageLocation();  // get the storage directory
100
-            String filePathDownload = !fileName.contains(InetAddress.getLocalHost().getHostAddress()) ? fileName
101
-                    : fileName.substring(fileName.indexOf(InetAddress.getLocalHost()
102
-                    .getHostAddress()) + InetAddress.getLocalHost().getHostAddress().length() + 1);
103
-            if (!filesStorage.isEmpty() && filePathDownload.contains(filesStorage)) {
104
-                filePathDownload = filePathDownload.substring(filesStorage.length() + 1);
105
-            }
106
-
107
-            String filePath = serverPath + "/download?fileName=" + URLEncoder
108
-                    .encode(filePathDownload, java.nio.charset.StandardCharsets.UTF_8.toString()) + "&userAddress"
109
-                    + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
110
-            return filePath;
111
-        } catch (UnsupportedEncodingException | UnknownHostException e) {
112
-            return "";
113
-        }
114
-    }
115
-
116
-    // get file URL
117
-    public String getHistoryFileUrl(final String fileName, final Integer version, final String file,
118
-                                    final Boolean forDocumentServer) {
119
-        try {
120
-            String serverPath = storagePathBuilder.getServerUrl(forDocumentServer);  // get server URL
121
-            String hostAddress = storagePathBuilder.getStorageLocation();  // get the storage directory
122
-            String filePathDownload = !fileName.contains(InetAddress.getLocalHost().getHostAddress()) ? fileName
123
-                    : fileName.substring(fileName.indexOf(InetAddress.getLocalHost().getHostAddress())
124
-                    + InetAddress.getLocalHost().getHostAddress().length() + 1);
125
-            String userAddress = forDocumentServer ? "&userAddress" + URLEncoder
126
-                    .encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString()) : "";
127
-            String filePath = serverPath + "/downloadhistory?fileName=" + URLEncoder
128
-                    .encode(filePathDownload, java.nio.charset.StandardCharsets.UTF_8.toString())
129
-                + "&ver=" + version + "&file=" + file
130
-                + userAddress;
131
-            return filePath;
132
-        } catch (UnsupportedEncodingException | UnknownHostException e) {
133
-            return "";
134
-        }
135
-    }
136
-
137
-    // get the callback URL
138
-    public String getCallback(final String fileName) {
139
-        String serverPath = storagePathBuilder.getServerUrl(true);
140
-        String storageAddress = storagePathBuilder.getStorageLocation();
141
-        try {
142
-            String query = trackUrl + "?fileName="
143
-                    + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString())
144
-                    + "&userAddress=" + URLEncoder
145
-                    .encode(storageAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
146
-            return serverPath + query;
147
-        } catch (UnsupportedEncodingException e) {
148
-            return "";
149
-        }
150
-    }
151
-
152
-    // get URL to download a file
153
-    public String getDownloadUrl(final String fileName, final Boolean isServer) {
154
-        String serverPath = storagePathBuilder.getServerUrl(isServer);
155
-        String storageAddress = storagePathBuilder.getStorageLocation();
156
-        try {
157
-            String userAddress = isServer ? "&userAddress=" + URLEncoder
158
-                    .encode(storageAddress, java.nio.charset.StandardCharsets.UTF_8.toString()) : "";
159
-            String query = downloadUrl + "?fileName="
160
-                    + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString())
161
-                    + userAddress;
162
-
163
-            return serverPath + query;
164
-        } catch (UnsupportedEncodingException e) {
165
-            return "";
166
-        }
167
-    }
168
-
169
-    // get file information
170
-    public ArrayList<Map<String, Object>> getFilesInfo() {
171
-        ArrayList<Map<String, Object>> files = new ArrayList<>();
172
-
173
-        // run through all the stored files
174
-        for (File file : storageMutator.getStoredFiles()) {
175
-            Map<String, Object> map = new LinkedHashMap<>();  // write all the parameters to the map
176
-            map.put("version", storagePathBuilder.getFileVersion(file.getName(), false));
177
-            map.put("id", serviceConverter
178
-                    .generateRevisionId(storagePathBuilder.getStorageLocation()
179
-                            + "/" + file.getName() + "/"
180
-                            + Paths.get(storagePathBuilder.getFileLocation(file.getName()))
181
-                            .toFile()
182
-                            .lastModified()));
183
-            map.put("contentLength", new BigDecimal(String.valueOf((file.length() / Double.valueOf(KILOBYTE_SIZE))))
184
-                    .setScale(2, RoundingMode.HALF_UP) + " KB");
185
-            map.put("pureContentLength", file.length());
186
-            map.put("title", file.getName());
187
-            map.put("updated", String.valueOf(new Date(file.lastModified())));
188
-            files.add(map);
189
-        }
190
-
191
-        return files;
192
-    }
193
-
194
-    // get file information by its ID
195
-    public ArrayList<Map<String, Object>> getFilesInfo(final String fileId) {
196
-        ArrayList<Map<String, Object>> file = new ArrayList<>();
197
-
198
-        for (Map<String, Object> map : getFilesInfo()) {
199
-            if (map.get("id").equals(fileId)) {
200
-                file.add(map);
201
-                break;
202
-            }
203
-        }
204
-
205
-        return file;
206
-    }
207
-
208
-    // get the path to the file version by the history path and file version
209
-    public String versionDir(final String path, final Integer version, final boolean historyPath) {
210
-        if (!historyPath) {
211
-            return storagePathBuilder.getHistoryDir(storagePathBuilder.getFileLocation(path)) + version;
212
-        }
213
-        return path + File.separator + version;
214
-    }
215
-
216
-    // create demo document
217
-    public String createDemo(final String fileExt, final Boolean sample, final String uid, final String uname) {
218
-        String demoName = (sample ? "sample." : "new.")
219
-                + fileExt;  // create sample or new template file with the necessary extension
220
-        String demoPath =
221
-            "assets"
222
-            + File.separator
223
-            + "document-templates"
224
-            + File.separator
225
-            + (sample ? "sample" : "new")
226
-            + File.separator
227
-            + demoName;
228
-
229
-        // get a file name with an index if the file with such a name already exists
230
-        String fileName = getCorrectName(demoName);
231
-
232
-        InputStream stream = Thread.currentThread()
233
-                                    .getContextClassLoader()
234
-                                    .getResourceAsStream(demoPath);  // get the input file stream
235
-
236
-        if (stream == null) {
237
-            return null;
238
-        }
239
-
240
-        storageMutator.createFile(Path.of(storagePathBuilder
241
-                .getFileLocation(fileName)), stream);  // create a file in the specified directory
242
-        storageMutator.createMeta(fileName, uid, uname);  // create meta information of the demo file
243
-
244
-        return fileName;
245
-    }
246
-}

+ 0
- 42
src/main/java/com/onlyoffice/integration/documentserver/managers/document/DocumentManager.java ファイルの表示

@@ -1,42 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.document;
20
-
21
-import java.util.ArrayList;
22
-import java.util.Map;
23
-
24
-// specify the document manager functions
25
-public interface DocumentManager {
26
-
27
-    // get a file name with an index if the file with such a name already exists
28
-    String getCorrectName(String fileName);
29
-    String getFileUri(String fileName, Boolean forDocumentServer);  // get file URL
30
-    String getHistoryFileUrl(String fileName, Integer version, String file, Boolean forDocumentServer);  // get file URL
31
-    String getCallback(String fileName);  // get the callback URL
32
-    String getDownloadUrl(String fileName, Boolean forDocumentServer);  // get URL to download a file
33
-    ArrayList<Map<String, Object>> getFilesInfo();  // get file information
34
-    ArrayList<Map<String, Object>> getFilesInfo(String fileId);  // get file information by its ID
35
-
36
-    //  get the path to the file version by the history path and file version
37
-    String versionDir(String path, Integer version, boolean historyPath);
38
-
39
-    // create demo document
40
-    String createDemo(String fileExt, Boolean sample, String uid, String uname) throws Exception;
41
-    String getCreateUrl(String fileName, Boolean sample);  // get URL to the created file
42
-}

+ 0
- 183
src/main/java/com/onlyoffice/integration/documentserver/managers/history/DefaultHistoryManager.java ファイルの表示

@@ -1,183 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.history;
20
-
21
-import com.fasterxml.jackson.core.JsonProcessingException;
22
-import com.fasterxml.jackson.databind.ObjectMapper;
23
-import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
24
-import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
25
-import com.onlyoffice.integration.documentserver.models.filemodel.Document;
26
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
27
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
28
-import lombok.SneakyThrows;
29
-import org.json.simple.JSONArray;
30
-import org.json.simple.JSONObject;
31
-import org.json.simple.parser.JSONParser;
32
-import org.springframework.beans.factory.annotation.Autowired;
33
-import org.springframework.stereotype.Component;
34
-
35
-import java.io.File;
36
-import java.io.FileInputStream;
37
-import java.util.ArrayList;
38
-import java.util.HashMap;
39
-import java.util.List;
40
-import java.util.Map;
41
-import java.util.Scanner;
42
-
43
-// todo: Rebuild completely
44
-@Component
45
-public class DefaultHistoryManager implements HistoryManager {
46
-
47
-    @Autowired
48
-    private FileStoragePathBuilder storagePathBuilder;
49
-
50
-    @Autowired
51
-    private DocumentManager documentManager;
52
-
53
-    @Autowired
54
-    private JwtManager jwtManager;
55
-
56
-    @Autowired
57
-    private FileUtility fileUtility;
58
-
59
-    @Autowired
60
-    private JSONParser parser;
61
-
62
-    @Autowired
63
-    private ObjectMapper objectMapper;
64
-
65
-    // todo: Refactoring
66
-    @SneakyThrows
67
-    public String[] getHistory(final Document document) {  // get document history
68
-
69
-        // get history directory
70
-        String histDir = storagePathBuilder.getHistoryDir(storagePathBuilder.getFileLocation(document.getTitle()));
71
-        Integer curVer = storagePathBuilder.getFileVersion(histDir, false);  // get current file version
72
-
73
-        if (curVer > 0) {  // check if the current file version is greater than 0
74
-            List<Object> hist = new ArrayList<>();
75
-            Map<String, Object> histData = new HashMap<>();
76
-
77
-            for (Integer i = 1; i <= curVer; i++) {  // run through all the file versions
78
-                Map<String, Object> obj = new HashMap<String, Object>();
79
-                Map<String, Object> dataObj = new HashMap<String, Object>();
80
-                String verDir = documentManager
81
-                        .versionDir(histDir, i, true);  // get the path to the given file version
82
-
83
-                String key = i == curVer ? document.getKey() : readFileToEnd(new File(verDir
84
-                        + File.separator + "key.txt"));  // get document key
85
-                obj.put("key", key);
86
-                obj.put("version", i);
87
-
88
-                if (i == 1) {  // check if the version number is equal to 1
89
-                    String createdInfo = readFileToEnd(new File(histDir
90
-                            + File.separator + "createdInfo.json"));  // get file with meta data
91
-                    JSONObject json = (JSONObject) parser.parse(createdInfo);  // and turn it into json object
92
-
93
-                    // write meta information to the object (user information and creation date)
94
-                    obj.put("created", json.get("created"));
95
-                    Map<String, Object> user = new HashMap<String, Object>();
96
-                    user.put("id", json.get("id"));
97
-                    user.put("name", json.get("name"));
98
-                    obj.put("user", user);
99
-                }
100
-
101
-                dataObj.put("fileType", fileUtility
102
-                        .getFileExtension(document.getTitle()).replace(".", ""));
103
-                dataObj.put("key", key);
104
-                dataObj.put("url", i == curVer ? document.getUrl()
105
-                        : documentManager.getHistoryFileUrl(document.getTitle(), i, "prev" + fileUtility
106
-                        .getFileExtension(document.getTitle()), true));
107
-                if (!document.getDirectUrl().equals("")) {
108
-                    dataObj.put("directUrl", i == curVer ? document.getDirectUrl()
109
-                            : documentManager.getHistoryFileUrl(document.getTitle(), i, "prev" + fileUtility
110
-                            .getFileExtension(document.getTitle()), false));
111
-                }
112
-                dataObj.put("version", i);
113
-
114
-                if (i > 1) {  //check if the version number is greater than 1
115
-                    // if so, get the path to the changes.json file
116
-                    JSONObject changes = (JSONObject) parser.parse(readFileToEnd(new File(documentManager
117
-                            .versionDir(histDir, i - 1, true) + File.separator + "changes.json")));
118
-                    JSONObject change = (JSONObject) ((JSONArray) changes.get("changes")).get(0);
119
-
120
-                    // write information about changes to the object
121
-                    obj.put("changes", changes.get("changes"));
122
-                    obj.put("serverVersion", changes.get("serverVersion"));
123
-                    obj.put("created", change.get("created"));
124
-                    obj.put("user", change.get("user"));
125
-
126
-                    // get the history data from the previous file version
127
-                    Map<String, Object> prev = (Map<String, Object>) histData.get(Integer.toString(i - 2));
128
-                    Map<String, Object> prevInfo = new HashMap<String, Object>();
129
-                    prevInfo.put("fileType", prev.get("fileType"));
130
-                    prevInfo.put("key", prev.get("key"));  // write key and URL information about previous file version
131
-                    prevInfo.put("url", prev.get("url"));
132
-                    if (!document.getDirectUrl().equals("")) {
133
-                        prevInfo.put("directUrl", prev.get("directUrl"));
134
-                    }
135
-
136
-                    // write information about previous file version to the data object
137
-                    dataObj.put("previous", prevInfo);
138
-                    // write the path to the diff.zip archive with differences in this file version
139
-                    Integer verdiff = i - 1;
140
-                    dataObj.put("changesUrl", documentManager
141
-                            .getHistoryFileUrl(document.getTitle(), verdiff, "diff.zip", true));
142
-                }
143
-
144
-                if (jwtManager.tokenEnabled()) {
145
-                    dataObj.put("token", jwtManager.createToken(dataObj));
146
-                }
147
-
148
-                hist.add(obj);
149
-                histData.put(Integer.toString(i - 1), dataObj);
150
-            }
151
-
152
-            // write history information about the current file version to the history object
153
-            Map<String, Object> histObj = new HashMap<String, Object>();
154
-            histObj.put("currentVersion", curVer);
155
-            histObj.put("history", hist);
156
-
157
-            try {
158
-                return new String[]{objectMapper.writeValueAsString(histObj),
159
-                        objectMapper.writeValueAsString(histData)};
160
-            } catch (JsonProcessingException e) {
161
-                e.printStackTrace();
162
-            }
163
-        }
164
-        return new String[]{"", ""};
165
-    }
166
-
167
-    // read a file
168
-    private String readFileToEnd(final File file) {
169
-        String output = "";
170
-        try {
171
-            try (FileInputStream is = new FileInputStream(file)) {
172
-                Scanner scanner = new Scanner(is);  // read data from the source
173
-                scanner.useDelimiter("\\A");
174
-                while (scanner.hasNext()) {
175
-                    output += scanner.next();
176
-                }
177
-                scanner.close();
178
-            }
179
-        } catch (Exception e) {
180
-        }
181
-        return output;
182
-    }
183
-}

+ 0
- 26
src/main/java/com/onlyoffice/integration/documentserver/managers/history/HistoryManager.java ファイルの表示

@@ -1,26 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.history;
20
-
21
-import com.onlyoffice.integration.documentserver.models.filemodel.Document;
22
-
23
-// specify the history manager functions
24
-public interface HistoryManager {
25
-    String[] getHistory(Document document);  // get document history
26
-}

+ 0
- 135
src/main/java/com/onlyoffice/integration/documentserver/managers/jwt/DefaultJwtManager.java ファイルの表示

@@ -1,135 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.jwt;
20
-
21
-import com.fasterxml.jackson.databind.ObjectMapper;
22
-import org.json.simple.JSONObject;
23
-import org.json.simple.parser.JSONParser;
24
-import org.primeframework.jwt.Signer;
25
-import org.primeframework.jwt.Verifier;
26
-import org.primeframework.jwt.domain.JWT;
27
-import org.primeframework.jwt.hmac.HMACSigner;
28
-import org.primeframework.jwt.hmac.HMACVerifier;
29
-import org.springframework.beans.factory.annotation.Autowired;
30
-import org.springframework.beans.factory.annotation.Value;
31
-import org.springframework.stereotype.Component;
32
-
33
-import java.util.LinkedHashMap;
34
-import java.util.Map;
35
-
36
-@Component
37
-public class DefaultJwtManager implements JwtManager {
38
-    @Value("${files.docservice.secret}")
39
-    private String tokenSecret;
40
-    @Value("${files.docservice.token-use-for-request}")
41
-    private String tokenUseForRequest;
42
-    @Autowired
43
-    private ObjectMapper objectMapper;
44
-    @Autowired
45
-    private JSONParser parser;
46
-
47
-    // create document token
48
-    @Override
49
-    public String createToken(final Map<String, Object> payloadClaims) {
50
-        try {
51
-            // build a HMAC signer using a SHA-256 hash
52
-            Signer signer = HMACSigner.newSHA256Signer(tokenSecret);
53
-            JWT jwt = new JWT();
54
-            for (String key : payloadClaims.keySet()) {  // run through all the keys from the payload
55
-                jwt.addClaim(key, payloadClaims.get(key));  // and write each claim to the jwt
56
-            }
57
-            return JWT.getEncoder().encode(jwt, signer);  // sign and encode the JWT to a JSON string representation
58
-        } catch (Exception e) {
59
-            return "";
60
-        }
61
-    }
62
-
63
-    // check if the token is enabled
64
-    @Override
65
-    public boolean tokenEnabled() {
66
-        return tokenSecret != null && !tokenSecret.isEmpty();
67
-    }
68
-
69
-    @Override
70
-    public boolean tokenUseForRequest() {
71
-        return Boolean.parseBoolean(tokenUseForRequest) && !tokenUseForRequest.isEmpty();
72
-    }
73
-
74
-    // read document token
75
-    @Override
76
-    public JWT readToken(final String token) {
77
-        try {
78
-            // build a HMAC verifier using the token secret
79
-            Verifier verifier = HMACVerifier.newVerifier(tokenSecret);
80
-
81
-            // verify and decode the encoded string JWT to a rich object
82
-            return JWT.getDecoder().decode(token, verifier);
83
-        } catch (Exception exception) {
84
-            return null;
85
-        }
86
-    }
87
-
88
-    // parse the body
89
-    @Override
90
-    public JSONObject parseBody(final String payload, final String header) {
91
-        JSONObject body;
92
-        try {
93
-            Object obj = parser.parse(payload);  // get body parameters by parsing the payload
94
-            body = (JSONObject) obj;
95
-        } catch (Exception ex) {
96
-            throw new RuntimeException("{\"error\":1,\"message\":\"JSON Parsing error\"}");
97
-        }
98
-        if (tokenEnabled() && tokenUseForRequest()) {  // check if the token is enabled
99
-            String token = (String) body.get("token");  // get token from the body
100
-            if (token == null) {  // if token is empty
101
-                if (header != null && header.trim()!="") {  // and the header is defined
102
-
103
-                    // get token from the header (it is placed after the Bearer prefix if it exists)
104
-                    token = header.startsWith("Bearer ") ? header.substring("Bearer ".length()) : header;
105
-                }
106
-            }
107
-            if (token == null || token.trim()=="") {
108
-                throw new RuntimeException("{\"error\":1,\"message\":\"JWT expected\"}");
109
-            }
110
-
111
-            JWT jwt = readToken(token);  // read token
112
-            if (jwt == null) {
113
-                throw new RuntimeException("{\"error\":1,\"message\":\"JWT validation failed\"}");
114
-            }
115
-            if (jwt.getObject("payload") != null) {  // get payload from the token and check if it is not empty
116
-                try {
117
-                    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> jwtPayload =
118
-                            (LinkedHashMap<String, Object>) jwt.getObject("payload");
119
-
120
-                    jwt.claims = jwtPayload;
121
-                } catch (Exception ex) {
122
-                    throw new RuntimeException("{\"error\":1,\"message\":\"Wrong payload\"}");
123
-                }
124
-            }
125
-            try {
126
-                Object obj = parser.parse(objectMapper.writeValueAsString(jwt.claims));
127
-                body = (JSONObject) obj;
128
-            } catch (Exception ex) {
129
-                throw new RuntimeException("{\"error\":1,\"message\":\"Parsing error\"}");
130
-            }
131
-        }
132
-
133
-        return body;
134
-    }
135
-}

+ 0
- 33
src/main/java/com/onlyoffice/integration/documentserver/managers/jwt/JwtManager.java ファイルの表示

@@ -1,33 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.jwt;
20
-
21
-import org.json.simple.JSONObject;
22
-import org.primeframework.jwt.domain.JWT;
23
-
24
-import java.util.Map;
25
-
26
-// specify the jwt manager functions
27
-public interface JwtManager {
28
-    boolean tokenEnabled();  // check if the token is enabled
29
-    boolean tokenUseForRequest();  // check if the token is enabled
30
-    String createToken(Map<String, Object> payloadClaims);  // create document token
31
-    JWT readToken(String token);  // read document token
32
-    JSONObject parseBody(String payload, String header);  // parse the body
33
-}

+ 0
- 70
src/main/java/com/onlyoffice/integration/documentserver/managers/template/SampleTemplateManager.java ファイルの表示

@@ -1,70 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.template;
20
-
21
-import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
22
-import com.onlyoffice.integration.documentserver.models.filemodel.Template;
23
-import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
24
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
25
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
26
-import org.springframework.beans.factory.annotation.Autowired;
27
-import org.springframework.beans.factory.annotation.Qualifier;
28
-import org.springframework.stereotype.Component;
29
-
30
-import java.util.List;
31
-
32
-@Component
33
-@Qualifier("sample")
34
-public class SampleTemplateManager implements TemplateManager {
35
-    @Autowired
36
-    private DocumentManager documentManager;
37
-
38
-    @Autowired
39
-    private FileStoragePathBuilder storagePathBuilder;
40
-
41
-    @Autowired
42
-    private FileUtility fileUtility;
43
-
44
-    // create a template document with the specified name
45
-    public List<Template> createTemplates(final String fileName) {
46
-        List<Template> templates = List.of(
47
-                new Template("", "Blank", documentManager
48
-                        .getCreateUrl(fileName, false)),  // create a blank template
49
-                new Template(getTemplateImageUrl(fileName), "With sample content", documentManager
50
-                        .getCreateUrl(fileName,
51
-                                true))  // create a template with sample content using the template image
52
-        );
53
-
54
-        return templates;
55
-    }
56
-
57
-    // get the template image URL for the specified file
58
-    public String getTemplateImageUrl(final String fileName) {
59
-        DocumentType fileType = fileUtility.getDocumentType(fileName);  // get the file type
60
-        String path = storagePathBuilder.getServerUrl(true);  // get server URL
61
-        if (fileType.equals(DocumentType.word)) {  // get URL to the template image for the word document type
62
-            return path + "/css/img/file_docx.svg";
63
-        } else if (fileType.equals(DocumentType.slide)) {  // get URL to the template image for the slide document type
64
-            return path + "/css/img/file_pptx.svg";
65
-        } else if (fileType.equals(DocumentType.cell)) {  // get URL to the template image for the cell document type
66
-            return path + "/css/img/file_xlsx.svg";
67
-        }
68
-        return path + "/css/img/file_docx.svg";  // get URL to the template image for the default document type (word)
69
-    }
70
-}

+ 0
- 28
src/main/java/com/onlyoffice/integration/documentserver/managers/template/TemplateManager.java ファイルの表示

@@ -1,28 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.managers.template;
20
-
21
-import com.onlyoffice.integration.documentserver.models.filemodel.Template;
22
-import java.util.List;
23
-
24
-// specify the template manager functions
25
-public interface TemplateManager {
26
-    List<Template> createTemplates(String fileName);  // create a template document with the specified name
27
-    String getTemplateImageUrl(String fileName);  // get the template image URL for the specified file
28
-}

+ 0
- 24
src/main/java/com/onlyoffice/integration/documentserver/models/AbstractModel.java ファイルの表示

@@ -1,24 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models;
20
-
21
-import java.io.Serializable;
22
-
23
-public abstract class AbstractModel implements Serializable {
24
-}

+ 0
- 53
src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Customization.java ファイルの表示

@@ -1,53 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.configurations;
20
-
21
-import lombok.Getter;
22
-import lombok.Setter;
23
-import org.springframework.beans.factory.annotation.Autowired;
24
-import org.springframework.context.annotation.Scope;
25
-import org.springframework.stereotype.Component;
26
-
27
-@Component
28
-@Scope("prototype")
29
-@Getter
30
-@Setter
31
-/* The parameters which allow to customize the editor interface so that it looked like your
32
- other products (if there are any) and change the presence or absence of the additional buttons,
33
-  links, change logos and editor owner details. */
34
-public class Customization {
35
-    @Autowired
36
-    private Logo logo;  // the image file at the top left corner of the Editor header
37
-    @Autowired
38
-    private Goback goback;  // the settings for the Open file location menu button and upper right corner button
39
-    private Boolean autosave = true;  // if the Autosave menu option is enabled or disabled
40
-    private Boolean comments = true;  // if the Comments menu button is displayed or hidden
41
-    private Boolean compactHeader = false;  /* if the additional action buttons are displayed
42
-    in the upper part of the editor window header next to the logo (false) or in the toolbar (true) */
43
-    private Boolean compactToolbar = false;  // if the top toolbar type displayed is full (false) or compact (true)
44
-    private Boolean compatibleFeatures = false;  // the use of functionality only compatible with the OOXML format
45
-    private Boolean forcesave = false;  /* add the request for the forced file saving to the callback handler
46
-     when saving the document within the document editing service */
47
-    private Boolean help = true;  //  if the Help menu button is displayed or hidden
48
-    private Boolean hideRightMenu = false;  // if the right menu is displayed or hidden on first loading
49
-    private Boolean hideRulers = false;  // if the editor rulers are displayed or hidden
50
-    private Boolean submitForm = false;  // if the Submit form button is displayed or hidden
51
-    private Boolean about = true;
52
-    private Boolean feedback = true;
53
-}

+ 0
- 40
src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Embedded.java ファイルの表示

@@ -1,40 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.configurations;
20
-
21
-import com.onlyoffice.integration.documentserver.models.enums.ToolbarDocked;
22
-import lombok.Getter;
23
-import lombok.Setter;
24
-import org.springframework.context.annotation.Scope;
25
-import org.springframework.stereotype.Component;
26
-
27
-@Component
28
-@Scope("prototype")
29
-@Getter
30
-@Setter
31
-/* The parameters which allow to change the settings
32
- which define the behavior of the buttons in the embedded mode */
33
-public class Embedded {
34
-    private String embedUrl;  /* the absolute URL to the document serving as a source file for the document embedded
35
-     into the web page */
36
-    private String saveUrl;  /* the absolute URL that will allow the document to be saved
37
-     onto the user personal computer */
38
-    private String shareUrl;  // the absolute URL that will allow other users to share this document
39
-    private ToolbarDocked toolbarDocked;  // the place for the embedded viewer toolbar, can be either top or bottom
40
-}

+ 0
- 48
src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Goback.java ファイルの表示

@@ -1,48 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.configurations;
20
-
21
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
22
-import lombok.Getter;
23
-import org.springframework.beans.factory.annotation.Autowired;
24
-import org.springframework.beans.factory.annotation.Value;
25
-import org.springframework.context.annotation.Scope;
26
-import org.springframework.stereotype.Component;
27
-
28
-import javax.annotation.PostConstruct;
29
-
30
-@Component
31
-@Scope("prototype")
32
-public class Goback {  // the settings for the Open file location menu button and upper right corner button
33
-
34
-    @Autowired
35
-    private FileStoragePathBuilder storagePathBuilder;
36
-
37
-    @Value("${url.index}")
38
-    private String indexMapping;
39
-
40
-    @Getter
41
-    private String url;  /* the absolute URL to the website address which will be opened
42
-    when clicking the Open file location menu button */
43
-
44
-    @PostConstruct
45
-    private void init() {
46
-        this.url = storagePathBuilder.getServerUrl(false) + indexMapping;
47
-    }
48
-}

+ 0
- 45
src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Info.java ファイルの表示

@@ -1,45 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.configurations;
20
-
21
-import lombok.Getter;
22
-import lombok.Setter;
23
-import org.springframework.context.annotation.Scope;
24
-import org.springframework.stereotype.Component;
25
-
26
-import java.text.SimpleDateFormat;
27
-import java.util.Date;
28
-import java.util.Locale;
29
-
30
-@Component
31
-@Scope("prototype")
32
-@Getter
33
-@Setter
34
-/* The additional parameters for the document (document owner, folder where the document is stored,
35
- uploading date, sharing settings) */
36
-public class Info {
37
-    private String owner = "Me";  // the name of the document owner/creator
38
-    private Boolean favorite = null;  // the highlighting state of the Favorite icon
39
-    private String uploaded = getDate();  // the document uploading date
40
-
41
-    private String getDate() {
42
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US);
43
-        return simpleDateFormat.format(new Date());
44
-    }
45
-}

+ 0
- 38
src/main/java/com/onlyoffice/integration/documentserver/models/configurations/Logo.java ファイルの表示

@@ -1,38 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.configurations;
20
-
21
-import lombok.Getter;
22
-import lombok.Setter;
23
-import org.springframework.beans.factory.annotation.Value;
24
-import org.springframework.context.annotation.Scope;
25
-import org.springframework.stereotype.Component;
26
-
27
-@Component
28
-@Scope("prototype")
29
-@Getter
30
-@Setter
31
-public class Logo {  // the image file at the top left corner of the Editor header
32
-    @Value("${logo.image}")
33
-    private String image;  // the path to the image file used to show in common work mode
34
-    @Value("${logo.imageEmbedded}")
35
-    private String imageEmbedded;  // the path to the image file used to show in the embedded mode
36
-    @Value("${logo.url}")
37
-    private String url;  // the absolute URL which will be used when someone clicks the logo image
38
-}

+ 0
- 32
src/main/java/com/onlyoffice/integration/documentserver/models/enums/Action.java ファイルの表示

@@ -1,32 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.enums;
20
-
21
-public enum Action {
22
-    edit,
23
-    review,
24
-    view,
25
-    embedded,
26
-    filter,
27
-    comment,
28
-    chat,
29
-    fillForms,
30
-    blockcontent,
31
-    protect
32
-}

+ 0
- 48
src/main/java/com/onlyoffice/integration/documentserver/models/enums/ConvertErrorType.java ファイルの表示

@@ -1,48 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.enums;
20
-
21
-public enum ConvertErrorType {
22
-    EMPTY_ERROR(0, ""),
23
-    CONVERTATION_UNKNOWN(-1, "Error convertation unknown"),
24
-    CONVERTATION_TIMEOUT(-2, "Error convertation timeout"),
25
-    CONVERTATION_ERROR(-3, "Error convertation error"),
26
-    DOWNLOAD_ERROR(-4, "Error download error"),
27
-    UNEXPECTED_GUID_ERROR(-5, "Error unexpected guid"),
28
-    DATABASE_ERROR(-6, "Error database"),
29
-    DOCUMENT_REQUEST_ERROR(-7, "Error document request"),
30
-    DOCUMENT_VKEY_ERROR(-8, "Error document VKey");
31
-
32
-    private final int code;
33
-    private final String label;
34
-
35
-    ConvertErrorType(final int codeParam, final String labelParam) {
36
-        this.code = codeParam;
37
-        this.label = labelParam;
38
-    }
39
-
40
-    public static String labelOfCode(final int code) {
41
-        for (ConvertErrorType convertErrorType : values()) {
42
-            if (convertErrorType.code == code) {
43
-                return convertErrorType.label;
44
-            }
45
-        }
46
-        return "ErrorCode = " + code;
47
-    }
48
-}

+ 0
- 25
src/main/java/com/onlyoffice/integration/documentserver/models/enums/DocumentType.java ファイルの表示

@@ -1,25 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.enums;
20
-
21
-public enum DocumentType {
22
-    word,
23
-    cell,
24
-    slide
25
-}

+ 0
- 24
src/main/java/com/onlyoffice/integration/documentserver/models/enums/Mode.java ファイルの表示

@@ -1,24 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.enums;
20
-
21
-public enum Mode {
22
-    edit,
23
-    view
24
-}

+ 0
- 24
src/main/java/com/onlyoffice/integration/documentserver/models/enums/ToolbarDocked.java ファイルの表示

@@ -1,24 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.enums;
20
-
21
-public enum ToolbarDocked {
22
-    top,
23
-    bottom
24
-}

+ 0
- 25
src/main/java/com/onlyoffice/integration/documentserver/models/enums/Type.java ファイルの表示

@@ -1,25 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.enums;
20
-
21
-public enum Type {
22
-    desktop,
23
-    mobile,
24
-    embedded
25
-}

+ 0
- 41
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/CommentGroup.java ファイルの表示

@@ -1,41 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import com.fasterxml.jackson.annotation.JsonInclude;
22
-import com.onlyoffice.integration.documentserver.serializers.SerializerFilter;
23
-import lombok.AllArgsConstructor;
24
-import lombok.Data;
25
-import lombok.NoArgsConstructor;
26
-import org.springframework.stereotype.Component;
27
-
28
-import java.util.List;
29
-
30
-@Component
31
-@Data
32
-@NoArgsConstructor
33
-@AllArgsConstructor
34
-public class CommentGroup {
35
-    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
36
-    private List<String> view;  // define a list of groups whose comments the user can view
37
-    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
38
-    private List<String> edit;  // define a list of groups whose comments the user can edit
39
-    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
40
-    private List<String> remove;  // define a list of groups whose comments the user can remove
41
-}

+ 0
- 49
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/Document.java ファイルの表示

@@ -1,49 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import com.onlyoffice.integration.documentserver.models.configurations.Info;
22
-import lombok.Getter;
23
-import lombok.Setter;
24
-import org.springframework.beans.factory.annotation.Autowired;
25
-import org.springframework.context.annotation.Scope;
26
-import org.springframework.stereotype.Component;
27
-
28
-import java.util.HashMap;
29
-
30
-@Component
31
-@Scope("prototype")
32
-@Getter
33
-@Setter
34
-public class Document {  // the parameters pertaining to the document (title, url, file type, etc.)
35
-    @Autowired
36
-    private Info info;  /* additional parameters for the document (document owner, folder where the document is stored,
37
-     uploading date, sharing settings) */
38
-    @Autowired
39
-    private Permission permissions;  // the permission for the document to be edited and downloaded or not
40
-    private String fileType;  //  the file type for the source viewed or edited document
41
-    private String key;  // the unique document identifier used by the service to recognize the document
42
-    private String urlUser;  /* the absolute URL that will allow the document to be saved
43
-    onto the user personal computer */
44
-    private String title;  /* the desired file name for the viewed or edited document which will also be used
45
-    as file name when the document is downloaded */
46
-    private String url;  // the absolute URL where the source viewed or edited document is stored
47
-    private String directUrl;
48
-    private HashMap<String, Object> referenceData;
49
-}

+ 0
- 59
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/EditorConfig.java ファイルの表示

@@ -1,59 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import com.onlyoffice.integration.documentserver.models.configurations.Customization;
22
-import com.onlyoffice.integration.documentserver.models.configurations.Embedded;
23
-import com.onlyoffice.integration.documentserver.models.enums.Mode;
24
-import lombok.AllArgsConstructor;
25
-import lombok.Data;
26
-import lombok.NoArgsConstructor;
27
-import org.springframework.beans.factory.annotation.Autowired;
28
-import org.springframework.context.annotation.Scope;
29
-import org.springframework.stereotype.Component;
30
-
31
-import java.util.HashMap;
32
-import java.util.List;
33
-
34
-@Component
35
-@Scope("prototype")
36
-@Data
37
-@NoArgsConstructor
38
-@AllArgsConstructor
39
-public class EditorConfig {  /* the parameters pertaining to the editor interface: opening mode (viewer or editor),
40
- interface language, additional buttons, etc. */
41
-    private HashMap<String, Object> actionLink = null;  /* the data which contains the information about the
42
-    action in the document that will be scrolled to */
43
-    private String callbackUrl;  // the absolute URL to the document storage service
44
-    private HashMap<String, Object> coEditing = null;
45
-    private String createUrl;  // the absolute URL of the document where it will be created and available after creation
46
-    @Autowired
47
-    private Customization customization;  /* the parameters which allow to customize the editor interface
48
-     so that it looked like your other products (if there are any) and change the presence or absence
49
-      of the additional buttons, links, change logos and editor owner details */
50
-    @Autowired
51
-    private Embedded embedded;  /* the parameters which allow to change the settings which define
52
-     the behavior of the buttons in the embedded mode */
53
-    private String lang;  // the editor interface language
54
-    private Mode mode;  // the editor opening mode
55
-    @Autowired
56
-    private User user;  // the user currently viewing or editing the document
57
-    private List<Template> templates;  /* the presence or absence
58
-     of the templates in the <b>Create New...</b> menu option */
59
-}

+ 0
- 44
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/FileModel.java ファイルの表示

@@ -1,44 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
22
-import com.onlyoffice.integration.documentserver.models.enums.Type;
23
-import lombok.Getter;
24
-import lombok.Setter;
25
-import org.springframework.beans.factory.annotation.Autowired;
26
-import org.springframework.context.annotation.Scope;
27
-import org.springframework.stereotype.Component;
28
-
29
-@Component
30
-@Scope("prototype")
31
-@Getter
32
-@Setter
33
-/* the file base parameters which include the platform type used,
34
- document display size (width and height) and type of the document opened */
35
-public class FileModel {
36
-    @Autowired
37
-    private Document document;  // the parameters pertaining to the document (title, url, file type, etc.)
38
-    private DocumentType documentType;  // the document type to be opened
39
-    @Autowired
40
-    private EditorConfig editorConfig;  /*  the parameters pertaining to the
41
-     editor interface: opening mode (viewer or editor), interface language, additional buttons, etc. */
42
-    private String token;  // the encrypted signature added to the Document Server config
43
-    private Type type;  // the platform type used to access the document
44
-}

+ 0
- 55
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/Permission.java ファイルの表示

@@ -1,55 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import com.fasterxml.jackson.annotation.JsonInclude;
22
-import com.onlyoffice.integration.documentserver.models.AbstractModel;
23
-import com.onlyoffice.integration.documentserver.serializers.SerializerFilter;
24
-import lombok.Getter;
25
-import lombok.Setter;
26
-import org.springframework.beans.factory.annotation.Autowired;
27
-import org.springframework.context.annotation.Scope;
28
-import org.springframework.stereotype.Component;
29
-
30
-import java.util.List;
31
-
32
-@Component
33
-@Scope("prototype")
34
-@Getter
35
-@Setter
36
-public class Permission extends AbstractModel {  // the permission for the document to be edited and downloaded or not
37
-    private Boolean comment = true;  // if the document can be commented or not
38
-    private Boolean copy = true;  // if the content can be copied to the clipboard or not
39
-    private Boolean download = true;  // if the document can be downloaded or only viewed or edited online
40
-    private Boolean edit = true;  // if the document can be edited or only viewed
41
-    private Boolean print = true;  // if the document can be printed or not
42
-    private Boolean fillForms = true;  // if the forms can be filled
43
-    private Boolean modifyFilter = true;  /* if the filter can applied globally (true) affecting all the
44
-     other users, or locally (false) */
45
-    private Boolean modifyContentControl = true;  // if the content control settings can be changed
46
-    private Boolean review = true;  // if the document can be reviewed or not
47
-    private Boolean chat = true;  // if a chat can be used
48
-    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
49
-    private List<String> reviewGroups;  // the groups whose changes the user can accept/reject
50
-    @Autowired
51
-    private CommentGroup commentGroups;  //  the groups whose comments the user can edit, remove and/or view
52
-    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
53
-    private List<String> userInfoGroups;
54
-    private Boolean protect = true;
55
-}

+ 0
- 42
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/ReferenceData.java ファイルの表示

@@ -1,42 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import java.util.HashMap;
22
-import java.util.Map;
23
-import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
24
-import org.springframework.beans.factory.annotation.Autowired;
25
-
26
-public class ReferenceData {
27
-    @Autowired
28
-    private FileStoragePathBuilder storagePathBuilder;
29
-    private final String instanceId;
30
-    private final Map<String, String> fileKey;
31
-    public ReferenceData(final String fileName, final String curUserHostAddress, final User user) {
32
-        instanceId = storagePathBuilder.getServerUrl(true);
33
-        Map<String, String> fileKeyList = new HashMap<>();
34
-        if (!user.getId().equals("uid-0")) {
35
-            fileKeyList.put("fileName", fileName);
36
-            fileKeyList.put("userAddress", curUserHostAddress);
37
-        } else {
38
-            fileKeyList = null;
39
-        }
40
-        fileKey = fileKeyList;
41
-    }
42
-}

+ 0
- 32
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/Template.java ファイルの表示

@@ -1,32 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Getter;
23
-import lombok.Setter;
24
-
25
-@Getter
26
-@Setter
27
-@AllArgsConstructor
28
-public class Template {  // the document template parameters
29
-    private String image;  // the absolute URL to the image for template
30
-    private String title;  // the template title that will be displayed in the <b>Create New...</b> menu option
31
-    private String url;  // the absolute URL to the document where it will be created and available after creation
32
-}

+ 0
- 42
src/main/java/com/onlyoffice/integration/documentserver/models/filemodel/User.java ファイルの表示

@@ -1,42 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.models.filemodel;
20
-
21
-import com.onlyoffice.integration.documentserver.models.AbstractModel;
22
-import lombok.Getter;
23
-import lombok.Setter;
24
-import org.springframework.context.annotation.Scope;
25
-import org.springframework.stereotype.Component;
26
-
27
-@Component
28
-@Scope("prototype")
29
-@Getter
30
-@Setter
31
-public class User extends AbstractModel {
32
-    private String id;
33
-    private String name;
34
-    private String group;
35
-
36
-    // the user configuration parameters
37
-    public void configure(final int idParam, final String nameParam, final String groupParam) {
38
-        this.id = "uid-" + idParam;  // the user id
39
-        this.name = nameParam;  // the user name
40
-        this.group = groupParam;  // the group the user belongs to
41
-    }
42
-}

+ 0
- 23
src/main/java/com/onlyoffice/integration/documentserver/serializers/FilterState.java ファイルの表示

@@ -1,23 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.serializers;
20
-
21
-public enum FilterState {
22
-    NULL
23
-}

+ 0
- 38
src/main/java/com/onlyoffice/integration/documentserver/serializers/SerializerFilter.java ファイルの表示

@@ -1,38 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.serializers;
20
-
21
-import java.util.List;
22
-
23
-public class SerializerFilter {
24
-    @Override
25
-    public boolean equals(final Object obj) {
26
-        if (obj instanceof List) {
27
-            if (((List<?>) obj).size() == 1 && ((List<?>) obj).get(0) == FilterState.NULL.toString()) {
28
-                return true;
29
-            }
30
-            return false;
31
-        }
32
-        return false;
33
-    }
34
-    @Override
35
-    public int hashCode() {
36
-        return super.hashCode();
37
-    }
38
-}

+ 0
- 42
src/main/java/com/onlyoffice/integration/documentserver/storage/FileStorageMutator.java ファイルの表示

@@ -1,42 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.storage;
20
-
21
-import org.springframework.core.io.Resource;
22
-
23
-import java.io.ByteArrayInputStream;
24
-import java.io.File;
25
-import java.io.InputStream;
26
-import java.nio.file.Path;
27
-
28
-// specify the file storage mutator functions
29
-public interface FileStorageMutator {
30
-    void createDirectory(Path path);  // create a new directory if it does not exist
31
-    boolean createFile(Path path, InputStream stream);  // create a new file if it does not exist
32
-    boolean deleteFile(String fileName);  // delete a file
33
-    boolean deleteFileHistory(String fileName);  // delete file history
34
-    String updateFile(String fileName, byte[] bytes);  // update a file
35
-    boolean writeToFile(String pathName, String payload);  // write the payload to the file
36
-    boolean moveFile(Path source, Path destination);  // move a file to the specified destination
37
-    Resource loadFileAsResource(String fileName);  // load file as a resource
38
-    Resource loadFileAsResourceHistory(String fileName, String version, String file);  // load file as a resource
39
-    File[] getStoredFiles();  // get a collection of all the stored files
40
-    void createMeta(String fileName, String uid, String uname);  // create the file meta information
41
-    boolean createOrUpdateFile(Path path, ByteArrayInputStream stream);  // create or update a file
42
-}

+ 0
- 31
src/main/java/com/onlyoffice/integration/documentserver/storage/FileStoragePathBuilder.java ファイルの表示

@@ -1,31 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.storage;
20
-
21
-// specify the file storage path builder functions
22
-public interface FileStoragePathBuilder {
23
-    void configure(String address);  // create a new storage folder
24
-    String getStorageLocation();  // get the storage directory
25
-    String getFileLocation(String fileName);  // get the directory of the specified file
26
-    String getServerUrl(Boolean forDocumentServer);  // get the server URL
27
-    String getHistoryDir(String fileName);  // get the history directory
28
-    int getFileVersion(String historyPath, Boolean ifIndexPage);  // get the file version
29
-    String getForcesavePath(String fileName, Boolean create);  /* get the path where all the
30
-    forcely saved file versions are saved or create it */
31
-}

+ 0
- 392
src/main/java/com/onlyoffice/integration/documentserver/storage/LocalFileStorage.java ファイルの表示

@@ -1,392 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.storage;
20
-
21
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
22
-import lombok.Getter;
23
-import lombok.SneakyThrows;
24
-import org.json.simple.JSONObject;
25
-import org.springframework.beans.factory.annotation.Autowired;
26
-import org.springframework.beans.factory.annotation.Value;
27
-import org.springframework.context.annotation.Primary;
28
-import org.springframework.core.io.Resource;
29
-import org.springframework.core.io.UrlResource;
30
-import org.springframework.stereotype.Component;
31
-import org.springframework.util.FileSystemUtils;
32
-
33
-import javax.servlet.http.HttpServletRequest;
34
-import java.io.ByteArrayInputStream;
35
-import java.io.File;
36
-import java.io.FileOutputStream;
37
-import java.io.FileWriter;
38
-import java.io.IOException;
39
-import java.io.InputStream;
40
-import java.net.InetAddress;
41
-import java.net.MalformedURLException;
42
-import java.net.URLDecoder;
43
-import java.net.UnknownHostException;
44
-import java.nio.charset.StandardCharsets;
45
-import java.nio.file.Files;
46
-import java.nio.file.Path;
47
-import java.nio.file.Paths;
48
-import java.nio.file.StandardCopyOption;
49
-import java.text.SimpleDateFormat;
50
-import java.util.Date;
51
-import java.util.stream.Collectors;
52
-import java.util.stream.Stream;
53
-
54
-import static com.onlyoffice.integration.documentserver.util.Constants.KILOBYTE_SIZE;
55
-
56
-// todo: Refactoring
57
-@Component
58
-@Primary
59
-public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuilder {
60
-
61
-    @Getter
62
-    private String storageAddress;
63
-
64
-    @Value("${files.storage.folder}")
65
-    private String storageFolder;
66
-
67
-    @Value("${files.docservice.url.example}")
68
-    private String docserviceUrlExample;
69
-
70
-    @Value("${files.docservice.history.postfix}")
71
-    private String historyPostfix;
72
-
73
-    @Autowired
74
-    private FileUtility fileUtility;
75
-
76
-    @Autowired
77
-    private HttpServletRequest request;
78
-
79
-    /*
80
-        This Storage configuration method should be called whenever a new storage folder is required
81
-     */
82
-    public void configure(final String address) {
83
-        this.storageAddress = address;
84
-        if (this.storageAddress == null) {
85
-            try {
86
-                this.storageAddress = InetAddress.getLocalHost().getHostAddress();
87
-            } catch (UnknownHostException e) {
88
-                this.storageAddress = "unknown_storage";
89
-            }
90
-        }
91
-        this.storageAddress.replaceAll("[^0-9a-zA-Z.=]", "_");
92
-        createDirectory(Paths.get(getStorageLocation()));
93
-    }
94
-
95
-    // get the storage directory
96
-    public String getStorageLocation() {
97
-        String serverPath = System.getProperty("user.dir");  // get the path to the server
98
-        String directory;  // create the storage directory
99
-        if (Paths.get(this.storageAddress).isAbsolute()) {
100
-            directory = this.storageAddress + File.separator;
101
-        } else {
102
-            directory = serverPath
103
-                    + File.separator + storageFolder
104
-                    + File.separator + this.storageAddress
105
-                    + File.separator;
106
-        }
107
-        if (!Files.exists(Paths.get(directory))) {
108
-            createDirectory(Paths.get(directory));
109
-        }
110
-
111
-        return directory;
112
-    }
113
-
114
-    // get the directory of the specified file
115
-    public String getFileLocation(final String fileName) {
116
-        if (fileName.contains(File.separator)) {
117
-            return getStorageLocation() + fileName;
118
-        }
119
-        return getStorageLocation() + fileUtility.getFileName(fileName);
120
-    }
121
-
122
-    // create a new directory if it does not exist
123
-    public void createDirectory(final Path path) {
124
-        if (Files.exists(path)) {
125
-            return;
126
-        }
127
-        try {
128
-            Files.createDirectories(path);
129
-        } catch (IOException e) {
130
-            e.printStackTrace();
131
-        }
132
-    }
133
-
134
-    // create a new file if it does not exist
135
-    public boolean createFile(final Path path, final InputStream stream) {
136
-        if (Files.exists(path)) {
137
-            return true;
138
-        }
139
-        try {
140
-            File file = Files.createFile(path).toFile();  // create a new file in the specified path
141
-            try (FileOutputStream out = new FileOutputStream(file)) {
142
-                int read;
143
-                final byte[] bytes = new byte[KILOBYTE_SIZE];
144
-                while ((read = stream.read(bytes)) != -1) {
145
-                    out.write(bytes, 0, read);  // write bytes to the output stream
146
-                }
147
-                out.flush();  // force write data to the output stream that can be cached in the current thread
148
-            }
149
-        } catch (IOException e) {
150
-            e.printStackTrace();
151
-        }
152
-        return false;
153
-    }
154
-
155
-    // delete a file
156
-    public boolean deleteFile(final String fileNameParam) {
157
-        String fileName = URLDecoder
158
-                .decode(fileNameParam, StandardCharsets.UTF_8);  // decode a x-www-form-urlencoded string
159
-        if (fileName.isBlank()) {
160
-            return false;
161
-        }
162
-
163
-        String filenameWithoutExt = fileUtility
164
-                .getFileNameWithoutExtension(fileName);  // get file name without extension
165
-
166
-        Path filePath = fileName.contains(File.separator)
167
-                ? Paths.get(fileName) : Paths.get(getFileLocation(fileName));  // get the path to the file
168
-        Path filePathWithoutExt = fileName.contains(File.separator)
169
-                ? Paths.get(filenameWithoutExt) : Paths
170
-                .get(getStorageLocation() + filenameWithoutExt);  // get the path to the file without extension
171
-
172
-        // delete the specified file; for directories, recursively delete any nested directories or files as well
173
-        boolean fileDeleted = FileSystemUtils.deleteRecursively(filePath.toFile());
174
-        /* delete the specified file without extension; for directories,
175
-         recursively delete any nested directories or files as well */
176
-        boolean fileWithoutExtDeleted = FileSystemUtils.deleteRecursively(filePathWithoutExt.toFile());
177
-
178
-        return fileDeleted && fileWithoutExtDeleted;
179
-    }
180
-
181
-    // delete file history
182
-    public boolean deleteFileHistory(final String fileNameParam) {
183
-        String fileName = URLDecoder
184
-                .decode(fileNameParam, StandardCharsets.UTF_8);  // decode a x-www-form-urlencoded string
185
-        if (fileName.isBlank()) {
186
-            return false;
187
-        }
188
-
189
-        Path fileHistoryPath = Paths
190
-                .get(getStorageLocation() + getHistoryDir(fileName));  // get the path to the history file
191
-        Path fileHistoryPathWithoutExt = Paths.get(getStorageLocation() + getHistoryDir(fileUtility
192
-                .getFileNameWithoutExtension(fileName)));  // get the path to the history file without extension
193
-
194
-        /* delete the specified history file; for directories,
195
-         recursively delete any nested directories or files as well */
196
-        boolean historyDeleted = FileSystemUtils.deleteRecursively(fileHistoryPath.toFile());
197
-
198
-        /* delete the specified history file without extension; for directories,
199
-         recursively delete any nested directories or files as well */
200
-        boolean historyWithoutExtDeleted = FileSystemUtils.deleteRecursively(fileHistoryPathWithoutExt.toFile());
201
-
202
-        return historyDeleted || historyWithoutExtDeleted;
203
-    }
204
-
205
-    // update a file
206
-    public String updateFile(final String fileName, final byte[] bytes) {
207
-        Path path = fileUtility
208
-                .generateFilepath(getStorageLocation(), fileName);  // generate the path to the specified file
209
-        try {
210
-            Files.write(path, bytes);  // write new information in the bytes format to the file
211
-            return path.getFileName().toString();
212
-        } catch (IOException e) {
213
-            e.printStackTrace();
214
-        }
215
-        return "";
216
-    }
217
-
218
-    // move a file to the specified destination
219
-    public boolean moveFile(final Path source, final Path destination) {
220
-        try {
221
-            Files.move(source, destination,
222
-                    new StandardCopyOption[]{StandardCopyOption.REPLACE_EXISTING});
223
-            return true;
224
-        } catch (IOException e) {
225
-            e.printStackTrace();
226
-        }
227
-        return false;
228
-    }
229
-
230
-    // write the payload to the file
231
-    public boolean writeToFile(final String pathName, final String payload) {
232
-        try (FileWriter fw = new FileWriter(pathName)) {
233
-            fw.write(payload);
234
-            return true;
235
-        } catch (IOException e) {
236
-            e.printStackTrace();
237
-        }
238
-        return false;
239
-    }
240
-
241
-    // get the path where all the forcely saved file versions are saved or create it
242
-    public String getForcesavePath(final String fileName, final Boolean create) {
243
-        String directory = getStorageLocation();
244
-
245
-        Path path = Paths.get(directory);  // get the storage directory
246
-        if (!Files.exists(path)) {
247
-            return "";
248
-        }
249
-
250
-        directory = getFileLocation(fileName) + historyPostfix + File.separator;
251
-
252
-        path = Paths.get(directory);   // get the history file directory
253
-        if (!create && !Files.exists(path)) {
254
-            return "";
255
-        }
256
-
257
-        createDirectory(path);  // create a new directory where all the forcely saved file versions will be saved
258
-
259
-        directory = directory + fileName;
260
-        path = Paths.get(directory);
261
-        if (!create && !Files.exists(path)) {
262
-            return "";
263
-        }
264
-
265
-        return directory;
266
-    }
267
-
268
-    // load file as a resource
269
-    public Resource loadFileAsResource(final String fileName) {
270
-        String fileLocation = getForcesavePath(fileName,
271
-                false);  // get the path where all the forcely saved file versions are saved
272
-        if (fileLocation.isBlank()) {  // if file location is empty
273
-            fileLocation = getFileLocation(fileName);  // get it by the file name
274
-        }
275
-        try {
276
-            Path filePath = Paths.get(fileLocation);  // get the path to the file location
277
-            Resource resource = new UrlResource(filePath.toUri());  // convert the file path to URL
278
-            if (resource.exists()) {
279
-                return resource;
280
-            }
281
-        } catch (MalformedURLException e) {
282
-            e.printStackTrace();
283
-        }
284
-        return null;
285
-    }
286
-
287
-    public Resource loadFileAsResourceHistory(final String fileName, final String version, final String file) {
288
-
289
-        String fileLocation = getStorageLocation() + fileName + "-hist" + File.separator + version
290
-                + File.separator + file;  // get it by the file name
291
-
292
-        try {
293
-            Path filePath = Paths.get(fileLocation);  // get the path to the file location
294
-            Resource resource = new UrlResource(filePath.toUri());  // convert the file path to URL
295
-            if (resource.exists()) {
296
-                return resource;
297
-            }
298
-        } catch (MalformedURLException e) {
299
-            e.printStackTrace();
300
-        }
301
-        return null;
302
-    }
303
-
304
-    // get a collection of all the stored files
305
-    public File[] getStoredFiles() {
306
-        File file = new File(getStorageLocation());
307
-        return file.listFiles(pathname -> pathname.isFile());
308
-    }
309
-
310
-    @SneakyThrows
311
-    public void createMeta(final String fileName,
312
-                           final String uid,
313
-                           final String uname) {  // create the file meta information
314
-        String histDir = getHistoryDir(getFileLocation(fileName));  // get the history directory
315
-
316
-        Path path = Paths.get(histDir);  // get the path to the history directory
317
-        createDirectory(path);  // create the history directory
318
-
319
-        // create the json object with the file metadata
320
-        JSONObject json = new JSONObject();
321
-        json.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
322
-                .format(new Date()));  // put the file creation date to the json object
323
-        json.put("id", uid);  // put the user ID to the json object
324
-        json.put("name", uname);  // put the user name to the json object
325
-
326
-        File meta = new File(histDir + File.separator
327
-                + "createdInfo.json");  // create the createdInfo.json file with the file meta information
328
-        try (FileWriter writer = new FileWriter(meta)) {
329
-            json.writeJSONString(writer);
330
-        } catch (IOException ex) {
331
-            ex.printStackTrace();
332
-        }
333
-    }
334
-
335
-    // create or update a file
336
-    public boolean createOrUpdateFile(final Path path, final ByteArrayInputStream stream) {
337
-        if (!Files.exists(path)) { // if the specified file does not exist
338
-            return createFile(path, stream);  // create it in the specified directory
339
-        } else {
340
-            try {
341
-                Files.write(path, stream
342
-                        .readAllBytes());  // otherwise, write new information in the bytes format to the file
343
-                return true;
344
-            } catch (IOException e) {
345
-                e.printStackTrace();
346
-            }
347
-        }
348
-        return false;
349
-    }
350
-
351
-    // get the server URL
352
-    public String getServerUrl(final Boolean forDocumentServer) {
353
-        if (forDocumentServer && !docserviceUrlExample.equals("")) {
354
-            return docserviceUrlExample;
355
-        } else {
356
-            return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
357
-                    + request.getContextPath();
358
-        }
359
-    }
360
-
361
-    // get the history directory
362
-    public String getHistoryDir(final String path) {
363
-        return path + historyPostfix;
364
-    }
365
-
366
-    // get the file version
367
-    public int getFileVersion(final String historyPath, final Boolean ifIndexPage) {
368
-        Path path;
369
-        if (ifIndexPage) {  // if the start page is opened
370
-            path = Paths.get(getStorageLocation()
371
-                    + getHistoryDir(historyPath));  // get the storage directory and add the history directory to it
372
-        } else {
373
-            path = Paths.get(historyPath);  // otherwise, get the path to the history directory
374
-            if (!Files.exists(path)) {
375
-                return 1;  // if the history directory does not exist, then the file version is 1
376
-        }
377
-        }
378
-
379
-        // run through all the files in the history directory
380
-        try (Stream<Path> stream = Files.walk(path, 1)) {
381
-            return stream
382
-                    .filter(file -> Files.isDirectory(file))  // take only directories from the history folder
383
-                    .map(Path::getFileName)  // get file names
384
-                    .map(Path::toString)  // and convert them into strings
385
-                    .collect(Collectors.toSet()).size();  /* convert stream into set
386
-                     and get its size which specifies the file version */
387
-        } catch (IOException e) {
388
-            e.printStackTrace();
389
-            return 0;
390
-        }
391
-    }
392
-}

+ 0
- 33
src/main/java/com/onlyoffice/integration/documentserver/util/Constants.java ファイルの表示

@@ -1,33 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.util;
20
-
21
-public final class Constants {
22
-    public static final Integer MAX_FILE_SIZE = 5 * 1024 * 1024;
23
-    public static final Integer CONVERT_TIMEOUT_MS = 120000;
24
-    public static final String CONVERTATION_ERROR_MESSAGE_TEMPLATE = "Error occurred in the ConvertService: ";
25
-    public static final Long FULL_LOADING_IN_PERCENT = 100L;
26
-    public static final Integer FILE_SAVE_TIMEOUT = 5000;
27
-    public static final Integer MAX_KEY_LENGTH = 20;
28
-    public static final Integer ANONYMOUS_USER_ID = 4;
29
-    public static final Integer KILOBYTE_SIZE = 1024;
30
-
31
-    private Constants() { }
32
-}
33
-

+ 0
- 36
src/main/java/com/onlyoffice/integration/documentserver/util/Misc.java ファイルの表示

@@ -1,36 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.util;
20
-
21
-import org.springframework.stereotype.Component;
22
-
23
-import java.util.List;
24
-import java.util.stream.Collectors;
25
-
26
-@Component
27
-public class Misc {
28
-
29
-    // convert user descriptions to the specified format
30
-    public String convertUserDescriptions(final String username, final List<String> description) {
31
-        String result = "<div class=\"user-descr\"><b>" + username + "</b><br/><ul>" + description.
32
-                stream().map(text -> "<li>" + text + "</li>")
33
-                .collect(Collectors.joining()) + "</ul></div>";
34
-        return result;
35
-    }
36
-}

+ 0
- 78
src/main/java/com/onlyoffice/integration/documentserver/util/SSLUtils.java ファイルの表示

@@ -1,78 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.util;
20
-
21
-import java.security.KeyManagementException;
22
-import java.security.NoSuchAlgorithmException;
23
-import java.security.cert.X509Certificate;
24
-
25
-import javax.net.ssl.HostnameVerifier;
26
-import javax.net.ssl.HttpsURLConnection;
27
-import javax.net.ssl.SSLContext;
28
-import javax.net.ssl.SSLSession;
29
-import javax.net.ssl.TrustManager;
30
-import javax.net.ssl.X509TrustManager;
31
-
32
-import org.springframework.stereotype.Component;
33
-/**
34
- * Disables and enables certificate and host-name checking in
35
- * HttpsURLConnection, the default JVM implementation of the HTTPS/TLS protocol.
36
- * Has no effect on implementations such as Apache Http Client, Ok Http.
37
-*/
38
-@Component
39
-public final class SSLUtils {
40
-
41
-    private final HostnameVerifier jvmHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
42
-
43
-    private final HostnameVerifier trivialHostnameVerifier = new HostnameVerifier() {
44
-        public boolean verify(final String hostname, final SSLSession sslSession) {
45
-            return true;
46
-        }
47
-    };
48
-
49
-    private final TrustManager[] unquestioningTrustManager = new TrustManager[] {
50
-            new X509TrustManager() {
51
-        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
52
-            return null;
53
-        }
54
-
55
-        public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
56
-        }
57
-
58
-        public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
59
-        }
60
-    } };
61
-
62
-    public void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException {
63
-        HttpsURLConnection.setDefaultHostnameVerifier(trivialHostnameVerifier);
64
-        // Install the all-trusting trust manager
65
-        SSLContext sc = SSLContext.getInstance("SSL");
66
-        sc.init(null, unquestioningTrustManager, null);
67
-        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
68
-    }
69
-
70
-    public void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException {
71
-        HttpsURLConnection.setDefaultHostnameVerifier(jvmHostnameVerifier);
72
-        // Return it to the initial state (discovered by reflection, now hardcoded)
73
-        SSLContext sc = SSLContext.getInstance("SSL");
74
-        sc.init(null, null, null);
75
-        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
76
-    }
77
-
78
-}

+ 0
- 203
src/main/java/com/onlyoffice/integration/documentserver/util/file/DefaultFileUtility.java ファイルの表示

@@ -1,203 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.util.file;
20
-
21
-import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
22
-import org.springframework.beans.factory.annotation.Qualifier;
23
-import org.springframework.beans.factory.annotation.Value;
24
-import org.springframework.stereotype.Component;
25
-
26
-import java.nio.file.Files;
27
-import java.nio.file.Path;
28
-import java.nio.file.Paths;
29
-import java.util.ArrayList;
30
-import java.util.Arrays;
31
-import java.util.List;
32
-
33
-import static com.onlyoffice.integration.documentserver.util.Constants.MAX_FILE_SIZE;
34
-
35
-@Component
36
-@Qualifier("default")
37
-public class DefaultFileUtility implements FileUtility {
38
-    @Value("${filesize-max}")
39
-    private String filesizeMax;
40
-
41
-    @Value("${files.docservice.viewed-docs}")
42
-    private String docserviceViewedDocs;
43
-
44
-    @Value("${files.docservice.edited-docs}")
45
-    private String docserviceEditedDocs;
46
-
47
-    @Value("${files.docservice.convert-docs}")
48
-    private String docserviceConvertDocs;
49
-
50
-    @Value("${files.docservice.fillforms-docs}")
51
-    private String docserviceFillDocs;
52
-
53
-    // document extensions
54
-    private List<String> extsDocument = Arrays.asList(
55
-                            ".doc", ".docx", ".docm",
56
-                            ".dot", ".dotx", ".dotm",
57
-                            ".odt", ".fodt", ".ott", ".rtf", ".txt",
58
-                            ".html", ".htm", ".mht", ".xml",
59
-                            ".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oform");
60
-
61
-    // spreadsheet extensions
62
-    private List<String> extsSpreadsheet = Arrays.asList(
63
-                            ".xls", ".xlsx", ".xlsm", ".xlsb",
64
-                            ".xlt", ".xltx", ".xltm",
65
-                            ".ods", ".fods", ".ots", ".csv");
66
-
67
-    // presentation extensions
68
-    private List<String> extsPresentation = Arrays.asList(
69
-                            ".pps", ".ppsx", ".ppsm",
70
-                            ".ppt", ".pptx", ".pptm",
71
-                            ".pot", ".potx", ".potm",
72
-                            ".odp", ".fodp", ".otp");
73
-
74
-    // get the document type
75
-    public DocumentType getDocumentType(final String fileName) {
76
-        String ext = getFileExtension(fileName).toLowerCase();  // get file extension from its name
77
-        // word type for document extensions
78
-        if (extsDocument.contains(ext)) {
79
-            return DocumentType.word;
80
-        }
81
-
82
-        // cell type for spreadsheet extensions
83
-        if (extsSpreadsheet.contains(ext)) {
84
-            return DocumentType.cell;
85
-        }
86
-
87
-        // slide type for presentation extensions
88
-        if (extsPresentation.contains(ext)) {
89
-            return DocumentType.slide;
90
-        }
91
-
92
-        // default file type is word
93
-        return DocumentType.word;
94
-    }
95
-
96
-    // get file name from its URL
97
-    public String getFileName(final String url) {
98
-        if (url == null) {
99
-            return "";
100
-        }
101
-
102
-        // get file name from the last part of URL
103
-        String fileName = url.substring(url.lastIndexOf('/') + 1);
104
-        fileName = fileName.split("\\?")[0];
105
-        return fileName;
106
-    }
107
-
108
-    // get file name without extension
109
-    public String getFileNameWithoutExtension(final String url) {
110
-        String fileName = getFileName(url);
111
-        if (fileName == null) {
112
-            return null;
113
-        }
114
-        String fileNameWithoutExt = fileName.substring(0, fileName.lastIndexOf('.'));
115
-        return fileNameWithoutExt;
116
-    }
117
-
118
-    // get file extension from URL
119
-    public String getFileExtension(final String url) {
120
-        String fileName = getFileName(url);
121
-        if (fileName == null) {
122
-            return null;
123
-        }
124
-        String fileExt = fileName.substring(fileName.lastIndexOf("."));
125
-        return fileExt.toLowerCase();
126
-    }
127
-
128
-    // get an editor internal extension
129
-    public String getInternalExtension(final DocumentType type) {
130
-        // .docx for word file type
131
-        if (type.equals(DocumentType.word)) {
132
-            return ".docx";
133
-        }
134
-
135
-        // .xlsx for cell file type
136
-        if (type.equals(DocumentType.cell)) {
137
-            return ".xlsx";
138
-        }
139
-
140
-        // .pptx for slide file type
141
-        if (type.equals(DocumentType.slide)) {
142
-            return ".pptx";
143
-        }
144
-
145
-        // the default file type is .docx
146
-        return ".docx";
147
-    }
148
-
149
-    public List<String> getFillExts() {
150
-        return Arrays.asList(docserviceFillDocs.split("\\|"));
151
-    }
152
-
153
-    // get file extensions that can be viewed
154
-    public List<String> getViewedExts() {
155
-        return Arrays.asList(docserviceViewedDocs.split("\\|"));
156
-    }
157
-
158
-    // get file extensions that can be edited
159
-    public List<String> getEditedExts() {
160
-        return Arrays.asList(docserviceEditedDocs.split("\\|"));
161
-    }
162
-
163
-    // get file extensions that can be converted
164
-    public List<String> getConvertExts() {
165
-        return Arrays.asList(docserviceConvertDocs.split("\\|"));
166
-    }
167
-
168
-    // get all the supported file extensions
169
-    public List<String> getFileExts() {
170
-        List<String> res = new ArrayList<>();
171
-
172
-        res.addAll(getViewedExts());
173
-        res.addAll(getEditedExts());
174
-        res.addAll(getConvertExts());
175
-        res.addAll(getFillExts());
176
-
177
-        return res;
178
-    }
179
-
180
-    // generate the file path from file directory and name
181
-    public Path generateFilepath(final String directory, final String fullFileName) {
182
-        String fileName = getFileNameWithoutExtension(fullFileName);  // get file name without extension
183
-        String fileExtension = getFileExtension(fullFileName);  // get file extension
184
-        Path path = Paths.get(directory + fullFileName);  // get the path to the files with the specified name
185
-
186
-        for (int i = 1; Files.exists(path); i++) {  // run through all the files with the specified name
187
-            // get a name of each file without extension and add an index to it
188
-            fileName = getFileNameWithoutExtension(fullFileName) + "(" + i + ")";
189
-
190
-            // create a new path for this file with the correct name and extension
191
-            path = Paths.get(directory + fileName + fileExtension);
192
-        }
193
-
194
-        path = Paths.get(directory + fileName + fileExtension);
195
-        return path;
196
-    }
197
-
198
-    // get maximum file size
199
-    public long getMaxFileSize() {
200
-        long size = Long.parseLong(filesizeMax);
201
-        return size > 0 ? size : MAX_FILE_SIZE;
202
-    }
203
-}

+ 0
- 41
src/main/java/com/onlyoffice/integration/documentserver/util/file/FileUtility.java ファイルの表示

@@ -1,41 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.util.file;
20
-
21
-import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
22
-
23
-import java.nio.file.Path;
24
-import java.util.List;
25
-
26
-// specify the file utility functions
27
-public interface FileUtility {
28
-    DocumentType getDocumentType(String fileName);  // get the document type
29
-    String getFileName(String url);  // get file name from its URL
30
-    String getFileNameWithoutExtension(String url);  // get file name without extension
31
-    String getFileExtension(String url);  // get file extension from URL
32
-    String getInternalExtension(DocumentType type);  // get an editor internal extension
33
-    List<String> getFileExts();  // get all the supported file extensions
34
-    List<String> getFillExts();  // get file extensions that can be filled
35
-    List<String> getViewedExts();  // get file extensions that can be viewed
36
-    List<String> getEditedExts();  // get file extensions that can be edited
37
-    List<String> getConvertExts();  // get file extensions that can be converted
38
-    Path generateFilepath(String directory, String fullFileName);  /* generate the file path
39
-     from file directory and name */
40
-    long getMaxFileSize();  // get maximum file size
41
-}

+ 0
- 267
src/main/java/com/onlyoffice/integration/documentserver/util/service/DefaultServiceConverter.java ファイルの表示

@@ -1,267 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.util.service;
20
-
21
-import com.fasterxml.jackson.databind.ObjectMapper;
22
-import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
23
-import com.onlyoffice.integration.documentserver.models.enums.ConvertErrorType;
24
-import com.onlyoffice.integration.documentserver.util.file.FileUtility;
25
-import com.onlyoffice.integration.dto.Convert;
26
-import com.onlyoffice.integration.dto.ConvertedData;
27
-import lombok.SneakyThrows;
28
-import org.json.simple.JSONObject;
29
-import org.json.simple.parser.JSONParser;
30
-import org.springframework.beans.factory.annotation.Autowired;
31
-import org.springframework.beans.factory.annotation.Value;
32
-import org.springframework.http.HttpStatus;
33
-import org.springframework.stereotype.Component;
34
-
35
-import javax.annotation.PostConstruct;
36
-import java.io.BufferedReader;
37
-import java.io.InputStream;
38
-import java.io.InputStreamReader;
39
-import java.io.OutputStream;
40
-import java.net.URL;
41
-import java.nio.charset.StandardCharsets;
42
-import java.util.HashMap;
43
-import java.util.Map;
44
-import java.util.UUID;
45
-
46
-import static com.onlyoffice.integration.documentserver.util.Constants.CONVERTATION_ERROR_MESSAGE_TEMPLATE;
47
-import static com.onlyoffice.integration.documentserver.util.Constants.CONVERT_TIMEOUT_MS;
48
-import static com.onlyoffice.integration.documentserver.util.Constants.FULL_LOADING_IN_PERCENT;
49
-import static com.onlyoffice.integration.documentserver.util.Constants.MAX_KEY_LENGTH;
50
-
51
-// todo: Refactoring
52
-@Component
53
-public class DefaultServiceConverter implements ServiceConverter {
54
-    @Value("${files.docservice.header}")
55
-    private String documentJwtHeader;
56
-    @Value("${files.docservice.url.site}")
57
-    private String docServiceUrl;
58
-    @Value("${files.docservice.url.converter}")
59
-    private String docServiceUrlConverter;
60
-    @Value("${files.docservice.timeout}")
61
-    private String docserviceTimeout;
62
-    private int convertTimeout;
63
-
64
-    @Autowired
65
-    private JwtManager jwtManager;
66
-    @Autowired
67
-    private FileUtility fileUtility;
68
-    @Autowired
69
-    private JSONParser parser;
70
-    @Autowired
71
-    private ObjectMapper objectMapper;
72
-
73
-    @PostConstruct
74
-    public void init() {
75
-        int timeout = Integer.parseInt(docserviceTimeout);  // parse the dcoument service timeout value
76
-        convertTimeout = timeout > 0 ? timeout : CONVERT_TIMEOUT_MS;
77
-    }
78
-
79
-    @SneakyThrows
80
-    private String postToServer(final Convert body, final String headerToken) {  // send the POST request to the server
81
-        String bodyString = objectMapper
82
-                .writeValueAsString(body);  // write the body request to the object mapper in the string format
83
-        URL url = null;
84
-        java.net.HttpURLConnection connection = null;
85
-        InputStream response = null;
86
-        String jsonString = null;
87
-
88
-        byte[] bodyByte = bodyString.getBytes(StandardCharsets.UTF_8);  // convert body string into bytes
89
-        try {
90
-            // set the request parameters
91
-            url = new URL(docServiceUrl + docServiceUrlConverter);
92
-            connection = (java.net.HttpURLConnection) url.openConnection();
93
-            connection.setRequestMethod("POST");
94
-            connection.setDoOutput(true);
95
-            connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
96
-            connection.setFixedLengthStreamingMode(bodyByte.length);
97
-            connection.setRequestProperty("Accept", "application/json");
98
-            connection.setConnectTimeout(convertTimeout);
99
-
100
-            // check if the token is enabled
101
-            if (jwtManager.tokenEnabled()) {
102
-                // set the JWT header to the request
103
-                connection.setRequestProperty(documentJwtHeader.isBlank()
104
-                        ? "Authorization" : documentJwtHeader, "Bearer " + headerToken);
105
-            }
106
-
107
-            connection.connect();
108
-
109
-            try (OutputStream os = connection.getOutputStream()) {
110
-                os.write(bodyByte);  // write bytes to the output stream
111
-                os.flush();  // force write data to the output stream that can be cached in the current thread
112
-            }
113
-
114
-            int statusCode = connection.getResponseCode();
115
-            if (statusCode != HttpStatus.OK.value()) {  // checking status code
116
-                connection.disconnect();
117
-                throw new RuntimeException("Convertation service returned status: " + statusCode);
118
-            }
119
-
120
-            response = connection.getInputStream();  // get the input stream
121
-            jsonString = convertStreamToString(response);  // convert the response stream into a string
122
-        } finally {
123
-            connection.disconnect();
124
-            return jsonString;
125
-        }
126
-    }
127
-
128
-    // get the URL to the converted file
129
-    public ConvertedData getConvertedData(final String documentUri, final String fromExtension,
130
-                                          final String toExtension, final String documentRevisionId,
131
-                                          final String filePass, final Boolean isAsync, final String lang) {
132
-        // check if the fromExtension parameter is defined; if not, get it from the document url
133
-        String fromExt = fromExtension == null || fromExtension.isEmpty()
134
-                ? fileUtility.getFileExtension(documentUri) : fromExtension;
135
-
136
-        // check if the file name parameter is defined; if not, get random uuid for this file
137
-        String title = fileUtility.getFileName(documentUri);
138
-        title = title == null || title.isEmpty() ? UUID.randomUUID().toString() : title;
139
-
140
-        String documentRevId = documentRevisionId == null || documentRevisionId.isEmpty()
141
-                ? documentUri : documentRevisionId;
142
-
143
-        documentRevId = generateRevisionId(documentRevId);  // create document token
144
-
145
-        // write all the necessary parameters to the body object
146
-        Convert body = new Convert();
147
-        body.setLang(lang);
148
-        body.setUrl(documentUri);
149
-        body.setOutputtype(toExtension.replace(".", ""));
150
-        body.setFiletype(fromExt.replace(".", ""));
151
-        body.setTitle(title);
152
-        body.setKey(documentRevId);
153
-        body.setFilePass(filePass);
154
-        if (isAsync) {
155
-            body.setAsync(true);
156
-        }
157
-
158
-        String headerToken = "";
159
-        if (jwtManager.tokenEnabled() && jwtManager.tokenUseForRequest()) {
160
-            HashMap<String, Object> map = new HashMap<String, Object>();
161
-            map.put("region", lang);
162
-            map.put("url", body.getUrl());
163
-            map.put("outputtype", body.getOutputtype());
164
-            map.put("filetype", body.getFiletype());
165
-            map.put("title", body.getTitle());
166
-            map.put("key", body.getKey());
167
-            map.put("password", body.getFilePass());
168
-            if (isAsync) {
169
-                map.put("async", body.getAsync());
170
-            }
171
-
172
-            // add token to the body if it is enabled
173
-            String token = jwtManager.createToken(map);
174
-            body.setToken(token);
175
-
176
-            Map<String, Object> payloadMap = new HashMap<String, Object>();
177
-            payloadMap.put("payload", map);  // create payload object
178
-            headerToken = jwtManager.createToken(payloadMap);  // create header token
179
-        }
180
-
181
-        String jsonString = postToServer(body, headerToken);
182
-
183
-        return getResponseData(jsonString);
184
-    }
185
-
186
-    // generate document key
187
-    public String generateRevisionId(final String expectedKey) {
188
-        /* if the expected key length is greater than 20
189
-        then he expected key is hashed and a fixed length value is stored in the string format */
190
-        String formatKey = expectedKey.length() > MAX_KEY_LENGTH
191
-                ? Integer.toString(expectedKey.hashCode()) : expectedKey;
192
-        String key = formatKey.replace("[^0-9-.a-zA-Z_=]", "_");
193
-
194
-        return key.substring(0, Math.min(key.length(), MAX_KEY_LENGTH));  // the resulting key length is 20 or less
195
-    }
196
-
197
-    // todo: Replace with a registry (callbacks package for reference)
198
-    // create an error message for an error code
199
-    private void processConvertServiceResponceError(final int errorCode) {
200
-        String errorMessage = CONVERTATION_ERROR_MESSAGE_TEMPLATE + ConvertErrorType.labelOfCode(errorCode);
201
-
202
-        throw new RuntimeException(errorMessage);
203
-    }
204
-
205
-    // get the response URL
206
-    @SneakyThrows
207
-    private ConvertedData getResponseData(final String jsonString) {
208
-        JSONObject jsonObj = convertStringToJSON(jsonString);
209
-
210
-        Object error = jsonObj.get("error");
211
-        if (error != null) {  // if an error occurs
212
-            processConvertServiceResponceError(Math.toIntExact((long) error));  // then get an error message
213
-        }
214
-
215
-        // check if the conversion is completed and save the result to a variable
216
-        Boolean isEndConvert = (Boolean) jsonObj.get("endConvert");
217
-
218
-        Long resultPercent = 0L;
219
-        String responseUri = null;
220
-        String responseFileType = null;
221
-        ConvertedData convertedData = new ConvertedData("", "");
222
-
223
-        if (isEndConvert) {  // if the conversion is completed
224
-            resultPercent = FULL_LOADING_IN_PERCENT;
225
-            responseUri = (String) jsonObj.get("fileUrl");  // get the file URL
226
-            responseFileType = (String) jsonObj.get("fileType");  // get the file type
227
-            convertedData.setUri(responseUri);
228
-            convertedData.setFileType(responseFileType);
229
-        } else {  // if the conversion isn't completed
230
-            resultPercent = (Long) jsonObj.get("percent");
231
-
232
-            // get the percentage value of the conversion process
233
-            resultPercent = resultPercent >= FULL_LOADING_IN_PERCENT ? FULL_LOADING_IN_PERCENT - 1 : resultPercent;
234
-        }
235
-
236
-        return convertedData;
237
-    }
238
-
239
-    // convert stream to string
240
-    @SneakyThrows
241
-    public String convertStreamToString(final InputStream stream) {
242
-        InputStreamReader inputStreamReader = new InputStreamReader(stream);  // create an object to get incoming stream
243
-        StringBuilder stringBuilder = new StringBuilder();  // create a string builder object
244
-
245
-        // create an object to read incoming streams
246
-        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
247
-        String line = bufferedReader.readLine();  // get incoming streams by lines
248
-
249
-        while (line != null) {
250
-            stringBuilder.append(line);  // concatenate strings using the string builder
251
-            line = bufferedReader.readLine();
252
-        }
253
-
254
-        String result = stringBuilder.toString();
255
-
256
-        return result;
257
-    }
258
-
259
-    // convert string to json
260
-    @SneakyThrows
261
-    public JSONObject convertStringToJSON(final String jsonString) {
262
-        Object obj = parser.parse(jsonString);  // parse json string
263
-        JSONObject jsonObj = (JSONObject) obj;  // and turn it into a json object
264
-
265
-        return jsonObj;
266
-    }
267
-}

+ 0
- 34
src/main/java/com/onlyoffice/integration/documentserver/util/service/ServiceConverter.java ファイルの表示

@@ -1,34 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.documentserver.util.service;
20
-
21
-import com.onlyoffice.integration.dto.ConvertedData;
22
-import org.json.simple.JSONObject;
23
-import java.io.InputStream;
24
-
25
-
26
-// specify the converter service functions
27
-public interface ServiceConverter {
28
-    ConvertedData getConvertedData(String documentUri, String fromExtension,  // get the URL to the converted file
29
-                                   String toExtension, String documentRevisionId,
30
-                                   String filePass, Boolean isAsync, String lang);
31
-    String generateRevisionId(String expectedKey);  // generate document key
32
-    String convertStreamToString(InputStream stream);  // convert stream to string
33
-    JSONObject convertStringToJSON(String jsonString);  // convert string to json
34
-}

+ 0
- 33
src/main/java/com/onlyoffice/integration/dto/Action.java ファイルの表示

@@ -1,33 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Getter;
23
-import lombok.NoArgsConstructor;
24
-import lombok.Setter;
25
-
26
-@Getter
27
-@Setter
28
-@AllArgsConstructor
29
-@NoArgsConstructor
30
-public class Action {
31
-    private String userid;
32
-    private com.onlyoffice.integration.documentserver.models.enums.Action type;
33
-}

+ 0
- 31
src/main/java/com/onlyoffice/integration/dto/ChangesHistory.java ファイルの表示

@@ -1,31 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Data;
23
-import lombok.NoArgsConstructor;
24
-
25
-@Data
26
-@AllArgsConstructor
27
-@NoArgsConstructor
28
-public class ChangesHistory {
29
-    private String created;
30
-    private ChangesUser user;
31
-}

+ 0
- 31
src/main/java/com/onlyoffice/integration/dto/ChangesUser.java ファイルの表示

@@ -1,31 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Data;
23
-import lombok.NoArgsConstructor;
24
-
25
-@Data
26
-@AllArgsConstructor
27
-@NoArgsConstructor
28
-public class ChangesUser {
29
-    private String id;
30
-    private String name;
31
-}

+ 0
- 40
src/main/java/com/onlyoffice/integration/dto/Convert.java ファイルの表示

@@ -1,40 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Getter;
23
-import lombok.NoArgsConstructor;
24
-import lombok.Setter;
25
-
26
-@Getter
27
-@Setter
28
-@AllArgsConstructor
29
-@NoArgsConstructor
30
-public class Convert {
31
-    private String url;
32
-    private String outputtype;
33
-    private String filetype;
34
-    private String title;
35
-    private String key;
36
-    private String filePass;
37
-    private Boolean async;
38
-    private String token;
39
-    private String lang;
40
-}

+ 0
- 33
src/main/java/com/onlyoffice/integration/dto/ConvertedData.java ファイルの表示

@@ -1,33 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Getter;
23
-import lombok.NoArgsConstructor;
24
-import lombok.Setter;
25
-
26
-@Getter
27
-@Setter
28
-@AllArgsConstructor
29
-@NoArgsConstructor
30
-public class ConvertedData {
31
-    private String uri;
32
-    private String fileType;
33
-}

+ 0
- 36
src/main/java/com/onlyoffice/integration/dto/Converter.java ファイルの表示

@@ -1,36 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import com.fasterxml.jackson.annotation.JsonProperty;
22
-import lombok.Getter;
23
-import lombok.NoArgsConstructor;
24
-import lombok.Setter;
25
-
26
-@Getter
27
-@Setter
28
-@NoArgsConstructor
29
-public class Converter {
30
-    @JsonProperty("filename")
31
-    private String fileName;
32
-    @JsonProperty("filePass")
33
-    private String filePass;
34
-    @JsonProperty("lang")
35
-    private String lang;
36
-}

+ 0
- 40
src/main/java/com/onlyoffice/integration/dto/History.java ファイルの表示

@@ -1,40 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import com.fasterxml.jackson.annotation.JsonProperty;
22
-import com.onlyoffice.integration.documentserver.models.filemodel.User;
23
-import lombok.AllArgsConstructor;
24
-import lombok.Data;
25
-import lombok.NoArgsConstructor;
26
-
27
-import java.util.List;
28
-
29
-@Data
30
-@AllArgsConstructor
31
-@NoArgsConstructor
32
-public class History {
33
-    @JsonProperty("serverVersion")
34
-    private String serverVersion;
35
-    private String key;
36
-    private Integer version;
37
-    private String created;
38
-    private User user;
39
-    private List<ChangesHistory> changes;
40
-}

+ 0
- 31
src/main/java/com/onlyoffice/integration/dto/Mentions.java ファイルの表示

@@ -1,31 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Getter;
23
-import lombok.Setter;
24
-
25
-@Getter
26
-@Setter
27
-@AllArgsConstructor
28
-public class Mentions {
29
-    private String name;
30
-    private String email;
31
-}

+ 0
- 46
src/main/java/com/onlyoffice/integration/dto/Track.java ファイルの表示

@@ -1,46 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.dto;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Getter;
23
-import lombok.NoArgsConstructor;
24
-import lombok.Setter;
25
-
26
-import java.util.List;
27
-
28
-@Getter
29
-@Setter
30
-@AllArgsConstructor
31
-@NoArgsConstructor
32
-public class Track {
33
-    private String filetype;
34
-    private String url;
35
-    private String key;
36
-    private String changesurl;
37
-    private History history;
38
-    private String token;
39
-    private Integer forcesavetype;
40
-    private Integer status;
41
-    private List<String> users;
42
-    private List<Action> actions;
43
-    private String userdata;
44
-    private String lastsave;
45
-    private Boolean notmodified;
46
-}

+ 0
- 41
src/main/java/com/onlyoffice/integration/entities/AbstractEntity.java ファイルの表示

@@ -1,41 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.entities;
20
-
21
-import lombok.AllArgsConstructor;
22
-import lombok.Getter;
23
-import lombok.NoArgsConstructor;
24
-import lombok.Setter;
25
-
26
-import javax.persistence.GeneratedValue;
27
-import javax.persistence.GenerationType;
28
-import javax.persistence.Id;
29
-import javax.persistence.MappedSuperclass;
30
-import java.io.Serializable;
31
-
32
-@MappedSuperclass
33
-@NoArgsConstructor
34
-@AllArgsConstructor
35
-@Setter
36
-@Getter
37
-public abstract class AbstractEntity implements Serializable {
38
-    @Id
39
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
40
-    private int id;
41
-}

+ 0
- 39
src/main/java/com/onlyoffice/integration/entities/Group.java ファイルの表示

@@ -1,39 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.entities;
20
-
21
-import lombok.Getter;
22
-import lombok.Setter;
23
-
24
-import javax.persistence.Column;
25
-import javax.persistence.Entity;
26
-import javax.persistence.OneToMany;
27
-import javax.persistence.Table;
28
-import java.util.List;
29
-
30
-@Entity
31
-@Table(name = "`group`")
32
-@Getter
33
-@Setter
34
-public class Group extends AbstractEntity {
35
-    @Column(unique = true)
36
-    private String name;
37
-    @OneToMany(mappedBy = "group")
38
-    private List<User> users;
39
-}

+ 0
- 56
src/main/java/com/onlyoffice/integration/entities/Permission.java ファイルの表示

@@ -1,56 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.entities;
20
-
21
-import lombok.Getter;
22
-import lombok.Setter;
23
-
24
-import javax.persistence.Entity;
25
-import javax.persistence.ManyToMany;
26
-import javax.persistence.Table;
27
-import java.util.List;
28
-
29
-@Entity
30
-@Table(name = "`permission`")
31
-@Getter
32
-@Setter
33
-public class Permission extends AbstractEntity {
34
-    private Boolean comment = true;
35
-    private Boolean copy = true;
36
-    private Boolean download = true;
37
-    private Boolean edit = true;
38
-    private Boolean print = true;
39
-    private Boolean fillForms = true;
40
-    private Boolean modifyFilter = true;
41
-    private Boolean modifyContentControl = true;
42
-    private Boolean review = true;
43
-    private Boolean chat = true;
44
-    private Boolean templates = true;
45
-    @ManyToMany
46
-    private List<Group> reviewGroups;
47
-    @ManyToMany
48
-    private List<Group> commentsViewGroups;
49
-    @ManyToMany
50
-    private List<Group> commentsEditGroups;
51
-    @ManyToMany
52
-    private List<Group> commentsRemoveGroups;
53
-    @ManyToMany
54
-    private List<Group> userInfoGroups;
55
-    private Boolean protect = true;
56
-}

+ 0
- 48
src/main/java/com/onlyoffice/integration/entities/User.java ファイルの表示

@@ -1,48 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.entities;
20
-
21
-import lombok.Getter;
22
-import lombok.Setter;
23
-
24
-import javax.persistence.CollectionTable;
25
-import javax.persistence.ElementCollection;
26
-import javax.persistence.Entity;
27
-import javax.persistence.ManyToOne;
28
-import javax.persistence.OneToOne;
29
-import javax.persistence.Table;
30
-import java.util.List;
31
-
32
-@Entity
33
-@Table(name = "`user`")
34
-@Getter
35
-@Setter
36
-public class User extends AbstractEntity {
37
-    private String name;
38
-    private String email;
39
-    private Boolean favorite;
40
-    @ManyToOne
41
-    private Group group;
42
-    @OneToOne
43
-    private Permission permissions;
44
-//    @Column(columnDefinition = "CLOB")
45
-    @ElementCollection
46
-    @CollectionTable(name = "user_descriptions")
47
-    private List<String> descriptions;
48
-}

+ 0
- 58
src/main/java/com/onlyoffice/integration/mappers/AbstractMapper.java ファイルの表示

@@ -1,58 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.mappers;
20
-
21
-import com.onlyoffice.integration.entities.AbstractEntity;
22
-import com.onlyoffice.integration.documentserver.models.AbstractModel;
23
-import org.modelmapper.Converter;
24
-import org.modelmapper.ModelMapper;
25
-import org.springframework.beans.factory.annotation.Autowired;
26
-
27
-import java.util.Objects;
28
-
29
-public abstract class AbstractMapper<E extends AbstractEntity, M extends AbstractModel> implements Mapper<E, M> {
30
-    @Autowired
31
-    private ModelMapper mapper;
32
-
33
-    private Class<M> modelClass;
34
-
35
-    AbstractMapper(final Class<M> modelClassParam) {
36
-        this.modelClass = modelClassParam;
37
-    }
38
-
39
-    @Override
40
-    public M toModel(final E entity) {  // convert the entity to the model
41
-        return Objects.isNull(entity)  // check if an entity is not empty
42
-                ? null
43
-                : mapper.map(entity, modelClass);  // and add it to the model mapper
44
-    }
45
-
46
-    Converter<E, M> modelConverter() {  // specify the model converter
47
-        return context -> {
48
-            E source = context.getSource();  // get the source entity
49
-            M destination = context.getDestination();  // get the destination model
50
-            handleSpecificFields(source, destination);  // map the entity to the model
51
-            return context.getDestination();
52
-        };
53
-    }
54
-
55
-
56
-    void handleSpecificFields(final E source, final M destination) {
57
-    }
58
-}

+ 0
- 27
src/main/java/com/onlyoffice/integration/mappers/Mapper.java ファイルの表示

@@ -1,27 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.mappers;
20
-
21
-import com.onlyoffice.integration.entities.AbstractEntity;
22
-import com.onlyoffice.integration.documentserver.models.AbstractModel;
23
-
24
-// specify the model mapper functions
25
-public interface Mapper<E extends AbstractEntity, M extends AbstractModel> {
26
-   M toModel(E entity);  // convert the entity to the model
27
-}

+ 0
- 69
src/main/java/com/onlyoffice/integration/mappers/PermissionsMapper.java ファイルの表示

@@ -1,69 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.mappers;
20
-
21
-import com.onlyoffice.integration.entities.Permission;
22
-import com.onlyoffice.integration.documentserver.models.filemodel.CommentGroup;
23
-import org.modelmapper.ModelMapper;
24
-import org.springframework.beans.factory.annotation.Autowired;
25
-import org.springframework.context.annotation.Primary;
26
-import org.springframework.stereotype.Component;
27
-
28
-import javax.annotation.PostConstruct;
29
-import java.util.stream.Collectors;
30
-
31
-@Component
32
-@Primary
33
-public class PermissionsMapper extends AbstractMapper<Permission,
34
-        com.onlyoffice.integration.documentserver.models.filemodel.Permission> {
35
-    @Autowired
36
-    private ModelMapper mapper;
37
-
38
-    public PermissionsMapper() {
39
-        super(com.onlyoffice.integration.documentserver.models.filemodel.Permission.class);
40
-    }
41
-
42
-    @PostConstruct
43
-    public void configure() {  // configure the permission mapper
44
-        mapper.createTypeMap(Permission.class, com.onlyoffice.integration.documentserver.models.filemodel
45
-                        .Permission.class)  // create the type map
46
-                .setPostConverter(modelConverter());  // and apply the post converter to it
47
-    }
48
-
49
-    @Override
50
-    void handleSpecificFields(final Permission source,
51
-                              final com.onlyoffice.integration.documentserver.models.filemodel
52
-                                      .Permission destination) {  // handle specific permission fields
53
-        destination.setReviewGroups(source.getReviewGroups().stream()
54
-                .map(g -> g.getName())
55
-                .collect(Collectors.toList()));  // set the reviewGroups parameter
56
-
57
-        // set the commentGroups parameter
58
-        destination.setCommentGroups(
59
-                new CommentGroup(
60
-                        source.getCommentsViewGroups().stream().map(g -> g.getName()).collect(Collectors.toList()),
61
-                        source.getCommentsEditGroups().stream().map(g -> g.getName()).collect(Collectors.toList()),
62
-                        source.getCommentsRemoveGroups().stream().map(g -> g.getName()).collect(Collectors.toList())
63
-                )
64
-        );
65
-        destination.setUserInfoGroups(source.getUserInfoGroups().stream()
66
-                .map(g -> g.getName())
67
-                .collect(Collectors.toList()));
68
-    }
69
-}

+ 0
- 53
src/main/java/com/onlyoffice/integration/mappers/UsersMapper.java ファイルの表示

@@ -1,53 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.mappers;
20
-
21
-import com.onlyoffice.integration.entities.User;
22
-import org.modelmapper.ModelMapper;
23
-import org.springframework.beans.factory.annotation.Autowired;
24
-import org.springframework.context.annotation.Primary;
25
-import org.springframework.stereotype.Component;
26
-
27
-import javax.annotation.PostConstruct;
28
-
29
-@Component
30
-@Primary
31
-public class UsersMapper extends AbstractMapper<User, com.onlyoffice.integration.documentserver.models.filemodel.User> {
32
-    @Autowired
33
-    private ModelMapper mapper;
34
-
35
-    public UsersMapper() {
36
-        super(com.onlyoffice.integration.documentserver.models.filemodel.User.class);
37
-    }
38
-
39
-    @PostConstruct
40
-    public void configure() {  // configure the users mapper
41
-        mapper.createTypeMap(User.class, com.onlyoffice.integration.documentserver.models.filemodel
42
-                        .User.class)  // create the type map
43
-                .setPostConverter(modelConverter());  // and apply the post converter to it
44
-    }
45
-
46
-    @Override
47
-    public void handleSpecificFields(final User source,
48
-                                     final com.onlyoffice.integration.documentserver.models.filemodel
49
-                                             .User destination) {  // handle specific users fields
50
-        destination.setGroup(source.getGroup() != null
51
-                ? source.getGroup().getName() : null);  // set the Group parameter
52
-    }
53
-}

+ 0
- 28
src/main/java/com/onlyoffice/integration/repositories/GroupRepository.java ファイルの表示

@@ -1,28 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.repositories;
20
-
21
-import com.onlyoffice.integration.entities.Group;
22
-import org.springframework.data.jpa.repository.JpaRepository;
23
-
24
-import java.util.Optional;
25
-
26
-public interface GroupRepository extends JpaRepository<Group, Integer> {
27
-    Optional<Group> findGroupByName(String name);
28
-}

+ 0
- 25
src/main/java/com/onlyoffice/integration/repositories/PermissionRepository.java ファイルの表示

@@ -1,25 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.repositories;
20
-
21
-import com.onlyoffice.integration.entities.Permission;
22
-import org.springframework.data.jpa.repository.JpaRepository;
23
-
24
-public interface PermissionRepository extends JpaRepository<Permission, Integer> {
25
-}

+ 0
- 25
src/main/java/com/onlyoffice/integration/repositories/UserRepository.java ファイルの表示

@@ -1,25 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.repositories;
20
-
21
-import com.onlyoffice.integration.entities.User;
22
-import org.springframework.data.jpa.repository.JpaRepository;
23
-
24
-public interface UserRepository extends JpaRepository<User, Integer> {
25
-}

+ 0
- 63
src/main/java/com/onlyoffice/integration/services/GroupServices.java ファイルの表示

@@ -1,63 +0,0 @@
1
-/**
2
- *
3
- * (c) Copyright Ascensio System SIA 2023
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- *     http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
-package com.onlyoffice.integration.services;
20
-
21
-import com.onlyoffice.integration.entities.Group;
22
-import com.onlyoffice.integration.repositories.GroupRepository;
23
-import org.springframework.beans.factory.annotation.Autowired;
24
-import org.springframework.stereotype.Service;
25
-import java.util.List;
26
-import java.util.Optional;
27
-import java.util.stream.Collectors;
28
-
29
-@Service
30
-public class GroupServices {
31
-
32
-    @Autowired
33
-    private GroupRepository groupRepository;
34
-
35
-    // create a new group with the specified name
36
-    public Group createGroup(final String name) {
37
-        if (name == null) {
38
-            return null;  // check if a name is specified
39
-        }
40
-        Optional<Group> group = groupRepository
41
-                .findGroupByName(name);  // check if group with such a name already exists
42
-        if (group.isPresent()) {
43
-            return group.get();  // if it exists, return it
44
-        }
45
-        Group newGroup = new Group();
46
-        newGroup.setName(name);  // otherwise, create a new group with the specified name
47
-
48
-        groupRepository.save(newGroup);  // save a new group
49
-
50
-        return newGroup;
51
-    }
52
-
53
-    // create a list of groups from the reviewGroups permission parameter
54
-    public List<Group> createGroups(final List<String> reviewGroups) {
55
-        if (reviewGroups == null) {
56
-            return null;  // check if the reviewGroups permission exists
57
-        }
58
-        // convert this parameter to a list of groups whose changes the user can accept/reject
59
-        return reviewGroups.stream()
60
-                .map(group -> createGroup(group))
61
-                .collect(Collectors.toList());
62
-    }
63
-}

+ 0
- 0
src/main/java/com/onlyoffice/integration/services/PermissionServices.java ファイルの表示


多くのファイルが変更されたため、一部のファイルはこの差分に表示されません