Skip to content

Commit 44a5731

Browse files
author
yevhenii-nadtochii
committed
Implement DistinctFieldView
1 parent a22309c commit 44a5731

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2025, TeamDev. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Redistribution and use in source and/or binary forms, with or without
11+
* modification, must retain the above copyright notice and the following
12+
* disclaimer.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
package io.spine.validation
28+
29+
import io.spine.core.Subscribe
30+
import io.spine.protodata.ast.FieldRef
31+
import io.spine.protodata.plugin.View
32+
import io.spine.server.entity.alter
33+
import io.spine.validation.event.DistinctFieldDiscovered
34+
35+
/**
36+
* A view of a field that is marked with `(distinct) = true` option.
37+
*/
38+
internal class DistinctFieldView : View<FieldRef, DistinctField, DistinctField.Builder>() {
39+
40+
@Subscribe
41+
fun on(e: DistinctFieldDiscovered) = alter {
42+
errorMessage = e.errorMessage
43+
subject = e.subject
44+
}
45+
}

model/src/main/kotlin/io/spine/validation/ValidationPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class ValidationPlugin(renderers: List<Renderer<*>> = emptyList(
4848
RequiredFieldView::class.java,
4949
PatternFieldView::class.java,
5050
GoesFieldView::class.java,
51+
DistinctFieldView::class.java,
5152
),
5253
viewRepositories = setOf<ViewRepository<*, *, *>>(
5354
CompiledMessageRepository(),

0 commit comments

Comments
 (0)