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();
}
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;
}
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;
}
Aggregations