use of co.aurasphere.botmill.fb.support.FbBotMillMonitor in project fb-botmill by BotMill.
the class FbBotMillBean method validate.
/**
* Validates the {@link FbBotMillResponse}.
*
* @param response
* the response
* @return true if the response is valid, false otherwise.
*/
protected boolean validate(FbBotMillResponse response) {
// If validations are not enabled, returns true.
if (!FbBotMillContext.getInstance().isValidationEnabled()) {
return true;
}
boolean valid = true;
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<FbBotMillResponse>> violations = validator.validate(response);
for (ConstraintViolation<FbBotMillResponse> v : violations) {
valid = false;
logger.error("FbBotMillResponse validation error. Message: [{}] Value: [{}], Class: [{}], Field: [{}]", v.getMessage(), v.getInvalidValue(), v.getRootBean(), v.getPropertyPath());
}
if (valid == false) {
// Sends the constraint violations through the callback.
List<FbBotMillMonitor> registeredMonitors = FbBotMillContext.getInstance().getRegisteredMonitors();
for (FbBotMillMonitor monitor : registeredMonitors) {
monitor.onValidationError(response, violations);
}
}
return valid;
}
use of co.aurasphere.botmill.fb.support.FbBotMillMonitor in project fb-botmill by BotMill.
the class FbBotMillNetworkController method propagateResponse.
/**
* Propagates the response to the registered {@link FbBotMillMonitor}.
*
* @param response
* the response to propagate.
*/
private static void propagateResponse(BotMillNetworkResponse response) {
String output = response.getResponse();
if (response.isError()) {
// Parses the error message and logs it.
FacebookErrorMessage errorMessage = FbBotMillJsonUtils.fromJson(output, FacebookErrorMessage.class);
FacebookError error = errorMessage.getError();
logger.error("Error message from Facebook. Message: [{}], Code: [{}], Type: [{}], FbTraceID: [{}].", error.getMessage(), error.getCode(), error.getType(), error.getFbTraceId());
// Sends the callback to the registered network monitors.
for (FbBotMillMonitor monitor : registeredMonitors) {
monitor.onError(errorMessage);
}
} else {
FacebookConfirmationMessage confirmationMessage = FbBotMillJsonUtils.fromJson(output, FacebookConfirmationMessage.class);
logger.debug("Confirmation from Facebook. Recipient ID: [{}], Message ID: [{}], Result Message: [{}]", confirmationMessage.getRecipientId(), confirmationMessage.getMessageId(), confirmationMessage.getResult());
// Sends the callback to the registered network monitors.
for (FbBotMillMonitor monitor : registeredMonitors) {
monitor.onConfirmation(confirmationMessage);
}
}
}
Aggregations