Search in sources :

Example 6 with IncorrectParameterException

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!");
    }
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) JsonNode(com.fasterxml.jackson.databind.JsonNode) AdminSettings(org.thingsboard.server.common.data.AdminSettings)

Example 7 with IncorrectParameterException

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);
    }
}
Also used : Customer(org.thingsboard.server.common.data.Customer) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) Asset(org.thingsboard.server.common.data.asset.Asset) AssetId(org.thingsboard.server.common.data.id.AssetId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with IncorrectParameterException

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);
    }
}
Also used : Customer(org.thingsboard.server.common.data.Customer) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Device(org.thingsboard.server.common.data.Device) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with IncorrectParameterException

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());
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 10 with IncorrectParameterException

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!");
    }
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Customer (org.thingsboard.server.common.data.Customer)4 ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)2 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)2 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)1 JsonValidator (com.github.fge.jsonschema.main.JsonValidator)1 IOException (java.io.IOException)1 AdminSettings (org.thingsboard.server.common.data.AdminSettings)1 Device (org.thingsboard.server.common.data.Device)1 User (org.thingsboard.server.common.data.User)1 Asset (org.thingsboard.server.common.data.asset.Asset)1 AssetId (org.thingsboard.server.common.data.id.AssetId)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)1