Search in sources :

Example 1 with FbBotMillMonitor

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;
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) FbBotMillResponse(co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse) ConstraintViolation(javax.validation.ConstraintViolation) FbBotMillMonitor(co.aurasphere.botmill.fb.support.FbBotMillMonitor) Validator(javax.validation.Validator)

Example 2 with FbBotMillMonitor

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);
        }
    }
}
Also used : FacebookConfirmationMessage(co.aurasphere.botmill.fb.model.incoming.FacebookConfirmationMessage) FacebookError(co.aurasphere.botmill.fb.model.incoming.FacebookError) FbBotMillMonitor(co.aurasphere.botmill.fb.support.FbBotMillMonitor) FacebookErrorMessage(co.aurasphere.botmill.fb.model.incoming.FacebookErrorMessage)

Aggregations

FbBotMillMonitor (co.aurasphere.botmill.fb.support.FbBotMillMonitor)2 FacebookConfirmationMessage (co.aurasphere.botmill.fb.model.incoming.FacebookConfirmationMessage)1 FacebookError (co.aurasphere.botmill.fb.model.incoming.FacebookError)1 FacebookErrorMessage (co.aurasphere.botmill.fb.model.incoming.FacebookErrorMessage)1 FbBotMillResponse (co.aurasphere.botmill.fb.model.outcoming.FbBotMillResponse)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Validator (javax.validation.Validator)1 ValidatorFactory (javax.validation.ValidatorFactory)1