use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class BasePluginService method savePlugin.
@Override
public PluginMetaData savePlugin(PluginMetaData plugin) {
pluginValidator.validate(plugin);
if (plugin.getTenantId() == null) {
log.trace("Save system plugin metadata with predefined id {}", SYSTEM_TENANT);
plugin.setTenantId(SYSTEM_TENANT);
}
if (plugin.getId() != null) {
PluginMetaData oldVersion = pluginDao.findById(plugin.getId());
if (plugin.getState() == null) {
plugin.setState(oldVersion.getState());
} else if (plugin.getState() != oldVersion.getState()) {
throw new IncorrectParameterException("Use Activate/Suspend method to control state of the plugin!");
}
} else {
if (plugin.getState() == null) {
plugin.setState(ComponentLifecycleState.SUSPENDED);
} else if (plugin.getState() != ComponentLifecycleState.SUSPENDED) {
throw new IncorrectParameterException("Use Activate/Suspend method to control state of the plugin!");
}
}
ComponentDescriptor descriptor = componentDescriptorService.findByClazz(plugin.getClazz());
if (descriptor == null) {
throw new IncorrectParameterException("Plugin descriptor not found!");
} else if (!ComponentType.PLUGIN.equals(descriptor.getType())) {
throw new IncorrectParameterException("Plugin class is actually " + descriptor.getType() + "!");
}
PluginMetaData savedPlugin = pluginDao.findByApiToken(plugin.getApiToken());
if (savedPlugin != null && (plugin.getId() == null || !savedPlugin.getId().getId().equals(plugin.getId().getId()))) {
throw new IncorrectParameterException("API token is already reserved!");
}
if (!componentDescriptorService.validate(descriptor, plugin.getConfiguration())) {
throw new IncorrectParameterException("Filters configuration is not valid!");
}
return pluginDao.save(plugin);
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class CustomerServiceImpl method findOrCreatePublicCustomer.
@Override
public Customer findOrCreatePublicCustomer(TenantId tenantId) {
log.trace("Executing findOrCreatePublicCustomer, tenantId [{}]", tenantId);
Validator.validateId(tenantId, INCORRECT_CUSTOMER_ID + tenantId);
Optional<Customer> publicCustomerOpt = customerDao.findCustomersByTenantIdAndTitle(tenantId.getId(), PUBLIC_CUSTOMER_TITLE);
if (publicCustomerOpt.isPresent()) {
return publicCustomerOpt.get();
} else {
Customer publicCustomer = new Customer();
publicCustomer.setTenantId(tenantId);
publicCustomer.setTitle(PUBLIC_CUSTOMER_TITLE);
try {
publicCustomer.setAdditionalInfo(new ObjectMapper().readValue("{ \"isPublic\": true }", JsonNode.class));
} catch (IOException e) {
throw new IncorrectParameterException("Unable to create public customer.", e);
}
return customerDao.save(publicCustomer);
}
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class CustomerServiceImpl method deleteCustomer.
@Override
public void deleteCustomer(CustomerId customerId) {
log.trace("Executing deleteCustomer [{}]", customerId);
Validator.validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
Customer customer = findCustomerById(customerId);
if (customer == null) {
throw new IncorrectParameterException("Unable to delete non-existent customer.");
}
dashboardService.unassignCustomerDashboards(customerId);
assetService.unassignCustomerAssets(customer.getTenantId(), customerId);
deviceService.unassignCustomerDevices(customer.getTenantId(), customerId);
userService.deleteCustomerUsers(customer.getTenantId(), customerId);
deleteEntityRelations(customerId);
customerDao.removeById(customerId.getId());
}
Aggregations