Search in sources :

Example 1 with BotDetectionAlertSubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO 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();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) BotDetectionAlertSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO)

Example 2 with BotDetectionAlertSubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO 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)

Example 3 with BotDetectionAlertSubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO in project carbon-apimgt by wso2.

the class BotDetectionMappingUtil method fromAlertSubscriptionToDTO.

/**
 * Converts a single Bot Detection Alert Subscription model into a Bot Detection Alert Subscription DTO
 *
 * @param alertSubscription Bot Detection Alert Subscription model object
 * @return Converted Bot Detection Alert Subscription DTO object
 */
public static BotDetectionAlertSubscriptionDTO fromAlertSubscriptionToDTO(BotDetectionData alertSubscription) {
    BotDetectionAlertSubscriptionDTO alertSubscriptionDTO = new BotDetectionAlertSubscriptionDTO();
    alertSubscriptionDTO.setUuid(alertSubscription.getUuid());
    alertSubscriptionDTO.setEmail(alertSubscription.getEmail());
    return alertSubscriptionDTO;
}
Also used : BotDetectionAlertSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO)

Aggregations

BotDetectionAlertSubscriptionDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO)3 BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)2 ArrayList (java.util.ArrayList)1 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)1 BotDetectionAlertSubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionListDTO)1