Browse Source

added jakarte validation

pull/14223/head
IrynaMatveieva 12 months ago
parent
commit
cb93f47138
  1. 3
      common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/PropagationCalculatedFieldConfiguration.java
  2. 4
      common/data/src/main/java/org/thingsboard/server/common/data/relation/RelationPathLevel.java
  3. 9
      common/data/src/test/java/org/thingsboard/server/common/data/cf/configuration/PropagationCalculatedFieldConfigurationTest.java

3
common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/PropagationCalculatedFieldConfiguration.java

@ -15,6 +15,7 @@
*/
package org.thingsboard.server.common.data.cf.configuration;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -30,6 +31,7 @@ public class PropagationCalculatedFieldConfiguration extends BaseCalculatedField
public static final String PROPAGATION_CONFIG_ARGUMENT = "propagationCtx";
@Valid
@NotNull
private RelationPathLevel relation;
@ -42,7 +44,6 @@ public class PropagationCalculatedFieldConfiguration extends BaseCalculatedField
@Override
public void validate() {
relation.validate();
baseCalculatedFieldRestriction();
propagationRestriction();
if (!applyExpressionToResolvedArguments) {

4
common/data/src/main/java/org/thingsboard/server/common/data/relation/RelationPathLevel.java

@ -15,9 +15,11 @@
*/
package org.thingsboard.server.common.data.relation;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.thingsboard.server.common.data.StringUtils;
public record RelationPathLevel(EntitySearchDirection direction, String relationType) {
public record RelationPathLevel(@NotNull EntitySearchDirection direction, @NotBlank String relationType) {
public void validate() {
if (direction == null) {

9
common/data/src/test/java/org/thingsboard/server/common/data/cf/configuration/PropagationCalculatedFieldConfigurationTest.java

@ -43,7 +43,6 @@ public class PropagationCalculatedFieldConfigurationTest {
@Test
void validateShouldThrowWhenConfigurationDisallowArgumentsWithReferencedEntity() {
var cfg = new PropagationCalculatedFieldConfiguration();
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE));
Argument argumentWithRefEntityIdSet = new Argument();
argumentWithRefEntityIdSet.setRefEntityId(new DeviceId(UUID.fromString("bda14084-f40e-4acc-9b85-9d1dd209bb64")));
cfg.setArguments(Map.of("argumentWithRefEntityIdSet", argumentWithRefEntityIdSet));
@ -55,7 +54,6 @@ public class PropagationCalculatedFieldConfigurationTest {
@Test
void validateShouldThrowWhenConfigurationDisallowArgumentsWithDynamicReferenceConfiguration() {
var cfg = new PropagationCalculatedFieldConfiguration();
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE));
Argument argumentWithDynamicRefEntitySource = new Argument();
argumentWithDynamicRefEntitySource.setRefDynamicSourceConfiguration(new CurrentOwnerDynamicSourceConfiguration());
cfg.setArguments(Map.of("argumentWithDynamicRefEntitySource", argumentWithDynamicRefEntitySource));
@ -67,7 +65,6 @@ public class PropagationCalculatedFieldConfigurationTest {
@Test
void validateShouldThrowWhenConfigurationHasNoArgumentsWithCurrentEntitySource() {
var cfg = new PropagationCalculatedFieldConfiguration();
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE));
Argument argumentWithRefEntityIdSet = new Argument();
argumentWithRefEntityIdSet.setRefEntityId(new DeviceId(UUID.fromString("3703e895-3f9b-4b75-a715-b68f1ad51944")));
cfg.setArguments(Map.of("argumentWithRefEntityIdSet", argumentWithRefEntityIdSet));
@ -75,13 +72,12 @@ public class PropagationCalculatedFieldConfigurationTest {
assertThatThrownBy(cfg::validate)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("At least one argument must be configured with the 'Current entity' " +
"source entity type for 'Expression result' propagation mode!");
"source entity type for 'Expression result' propagation mode!");
}
@Test
void validateShouldThrowWhenUsedReservedPropagationArgumentName() {
var cfg = new PropagationCalculatedFieldConfiguration();
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE));
cfg.setArguments(Map.of(PROPAGATION_CONFIG_ARGUMENT, new Argument()));
assertThatThrownBy(cfg::validate)
.isInstanceOf(IllegalArgumentException.class)
@ -91,7 +87,6 @@ public class PropagationCalculatedFieldConfigurationTest {
@Test
void validateShouldThrowWhenUsedReservedCtxArgumentName() {
var cfg = new PropagationCalculatedFieldConfiguration();
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE));
cfg.setArguments(Map.of("ctx", new Argument()));
assertThatThrownBy(cfg::validate)
.isInstanceOf(IllegalArgumentException.class)
@ -112,7 +107,6 @@ public class PropagationCalculatedFieldConfigurationTest {
@Test
void validateShouldThrowWhenReferencedEntityKeyTypeIsTsRolling() {
var cfg = new PropagationCalculatedFieldConfiguration();
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE));
ReferencedEntityKey referencedEntityKey = new ReferencedEntityKey("someKey", ArgumentType.TS_ROLLING, null);
Argument argument = new Argument();
argument.setRefEntityKey(referencedEntityKey);
@ -126,7 +120,6 @@ public class PropagationCalculatedFieldConfigurationTest {
@Test
void validateShouldThrowWhenExpressionIsNotSet() {
var cfg = new PropagationCalculatedFieldConfiguration();
cfg.setRelation(new RelationPathLevel(EntitySearchDirection.TO, EntityRelation.CONTAINS_TYPE));
cfg.setArguments(Map.of("someArgumentName", new Argument()));
cfg.setApplyExpressionToResolvedArguments(true);
assertThatThrownBy(cfg::validate)

Loading…
Cancel
Save