Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
formcycle-plugin
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
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
OZG-Cloud
app
formcycle-plugin
Commits
fce46dba
Commit
fce46dba
authored
10 months ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-5835 don't add warning if no attachments uploaded
parent
be773a08
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/de/ozgcloud/formcycle/OzgPluginExecutor.java
+23
-12
23 additions, 12 deletions
src/main/java/de/ozgcloud/formcycle/OzgPluginExecutor.java
src/test/java/de/ozgcloud/formcycle/OzgPluginExecutorTest.java
+67
-71
67 additions, 71 deletions
...est/java/de/ozgcloud/formcycle/OzgPluginExecutorTest.java
with
90 additions
and
83 deletions
src/main/java/de/ozgcloud/formcycle/OzgPluginExecutor.java
+
23
−
12
View file @
fce46dba
...
@@ -58,23 +58,19 @@ public final class OzgPluginExecutor {
...
@@ -58,23 +58,19 @@ public final class OzgPluginExecutor {
public
ExecutionResult
execute
()
{
public
ExecutionResult
execute
()
{
LOG
.
debug
(
"Executing plugin WorkflowElementNodePlugin"
);
LOG
.
debug
(
"Executing plugin WorkflowElementNodePlugin"
);
var
formData
=
pluginFormDataAdapter
.
readFormData
();
var
formData
=
addAttachedFiles
(
pluginFormDataAdapter
.
readFormData
());
return
buildExecutionResult
(
sendFormData
(
addAttachedFiles
(
formData
)),
formData
);
return
buildExecutionResult
(
sendFormData
(
formData
),
formData
);
}
FormCycleConfirmationResponse
sendFormData
(
FormData
formData
)
{
return
ozgHttpClient
.
send
(
ozgCloudFormDataMapper
.
map
(
formData
),
formData
.
getAttachments
(),
formData
.
getRepresentations
());
}
}
FormData
addAttachedFiles
(
FormData
formData
)
{
FormData
addAttachedFiles
(
FormData
formData
)
{
var
formDataBuilder
=
formData
.
toBuilder
();
var
formDataBuilder
=
formData
.
toBuilder
();
var
attachedFiles
=
getAttachedFiles
(
formData
.
getAttachmentUuids
());
var
attachedFiles
=
getAttachedFiles
(
formData
.
getAttachmentUuids
());
Optional
.
ofNullable
(
attachedFiles
.
get
(
AttachmentType
.
REPRESENTATION
)).
ifPresentOrElse
(
formDataBuilder:
:
representations
,
Optional
.
ofNullable
(
attachedFiles
.
get
(
AttachmentType
.
REPRESENTATION
)).
ifPresentOrElse
(
formDataBuilder:
:
representations
,
()
->
formDataBuilder
.
warning
(
build
Warning
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
,
()
->
formDataBuilder
.
warning
(
build
MissingRepresentationsWarning
(
formData
.
getRequestId
())));
"Representation is missing. Ensure workflow is configured to attach form view to form data."
)));
if
(!
formData
.
getAttachmentUuids
().
isEmpty
())
{
Optional
.
ofNullable
(
attachedFiles
.
get
(
AttachmentType
.
ATTACHMENT
)).
ifPresentOrElse
(
formDataBuilder:
:
attachments
,
Optional
.
ofNullable
(
attachedFiles
.
get
(
AttachmentType
.
ATTACHMENT
)).
ifPresentOrElse
(
formDataBuilder:
:
attachments
,
()
->
formDataBuilder
.
warning
(
()
->
formDataBuilder
.
warning
(
buildMissingAttachmentsWarning
(
formData
.
getRequestId
())));
buildWarning
(
OzgPluginSoftError
.
MISSING_ATTACHMENTS
,
"Attachments were found in form data, but files are missing."
)));
}
return
formDataBuilder
.
build
();
return
formDataBuilder
.
build
();
}
}
...
@@ -90,10 +86,25 @@ public final class OzgPluginExecutor {
...
@@ -90,10 +86,25 @@ public final class OzgPluginExecutor {
return
resultMap
;
return
resultMap
;
}
}
Warning
buildWarning
(
OzgPluginSoftError
warningCode
,
String
message
)
{
Warning
buildMissingRepresentationsWarning
(
String
requestId
)
{
return
buildWarning
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
,
String
.
format
(
"Representation is missing. Ensure workflow is configured to attach form view to form data. (Request ID: %s)"
,
requestId
));
}
Warning
buildMissingAttachmentsWarning
(
String
requestId
)
{
return
buildWarning
(
OzgPluginSoftError
.
MISSING_ATTACHMENTS
,
String
.
format
(
"Attachments uploaded in the form were not included in the form data. (RequestId: %s)"
,
requestId
));
}
private
Warning
buildWarning
(
OzgPluginSoftError
warningCode
,
String
message
)
{
return
Warning
.
builder
().
errorCode
(
warningCode
).
message
(
message
).
build
();
return
Warning
.
builder
().
errorCode
(
warningCode
).
message
(
message
).
build
();
}
}
FormCycleConfirmationResponse
sendFormData
(
FormData
formData
)
{
return
ozgHttpClient
.
send
(
ozgCloudFormDataMapper
.
map
(
formData
),
formData
.
getAttachments
(),
formData
.
getRepresentations
());
}
ExecutionResult
buildExecutionResult
(
FormCycleConfirmationResponse
response
,
FormData
formData
)
{
ExecutionResult
buildExecutionResult
(
FormCycleConfirmationResponse
response
,
FormData
formData
)
{
LOG
.
debug
(
"Formcycle adapter response: {}"
,
response
);
LOG
.
debug
(
"Formcycle adapter response: {}"
,
response
);
return
ExecutionResult
.
builder
().
vorgangnummer
(
response
.
getVorgangNummer
()).
warnings
(
formData
.
getWarnings
()).
build
();
return
ExecutionResult
.
builder
().
vorgangnummer
(
response
.
getVorgangNummer
()).
warnings
(
formData
.
getWarnings
()).
build
();
...
...
This diff is collapsed.
Click to expand it.
src/test/java/de/ozgcloud/formcycle/OzgPluginExecutorTest.java
+
67
−
71
View file @
fce46dba
...
@@ -134,66 +134,6 @@ class OzgPluginExecutorTest {
...
@@ -134,66 +134,6 @@ class OzgPluginExecutorTest {
}
}
}
}
@Nested
@DisplayName
(
"Send data"
)
class
TestSendData
{
@Mock
private
FormCycleFormData
formcycleFormData
;
@Mock
private
FormCycleConfirmationResponse
response
;
@Captor
private
ArgumentCaptor
<
List
<
FormcycleAttachment
>>
attachmentsCapture
;
@Captor
private
ArgumentCaptor
<
List
<
FormcycleAttachment
>>
representationsCapture
;
@Test
void
shouldCallMapper
()
{
sendFormData
();
verify
(
ozgCloudFormDataMapper
).
map
(
FORM_DATA
);
}
@Test
void
shouldSendFormData
()
{
when
(
ozgCloudFormDataMapper
.
map
(
any
())).
thenReturn
(
formcycleFormData
);
sendFormData
();
verify
(
ozgHttpClient
).
send
(
eq
(
formcycleFormData
),
any
(),
any
());
}
@Test
void
shouldSendAttachments
()
{
sendFormData
();
verify
(
ozgHttpClient
).
send
(
any
(),
attachmentsCapture
.
capture
(),
any
());
assertThat
(
attachmentsCapture
.
getValue
()).
hasSize
(
1
).
first
().
extracting
(
"uuid"
).
isEqualTo
(
FormDataTestFactory
.
ATTACHMENT_UUID
);
}
@Test
void
shouldSendRepresentations
()
{
sendFormData
();
verify
(
ozgHttpClient
).
send
(
any
(),
any
(),
representationsCapture
.
capture
());
assertThat
(
representationsCapture
.
getValue
()).
hasSize
(
1
).
first
().
extracting
(
"uuid"
).
isEqualTo
(
FormDataTestFactory
.
REPRESENTATION_UUID
);
}
@Test
void
shouldReturnResponse
()
{
when
(
ozgHttpClient
.
send
(
any
(),
any
(),
any
())).
thenReturn
(
response
);
var
result
=
sendFormData
();
assertThat
(
result
).
isSameAs
(
response
);
}
private
FormCycleConfirmationResponse
sendFormData
()
{
return
executor
.
sendFormData
(
FORM_DATA
);
}
}
@Nested
@Nested
class
TestAddAttachedFiles
{
class
TestAddAttachedFiles
{
...
@@ -239,6 +179,18 @@ class OzgPluginExecutorTest {
...
@@ -239,6 +179,18 @@ class OzgPluginExecutorTest {
assertThat
(
result
.
getWarnings
()).
isEmpty
();
assertThat
(
result
.
getWarnings
()).
isEmpty
();
}
}
@Test
void
shouldNotAddMissingAttachmentWarning
()
{
var
attachedFiles
=
Map
.
of
(
AttachmentType
.
REPRESENTATION
,
List
.
of
(
FormcycleAttachmentTestFactory
.
createBuilder
().
uuid
(
FormDataTestFactory
.
REPRESENTATION_UUID
).
build
()));
doReturn
(
attachedFiles
).
when
(
executor
).
getAttachedFiles
(
any
());
var
result
=
executor
.
addAttachedFiles
(
formData
.
toBuilder
().
clearAttachmentUuids
().
build
());
assertThat
(
result
.
getWarnings
()).
isEmpty
();
}
private
void
mockGetAttachedFiles
()
{
private
void
mockGetAttachedFiles
()
{
var
attachedFiles
=
Map
.
of
(
var
attachedFiles
=
Map
.
of
(
AttachmentType
.
ATTACHMENT
,
AttachmentType
.
ATTACHMENT
,
...
@@ -251,18 +203,26 @@ class OzgPluginExecutorTest {
...
@@ -251,18 +203,26 @@ class OzgPluginExecutorTest {
@Nested
@Nested
class
TestAddWarnings
{
class
TestAddWarnings
{
@BeforeEach
@Mock
void
setup
()
{
private
Warning
warning
;
@Test
void
shouldCallBuildMissingRepresentationsWarning
()
{
doReturn
(
Map
.
of
(
AttachmentType
.
ATTACHMENT
,
List
.
of
(
FormcycleAttachmentTestFactory
.
create
()))).
when
(
executor
).
getAttachedFiles
(
any
());
executor
.
addAttachedFiles
(
formData
);
verify
(
executor
).
buildMissingRepresentationsWarning
(
formData
.
getRequestId
());
}
}
@Test
@Test
void
shouldAddWhenMissingRepresentations
()
{
void
shouldAddWhenMissingRepresentations
()
{
doReturn
(
Map
.
of
(
AttachmentType
.
ATTACHMENT
,
List
.
of
(
FormcycleAttachmentTestFactory
.
create
()))).
when
(
executor
).
getAttachedFiles
(
any
());
doReturn
(
Map
.
of
(
AttachmentType
.
ATTACHMENT
,
List
.
of
(
FormcycleAttachmentTestFactory
.
create
()))).
when
(
executor
).
getAttachedFiles
(
any
());
doReturn
(
warning
).
when
(
executor
).
buildMissingRepresentationsWarning
(
any
());
var
result
=
executor
.
addAttachedFiles
(
formData
);
var
result
=
executor
.
addAttachedFiles
(
formData
);
assertThat
(
result
.
getWarnings
()).
hasSize
(
1
).
first
().
extracting
(
Warning:
:
getErrorCode
)
assertThat
(
result
.
getWarnings
()).
hasSize
(
1
).
first
().
isSameAs
(
warning
);
.
isEqualTo
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
.
name
());
}
}
@Test
@Test
...
@@ -274,15 +234,25 @@ class OzgPluginExecutorTest {
...
@@ -274,15 +234,25 @@ class OzgPluginExecutorTest {
assertThat
(
result
.
getRepresentations
()).
isEmpty
();
assertThat
(
result
.
getRepresentations
()).
isEmpty
();
}
}
@Test
void
shouldCallBuildMissingAttachmentsWarning
()
{
doReturn
(
Map
.
of
(
AttachmentType
.
REPRESENTATION
,
List
.
of
(
FormcycleAttachmentTestFactory
.
create
()))).
when
(
executor
)
.
getAttachedFiles
(
any
());
executor
.
addAttachedFiles
(
formData
);
verify
(
executor
).
buildMissingAttachmentsWarning
(
formData
.
getRequestId
());
}
@Test
@Test
void
shouldAddWhenMissingAttachments
()
{
void
shouldAddWhenMissingAttachments
()
{
doReturn
(
Map
.
of
(
AttachmentType
.
REPRESENTATION
,
List
.
of
(
FormcycleAttachmentTestFactory
.
create
()))).
when
(
executor
)
doReturn
(
Map
.
of
(
AttachmentType
.
REPRESENTATION
,
List
.
of
(
FormcycleAttachmentTestFactory
.
create
()))).
when
(
executor
)
.
getAttachedFiles
(
any
());
.
getAttachedFiles
(
any
());
doReturn
(
warning
).
when
(
executor
).
buildMissingAttachmentsWarning
(
any
());
var
result
=
executor
.
addAttachedFiles
(
formData
);
var
result
=
executor
.
addAttachedFiles
(
formData
);
assertThat
(
result
.
getWarnings
()).
hasSize
(
1
).
first
().
extracting
(
Warning:
:
getErrorCode
)
assertThat
(
result
.
getWarnings
()).
hasSize
(
1
).
first
().
isSameAs
(
warning
);
.
isEqualTo
(
OzgPluginSoftError
.
MISSING_ATTACHMENTS
.
name
());
}
}
@Test
@Test
...
@@ -362,22 +332,48 @@ class OzgPluginExecutorTest {
...
@@ -362,22 +332,48 @@ class OzgPluginExecutorTest {
}
}
@Nested
@Nested
class
TestBuildWarning
{
class
TestBuild
MissingRepresentations
Warning
{
private
final
String
MESSAGE
=
"message
"
;
private
final
String
REQUEST_ID
=
"REQUEST_ID
"
;
@Test
@Test
void
shouldSetErrorCode
()
{
void
shouldSetErrorCode
()
{
var
warning
=
executor
.
build
Warning
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
,
MESSAGE
);
var
warning
=
executor
.
build
MissingRepresentationsWarning
(
REQUEST_ID
);
assertThat
(
warning
.
getErrorCode
()).
isEqualTo
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
.
toString
());
assertThat
(
warning
.
getErrorCode
()).
isEqualTo
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
.
name
());
}
}
@Test
@Test
void
shouldSetMessage
()
{
void
shouldSetMessage
()
{
var
warning
=
executor
.
buildWarning
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
,
MESSAGE
);
var
warning
=
executor
.
buildWarning
(
OzgPluginSoftError
.
MISSING_REPRESENTATION
,
MESSAGE
);
assertThat
(
warning
.
getMessage
()).
isEqualTo
(
MESSAGE
);
@Test
void
shouldSendAttachments
()
{
sendFormData
();
verify
(
ozgHttpClient
).
send
(
any
(),
attachmentsCapture
.
capture
(),
any
());
assertThat
(
attachmentsCapture
.
getValue
()).
hasSize
(
1
).
first
().
extracting
(
"uuid"
).
isEqualTo
(
FormDataTestFactory
.
ATTACHMENT_UUID
);
}
@Test
void
shouldSendRepresentations
()
{
sendFormData
();
verify
(
ozgHttpClient
).
send
(
any
(),
any
(),
representationsCapture
.
capture
());
assertThat
(
representationsCapture
.
getValue
()).
hasSize
(
1
).
first
().
extracting
(
"uuid"
).
isEqualTo
(
FormDataTestFactory
.
REPRESENTATION_UUID
);
}
@Test
void
shouldReturnResponse
()
{
when
(
ozgHttpClient
.
send
(
any
(),
any
(),
any
())).
thenReturn
(
response
);
var
result
=
sendFormData
();
assertThat
(
result
).
isSameAs
(
response
);
}
private
FormCycleConfirmationResponse
sendFormData
()
{
return
executor
.
sendFormData
(
FORM_DATA
);
}
}
}
}
...
...
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