Commit d5c7f7fc9eed061bab965da9f66ea8899e9c5666
Committed by
GitHub
Merge pull request #5526 from ViacheslavKlimov/fix/fields-length-validation
[3.3.2] [WIP] Fields length validation
Showing
8 changed files
with
16 additions
and
2 deletions
@@ -19,6 +19,7 @@ import io.swagger.annotations.ApiModel; | @@ -19,6 +19,7 @@ import io.swagger.annotations.ApiModel; | ||
19 | import io.swagger.annotations.ApiModelProperty; | 19 | import io.swagger.annotations.ApiModelProperty; |
20 | import lombok.Data; | 20 | import lombok.Data; |
21 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; | 21 | import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
22 | +import org.thingsboard.server.common.data.validation.Length; | ||
22 | import org.thingsboard.server.common.data.validation.NoXss; | 23 | import org.thingsboard.server.common.data.validation.NoXss; |
23 | 24 | ||
24 | import javax.validation.Valid; | 25 | import javax.validation.Valid; |
@@ -32,6 +33,7 @@ public class DeviceProfileAlarm implements Serializable { | @@ -32,6 +33,7 @@ public class DeviceProfileAlarm implements Serializable { | ||
32 | 33 | ||
33 | @ApiModelProperty(position = 1, value = "String value representing the alarm rule id", example = "highTemperatureAlarmID") | 34 | @ApiModelProperty(position = 1, value = "String value representing the alarm rule id", example = "highTemperatureAlarmID") |
34 | private String id; | 35 | private String id; |
36 | + @Length(fieldName = "alarm type") | ||
35 | @NoXss | 37 | @NoXss |
36 | @ApiModelProperty(position = 2, value = "String value representing type of the alarm", example = "High Temperature Alarm") | 38 | @ApiModelProperty(position = 2, value = "String value representing type of the alarm", example = "High Temperature Alarm") |
37 | private String alarmType; | 39 | private String alarmType; |
@@ -21,6 +21,7 @@ import io.swagger.annotations.ApiModelProperty; | @@ -21,6 +21,7 @@ import io.swagger.annotations.ApiModelProperty; | ||
21 | import lombok.Data; | 21 | import lombok.Data; |
22 | import org.thingsboard.server.common.data.id.RuleChainId; | 22 | import org.thingsboard.server.common.data.id.RuleChainId; |
23 | 23 | ||
24 | +import javax.validation.Valid; | ||
24 | import java.util.ArrayList; | 25 | import java.util.ArrayList; |
25 | import java.util.List; | 26 | import java.util.List; |
26 | 27 | ||
@@ -37,6 +38,7 @@ public class RuleChainMetaData { | @@ -37,6 +38,7 @@ public class RuleChainMetaData { | ||
37 | @ApiModelProperty(position = 2, required = true, value = "Index of the first rule node in the 'nodes' list") | 38 | @ApiModelProperty(position = 2, required = true, value = "Index of the first rule node in the 'nodes' list") |
38 | private Integer firstNodeIndex; | 39 | private Integer firstNodeIndex; |
39 | 40 | ||
41 | + @Valid | ||
40 | @ApiModelProperty(position = 3, required = true, value = "List of rule node JSON objects") | 42 | @ApiModelProperty(position = 3, required = true, value = "List of rule node JSON objects") |
41 | private List<RuleNode> nodes; | 43 | private List<RuleNode> nodes; |
42 | 44 |
@@ -52,6 +52,7 @@ import org.thingsboard.server.common.data.rule.RuleNode; | @@ -52,6 +52,7 @@ import org.thingsboard.server.common.data.rule.RuleNode; | ||
52 | import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; | 52 | import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
53 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 53 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
54 | import org.thingsboard.server.dao.exception.DataValidationException; | 54 | import org.thingsboard.server.dao.exception.DataValidationException; |
55 | +import org.thingsboard.server.dao.service.ConstraintValidator; | ||
55 | import org.thingsboard.server.dao.service.DataValidator; | 56 | import org.thingsboard.server.dao.service.DataValidator; |
56 | import org.thingsboard.server.dao.service.PaginatedRemover; | 57 | import org.thingsboard.server.dao.service.PaginatedRemover; |
57 | import org.thingsboard.server.dao.service.Validator; | 58 | import org.thingsboard.server.dao.service.Validator; |
@@ -135,6 +136,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -135,6 +136,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
135 | if (ruleChain == null) { | 136 | if (ruleChain == null) { |
136 | return false; | 137 | return false; |
137 | } | 138 | } |
139 | + ConstraintValidator.validateFields(ruleChainMetaData); | ||
138 | 140 | ||
139 | if (CollectionUtils.isNotEmpty(ruleChainMetaData.getConnections())) { | 141 | if (CollectionUtils.isNotEmpty(ruleChainMetaData.getConnections())) { |
140 | validateCircles(ruleChainMetaData.getConnections()); | 142 | validateCircles(ruleChainMetaData.getConnections()); |
@@ -45,6 +45,9 @@ | @@ -45,6 +45,9 @@ | ||
45 | <mat-error *ngIf="alarmFormGroup.get('alarmType').hasError('unique')"> | 45 | <mat-error *ngIf="alarmFormGroup.get('alarmType').hasError('unique')"> |
46 | {{ 'device-profile.alarm-type-unique' | translate }} | 46 | {{ 'device-profile.alarm-type-unique' | translate }} |
47 | </mat-error> | 47 | </mat-error> |
48 | + <mat-error *ngIf="alarmFormGroup.get('alarmType').hasError('maxlength')"> | ||
49 | + {{ 'device-profile.alarm-type-max-length' | translate }} | ||
50 | + </mat-error> | ||
48 | </mat-form-field> | 51 | </mat-form-field> |
49 | </div> | 52 | </div> |
50 | <mat-expansion-panel class="advanced-settings" [expanded]="false"> | 53 | <mat-expansion-panel class="advanced-settings" [expanded]="false"> |
@@ -93,7 +93,7 @@ export class DeviceProfileAlarmComponent implements ControlValueAccessor, OnInit | @@ -93,7 +93,7 @@ export class DeviceProfileAlarmComponent implements ControlValueAccessor, OnInit | ||
93 | ngOnInit() { | 93 | ngOnInit() { |
94 | this.alarmFormGroup = this.fb.group({ | 94 | this.alarmFormGroup = this.fb.group({ |
95 | id: [null, Validators.required], | 95 | id: [null, Validators.required], |
96 | - alarmType: [null, Validators.required], | 96 | + alarmType: [null, [Validators.required, Validators.maxLength(255)]], |
97 | createRules: [null], | 97 | createRules: [null], |
98 | clearRule: [null], | 98 | clearRule: [null], |
99 | propagate: [null], | 99 | propagate: [null], |
@@ -32,6 +32,9 @@ | @@ -32,6 +32,9 @@ | ||
32 | || ruleNodeFormGroup.get('name').hasError('pattern')"> | 32 | || ruleNodeFormGroup.get('name').hasError('pattern')"> |
33 | {{ 'rulenode.name-required' | translate }} | 33 | {{ 'rulenode.name-required' | translate }} |
34 | </mat-error> | 34 | </mat-error> |
35 | + <mat-error *ngIf="ruleNodeFormGroup.get('name').hasError('maxlength')"> | ||
36 | + {{ 'rulenode.name-max-length' | translate }} | ||
37 | + </mat-error> | ||
35 | </mat-form-field> | 38 | </mat-form-field> |
36 | <mat-checkbox formControlName="debugMode"> | 39 | <mat-checkbox formControlName="debugMode"> |
37 | {{ 'rulenode.debug-mode' | translate }} | 40 | {{ 'rulenode.debug-mode' | translate }} |
@@ -78,7 +78,7 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O | @@ -78,7 +78,7 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O | ||
78 | if (this.ruleNode.component.type !== RuleNodeType.RULE_CHAIN) { | 78 | if (this.ruleNode.component.type !== RuleNodeType.RULE_CHAIN) { |
79 | 79 | ||
80 | this.ruleNodeFormGroup = this.fb.group({ | 80 | this.ruleNodeFormGroup = this.fb.group({ |
81 | - name: [this.ruleNode.name, [Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*')]], | 81 | + name: [this.ruleNode.name, [Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*'), Validators.maxLength(255)]], |
82 | debugMode: [this.ruleNode.debugMode, []], | 82 | debugMode: [this.ruleNode.debugMode, []], |
83 | configuration: [this.ruleNode.configuration, [Validators.required]], | 83 | configuration: [this.ruleNode.configuration, [Validators.required]], |
84 | additionalInfo: this.fb.group( | 84 | additionalInfo: this.fb.group( |
@@ -1169,6 +1169,7 @@ | @@ -1169,6 +1169,7 @@ | ||
1169 | "alarm-type": "Alarm type", | 1169 | "alarm-type": "Alarm type", |
1170 | "alarm-type-required": "Alarm type is required.", | 1170 | "alarm-type-required": "Alarm type is required.", |
1171 | "alarm-type-unique": "Alarm type must be unique within the device profile alarm rules.", | 1171 | "alarm-type-unique": "Alarm type must be unique within the device profile alarm rules.", |
1172 | + "alarm-type-max-length": "Alarm type should be less than 256", | ||
1172 | "create-alarm-pattern": "Create <b>{{alarmType}}</b> alarm", | 1173 | "create-alarm-pattern": "Create <b>{{alarmType}}</b> alarm", |
1173 | "create-alarm-rules": "Create alarm rules", | 1174 | "create-alarm-rules": "Create alarm rules", |
1174 | "no-create-alarm-rules": "No create conditions configured", | 1175 | "no-create-alarm-rules": "No create conditions configured", |
@@ -2578,6 +2579,7 @@ | @@ -2578,6 +2579,7 @@ | ||
2578 | "add": "Add rule node", | 2579 | "add": "Add rule node", |
2579 | "name": "Name", | 2580 | "name": "Name", |
2580 | "name-required": "Name is required.", | 2581 | "name-required": "Name is required.", |
2582 | + "name-max-length": "Name should be less than 256", | ||
2581 | "type": "Type", | 2583 | "type": "Type", |
2582 | "description": "Description", | 2584 | "description": "Description", |
2583 | "delete": "Delete rule node", | 2585 | "delete": "Delete rule node", |