use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class DefaultMailService method updateMailConfiguration.
@Override
public void updateMailConfiguration() {
AdminSettings settings = adminSettingsService.findAdminSettingsByKey("mail");
if (settings != null) {
JsonNode jsonConfig = settings.getJsonValue();
mailSender = createMailSender(jsonConfig);
mailFrom = jsonConfig.get("mailFrom").asText();
} else {
throw new IncorrectParameterException("Failed to date mail configuration. Settings not found!");
}
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class AssetController method unassignAssetFromCustomer.
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/asset/{assetId}", method = RequestMethod.DELETE)
@ResponseBody
public Asset unassignAssetFromCustomer(@PathVariable(ASSET_ID) String strAssetId) throws ThingsboardException {
checkParameter(ASSET_ID, strAssetId);
try {
AssetId assetId = new AssetId(toUUID(strAssetId));
Asset asset = checkAssetId(assetId);
if (asset.getCustomerId() == null || asset.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) {
throw new IncorrectParameterException("Asset isn't assigned to any customer!");
}
Customer customer = checkCustomerId(asset.getCustomerId());
Asset savedAsset = checkNotNull(assetService.unassignAssetFromCustomer(assetId));
logEntityAction(assetId, asset, asset.getCustomerId(), ActionType.UNASSIGNED_FROM_CUSTOMER, null, strAssetId, customer.getId().toString(), customer.getName());
return savedAsset;
} catch (Exception e) {
logEntityAction(emptyId(EntityType.ASSET), null, null, ActionType.UNASSIGNED_FROM_CUSTOMER, e, strAssetId);
throw handleException(e);
}
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class DeviceController method unassignDeviceFromCustomer.
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/device/{deviceId}", method = RequestMethod.DELETE)
@ResponseBody
public Device unassignDeviceFromCustomer(@PathVariable(DEVICE_ID) String strDeviceId) throws ThingsboardException {
checkParameter(DEVICE_ID, strDeviceId);
try {
DeviceId deviceId = new DeviceId(toUUID(strDeviceId));
Device device = checkDeviceId(deviceId);
if (device.getCustomerId() == null || device.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) {
throw new IncorrectParameterException("Device isn't assigned to any customer!");
}
Customer customer = checkCustomerId(device.getCustomerId());
Device savedDevice = checkNotNull(deviceService.unassignDeviceFromCustomer(deviceId));
logEntityAction(deviceId, device, device.getCustomerId(), ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDeviceId, customer.getId().toString(), customer.getName());
return savedDevice;
} catch (Exception e) {
logEntityAction(emptyId(EntityType.DEVICE), null, null, ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDeviceId);
throw handleException(e);
}
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class WidgetsBundleServiceImpl method deleteWidgetsBundle.
@Override
public void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId) {
log.trace("Executing deleteWidgetsBundle [{}]", widgetsBundleId);
Validator.validateId(widgetsBundleId, "Incorrect widgetsBundleId " + widgetsBundleId);
WidgetsBundle widgetsBundle = findWidgetsBundleById(widgetsBundleId);
if (widgetsBundle == null) {
throw new IncorrectParameterException("Unable to delete non-existent widgets bundle.");
}
widgetTypeService.deleteWidgetTypesByTenantIdAndBundleAlias(widgetsBundle.getTenantId(), widgetsBundle.getAlias());
widgetsBundleDao.removeById(widgetsBundleId.getId());
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class BaseRuleService method validateComponentJson.
private void validateComponentJson(JsonNode json, ComponentType type) {
if (json == null || json.isNull()) {
throw new IncorrectParameterException(type.name() + " is required!");
}
String clazz = getIfValid(type.name(), json, "clazz", JsonNode::isTextual, JsonNode::asText);
String name = getIfValid(type.name(), json, "name", JsonNode::isTextual, JsonNode::asText);
JsonNode configuration = getIfValid(type.name(), json, "configuration", JsonNode::isObject, node -> node);
ComponentDescriptor descriptor = componentDescriptorService.findByClazz(clazz);
if (descriptor == null) {
throw new IncorrectParameterException(type.name() + " clazz " + clazz + " is not a valid component!");
}
if (descriptor.getType() != type) {
throw new IncorrectParameterException("Clazz " + clazz + " is not a valid " + type.name() + " component!");
}
if (!componentDescriptorService.validate(descriptor, configuration)) {
throw new IncorrectParameterException(type.name() + " configuration is not valid!");
}
}
Aggregations