Skip to content

Commit def5c69

Browse files
Added common API tests
1 parent c56470f commit def5c69

File tree

12 files changed

+970
-4
lines changed

12 files changed

+970
-4
lines changed

Demos/Dropwizard/src/main/java/com/groupdocs/ui/viewer/dropwizard/resources/ViewerResources.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.groupdocs.ui.viewer.dropwizard.common.config.GlobalConfiguration;
55
import com.groupdocs.ui.viewer.dropwizard.common.exception.TotalGroupDocsException;
66
import com.groupdocs.ui.viewer.dropwizard.common.resources.Resources;
7+
import com.groupdocs.ui.viewer.dropwizard.common.util.Utils;
78
import com.groupdocs.ui.viewer.dropwizard.config.ViewerConfiguration;
89
import com.groupdocs.ui.viewer.dropwizard.common.entity.web.request.FileTreeRequest;
910
import com.groupdocs.ui.viewer.dropwizard.common.entity.web.request.LoadDocumentPageRequest;
@@ -17,6 +18,7 @@
1718
import com.groupdocs.ui.viewer.dropwizard.service.ViewerServiceImpl;
1819
import com.groupdocs.ui.viewer.dropwizard.views.Viewer;
1920
import com.groupdocs.viewer.License;
21+
import com.groupdocs.viewer.utils.PathUtils;
2022
import org.apache.commons.io.FilenameUtils;
2123
import org.apache.commons.lang3.StringUtils;
2224
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
@@ -226,7 +228,8 @@ public PageDescriptionEntity rotateDocumentPages(RotateDocumentPagesRequest rota
226228
@Path(value = "/downloadDocument")
227229
@Produces(APPLICATION_OCTET_STREAM)
228230
public void downloadDocument(@QueryParam("path") String documentGuid, @Context HttpServletResponse response) {
229-
downloadFile(response, documentGuid);
231+
String documentPath = PathUtils.combine(viewerService.getViewerConfiguration().getFilesDirectory(), Utils.normalizeGuidToPath(documentGuid));
232+
downloadFile(response, documentPath);
230233
}
231234

232235
@GET

Demos/Spring/src/main/java/com/groupdocs/ui/viewer/spring/resources/ViewerResources.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.groupdocs.ui.viewer.spring.common.entity.web.UploadedDocumentEntity;
1515
import com.groupdocs.ui.viewer.spring.service.ViewerService;
1616
import com.groupdocs.ui.viewer.spring.common.util.Utils;
17+
import com.groupdocs.viewer.utils.PathUtils;
1718
import org.apache.commons.io.FilenameUtils;
1819
import org.apache.commons.io.IOUtils;
1920
import org.slf4j.Logger;
@@ -173,11 +174,12 @@ public PageDescriptionEntity rotateDocumentPages(@RequestBody RotateDocumentPage
173174
*/
174175
@RequestMapping(method = RequestMethod.GET, value = "/downloadDocument")
175176
public void downloadDocument(@RequestParam(name = "path") String documentGuid, HttpServletResponse response) {
176-
File file = new File(documentGuid);
177+
String documentPath = PathUtils.combine(viewerService.getViewerConfiguration().getFilesDirectory(), Utils.normalizeGuidToPath(documentGuid));
178+
File file = new File(documentPath);
177179
// set response content info
178180
addFileDownloadHeaders(response, file.getName(), file.length());
179181
// download the document
180-
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(documentGuid));
182+
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(documentPath));
181183
ServletOutputStream outputStream = response.getOutputStream()) {
182184

183185
IOUtils.copyLarge(inputStream, outputStream);

Demos/Spring/src/main/resources/templates/viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
33
<head>
44
<meta charset="utf-8"/>
5-
<title>Viewer</title>
5+
<title>GroupDocs.Viewer for Java Spring</title>
66
<base href="/"/>
77

88
<meta name="viewport" content="width=device-width, initial-scale=1"/>
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
package com.groupdocs.ui.viewer.demosapitests;
2+
3+
import java.util.Objects;
4+
5+
public class LoadConfigResponse {
6+
private boolean pageSelector;
7+
private Boolean download;
8+
private Boolean upload;
9+
private Boolean print;
10+
private Boolean browse;
11+
private Boolean rewrite;
12+
private Boolean enableRightClick;
13+
private String filesDirectory;
14+
private String fontsDirectory;
15+
private Integer preloadPageCount;
16+
private Boolean zoom;
17+
private Boolean search;
18+
private Boolean thumbnails;
19+
private Boolean rotate;
20+
private String defaultDocument;
21+
private Boolean htmlMode;
22+
private boolean cache;
23+
private boolean saveRotateState;
24+
private String watermarkText;
25+
private Boolean printAllowed;
26+
private Boolean showGridLines;
27+
private String cacheFolderName;
28+
29+
public boolean isPageSelector() {
30+
return pageSelector;
31+
}
32+
33+
public void setPageSelector(boolean pageSelector) {
34+
this.pageSelector = pageSelector;
35+
}
36+
37+
public Boolean getDownload() {
38+
return download;
39+
}
40+
41+
public void setDownload(Boolean download) {
42+
this.download = download;
43+
}
44+
45+
public Boolean getUpload() {
46+
return upload;
47+
}
48+
49+
public void setUpload(Boolean upload) {
50+
this.upload = upload;
51+
}
52+
53+
public Boolean getPrint() {
54+
return print;
55+
}
56+
57+
public void setPrint(Boolean print) {
58+
this.print = print;
59+
}
60+
61+
public Boolean getBrowse() {
62+
return browse;
63+
}
64+
65+
public void setBrowse(Boolean browse) {
66+
this.browse = browse;
67+
}
68+
69+
public Boolean getRewrite() {
70+
return rewrite;
71+
}
72+
73+
public void setRewrite(Boolean rewrite) {
74+
this.rewrite = rewrite;
75+
}
76+
77+
public Boolean getEnableRightClick() {
78+
return enableRightClick;
79+
}
80+
81+
public void setEnableRightClick(Boolean enableRightClick) {
82+
this.enableRightClick = enableRightClick;
83+
}
84+
85+
public String getFilesDirectory() {
86+
return filesDirectory;
87+
}
88+
89+
public void setFilesDirectory(String filesDirectory) {
90+
this.filesDirectory = filesDirectory;
91+
}
92+
93+
public String getFontsDirectory() {
94+
return fontsDirectory;
95+
}
96+
97+
public void setFontsDirectory(String fontsDirectory) {
98+
this.fontsDirectory = fontsDirectory;
99+
}
100+
101+
public Integer getPreloadPageCount() {
102+
return preloadPageCount;
103+
}
104+
105+
public void setPreloadPageCount(Integer preloadPageCount) {
106+
this.preloadPageCount = preloadPageCount;
107+
}
108+
109+
public Boolean getZoom() {
110+
return zoom;
111+
}
112+
113+
public void setZoom(Boolean zoom) {
114+
this.zoom = zoom;
115+
}
116+
117+
public Boolean getSearch() {
118+
return search;
119+
}
120+
121+
public void setSearch(Boolean search) {
122+
this.search = search;
123+
}
124+
125+
public Boolean getThumbnails() {
126+
return thumbnails;
127+
}
128+
129+
public void setThumbnails(Boolean thumbnails) {
130+
this.thumbnails = thumbnails;
131+
}
132+
133+
public Boolean getRotate() {
134+
return rotate;
135+
}
136+
137+
public void setRotate(Boolean rotate) {
138+
this.rotate = rotate;
139+
}
140+
141+
public String getDefaultDocument() {
142+
return defaultDocument;
143+
}
144+
145+
public void setDefaultDocument(String defaultDocument) {
146+
this.defaultDocument = defaultDocument;
147+
}
148+
149+
public Boolean getHtmlMode() {
150+
return htmlMode;
151+
}
152+
153+
public void setHtmlMode(Boolean htmlMode) {
154+
this.htmlMode = htmlMode;
155+
}
156+
157+
public boolean isCache() {
158+
return cache;
159+
}
160+
161+
public void setCache(boolean cache) {
162+
this.cache = cache;
163+
}
164+
165+
public boolean isSaveRotateState() {
166+
return saveRotateState;
167+
}
168+
169+
public void setSaveRotateState(boolean saveRotateState) {
170+
this.saveRotateState = saveRotateState;
171+
}
172+
173+
public String getWatermarkText() {
174+
return watermarkText;
175+
}
176+
177+
public void setWatermarkText(String watermarkText) {
178+
this.watermarkText = watermarkText;
179+
}
180+
181+
public Boolean getPrintAllowed() {
182+
return printAllowed;
183+
}
184+
185+
public void setPrintAllowed(Boolean printAllowed) {
186+
this.printAllowed = printAllowed;
187+
}
188+
189+
public Boolean getShowGridLines() {
190+
return showGridLines;
191+
}
192+
193+
public void setShowGridLines(Boolean showGridLines) {
194+
this.showGridLines = showGridLines;
195+
}
196+
197+
public String getCacheFolderName() {
198+
return cacheFolderName;
199+
}
200+
201+
public void setCacheFolderName(String cacheFolderName) {
202+
this.cacheFolderName = cacheFolderName;
203+
}
204+
205+
@Override
206+
public boolean equals(Object o) {
207+
if (this == o) return true;
208+
if (o == null || getClass() != o.getClass()) return false;
209+
LoadConfigResponse that = (LoadConfigResponse) o;
210+
return pageSelector == that.pageSelector && cache == that.cache && saveRotateState == that.saveRotateState && Objects.equals(download, that.download) && Objects.equals(upload, that.upload) && Objects.equals(print, that.print) && Objects.equals(browse, that.browse) && Objects.equals(rewrite, that.rewrite) && Objects.equals(enableRightClick, that.enableRightClick) && Objects.equals(filesDirectory, that.filesDirectory) && Objects.equals(fontsDirectory, that.fontsDirectory) && Objects.equals(preloadPageCount, that.preloadPageCount) && Objects.equals(zoom, that.zoom) && Objects.equals(search, that.search) && Objects.equals(thumbnails, that.thumbnails) && Objects.equals(rotate, that.rotate) && Objects.equals(defaultDocument, that.defaultDocument) && Objects.equals(htmlMode, that.htmlMode) && Objects.equals(watermarkText, that.watermarkText) && Objects.equals(printAllowed, that.printAllowed) && Objects.equals(showGridLines, that.showGridLines) && Objects.equals(cacheFolderName, that.cacheFolderName);
211+
}
212+
213+
@Override
214+
public int hashCode() {
215+
return Objects.hash(pageSelector, download, upload, print, browse, rewrite, enableRightClick, filesDirectory, fontsDirectory, preloadPageCount, zoom, search, thumbnails, rotate, defaultDocument, htmlMode, cache, saveRotateState, watermarkText, printAllowed, showGridLines, cacheFolderName);
216+
}
217+
218+
@Override
219+
public String toString() {
220+
return "LoadConfig{" +
221+
"pageSelector=" + pageSelector +
222+
", download=" + download +
223+
", upload=" + upload +
224+
", print=" + print +
225+
", browse=" + browse +
226+
", rewrite=" + rewrite +
227+
", enableRightClick=" + enableRightClick +
228+
", filesDirectory='" + filesDirectory + '\'' +
229+
", fontsDirectory='" + fontsDirectory + '\'' +
230+
", preloadPageCount=" + preloadPageCount +
231+
", zoom=" + zoom +
232+
", search=" + search +
233+
", thumbnails=" + thumbnails +
234+
", rotate=" + rotate +
235+
", defaultDocument='" + defaultDocument + '\'' +
236+
", htmlMode=" + htmlMode +
237+
", cache=" + cache +
238+
", saveRotateState=" + saveRotateState +
239+
", watermarkText='" + watermarkText + '\'' +
240+
", printAllowed=" + printAllowed +
241+
", showGridLines=" + showGridLines +
242+
", cacheFolderName='" + cacheFolderName + '\'' +
243+
'}';
244+
}
245+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.groupdocs.ui.viewer.demosapitests;
2+
3+
import java.util.Objects;
4+
5+
public class LoadFileTreeResponse {
6+
private String guid;
7+
private String name;
8+
private Boolean isDirectory;
9+
private Long size = 0L;
10+
11+
public String getGuid() {
12+
return guid;
13+
}
14+
15+
public void setGuid(String guid) {
16+
this.guid = guid;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public void setName(String name) {
24+
this.name = name;
25+
}
26+
27+
public Boolean getDirectory() {
28+
return isDirectory;
29+
}
30+
31+
public void setDirectory(Boolean directory) {
32+
isDirectory = directory;
33+
}
34+
35+
public Long getSize() {
36+
return size;
37+
}
38+
39+
public void setSize(Long size) {
40+
this.size = size;
41+
}
42+
43+
@Override
44+
public boolean equals(Object o) {
45+
if (this == o) return true;
46+
if (o == null || getClass() != o.getClass()) return false;
47+
LoadFileTreeResponse that = (LoadFileTreeResponse) o;
48+
return Objects.equals(guid, that.guid) && Objects.equals(name, that.name) && Objects.equals(isDirectory, that.isDirectory) && Objects.equals(size, that.size);
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(guid, name, isDirectory, size);
54+
}
55+
56+
@Override
57+
public String toString() {
58+
return "FileDescriptionEntity{" +
59+
"guid='" + guid + '\'' +
60+
", name='" + name + '\'' +
61+
", isDirectory=" + isDirectory +
62+
", size=" + size +
63+
'}';
64+
}
65+
}

0 commit comments

Comments
 (0)