use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class AlertSubscriptionsApiServiceImpl method getBotDetectionAlertSubscriptions.
/**
* Retrieve a list of bot detection alert subscriptions
*
* @param messageContext CXF Message Context
* @return list of bot detection alert subscriptions
* @throws APIManagementException if an error occurs when retrieving bot detection alert subscriptions
*/
@Override
public Response getBotDetectionAlertSubscriptions(MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
List<BotDetectionData> botDetectionDataList = apiAdmin.getBotDetectionAlertSubscriptions();
BotDetectionAlertSubscriptionListDTO listDTO = BotDetectionMappingUtil.fromAlertSubscriptionListToListDTO(botDetectionDataList);
return Response.ok().entity(listDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class AlertSubscriptionsApiServiceImpl method subscribeForBotDetectionAlerts.
/**
* Subscribe for bot detection alerts
*
* @param body email to be registered for the subscription
* @param messageContext CXF Message Context
* @return alert subscription DTO containing the uuid of the subscription and the registered email
* @throws APIManagementException if an error occurs when subscribing for bot detection alerts
*/
@Override
public Response subscribeForBotDetectionAlerts(BotDetectionAlertSubscriptionDTO body, MessageContext messageContext) throws APIManagementException {
String email = body.getEmail();
if (StringUtils.isBlank(email)) {
String propertyName = AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD;
throw new APIManagementException(propertyName + " property value of payload cannot be blank", ExceptionCodes.from(ExceptionCodes.BLANK_PROPERTY_VALUE, propertyName));
}
APIAdmin apiAdmin = new APIAdminImpl();
BotDetectionData alertSubscription = apiAdmin.getBotDetectionAlertSubscription(AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD, email);
if (alertSubscription != null) {
RestApiUtil.handleResourceAlreadyExistsError("Email: " + email + " has already been subscribed for bot detection alerts", log);
}
apiAdmin.addBotDetectionAlertSubscription(email);
BotDetectionData newAlertSubscription = apiAdmin.getBotDetectionAlertSubscription(AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD, email);
BotDetectionAlertSubscriptionDTO alertSubscriptionDTO = BotDetectionMappingUtil.fromAlertSubscriptionToDTO(newAlertSubscription);
return Response.ok(alertSubscriptionDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class AlertSubscriptionsApiServiceImpl method unsubscribeFromBotDetectionAlerts.
/**
* Unsubscribe from bot detection alerts
*
* @param uuid uuid of the subscription
* @param messageContext CXF Message Context
* @return 200 OK response if the subscription is deleted successfully
* @throws APIManagementException if an error occurs when un-subscribing from bot detection alerts
*/
@Override
public Response unsubscribeFromBotDetectionAlerts(String uuid, MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
BotDetectionData alertSubscription = apiAdmin.getBotDetectionAlertSubscription("uuid", uuid);
if (alertSubscription == null) {
RestApiUtil.handleResourceNotFoundError("Bot detection alert subscription with uuid: " + uuid + " does not exist.", log);
}
apiAdmin.deleteBotDetectionAlertSubscription(uuid);
return Response.ok().build();
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class BotDetectionDataApiServiceImpl method getBotDetectionData.
/**
* Get all bot detected data
*
* @param messageContext CXF Message Context
* @return list of all bot detected data
* @throws APIManagementException if an error occurs when retrieving bot detection data
*/
public Response getBotDetectionData(MessageContext messageContext) throws APIManagementException {
if (APIUtil.isAnalyticsEnabled()) {
APIAdmin apiAdmin = new APIAdminImpl();
List<BotDetectionData> botDetectionDataList = apiAdmin.retrieveBotDetectionData();
BotDetectionDataListDTO listDTO = BotDetectionMappingUtil.fromBotDetectionModelToDTO(botDetectionDataList);
return Response.ok().entity(listDTO).build();
} else {
throw new APIManagementException("Analytics Not Enabled", ExceptionCodes.from(ExceptionCodes.ANALYTICS_NOT_ENABLED, "Bot Detection Data is", "Bot Detection Data"));
}
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class ApiMgtDAO method getBotDetectionAlertSubscriptions.
/**
* Retrieve all bot detection alert subscriptions
*
* @throws APIManagementException if an error occurs when retrieving bot detection alert subscriptions
*/
public List<BotDetectionData> getBotDetectionAlertSubscriptions() throws APIManagementException {
List<BotDetectionData> list = new ArrayList<>();
String query = SQLConstants.BotDataConstants.GET_SAVED_ALERT_EMAILS;
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement ps = connection.prepareStatement(query)) {
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()) {
BotDetectionData botDetectedData = new BotDetectionData();
botDetectedData.setUuid(resultSet.getString("UUID"));
botDetectedData.setEmail(resultSet.getString("SUBSCRIBER_ADDRESS"));
list.add(botDetectedData);
}
} catch (SQLException e) {
handleException("Error while retrieving bot detection alert subscriptions", e);
}
return list;
}
Aggregations