use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class ApiMgtDAO method getBotDetectionAlertSubscription.
/**
* Retrieve a bot detection alert subscription by querying a particular field (uuid or email)
*
* @param field field to be queried to obtain the bot detection alert subscription. Can be uuid or email
* @param value value corresponding to the field (uuid or email value)
* @return if subscription exist, returns the bot detection alert subscription, else returns a null object
* @throws APIManagementException if an error occurs when retrieving a bot detection alert subscription
*/
public BotDetectionData getBotDetectionAlertSubscription(String field, String value) throws APIManagementException {
BotDetectionData alertSubscription = null;
String query = "";
if (AlertMgtConstants.BOT_DETECTION_UUID_FIELD.equals(field)) {
query = SQLConstants.BotDataConstants.GET_ALERT_SUBSCRIPTION_BY_UUID;
}
if (AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD.equals(field)) {
query = SQLConstants.BotDataConstants.GET_ALERT_SUBSCRIPTION_BY_EMAIL;
}
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, value);
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
alertSubscription = new BotDetectionData();
alertSubscription.setUuid(resultSet.getString("UUID"));
alertSubscription.setEmail(resultSet.getString("SUBSCRIBER_ADDRESS"));
}
} catch (SQLException e) {
handleException("Failed to retrieve bot detection alert subscription of " + field + ": " + value, e);
}
return alertSubscription;
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class APIAdminImpl method retrieveBotDetectionData.
@Override
public List<BotDetectionData> retrieveBotDetectionData() throws APIManagementException {
List<BotDetectionData> botDetectionDatalist = new ArrayList<>();
String appName = AlertMgtConstants.APIM_ALERT_BOT_DETECTION_APP;
String query = SQLConstants.BotDataConstants.GET_BOT_DETECTED_DATA;
JSONObject botDataJsonObject = APIUtil.executeQueryOnStreamProcessor(appName, query);
if (botDataJsonObject != null) {
JSONArray botDataJsonArray = (JSONArray) botDataJsonObject.get("records");
if (botDataJsonArray != null && botDataJsonArray.size() != 0) {
for (Object botData : botDataJsonArray) {
JSONArray values = (JSONArray) botData;
BotDetectionData botDetectionData = new BotDetectionData();
botDetectionData.setCurrentTime((Long) values.get(0));
botDetectionData.setMessageID((String) values.get(1));
botDetectionData.setApiMethod((String) values.get(2));
botDetectionData.setHeaderSet((String) values.get(3));
botDetectionData.setMessageBody(extractBotDetectionDataContent((String) values.get(4)));
botDetectionData.setClientIp((String) values.get(5));
botDetectionDatalist.add(botDetectionData);
}
}
}
return botDetectionDatalist;
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class BotDetectionMappingUtil method fromBotDetectionModelToDTO.
/**
* Converts a list of Bot Detection Data model objects into a List DTO
*
* @param botDetectionDataList list of Bot Detection data
* @return A List DTO of converted Bot Detection data
*/
public static BotDetectionDataListDTO fromBotDetectionModelToDTO(List<BotDetectionData> botDetectionDataList) {
BotDetectionDataListDTO listDTO = new BotDetectionDataListDTO();
List<BotDetectionDataDTO> botDetectionDataDTOs = new ArrayList<>();
for (BotDetectionData botData : botDetectionDataList) {
botDetectionDataDTOs.add(fromBotDetectionModelToDTO(botData));
}
listDTO.setList(botDetectionDataDTOs);
listDTO.setCount(botDetectionDataDTOs.size());
return listDTO;
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class BotDetectionMappingUtil method fromBotDetectionModelToDTO.
/**
* Converts a single Bot Detection Data model into Bot Detection DTO
*
* @param botDetectionData Bot Detection Data model object
* @return Converted Bot Detection Data DTO object
*/
public static BotDetectionDataDTO fromBotDetectionModelToDTO(BotDetectionData botDetectionData) {
BotDetectionDataDTO botDetectionDataDTO = new BotDetectionDataDTO();
botDetectionDataDTO.setRecordedTime(botDetectionData.getCurrentTime());
botDetectionDataDTO.setMessageID(botDetectionData.getMessageID());
botDetectionDataDTO.setApiMethod(botDetectionData.getApiMethod());
botDetectionDataDTO.setHeaderSet(botDetectionData.getHeaderSet());
botDetectionDataDTO.setMessageBody(botDetectionData.getMessageBody());
botDetectionDataDTO.setClientIp(botDetectionData.getClientIp());
return botDetectionDataDTO;
}
use of org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData in project carbon-apimgt by wso2.
the class BotDetectionMappingUtil method fromAlertSubscriptionListToListDTO.
/**
* Converts a list of Bot Detection Alert Subscription model objects into a list DTO
*
* @param alertSubscriptionList list of Bot Detection Alert Subscriptions
* @return A List DTO of converted Bot Detection Alert Subscriptions
*/
public static BotDetectionAlertSubscriptionListDTO fromAlertSubscriptionListToListDTO(List<BotDetectionData> alertSubscriptionList) {
BotDetectionAlertSubscriptionListDTO listDTO = new BotDetectionAlertSubscriptionListDTO();
List<BotDetectionAlertSubscriptionDTO> alertSubscriptionDTOs = new ArrayList<>();
for (BotDetectionData alertSubscription : alertSubscriptionList) {
alertSubscriptionDTOs.add(fromAlertSubscriptionToDTO(alertSubscription));
}
listDTO.setList(alertSubscriptionDTOs);
listDTO.setCount(alertSubscriptionDTOs.size());
return listDTO;
}
Aggregations