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.CacheManager;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.thingsboard.server.common.data.Device;
|
import org.thingsboard.server.common.data.Device;
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
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.Tenant;
|
||||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
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.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.DeviceProfileData;
|
||||||
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
|
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
|
||||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
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.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_PROFILE_CACHE;
|
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_PROFILE_CACHE;
|
||||||
import static org.thingsboard.server.dao.service.Validator.validateId;
|
import static org.thingsboard.server.dao.service.Validator.validateId;
|
||||||
@ -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!");
|
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
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user