Search in sources :

Example 6 with BotDetectionData

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) PreparedStatement(java.sql.PreparedStatement)

Example 7 with BotDetectionData

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;
}
Also used : JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.simple.JSONObject)

Example 8 with BotDetectionData

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;
}
Also used : BotDetectionDataDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataDTO) ArrayList(java.util.ArrayList) BotDetectionDataListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataListDTO) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)

Example 9 with BotDetectionData

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;
}
Also used : BotDetectionDataDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataDTO)

Example 10 with BotDetectionData

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;
}
Also used : ArrayList(java.util.ArrayList) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) BotDetectionAlertSubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionListDTO) BotDetectionAlertSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO)

Aggregations

BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)9 ArrayList (java.util.ArrayList)4 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)4 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)4 BotDetectionAlertSubscriptionDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 BotDetectionAlertSubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionListDTO)2 BotDetectionDataDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataDTO)2 BotDetectionDataListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionDataListDTO)2 JsonObject (com.google.gson.JsonObject)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1