Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
pse-trapp-public
IntentFinder
Commits
2ae87e62
Commit
2ae87e62
authored
Jun 01, 2021
by
Chiraz Boukadida
Browse files
[feat/
#31
] Implementation Endpoint Hochladen einer DOCX-FAQ-Datei mit Änderungen
parent
04a13da9
Pipeline
#72885
passed with stages
in 2 minutes and 17 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
PM/Team1/sprints.md
View file @
2ae87e62
...
@@ -21,5 +21,26 @@ Persistierung der ausgelesenen Daten.
...
@@ -21,5 +21,26 @@ Persistierung der ausgelesenen Daten.
**2. Sprint: 12.5. - 9.6**
**2. Sprint: 12.5. - 9.6**
**Sprintziel:**
Extrahierung einzelner Fragen und dazugehörigen Antworten von unterschiedlichen Medien.
Fragemöglichkeit generieren. Persistierung der ausgelesenen Daten.
#27 Definition guter Testfälle und Beispiele (FAQ, ...)
#41 Spike: Fragengenerierung
#25 Recherche/Definition Endpoints
#26 Chatbot-Vokabeln
#33 Abbildung der JSON-Konfiguration in eine geeignete Kotlin-Datenstruktur und Implementation des zugehörigen Endpoints
#30 Implementation Endpoint Hochladen einer DOCX-Datei
#31 Implementation Endpoint Hochladen einer DOCX-FAQ-Datei mit Änderungen
#34 Definition einer MongoDB-Struktur
#36 Methoden zum Lesen, Schreiben und Ändern der MongoDB
#38 Extraction von Fragen und Antworten einer HTML-FAQ-Datei auf Basis einer Konfiguration
#37 Extraction von Fragen und Antworten einer DOCX-FAQ-Datei auf Basis einer Konfiguration
#39 Daten in die MongoDB schreiben und Zusammenfassung einbinden
#28 Überarbeitung ID-Generierung
#40 Einlesen und Parsen einer HTML-Seite mit JSOUP, Zerlegen in semantische Blöcke
#43 Question Generator
#55 Fragemöglichkeit mit Chatette generieren
#56 Fragemöglichkeit mit Bibliothek Question Generator generieren
**3. Sprint: 9.6. - 7.7**
**3. Sprint: 9.6. - 7.7**
src/ktor-server/src/main/kotlin/de/h_da/fbi/smebt/intentfinder/client/Application.kt
deleted
100644 → 0
View file @
04a13da9
package
de.h_da.fbi.smebt.intentfinder.client
import
de.h_da.fbi.smebt.intentfinder.server.sources.DocxReader
import
io.ktor.client.*
import
io.ktor.client.engine.cio.*
import
io.ktor.client.request.forms.*
import
io.ktor.client.statement.*
import
io.ktor.http.*
import
java.io.File
suspend
fun
main
()
{
val
client
=
HttpClient
(
CIO
)
val
response
:
HttpResponse
=
client
.
submitFormWithBinaryData
(
url
=
"http://localhost:8080/file"
,
formData
=
formData
{
append
(
"description"
,
"docx Document"
)
append
(
"Dok"
,
File
(
"uploads/Dok.docx"
).
readBytes
(),
Headers
.
build
{
append
(
HttpHeaders
.
ContentType
,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)
append
(
HttpHeaders
.
ContentDisposition
,
"filename=Dok.docx"
)
})
}
)
println
(
response
.
readText
())
println
(
response
.
status
)
val
fileName
=
"Dok1.docx"
val
PutClient
=
HttpClient
(
CIO
)
val
putResponse
:
HttpResponse
=
PutClient
.
submitFormWithBinaryData
(
url
=
"http://localhost:8080/file?filename=Dok1.docx/"
,
// url = "http://localhost:8080/file/{fileName}/",
// url = "http://localhost:8080/file/{$fileName}/",
// url = "http://localhost:8080/file/$fileName/",
//url = "http://localhost:8080/file/Dok1.docx/",
formData
=
formData
{
append
(
"description"
,
"docx Document"
)
append
(
"fileName"
,
File
(
"uploads/Dok1.docx"
).
readBytes
(),
Headers
.
build
{
append
(
HttpHeaders
.
ContentType
,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)
append
(
HttpHeaders
.
ContentDisposition
,
"filename=Dok1.docx"
)
})
}
)
println
(
putResponse
.
readText
())
println
(
putResponse
.
status
)
try
{
val
reader
=
DocxReader
(
"uploads/Dok.docx"
)
val
fileContent
=
reader
.
readFile
()
println
(
fileContent
)
val
reader1
=
DocxReader
(
"uploads/Dok1.docx"
)
val
fileContent1
=
reader1
.
readFile
()
println
(
fileContent1
)
}
catch
(
exception
:
Exception
)
{
print
(
exception
.
message
)
}
}
\ No newline at end of file
src/ktor-server/src/main/kotlin/de/h_da/fbi/smebt/intentfinder/server/Application.kt
View file @
2ae87e62
...
@@ -14,6 +14,13 @@ import io.ktor.serialization.*
...
@@ -14,6 +14,13 @@ import io.ktor.serialization.*
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.Json
import
registerUploadRoutes
import
registerUploadRoutes
import
java.io.File
import
java.io.File
import
java.nio.file.Files
import
java.nio.file.Paths
import
kotlinx.serialization.Serializable
@Serializable
data class
FileStatus
(
val
path
:
String
,
val
status
:
String
)
fun
main
(
args
:
Array
<
String
>):
Unit
=
io
.
ktor
.
server
.
netty
.
EngineMain
.
main
(
args
)
fun
main
(
args
:
Array
<
String
>):
Unit
=
io
.
ktor
.
server
.
netty
.
EngineMain
.
main
(
args
)
...
@@ -36,10 +43,14 @@ fun Application.module(testing: Boolean = false) {
...
@@ -36,10 +43,14 @@ fun Application.module(testing: Boolean = false) {
var
fileDescription
=
""
var
fileDescription
=
""
var
fileName
=
""
var
fileName
=
""
post
(
"/file"
)
{
post
(
"/file
/{chatbotId}
"
)
{
var
status
=
"error"
val
multipartData
=
call
.
receiveMultipart
()
val
multipartData
=
call
.
receiveMultipart
()
val
pathFile
=
call
.
parameters
[
"chatbotId"
].
toString
()
val
pathAsFile
=
File
(
"uploads/$pathFile"
)
if
(!
Files
.
exists
(
Paths
.
get
(
pathFile
)))
{
pathAsFile
.
mkdir
()
}
multipartData
.
forEachPart
{
part
->
multipartData
.
forEachPart
{
part
->
when
(
part
)
{
when
(
part
)
{
is
PartData
.
FormItem
->
{
is
PartData
.
FormItem
->
{
...
@@ -48,51 +59,77 @@ fun Application.module(testing: Boolean = false) {
...
@@ -48,51 +59,77 @@ fun Application.module(testing: Boolean = false) {
is
PartData
.
FileItem
->
{
is
PartData
.
FileItem
->
{
fileName
=
part
.
originalFileName
as
String
fileName
=
part
.
originalFileName
as
String
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
val
file
=
File
(
"uploads/$fileName"
)
val
file
=
File
(
"uploads/$
pathFile/$
fileName"
)
if
(!
file
.
exists
())
{
if
(!
file
.
exists
())
{
call
.
respond
(
HttpStatusCode
.
NotFound
)
file
.
createNewFile
()
file
.
writeBytes
(
fileBytes
)
//call.respond("file not found but created")
status
=
"created"
}
else
{
}
else
{
File
(
"uploads/$fileName"
)
.
writeBytes
(
fileBytes
)
file
.
writeBytes
(
fileBytes
)
status
=
"updated"
}
}
}
}
}
}
}
}
call
.
respond
Text
(
"$fileDescription is uploaded to 'uploads/$fileName'"
)
call
.
respond
(
FileStatus
(
path
=
"'uploads/$pathFile/$fileName'"
,
status
=
"$status"
)
)
}
}
put
(
"/file/{filename}/{id}"
)
{
put
(
"/file/{chatbotId}/{id}/{filename}"
)
{
val
name
=
call
.
parameters
[
"filename"
].
toString
()
val
name
=
call
.
parameters
[
"filename"
].
toString
()
val
file
=
File
(
"uploads/$name "
)
val
pathFile
=
call
.
parameters
[
"chatbotId"
].
toString
()
var
status
=
"error"
val
pathAsFile
=
File
(
"uploads/$pathFile"
)
if
(!
Files
.
exists
(
Paths
.
get
(
pathFile
)))
{
pathAsFile
.
mkdir
()
}
val
file
=
File
(
"uploads/$pathFile/$name "
)
val
multipartData
=
call
.
receiveMultipart
()
val
multipartData
=
call
.
receiveMultipart
()
if
(!
file
.
exists
())
{
var
fileContent
=
""
call
.
respond
(
HttpStatusCode
.
NotFound
)
multipartData
.
forEachPart
{
part
->
}
else
{
when
(
part
)
{
multipartData
.
forEachPart
{
part
->
is
PartData
.
FormItem
->
{
when
(
part
)
{
if
(
part
.
name
.
toString
().
equals
(
"description"
))
is
PartData
.
FormItem
->
{
{
fileDescription
=
part
.
value
fileDescription
=
part
.
value
}
if
(
part
.
name
.
toString
().
equals
(
"id"
))
{
var
fileId
=
part
.
value
if
(
!
fileId
.
equals
(
call
.
parameters
[
"id"
].
toString
()))
call
.
respond
(
"file not found"
)
}
}
is
PartData
.
FileItem
->
{
}
val
reader
=
DocxReader
(
"uploads/Dok.docx"
)
is
PartData
.
FileItem
->
{
if
(!
reader
.
readFile
().
equals
(
part
.
streamProvider
().
toString
()))
{
if
(
file
.
exists
())
{
fileName
=
part
.
originalFileName
as
String
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
File
(
"uploads/$fileName"
).
writeBytes
(
fileBytes
)
if
(
file
.
readText
().
equals
(
part
.
streamProvider
().
toString
()))
{
call
.
respondText
(
"file exist but no change detected"
)
}
else
{
}
else
{
println
(
"no change detected"
)
fileName
=
part
.
originalFileName
as
String
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
File
(
"uploads/$pathFile/$fileName"
).
writeBytes
(
fileBytes
)
fileContent
=
part
.
streamProvider
().
reader
().
readText
()
status
=
"updated"
}
}
}
else
{
file
.
createNewFile
()
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
file
.
writeBytes
(
fileBytes
)
status
=
"created"
}
}
}
}
}
}
}
}
val
reader
=
DocxReader
(
"uploads/Dok.docx"
)
val
fileContent
=
reader
.
readFile
()
call
.
respondText
(
"$fileDescription is uploaded to 'uploads/$fileName and contains: \n $fileContent' "
)
call
.
respond
(
FileStatus
(
path
=
"'uploads/$pathFile/$fileName'"
,
status
=
"$status"
))
}
}
}
}
registerUploadRoutes
()
registerUploadRoutes
()
}
}
\ No newline at end of file
src/ktor-server/src/main/kotlin/de/h_da/fbi/smebt/intentfinder/server/sources/DocxReader.kt
View file @
2ae87e62
...
@@ -135,10 +135,10 @@ class DocxReader(private val fileName: String) {
...
@@ -135,10 +135,10 @@ class DocxReader(private val fileName: String) {
if
(
run
.
text
().
trim
().
isNotEmpty
())
{
if
(
run
.
text
().
trim
().
isNotEmpty
())
{
if
(
result
.
containsKey
(
i
)){
if
(
result
.
containsKey
(
i
)){
if
(!
result
.
get
(
i
)
!!
.
coloredText
.
contains
(
run
.
text
().
trim
()))
{
if
(!
result
.
get
(
i
)
!!
.
coloredText
.
contains
(
run
.
text
().
trim
()))
{
val
tmp
=
result
.
get
(
i
)
val
tmp
=
result
.
get
(
i
)
tmp
!!
.
coloredText
+=
run
.
text
()
tmp
!!
.
coloredText
+=
run
.
text
()
result
.
replace
(
i
,
tmp
!!
)
result
.
replace
(
i
,
tmp
!!
)
}
}
}
}
else
{
else
{
result
.
put
(
i
,
ColoredPart
(
run
.
text
().
trim
(),
paragraphs
!!
[
i
].
text
))
result
.
put
(
i
,
ColoredPart
(
run
.
text
().
trim
(),
paragraphs
!!
[
i
].
text
))
...
...
src/ktor-server/src/test/Upload.http
View file @
2ae87e62
...
@@ -7,15 +7,20 @@ Content-Type: text/plain
...
@@ -7,15 +7,20 @@ Content-Type: text/plain
docx Document
docx Document
--FileBoundary
--FileBoundary
Content-Disposition: form-data; name="id"
Content-Type: text/plain
1
--FileBoundary
Content-Disposition: form-data; name="Dok"; filename="Dok.docx"
Content-Disposition: form-data; name="Dok"; filename="Dok.docx"
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
< ./Dok.docx
--FileBoundary--
--FileBoundary--
###
###
PUT
POST
http://0.0.0.0:8080/file/Dok1.docx
/
PUT http://0.0.0.0:8080/file/Dok1.docx
Content-Type: multipart/form-data;boundary=FileBoundary
Content-Type: multipart/form-data;boundary=FileBoundary
--FileBoundary
--FileBoundary
...
@@ -24,8 +29,16 @@ Content-Type: text/plain
...
@@ -24,8 +29,16 @@ Content-Type: text/plain
docx Document
docx Document
--FileBoundary
--FileBoundary
Content-Disposition: form-data; name="id"
Content-Type: text/plain
1
--FileBoundary
Content-Disposition: form-data; name="Dok"; filename="Dok1.docx"
Content-Disposition: form-data; name="Dok"; filename="Dok1.docx"
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
< ./Dok1.docx
--FileBoundary--
--FileBoundary--
\ No newline at end of file
###
\ No newline at end of file
src/ktor-server/src/test/kotlin/de/h_da/fbi/smebt/intentfinder/server/sources/DocxReaderTest.kt
View file @
2ae87e62
...
@@ -62,4 +62,4 @@ internal class DocxReaderTest {
...
@@ -62,4 +62,4 @@ internal class DocxReaderTest {
// }
// }
}
}
\ No newline at end of file
src/ktor-server/src/test/kotlin/de/h_da/fbi/smebt/intentfinder/server/sources/UploadTest.kt
View file @
2ae87e62
...
@@ -16,4 +16,12 @@ class UploadTest {
...
@@ -16,4 +16,12 @@ class UploadTest {
}
}
}
}
}
}
@Test
fun
testUploadFileChange
()
{
withTestApplication
({
module
(
testing
=
true
)
})
{
handleRequest
(
HttpMethod
.
Put
,
"/file/Dok1.docx"
).
apply
{
assertEquals
(
HttpStatusCode
.
OK
,
response
.
status
())
}
}
}
}
}
\ No newline at end of file
src/ktor-server/uploads/1/Dok.docx
0 → 100644
View file @
2ae87e62
File added
src/ktor-server/uploads/Dok.docx
View file @
2ae87e62
No preview for this file type
src/ktor-server/uploads/Dok1.docx
View file @
2ae87e62
No preview for this file type
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment