Skip to content

Commit 8fff1f3

Browse files
Updated to show lost of changes
1 parent 9db7c0d commit 8fff1f3

7 files changed

Lines changed: 165 additions & 27 deletions

File tree

Demos/Ktor/comparison-ktor/src/main/kotlin/com/groupdocs/ui/Application.kt

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.groupdocs.ui
22

3+
import com.groupdocs.comparison.license.License
34
import com.groupdocs.ui.config.ApplicationConfig
45
import com.groupdocs.ui.config.ServerConfig
56
import com.groupdocs.ui.di.ModulesInjection
6-
import com.groupdocs.ui.status.InternalServerException
77
import com.typesafe.config.ConfigFactory
88
import io.ktor.server.application.*
99
import io.ktor.server.config.*
@@ -15,6 +15,11 @@ import kotlinx.serialization.hocon.Hocon
1515
import org.koin.core.logger.PrintLogger
1616
import org.koin.dsl.module
1717
import org.koin.ktor.plugin.Koin
18+
import java.io.BufferedInputStream
19+
import java.net.URL
20+
import java.nio.file.Files
21+
import java.nio.file.Path
22+
import java.nio.file.Paths
1823

1924
@ExperimentalSerializationApi
2025
@KtorExperimentalAPI
@@ -40,6 +45,10 @@ fun main(args: Array<String>) {
4045
}
4146
main()
4247
}
48+
49+
comparisonConfig.application.licensePathOrNull?.let { path ->
50+
setGroupdocsLicense(path)
51+
}
4352
}.start(wait = true)
4453
}
4554

@@ -68,4 +77,36 @@ fun extractComparisonConfig(): ApplicationConfig {
6877
useConfigNamingConvention = false
6978
}
7079
return hocon.decodeFromConfig(ApplicationConfig.serializer(), ConfigFactory.load("application.conf"))
71-
}
80+
}
81+
82+
fun Application.setGroupdocsLicense(licensePath: String) {
83+
try {
84+
log.debug("Setting Groupdocs license...")
85+
86+
val licenseExtension = Defaults.Application.DEFAULT_LICENSE_EXTENSION
87+
val license = License()
88+
if (licensePath.startsWith("http://") || licensePath.startsWith("https://")) {
89+
val url = URL(licensePath)
90+
BufferedInputStream(url.openStream()).use { inputStream -> license.setLicense(inputStream) }
91+
} else {
92+
val path = Paths.get(licensePath)
93+
if (Files.exists(path)) {
94+
if (Files.isRegularFile(path)) {
95+
license.setLicense(licensePath)
96+
} else {
97+
Files.list(path).use { pathStream ->
98+
val first =
99+
pathStream.filter { path ->
100+
path.endsWith(licenseExtension)
101+
}.findFirst()
102+
first.ifPresent { licensePath: Path? ->
103+
license.setLicense(licensePath)
104+
}
105+
}
106+
}
107+
}
108+
}
109+
} catch (e: Exception) {
110+
log.warn("Can not verify Comparison license!", e)
111+
}
112+
}

Demos/Ktor/comparison-ktor/src/main/kotlin/com/groupdocs/ui/config/ApplicationConfig.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ import java.nio.file.Path
55

66
@kotlinx.serialization.Serializable
77
data class ApplicationConfig(
8+
val application: Application = Application(),
89
val common: Common = Common(),
910
val comparison: Comparison = Comparison(),
1011
val local: Local = Local(),
1112
)
1213

