use of org.thingsboard.server.dao.exception.DataValidationException in project thingsboard by thingsboard.
the class DashboardServiceImpl method unassignDashboardFromCustomer.
@Override
public Dashboard unassignDashboardFromCustomer(DashboardId dashboardId, CustomerId customerId) {
Dashboard dashboard = findDashboardById(dashboardId);
Customer customer = customerDao.findById(customerId.getId());
if (customer == null) {
throw new DataValidationException("Can't unassign dashboard from non-existent customer!");
}
if (dashboard.removeAssignedCustomer(customer)) {
try {
deleteRelation(new EntityRelation(customerId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD));
} catch (ExecutionException | InterruptedException e) {
log.warn("[{}] Failed to delete dashboard relation. Customer Id: [{}]", dashboardId, customerId);
throw new RuntimeException(e);
}
return saveDashboard(dashboard);
} else {
return dashboard;
}
}
use of org.thingsboard.server.dao.exception.DataValidationException in project thingsboard by thingsboard.
the class BaseComponentDescriptorService method validate.
@Override
public boolean validate(ComponentDescriptor component, JsonNode configuration) {
JsonValidator validator = JsonSchemaFactory.byDefault().getValidator();
try {
if (!component.getConfigurationDescriptor().has("schema")) {
throw new DataValidationException("Configuration descriptor doesn't contain schema property!");
}
JsonNode configurationSchema = component.getConfigurationDescriptor().get("schema");
ProcessingReport report = validator.validate(configurationSchema, configuration);
return report.isSuccess();
} catch (ProcessingException e) {
throw new IncorrectParameterException(e.getMessage(), e);
}
}
use of org.thingsboard.server.dao.exception.DataValidationException in project thingsboard by thingsboard.
the class BasePluginService method suspendPluginById.
@Override
public void suspendPluginById(PluginId pluginId) {
PluginMetaData plugin = pluginDao.findById(pluginId);
List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken()).stream().filter(rule -> rule.getState() == ComponentLifecycleState.ACTIVE).collect(Collectors.toList());
if (affectedRules.isEmpty()) {
updateLifeCycleState(pluginId, ComponentLifecycleState.SUSPENDED);
} else {
throw new DataValidationException("Can't suspend plugin that has active rules!");
}
}
use of org.thingsboard.server.dao.exception.DataValidationException in project thingsboard by thingsboard.
the class BasePluginService method checkRulesAndDelete.
private void checkRulesAndDelete(UUID pluginId) {
PluginMetaData plugin = pluginDao.findById(pluginId);
List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken());
if (affectedRules.isEmpty()) {
pluginDao.deleteById(pluginId);
} else {
throw new DataValidationException("Plugin deletion will affect existing rules!");
}
}
use of org.thingsboard.server.dao.exception.DataValidationException in project thingsboard by thingsboard.
the class DashboardServiceImpl method assignDashboardToCustomer.
@Override
public Dashboard assignDashboardToCustomer(DashboardId dashboardId, CustomerId customerId) {
Dashboard dashboard = findDashboardById(dashboardId);
Customer customer = customerDao.findById(customerId.getId());
if (customer == null) {
throw new DataValidationException("Can't assign dashboard to non-existent customer!");
}
if (!customer.getTenantId().getId().equals(dashboard.getTenantId().getId())) {
throw new DataValidationException("Can't assign dashboard to customer from different tenant!");
}
if (dashboard.addAssignedCustomer(customer)) {
try {
createRelation(new EntityRelation(customerId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD));
} catch (ExecutionException | InterruptedException e) {
log.warn("[{}] Failed to create dashboard relation. Customer Id: [{}]", dashboardId, customerId);
throw new RuntimeException(e);
}
return saveDashboard(dashboard);
} else {
return dashboard;
}
}
Aggregations