Browse Source
Merge pull request #5526 from ViacheslavKlimov/fix/fields-length-validation
[3.3.2] [WIP] Fields length validation
pull/5531/head
Igor Kulikov
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with
16 additions and
2 deletions
-
common/data/src/main/java/org/thingsboard/server/common/data/device/profile/DeviceProfileAlarm.java
-
common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChainMetaData.java
-
dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java
-
ui-ngx/src/app/modules/home/components/profile/alarm/device-profile-alarm.component.html
-
ui-ngx/src/app/modules/home/components/profile/alarm/device-profile-alarm.component.ts
-
ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html
-
ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts
-
ui-ngx/src/assets/locale/locale.constant-en_US.json
|
|
|
@ -19,6 +19,7 @@ import io.swagger.annotations.ApiModel; |
|
|
|
import io.swagger.annotations.ApiModelProperty; |
|
|
|
import lombok.Data; |
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
|
|
|
import org.thingsboard.server.common.data.validation.Length; |
|
|
|
import org.thingsboard.server.common.data.validation.NoXss; |
|
|
|
|
|
|
|
import javax.validation.Valid; |
|
|
|
@ -32,6 +33,7 @@ public class DeviceProfileAlarm implements Serializable { |
|
|
|
|
|
|
|
@ApiModelProperty(position = 1, value = "String value representing the alarm rule id", example = "highTemperatureAlarmID") |
|
|
|
private String id; |
|
|
|
@Length(fieldName = "alarm type") |
|
|
|
@NoXss |
|
|
|
@ApiModelProperty(position = 2, value = "String value representing type of the alarm", example = "High Temperature Alarm") |
|
|
|
private String alarmType; |
|
|
|
|
|
|
|
@ -21,6 +21,7 @@ import io.swagger.annotations.ApiModelProperty; |
|
|
|
import lombok.Data; |
|
|
|
import org.thingsboard.server.common.data.id.RuleChainId; |
|
|
|
|
|
|
|
import javax.validation.Valid; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@ -37,6 +38,7 @@ public class RuleChainMetaData { |
|
|
|
@ApiModelProperty(position = 2, required = true, value = "Index of the first rule node in the 'nodes' list") |
|
|
|
private Integer firstNodeIndex; |
|
|
|
|
|
|
|
@Valid |
|
|
|
@ApiModelProperty(position = 3, required = true, value = "List of rule node JSON objects") |
|
|
|
private List<RuleNode> nodes; |
|
|
|
|
|
|
|
|
|
|
|
@ -52,6 +52,7 @@ import org.thingsboard.server.common.data.rule.RuleNode; |
|
|
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|
|
|
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
import org.thingsboard.server.dao.service.ConstraintValidator; |
|
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
|
import org.thingsboard.server.dao.service.PaginatedRemover; |
|
|
|
import org.thingsboard.server.dao.service.Validator; |
|
|
|
@ -135,6 +136,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC |
|
|
|
if (ruleChain == null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
ConstraintValidator.validateFields(ruleChainMetaData); |
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(ruleChainMetaData.getConnections())) { |
|
|
|
validateCircles(ruleChainMetaData.getConnections()); |
|
|
|
|
|
|
|
@ -45,6 +45,9 @@ |
|
|
|
<mat-error *ngIf="alarmFormGroup.get('alarmType').hasError('unique')"> |
|
|
|
{{ 'device-profile.alarm-type-unique' | translate }} |
|
|
|
</mat-error> |
|
|
|
<mat-error *ngIf="alarmFormGroup.get('alarmType').hasError('maxlength')"> |
|
|
|
{{ 'device-profile.alarm-type-max-length' | translate }} |
|
|
|
</mat-error> |
|
|
|
</mat-form-field> |
|
|
|
</div> |
|
|
|
<mat-expansion-panel class="advanced-settings" [expanded]="false"> |
|
|
|
|
|
|
|
@ -93,7 +93,7 @@ export class DeviceProfileAlarmComponent implements ControlValueAccessor, OnInit |
|
|
|
ngOnInit() { |
|
|
|
this.alarmFormGroup = this.fb.group({ |
|
|
|
id: [null, Validators.required], |
|
|
|
alarmType: [null, Validators.required], |
|
|
|
alarmType: [null, [Validators.required, Validators.maxLength(255)]], |
|
|
|
createRules: [null], |
|
|
|
clearRule: [null], |
|
|
|
propagate: [null], |
|
|
|
|
|
|
|
@ -32,6 +32,9 @@ |
|
|
|
|| ruleNodeFormGroup.get('name').hasError('pattern')"> |
|
|
|
{{ 'rulenode.name-required' | translate }} |
|
|
|
</mat-error> |
|
|
|
<mat-error *ngIf="ruleNodeFormGroup.get('name').hasError('maxlength')"> |
|
|
|
{{ 'rulenode.name-max-length' | translate }} |
|
|
|
</mat-error> |
|
|
|
</mat-form-field> |
|
|
|
<mat-checkbox formControlName="debugMode"> |
|
|
|
{{ 'rulenode.debug-mode' | translate }} |
|
|
|
|
|
|
|
@ -78,7 +78,7 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O |
|
|
|
if (this.ruleNode.component.type !== RuleNodeType.RULE_CHAIN) { |
|
|
|
|
|
|
|
this.ruleNodeFormGroup = this.fb.group({ |
|
|
|
name: [this.ruleNode.name, [Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*')]], |
|
|
|
name: [this.ruleNode.name, [Validators.required, Validators.pattern('(.|\\s)*\\S(.|\\s)*'), Validators.maxLength(255)]], |
|
|
|
debugMode: [this.ruleNode.debugMode, []], |
|
|
|
configuration: [this.ruleNode.configuration, [Validators.required]], |
|
|
|
additionalInfo: this.fb.group( |
|
|
|
|
|
|
|
@ -1169,6 +1169,7 @@ |
|
|
|
"alarm-type": "Alarm type", |
|
|
|
"alarm-type-required": "Alarm type is required.", |
|
|
|
"alarm-type-unique": "Alarm type must be unique within the device profile alarm rules.", |
|
|
|
"alarm-type-max-length": "Alarm type should be less than 256", |
|
|
|
"create-alarm-pattern": "Create <b>{{alarmType}}</b> alarm", |
|
|
|
"create-alarm-rules": "Create alarm rules", |
|
|
|
"no-create-alarm-rules": "No create conditions configured", |
|
|
|
@ -2578,6 +2579,7 @@ |
|
|
|
"add": "Add rule node", |
|
|
|
"name": "Name", |
|
|
|
"name-required": "Name is required.", |
|
|
|
"name-max-length": "Name should be less than 256", |
|
|
|
"type": "Type", |
|
|
|
"description": "Description", |
|
|
|
"delete": "Delete rule node", |
|
|
|
|