Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FIT-Connect Tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FIT-Connect
FIT-Connect Tools
Commits
1f05201e
Commit
1f05201e
authored
1 year ago
by
Martin Vogel
Browse files
Options
Downloads
Patches
Plain Diff
refactor: serialize metadata to json and add file-ending to attachments (
planning#1796
)
parent
5deaca57
No related branches found
No related tags found
1 merge request
!77
#1796 CLI Erweiterungen
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/cli/src/main/java/dev/fitko/fitconnect/cli/CommandExecutor.java
+23
-2
23 additions, 2 deletions
...c/main/java/dev/fitko/fitconnect/cli/CommandExecutor.java
with
23 additions
and
2 deletions
java/cli/src/main/java/dev/fitko/fitconnect/cli/CommandExecutor.java
+
23
−
2
View file @
1f05201e
package
dev.fitko.fitconnect.cli
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
dev.fitko.fitconnect.api.domain.crypto.JWKPair
;
import
dev.fitko.fitconnect.api.domain.model.attachment.Attachment
;
import
dev.fitko.fitconnect.api.domain.model.metadata.Metadata
;
import
dev.fitko.fitconnect.api.domain.model.submission.SentSubmission
;
import
dev.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup
;
import
dev.fitko.fitconnect.api.domain.sender.SendableSubmission
;
...
...
@@ -23,6 +26,7 @@ import dev.fitko.fitconnect.client.SenderClient;
import
dev.fitko.fitconnect.client.SubscriberClient
;
import
dev.fitko.fitconnect.core.utils.StopWatch
;
import
org.apache.tika.Tika
;
import
org.apache.tika.mime.MimeType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -50,12 +54,16 @@ class CommandExecutor {
private
final
TestKeyBuilder
testKeyBuilder
;
private
final
Supplier
<
SenderClient
>
senderSupplier
;
private
final
Supplier
<
SubscriberClient
>
subscriberSupplier
;
private
final
Tika
mimeTypeDetector
;
private
final
ObjectWriter
jsonWriter
;
CommandExecutor
(
final
Supplier
<
SenderClient
>
senderSupplier
,
final
Supplier
<
SubscriberClient
>
subscriberSupplier
,
final
BatchImporter
batchImporter
,
final
TestKeyBuilder
testKeyBuilder
)
{
this
.
batchImporter
=
batchImporter
;
this
.
testKeyBuilder
=
testKeyBuilder
;
this
.
senderSupplier
=
senderSupplier
;
this
.
subscriberSupplier
=
subscriberSupplier
;
this
.
mimeTypeDetector
=
new
Tika
();
this
.
jsonWriter
=
new
ObjectMapper
().
writerWithDefaultPrettyPrinter
();
}
void
getOneSubmission
(
final
GetOneSubmissionCommand
getOneSubmissionCommand
)
throws
IOException
{
...
...
@@ -93,7 +101,6 @@ class CommandExecutor {
SentSubmission
sendSubmission
(
final
SendSubmissionCommand
sendSubmissionCommand
)
throws
IOException
{
LOGGER
.
info
(
"Sending new submission to destination {}"
,
sendSubmissionCommand
.
destinationId
);
final
Tika
mimeTypeDetector
=
new
Tika
();
final
var
startTime
=
StopWatch
.
start
();
final
List
<
Attachment
>
attachments
=
sendSubmissionCommand
.
attachments
.
stream
().
map
(
toAttachment
(
mimeTypeDetector
)).
collect
(
Collectors
.
toList
());
final
SentSubmission
submission
;
...
...
@@ -189,15 +196,29 @@ class CommandExecutor {
LOGGER
.
info
(
"Writing data.{}"
,
fileEnding
);
Files
.
write
(
filePath
,
receivedSubmission
.
getDataAsString
().
getBytes
(
StandardCharsets
.
UTF_8
));
LOGGER
.
info
(
"Writing metadata"
);
final
Metadata
metadata
=
receivedSubmission
.
getMetadata
();
Files
.
write
(
Path
.
of
(
dataDirPath
,
"metadata.json"
),
jsonWriter
.
writeValueAsString
(
metadata
).
getBytes
());
final
List
<
Attachment
>
attachments
=
receivedSubmission
.
getAttachments
();
for
(
int
i
=
0
;
i
<
attachments
.
size
();
i
++)
{
final
Attachment
attachment
=
attachments
.
get
(
i
);
final
String
filename
=
attachment
.
getFileName
()
!=
null
?
a
ttachment
.
get
File
N
ame
(
)
:
"
attachment
_"
+
i
;
final
String
filename
=
getA
ttachmentFile
n
ame
(
attachment
,
i
)
;
LOGGER
.
info
(
"Writing attachment {}"
,
filename
);
Files
.
write
(
Path
.
of
(
dataDirPath
,
filename
),
attachment
.
getDataAsBytes
());
}
}
private
String
getAttachmentFilename
(
Attachment
attachment
,
int
i
)
{
if
(
attachment
.
getFileName
()
==
null
)
{
if
(
MimeType
.
isValid
(
attachment
.
getMimeType
()))
{
return
"attachment_"
+
i
+
"."
+
attachment
.
getMimeType
().
split
(
"/"
)[
1
];
}
return
attachment
+
"_"
+
i
;
}
return
attachment
.
getFileName
();
}
private
SendSubmissionCommand
mapToSubmissionToSend
(
final
ImportRecord
importRecord
)
{
final
var
submission
=
new
SendSubmissionCommand
();
submission
.
setDestinationId
(
importRecord
.
getDestinationId
());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment