added validations for DeviceProfileAlarm type
This commit is contained in:
parent
566f24f429
commit
aa61db22f2
@ -23,16 +23,17 @@ import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
|
||||
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
@ -48,7 +49,9 @@ import org.thingsboard.server.dao.tenant.TenantDao;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_PROFILE_CACHE;
|
||||
import static org.thingsboard.server.dao.service.Validator.validateId;
|
||||
@ -115,7 +118,7 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
|
||||
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_profile_name_unq_key")) {
|
||||
throw new DataValidationException("Device profile with such name already exists!");
|
||||
} else if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_provision_key_unq_key")) {
|
||||
throw new DataValidationException("Device profile with such provision device key already exists!");
|
||||
throw new DataValidationException("Device profile with such provision device key already exists!");
|
||||
} else {
|
||||
throw t;
|
||||
}
|
||||
@ -311,6 +314,21 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
|
||||
throw new DataValidationException("Another default device profile is present in scope of current tenant!");
|
||||
}
|
||||
}
|
||||
List<DeviceProfileAlarm> profileAlarms = deviceProfile.getProfileData().getAlarms();
|
||||
|
||||
if (!CollectionUtils.isEmpty(profileAlarms)) {
|
||||
Set<String> alarmTypes = new HashSet<>();
|
||||
for (DeviceProfileAlarm alarm : profileAlarms) {
|
||||
String alarmType = alarm.getAlarmType();
|
||||
if (StringUtils.isEmpty(alarmType)) {
|
||||
throw new DataValidationException("Alarm rule type should be specified!");
|
||||
}
|
||||
if (!alarmTypes.add(alarmType)) {
|
||||
throw new DataValidationException(String.format("Can't create device profile with the same alarm rule types: \"%s\"!", alarmType));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user