Skip to content

Commit aa3e628

Browse files
Updated frontend.
Updated to have option in configuration to use Google Drive API as files source Implemented provider to use files from Google Drive using it's API (simple sample)
1 parent d2ae10e commit aa3e628

52 files changed

Lines changed: 2222 additions & 1310 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Demos/Dropwizard/src/main/java/com/groupdocs/ui/common/util/Utils.java

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static com.groupdocs.ui.common.exception.PasswordExceptions.PASSWORD_REQUIRED;
2626

2727
public class Utils {
28-
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
2928

3029
private static final List<String> SUPPORTED_FORMATS = Arrays.asList(
3130
"jpg",
@@ -48,10 +47,6 @@ public static java.util.List<FileDescriptionEntity> orderByTypeAndName(List<File
4847

4948
/**
5049
* Read stream and convert to string
51-
*
52-
* @param inputStream
53-
* @return
54-
* @throws IOException
5550
*/
5651
public static String getStringFromStream(InputStream inputStream) throws IOException {
5752
byte[] bytes = IOUtils.toByteArray(inputStream);
@@ -80,103 +75,4 @@ public static String parseFileExtension(String documentGuid) {
8075
public static boolean checkSupportedFiles(String extension) {
8176
return SUPPORTED_FORMATS.contains(extension);
8277
}
83-
84-
/**
85-
* Get correct message for security exceptions
86-
*
87-
* @param password
88-
* @return
89-
*/
90-
public static String getExceptionMessage(String password) {
91-
return StringUtils.isEmpty(password) ? PASSWORD_REQUIRED : INCORRECT_PASSWORD;
92-
}
93-
94-
/**
95-
* Rename file if exist
96-
*
97-
* @param directory directory where files are located
98-
* @param fileName file name
99-
* @return new file with new file name
100-
*/
101-
public static File getFreeFileName(String directory, String fileName) {
102-
File file = null;
103-
try {
104-
File folder = new File(directory);
105-
File[] listOfFiles = folder.listFiles();
106-
for (int i = 0; i < listOfFiles.length; i++) {
107-
int number = i + 1;
108-
String newFileName = FilenameUtils.removeExtension(fileName) + "-Copy(" + number + ")." + FilenameUtils.getExtension(fileName);
109-
file = new File(directory + File.separator + newFileName);
110-
if (file.exists()) {
111-
continue;
112-
} else {
113-
break;
114-
}
115-
}
116-
} catch (Exception e) {
117-
e.printStackTrace();
118-
}
119-
return file;
120-
}
121-
122-
/**
123-
* Create file in previewPath and name imageGuid
124-
* if the file is already exist, create new file with next number in name
125-
* examples, 001, 002, 003, etc
126-
*
127-
* @param previewPath path to file folder
128-
* @param imageGuid path to file
129-
* @return created file
130-
*/
131-
public static File getFileWithUniqueName(String previewPath, String imageGuid, String ext) {
132-
if (!StringUtils.isEmpty(imageGuid) && new File(imageGuid).exists()) {
133-
return new File(imageGuid);
134-
} else {
135-
File[] listOfFiles = new File(previewPath).listFiles();
136-
return createUniqueFile(previewPath, listOfFiles, ext);
137-
}
138-
}
139-
140-
private static File createUniqueFile(String previewPath, File[] listOfFiles, String ext) {
141-
for (int i = 0; i <= listOfFiles.length; i++) {
142-
// set file name, for example 001
143-
String fileName = String.format("%03d", i + 1);
144-
File file = new File(String.format("%s%s%s.%s", previewPath, File.separator, fileName, ext));
145-
// check if file with such name already exists
146-
if (file.exists()) {
147-
continue;
148-
} else {
149-
return file;
150-
}
151-
}
152-
return new File(String.format("%s%s001.png", previewPath, File.separator));
153-
}
154-
155-
/**
156-
* Generate empty image for future signing with signature, such approach required to get signature as image
157-
*
158-
* @param width image width
159-
* @param height image height
160-
* @return
161-
*/
162-
public static BufferedImage getBufferedImage(int width, int height) {
163-
BufferedImage bufImage = null;
164-
try {
165-
bufImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
166-
// Create a graphics contents on the buffered image
167-
Graphics2D g2d = bufImage.createGraphics();
168-
// Draw graphics
169-
g2d.setColor(Color.WHITE);
170-
g2d.fillRect(0, 0, width, height);
171-
// Graphics context no longer needed so dispose it
172-
g2d.dispose();
173-
return bufImage;
174-
} catch (Exception ex) {
175-
throw new TotalGroupDocsException(ex.getMessage(), ex);
176-
} finally {
177-
if (bufImage != null) {
178-
bufImage.flush();
179-
}
180-
}
181-
}
18278
}

Demos/Spring/client/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@
3737
"@angular/platform-browser": "^8.2.14",
3838
"@angular/platform-browser-dynamic": "^8.2.14",
3939
"@angular/router": "^8.2.14",
40-
"@groupdocs.examples.angular/comparison": "^0.8.20",
40+
"@groupdocs.examples.angular/comparison": "^0.8.80",
4141
"@nrwl/angular": "^8.8.2",
4242
"core-js": "^2.6.10",
4343
"rxjs": "~6.4.0",
4444
"zone.js": "^0.9.1"
4545
},
4646
"devDependencies": {
47-
"@angular-devkit/build-angular": "^0.800.1",
48-
"@angular/cli": "8.1.1",
47+
"@angular-devkit/build-angular": "^0.800.0",
48+
"@angular/cli": "8.0.0",
4949
"@angular/compiler-cli": "^8.2.14",
5050
"@angular/language-service": "^8.2.14",
51-
"@nrwl/cypress": "8.4.3",
52-
"@nrwl/jest": "8.4.3",
53-
"@nrwl/workspace": "8.4.3",
51+
"@nrwl/cypress": "8.2.0",
52+
"@nrwl/jest": "8.2.0",
53+
"@nrwl/workspace": "8.2.0",
5454
"@types/jest": "24.0.9",
5555
"@types/node": "~8.9.4",
5656
"codelyzer": "~5.0.1",
57-
"cypress": "3.4.0",
57+
"cypress": "~3.3.1",
5858
"dotenv": "6.2.0",
5959
"jest": "24.1.0",
6060
"jest-preset-angular": "7.0.0",

Demos/Spring/configuration.yml

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ server:
1212
# Application (global) configurations
1313
################################################
1414
application:
15-
# License path
16-
# Absolute or relative path to GroupDocs license file
17-
licensePath: ${LIC_PATH:Licenses}
15+
# Absolute or relative path to GroupDocs license
16+
# Can be as a path to license file, to directory, in which license file is placed (*.lic) or url to download license file
17+
# Default value is `Licenses`
18+
licensePath: ${LIC_PATH:}
1819
# Host name or ip for server instance
1920
hostAddress: ${HOST_ADDRESS:}
2021

@@ -23,9 +24,9 @@ application:
2324
################################################
2425
common:
2526
# File rewriting on document uploading
26-
# Set false to keep both files
27+
# Set false to cancel uploading in case of existence of file with the same name
2728
# Set true to replace files with same name
28-
rewrite: true
29+
rewrite: ${REWRITE:true}
2930
# Page navigation
3031
# Set false to disable document navigation (go to next, previous, last and first page)
3132
pageSelector: true
@@ -42,19 +43,58 @@ common:
4243
# Set false to disable document browse
4344
browse: ${BROWSE_ON:true}
4445
# Set false to disable right mouse click
45-
enableRightClick: ${RIGHTCLICK_ON:false}
46+
enableRightClick: ${RIGHTCLICK_ON:true}
4647

4748
################################################
4849
# GroupDocs.Comparison configurations
4950
################################################
5051
comparison:
51-
# Files directory path
52-
# Absolute or relative path to files directory
53-
filesDirectory: ${FILES_DIR:DocumentSamples}
54-
# FResult files directory path
55-
# Absolute path to result files directory
56-
resultDirectory: ${RESULT_DIR:DocumentSamples}
52+
# Files provider, where to get files to show them in browse dialog
53+
# Available values are `google` - using Google Drive API, `local` - using local directories
54+
filesProviderType: ${FILES_PROVIDER_TYPE:local}
5755
# Result pages preload
5856
# How many pages from a result document should be loaded, remaining pages will be loaded on page scrolling
5957
# Set 0 to load all pages at once
60-
preloadResultPageCount: 0
58+
preloadResultPageCount: 0
59+
# Page width that will be used to resize preview images before displaying them
60+
# Default value is 768
61+
previewPageWidth: ${PREVIEW_PAGE_WIDTH:}
62+
# Ratio to calculate height of preview images using width
63+
# Default value is 1.3
64+
previewPageRatio: ${PREVIEW_PAGE_RATIO:}
65+
# Absolute or relative path to directory to save cache files
66+
# Default value is system temp directory. The path is always local
67+
cacheDirectory: ${CACHE_DIR:}
68+
# Absolute or relative path to directory to save temporary files
69+
# Default value is system temp directory. The path is always local
70+
tempDirectory: ${TEMP_DIR:}
71+
################################################
72+
# Local files provider Configuration
73+
################################################
74+
local:
75+
# Files directory path
76+
# Absolute or relative path to files directory, default value is `DocumentSamples`.
77+
filesDirectory: ${FILES_DIR:DocumentSamples}
78+
# Result files directory path
79+
# Absolute or relative path to result files directory, default value is `DocumentSamples/Temp`.
80+
resultDirectory: ${RESULT_DIR:}
81+
################################################
82+
# Google API files provider Configuration
83+
################################################
84+
google:
85+
# When false or empty, file with name `credentials.json` from resources will be used
86+
useCredentialsPath: ${USE_CREDENTIALS_PATH:false}
87+
# When useCredentialsPath is true, this path will be used as a path to google credentials file (usually `credentials.json`)
88+
credentialsPath: ${CREDENTIALS_PATH:}
89+
# Path to directory to save stored credentials. When empty, credentials will not be saved
90+
tokensDirectoryPath: ${TOKENS_DIRECTORY_PATH:}
91+
# Client application name
92+
applicationName: ${APPLICATION_NAME:GroupDocs.Comparison for Java Dropwizard sample}
93+
# Files access type, available options are `offline` and `online`.
94+
# Default value is `offline`
95+
accessType: offline
96+
# Port that will be used for Google Drive API authorization callback.
97+
# Default value is `8888`
98+
localServerReceiverPort: ${LOCAL_SERVER_RECEIVER_PORT:8888}
99+
# user ID or null if not using a persisted credential store
100+
authorizationUserId: user

Demos/Spring/pom.xml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</profiles>
5252

5353
<properties>
54-
<start-class>com.groupdocs.ui.Application</start-class>
54+
<start-class>com.groupdocs.ui.common.Application</start-class>
5555
<java.version>1.8</java.version>
5656
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5757
</properties>
@@ -131,6 +131,24 @@
131131
<artifactId>guava</artifactId>
132132
<version>23.0</version>
133133
</dependency>
134+
135+
<!-- Google API -->
136+
<dependency>
137+
<groupId>com.google.api-client</groupId>
138+
<artifactId>google-api-client</artifactId>
139+
<version>1.33.0</version>
140+
</dependency>
141+
<dependency>
142+
<groupId>com.google.apis</groupId>
143+
<artifactId>google-api-services-drive</artifactId>
144+
<version>v3-rev20211107-1.32.1</version>
145+
</dependency>
146+
<dependency>
147+
<groupId>com.google.oauth-client</groupId>
148+
<artifactId>google-oauth-client-jetty</artifactId>
149+
<version>1.32.1</version>
150+
</dependency>
151+
134152
<dependency>
135153
<groupId>junit</groupId>
136154
<artifactId>junit</artifactId>
@@ -143,7 +161,7 @@
143161
<repository>
144162
<id>com.springsource.repository.bundles.external</id>
145163
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
146-
<url>http://repository.springsource.com/maven/bundles/external</url>
164+
<url>https://repository.springsource.com/maven/bundles/external</url>
147165
</repository>
148166
<repository>
149167
<id>maven.groupdocs.com</id>

Demos/Spring/src/main/java/com/groupdocs/ui/ApplicationStartup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.groupdocs.ui;
22

3-
import com.groupdocs.ui.config.ServerConfiguration;
3+
import com.groupdocs.ui.common.config.ServerConfiguration;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.boot.web.context.WebServerInitializedEvent;
66
import org.springframework.context.ApplicationListener;

Demos/Spring/src/main/java/com/groupdocs/ui/Application.java renamed to Demos/Spring/src/main/java/com/groupdocs/ui/common/Application.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.groupdocs.ui;
1+
package com.groupdocs.ui.common;
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
@@ -19,7 +19,18 @@
1919
import java.io.File;
2020
import java.net.MalformedURLException;
2121

22-
@SpringBootApplication
22+
//@EnableAutoConfiguration
23+
@SpringBootApplication(
24+
scanBasePackages = {
25+
"com.groupdocs.ui",
26+
// "com.groupdocs.ui.common",
27+
// "com.groupdocs.ui.comparison",
28+
// "com.groupdocs.ui.common.config",
29+
// "com.groupdocs.ui.comparison.config",
30+
// "com.groupdocs.ui.comparison.resources",
31+
// "com.groupdocs.ui.comparison.service"
32+
}
33+
)
2334
public class Application extends SpringBootServletInitializer {
2435

2536
private static final Logger logger = LoggerFactory.getLogger(Application.class);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.groupdocs.ui.common;
2+
3+
public interface Defaults {
4+
interface Application {
5+
String DEFAULT_LICENSE_PATH = "Licenses";
6+
String DEFAULT_LICENSE_EXTENSION = ".lic";
7+
}
8+
9+
interface Comparison {
10+
enum FilesProviderType {
11+
LOCAL, GOOGLE
12+
}
13+
14+
int DEFAULT_PRELOAD_RESULT_PAGE_COUNT = 2;
15+
int DEFAULT_PREVIEW_PAGE_WIDTH = 768;
16+
float DEFAULT_PREVIEW_PAGE_RATIO = 1.3F;
17+
FilesProviderType DEFAULT_FILES_PROVIDER_TYPE = FilesProviderType.LOCAL;
18+
}
19+
20+
interface Local {
21+
22+
String DEFAULT_FILES_DIRECTORY = "DocumentSamples";
23+
String DEFAULT_RESULT_DIRECTORY = "DocumentSamples/Temp";
24+
String DEFAULT_CACHE_DIRECTORY = System.getProperty("java.io.tmpdir");
25+
String DEFAULT_TEMP_DIRECTORY = System.getProperty("java.io.tmpdir");
26+
}
27+
28+
interface Google {
29+
30+
enum AccessType {
31+
OFFLINE, ONLINE
32+
}
33+
34+
int DEFAULT_LOCAL_SERVER_RECEIVER_PORT = 8888;
35+
AccessType DEFAULT_ACCESS_TYPE = AccessType.OFFLINE;
36+
String DEFAULT_CREDENTIALS_PATH = "credentials.json";
37+
}
38+
}

0 commit comments

Comments
 (0)