use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class UserServiceImpl method requestPasswordReset.
@Override
public UserCredentials requestPasswordReset(String email) {
log.trace("Executing requestPasswordReset email [{}]", email);
validateString(email, "Incorrect email " + email);
User user = userDao.findByEmail(email);
if (user == null) {
throw new IncorrectParameterException(String.format("Unable to find user by email [%s]", email));
}
UserCredentials userCredentials = userCredentialsDao.findByUserId(user.getUuidId());
if (!userCredentials.isEnabled()) {
throw new IncorrectParameterException("Unable to reset password for inactive user");
}
userCredentials.setResetToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH));
return saveUserCredentials(userCredentials);
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class UserServiceImpl method activateUserCredentials.
@Override
public UserCredentials activateUserCredentials(String activateToken, String password) {
log.trace("Executing activateUserCredentials activateToken [{}], password [{}]", activateToken, password);
validateString(activateToken, "Incorrect activateToken " + activateToken);
validateString(password, "Incorrect password " + password);
UserCredentials userCredentials = userCredentialsDao.findByActivateToken(activateToken);
if (userCredentials == null) {
throw new IncorrectParameterException(String.format("Unable to find user credentials by activateToken [%s]", activateToken));
}
if (userCredentials.isEnabled()) {
throw new IncorrectParameterException("User credentials already activated");
}
userCredentials.setEnabled(true);
userCredentials.setActivateToken(null);
userCredentials.setPassword(password);
return saveUserCredentials(userCredentials);
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException 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.IncorrectParameterException in project thingsboard by thingsboard.
the class BaseRuleService method validateRuleAndPluginState.
private void validateRuleAndPluginState(RuleMetaData rule) {
if (org.springframework.util.StringUtils.isEmpty(rule.getPluginToken())) {
return;
}
PluginMetaData pluginMd = pluginService.findPluginByApiToken(rule.getPluginToken());
if (pluginMd == null) {
throw new IncorrectParameterException("Rule points to non-existent plugin!");
}
if (!pluginMd.getTenantId().equals(systemTenantId) && !pluginMd.getTenantId().equals(rule.getTenantId())) {
throw new IncorrectParameterException("Rule access plugin that belongs to different tenant!");
}
if (rule.getState() == ComponentLifecycleState.ACTIVE && pluginMd.getState() != ComponentLifecycleState.ACTIVE) {
throw new IncorrectParameterException("Can't save active rule that points to inactive plugin!");
}
ComponentDescriptor pluginDescriptor = componentDescriptorService.findByClazz(pluginMd.getClazz());
String actionClazz = getIfValid(ComponentType.ACTION.name(), rule.getAction(), "clazz", JsonNode::isTextual, JsonNode::asText);
if (!Arrays.asList(pluginDescriptor.getActions().split(",")).contains(actionClazz)) {
throw new IncorrectParameterException("Rule's action is not supported by plugin with token " + rule.getPluginToken() + "!");
}
}
use of org.thingsboard.server.dao.exception.IncorrectParameterException in project thingsboard by thingsboard.
the class BaseRuleService method saveRule.
@Override
public RuleMetaData saveRule(RuleMetaData rule) {
ruleValidator.validate(rule);
if (rule.getTenantId() == null) {
log.trace("Save system rule metadata with predefined id {}", systemTenantId);
rule.setTenantId(systemTenantId);
}
if (rule.getId() != null) {
RuleMetaData oldVersion = ruleDao.findById(rule.getId());
if (rule.getState() == null) {
rule.setState(oldVersion.getState());
} else if (rule.getState() != oldVersion.getState()) {
throw new IncorrectParameterException("Use Activate/Suspend method to control state of the rule!");
}
} else {
if (rule.getState() == null) {
rule.setState(ComponentLifecycleState.SUSPENDED);
} else if (rule.getState() != ComponentLifecycleState.SUSPENDED) {
throw new IncorrectParameterException("Use Activate/Suspend method to control state of the rule!");
}
}
validateFilters(rule.getFilters());
if (rule.getProcessor() != null && !rule.getProcessor().isNull()) {
validateComponentJson(rule.getProcessor(), ComponentType.PROCESSOR);
}
if (rule.getAction() != null && !rule.getAction().isNull()) {
validateComponentJson(rule.getAction(), ComponentType.ACTION);
}
validateRuleAndPluginState(rule);
return ruleDao.save(rule);
}
Aggregations