Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alfa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
alfa
Commits
10e4077a
Commit
10e4077a
authored
11 months ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-5841 OZG-5952 Refactor the validator
parent
286eab25
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
alfa-xdomea/src/main/java/de/ozgcloud/alfa/export/BehoerdenschluesselPropertiesValidator.java
+24
-12
24 additions, 12 deletions
...d/alfa/export/BehoerdenschluesselPropertiesValidator.java
with
24 additions
and
12 deletions
alfa-xdomea/src/main/java/de/ozgcloud/alfa/export/BehoerdenschluesselPropertiesValidator.java
+
24
−
12
View file @
10e4077a
package
de.ozgcloud.alfa.export
;
import
java.util.Optional
;
import
java.util.function.Supplier
;
import
org.springframework.validation.Errors
;
import
org.springframework.validation.Validator
;
...
...
@@ -12,24 +15,33 @@ public class BehoerdenschluesselPropertiesValidator implements Validator {
@Override
public
void
validate
(
Object
target
,
Errors
errors
)
{
var
props
=
getBehoerdenschluesselProperties
((
XdomeaProperties
)
target
);
if
(
props
.
getBehoerdenschluessel
().
is
Empty
())
{
return
;
var
prop
ertie
s
=
getBehoerdenschluesselProperties
((
XdomeaProperties
)
target
);
if
(
prop
ertie
s
.
getBehoerdenschluessel
().
is
Present
())
{
validateProperties
(
properties
,
errors
)
;
}
try
{
if
(
props
.
getBehoerdenschluesselUri
().
isEmpty
())
{
errors
.
rejectValue
(
"behoerdenschluesselUri"
,
"ozgcloud.xdomea.behoerdenschluessel-uri.empty"
,
"behoerdenschluessel-uri must be set"
);
}
if
(
props
.
getBehoerdenschluesselVersion
().
isEmpty
())
{
errors
.
rejectValue
(
"behoerdenschluesselVersion"
,
"ozgcloud.xdomea.behoerdenschluessel-version.empty"
,
"b
ehoerdenschluessel
-version must be set"
);
BehoerdenschluesselProperties
getBehoerdenschluesselProperties
(
XdomeaProperties
xdomeaProperties
)
{
return
new
B
ehoerdenschluessel
Properties
(
xdomeaProperties
);
}
private
void
validateProperties
(
BehoerdenschluesselProperties
props
,
Errors
errors
)
{
try
{
validateNotEmpty
(
props
,
errors
);
}
catch
(
AmbiguousCodelistePatternException
e
)
{
errors
.
reject
(
"ozgcloud.xdomea.codeliste.pattern.ambiguous"
,
e
.
getMessage
());
}
}
BehoerdenschluesselProperties
getBehoerdenschluesselProperties
(
XdomeaProperties
xdomeaProperties
)
{
return
new
BehoerdenschluesselProperties
(
xdomeaProperties
);
private
void
validateNotEmpty
(
BehoerdenschluesselProperties
props
,
Errors
errors
)
{
validateNotEmpty
(
props:
:
getBehoerdenschluesselUri
,
"behoerdenschluesselUri"
,
"behoerdenschluessel-uri"
,
errors
);
validateNotEmpty
(
props:
:
getBehoerdenschluesselVersion
,
"behoerdenschluesselVersion"
,
"behoerdenschluessel-version"
,
errors
);
}
private
<
T
>
void
validateNotEmpty
(
Supplier
<
Optional
<
T
>>
propertyAccessor
,
String
fieldName
,
String
propertyName
,
Errors
errors
)
{
var
propertyValue
=
propertyAccessor
.
get
();
if
(
propertyValue
.
isEmpty
())
{
errors
.
rejectValue
(
fieldName
,
String
.
format
(
"ozgcloud.xdomea.%s.empty"
,
propertyName
),
String
.
format
(
"%s must be set"
,
propertyName
));
}
}
}
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