14+
@kotlinx.serialization.Serializable
15+
data class Application(
16+
private val licensePath: String = "",
17+
val hostAddress: String = "",
18+
) {
19+
val licensePathOrNull: String?
20+
get() = licensePath.ifBlank { null }
21+
}
22+
1323
@kotlinx.serialization.Serializable
1424
data class Common(
1525
val pageSelector: Boolean = false,
@@ -26,10 +36,10 @@ data class Common(
2636
data class Comparison(
2737
private val filesProviderType: String = "",
2838
val preloadResultPageCount: Int = 0,
29-
val previewPageWidth: Int = 0,
30-
val previewPageRatio: Float = 0f,
31-
val cacheDirectory: String = "",
32-
val tempDirectory: String = "",
39+
private val previewPageWidth: Int = 0,
40+
private val previewPageRatio: Float = 0f,
41+
private val cacheDirectory: String = "",
42+
private val tempDirectory: String = "",
3343
) {
3444
val filesProviderTypeOrDefault: Defaults.Comparison.FilesProviderType
3545
get() =
@@ -48,8 +58,8 @@ data class Comparison(
4858

4959
@kotlinx.serialization.Serializable
5060
data class Local(
51-
val filesDirectory: String = "",
52-
val resultDirectory: String = "",
61+
private val filesDirectory: String = "",
62+
private val resultDirectory: String = "",
5363
) {
5464

5565
val filesDirectoryOrDefault: Path

Demos/Ktor/comparison-ktor/src/main/kotlin/com/groupdocs/ui/model/CompareResponse.kt

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.groupdocs.ui.model
22

3-
import com.groupdocs.comparison.result.ChangeInfo
4-
53
data class CompareResponse(
64
/**
75
* List of change information
86
*/
9-
val changes: List<ChangeInfo>,
7+
val changes: List<DocumentChange>,
108

119
/**
1210
* List of images of pages with marked changes
@@ -21,7 +19,7 @@ data class CompareResponse(
2119
/**
2220
* Extension of compared files, for saving total results
2321
*/
24-
val extension: String = ""
22+
val extension: String? = null
2523
)
2624

2725
/**
@@ -35,4 +33,37 @@ data class ComparePage(
3533
val width: Int = 0,
3634
val height: Int = 0,
3735
val number: Int = 0,
36+
)
37+
38+
data class DocumentChange(
39+
val id: Int,
40+
val type: Int,
41+
val comparisonAction: Int,
42+
val sourceText: String,
43+
val targetText: String,
44+
val text: String,
45+
val componentType: String,
46+
val box: ChangeBox,
47+
val authors: List<String>,
48+
val pageInfo: PageInfo,
49+
val styleChanges: List<StyleChange>,
50+
)
51+
52+
data class ChangeBox(
53+
val y: Double,
54+
val x: Double,
55+
val height: Double,
56+
val width: Double
57+
)
58+
59+
data class PageInfo(
60+
val height: Int,
61+
val width: Int,
62+
val pageNumber: Int
63+
)
64+
65+
data class StyleChange(
66+
val oldValue: Any,
67+
val newValue: Any,
68+
val propertyName: String
3869
)

Demos/Ktor/comparison-ktor/src/main/kotlin/com/groupdocs/ui/model/TreeResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ data class FileDescriptionEntity(
44
val guid: String? = null,
55
val name: String? = null,
66
val docType: String? = null,
7-
val isDirectory: Boolean? = null,
7+
val directory: Boolean? = null,
88
val size: Long? = null
99
)

Demos/Ktor/comparison-ktor/src/main/kotlin/com/groupdocs/ui/modules/compare/CompareController.kt

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.groupdocs.ui.modules.compare
22

33
import com.groupdocs.ui.manager.PathManager
4-
import com.groupdocs.ui.model.ComparePage
5-
import com.groupdocs.ui.model.CompareRequest
6-
import com.groupdocs.ui.model.CompareResponse
4+
import com.groupdocs.ui.model.*
75
import com.groupdocs.ui.modules.BaseController
86
import com.groupdocs.ui.status.InternalServerException
97
import com.groupdocs.ui.usecase.AreFilesSupportedUseCase
@@ -17,6 +15,7 @@ import java.io.BufferedInputStream
1715
import java.io.BufferedOutputStream
1816
import java.io.FileInputStream
1917
import java.io.FileOutputStream
18+
import java.nio.file.Files
2019
import java.util.*
2120

2221
class CompareControllerImpl(
@@ -46,7 +45,10 @@ class CompareControllerImpl(
4645
targetName = targetFilePath.fileName.toString(),
4746
extension = resultExtension
4847
)
49-
val changes = withContext(Dispatchers.IO) {
48+
if (Files.notExists(resultPath.parent)) {
49+
throw InternalServerException("Result directory does not exist") // TODO: Need another exception type
50+
}
51+
val changeInfos = withContext(Dispatchers.IO) {
5052
BufferedOutputStream(FileOutputStream(resultPath.toFile())).use { outputStream ->
5153
return@withContext compareDocuments(
5254
sourcePath = sourceFilePath,
@@ -82,11 +84,47 @@ class CompareControllerImpl(
8284
pages
8385
}
8486

87+
val changes = changeInfos.map { changeInfo ->
88+
DocumentChange(
89+
id = changeInfo.id,
90+
type = changeInfo.type,
91+
comparisonAction = changeInfo.comparisonAction,
92+
sourceText = changeInfo.sourceText,
93+
targetText = changeInfo.targetText,
94+
text = changeInfo.text,
95+
componentType = changeInfo.componentType,
96+
box = ChangeBox(
97+
x = changeInfo.box.x,
98+
y = changeInfo.box.y,
99+
width = changeInfo.box.width,
100+
height = changeInfo.box.height
101+
),
102+
authors = changeInfo.authors,
103+
pageInfo = PageInfo(
104+
pageNumber = changeInfo.pageInfo.pageNumber,
105+
width = changeInfo.pageInfo.width,
106+
height = changeInfo.pageInfo.height
107+
),
108+
styleChanges = changeInfo.styleChanges.map { styleChangeInfo ->
109+
StyleChange(
110+
propertyName = styleChangeInfo.propertyName,
111+
oldValue = styleChangeInfo.oldValue,
112+
newValue = styleChangeInfo.newValue
113+
)
114+
}
115+
)
116+
}
117+
118+
val filesDirectory = pathManager.filesDirectory
85119
val resultDirectory = pathManager.resultDirectory
120+
121+
val guid = if (resultDirectory.startsWith(filesDirectory)) {
122+
filesDirectory.relativize(resultPath)
123+
} else resultDirectory.relativize(resultPath)
124+
86125
return CompareResponse(
87-
guid = resultDirectory.relativize(resultPath).toString(),
126+
guid = guid.toString(),
88127
changes = changes,
89-
extension = resultExtension,
90128
pages = pages
91129
)
92130
}

Demos/Ktor/comparison-ktor/src/main/kotlin/com/groupdocs/ui/modules/tree/TreeController.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ class TreeControllerImpl(
2424
val isDirectory = it is LocalStorageEntry.Directory
2525
val size = if (it is LocalStorageEntry.File) it.size else 0
2626

27+
val filesDirectory = pathManager.filesDirectory
28+
val fileFullPath = it.fullPath
29+
val guid = filesDirectory.relativize(fileFullPath).toString()
2730
FileDescriptionEntity(
28-
guid = it.fullPath.toString(),
31+
guid = guid,
2932
name = it.name,
3033
docType = docType,
31-
isDirectory = isDirectory,
34+
directory = isDirectory,
3235
size = size
3336
)
3437
}

Demos/Ktor/comparison-ktor/src/main/resources/application.conf

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
# Absolute or relative path to GroupDocs license
77
# Can be as a path to license file, to directory, in which license file is placed (*.lic) or url to download license file
88
# Default value is `Licenses`
9-
licensePath = null
9+
licensePath = ""
10+
licensePath = ${?LIC_PATH}
1011
# Host name or ip for server instance
11-
hostAddress = null
12+
hostAddress = ""
13+
hostAddress = ${?HOST_ADDRESS}
1214
}
1315
################################################
1416
# Common configurations
@@ -18,23 +20,29 @@
1820
# Set false to cancel uploading in case of existence of file with the same name
1921
# Set true to replace files with same name
2022
rewrite = true
23+
rewrite = ${?REWRITE}
2124
# Page navigation
2225
# Set false to disable document navigation (go to next, previous, last and first page)
2326
pageSelector = true
2427
# Document download
2528
# Set false to disable document download
2629
download = true
30+
download = ${?DOWNLOAD_ON}
2731
# Document upload
2832
# Set false to disable document upload
2933
upload = true
34+
upload = ${?UPLOAD_ON}
3035
# Document print
3136
# Set false to disable document print
3237
print = true
38+
print = ${?PRINT_ON}
3339
# File browser
3440
# Set false to disable document browse
3541
browse = true
42+
browse = ${?BROWSE_ON}
3643
# Set false to disable right mouse click
3744
enableRightClick = true
45+
enableRightClick = ${?RIGHTCLICK_ON}
3846
}
3947
################################################
4048
# GroupDocs.Comparison configurations
@@ -43,23 +51,28 @@
4351
# Files provider, where to get files to show them in browse dialog
4452
# Available values are `google` - using Google Drive API, `dropbox` - using Dropbox API, `local` - using local directories
4553
filesProviderType = "local"
54+
filesProviderType = ${?FILES_PROVIDER_TYPE}
4655
# Result pages preload
4756
# How many pages from a result document should be loaded, remaining pages will be loaded on page scrolling
4857
# Set 0 to load all pages at once
4958
preloadResultPageCount = 0
5059
# Page width that will be used to resize preview images before displaying them
5160
# Default value is 768
52-
previewPageWidth = 768
61+
previewPageWidth = 0
62+
previewPageWidth = ${?PREVIEW_PAGE_WIDTH}
5363
# Ratio to calculate height of preview images using width
5464
# Default value is 1.3
55-
previewPageRatio = 1.3
65+
previewPageRatio = 0
66+
previewPageRatio = ${?PREVIEW_PAGE_RATIO}
5667
# Absolute or relative path to directory to save cache files
5768
# Default value is system temp directory. The path is always local
58-
cacheDirectory = "asd"
69+
cacheDirectory = ""
70+
cacheDirectory = ${?CACHE_DIR}
5971
# Absolute or relative path to directory to save temporary files
6072
# in case of using local files provider, relative path will be resolved with filesDirectory as base path
6173
# Default value is system temp directory. The path is always local
6274
tempDirectory = ""
75+
tempDirectory = ${?TEMP_DIR}
6376
}
6477
################################################
6578
# Local files provider Configuration
@@ -69,9 +82,11 @@
6982
# Directory must be created before app starts
7083
# Absolute or relative path to files directory, default value is `DocumentSamples`.
7184
filesDirectory = "DocumentSamples"
85+
filesDirectory = ${?FILES_DIR}
7286
# Result files directory path
7387
# Directory must be created before app starts
7488
# Absolute or relative path to result files directory, default value is `ResultFiles`.
75-
resultDirectory = "ResultFiles"
89+
resultDirectory = ""
90+
resultDirectory = ${?RESULT_DIR}
7691
}
7792
}

0 commit comments

Comments
 (0)