Search in sources :

Example 1 with AlertTypeDTO

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

the class AlertMgtUtils method alertTypesToMap.

/**
 * Converts a list of AlertTypeDTOs to HashMap.
 *
 * @param alertTypes : The AlertTypeDTO list
 * @return A HashMap of the alert types
 */
static Map<String, String> alertTypesToMap(List<AlertTypeDTO> alertTypes) {
    List<Integer> alertTypeIds = new ArrayList<>();
    List<String> alertTypeNames = new ArrayList<>();
    Map<String, String> alertTypesMap = new HashMap<>();
    for (AlertTypeDTO alertTypeDTO : alertTypes) {
        alertTypeIds.add(alertTypeDTO.getId());
        alertTypeNames.add(alertTypeDTO.getName());
    }
    alertTypesMap.put("ids", StringUtils.join(alertTypeIds, ","));
    alertTypesMap.put("names", StringUtils.join(alertTypeNames, ","));
    return alertTypesMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlertTypeDTO(org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO)

Example 2 with AlertTypeDTO

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

the class AlertsMappingUtil method fromAlertTypeToAlertTypeDTO.

/**
 * Map AlertType to AlertTypeDTO
 *
 * @param alert
 * @return
 */
public static AlertTypeDTO fromAlertTypeToAlertTypeDTO(org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO alert) {
    AlertTypeDTO alertTypeDTO = new AlertTypeDTO();
    alertTypeDTO.setId(alert.getId().toString());
    alertTypeDTO.setName(alert.getName());
    return alertTypeDTO;
}
Also used : AlertTypeDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertTypeDTO)

Example 3 with AlertTypeDTO

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

the class AlertMgtUtils method toAlertTypeDTO.

/**
 * Convert the alert types to alert type dtos.
 *
 * @param alertTypes: The alert types map.
 * @return A list of AlertTypeDTOs.
 */
public static List<AlertTypeDTO> toAlertTypeDTO(Map<Integer, String> alertTypes) {
    List<AlertTypeDTO> alertTypeDTOList = new ArrayList<>();
    if (alertTypes != null) {
        for (Map.Entry entry : alertTypes.entrySet()) {
            AlertTypeDTO alertTypeDTO = new AlertTypeDTO();
            alertTypeDTO.setId((Integer) entry.getKey());
            alertTypeDTO.setName(entry.getValue().toString());
            alertTypeDTOList.add(alertTypeDTO);
        }
    }
    return alertTypeDTOList;
}
Also used : ArrayList(java.util.ArrayList) AlertTypeDTO(org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with AlertTypeDTO

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

the class AlertSubscriptionsApiServiceImpl method subscribeToAlerts.

/**
 * Subscribes the logged in user for requested admin alert types
 *
 * @param body
 * @param messageContext
 * @return
 */
@Override
public Response subscribeToAlerts(AlertsSubscriptionDTO body, MessageContext messageContext) {
    // Validate for empty list of emails
    List<String> emailsList = body.getEmailList();
    if (emailsList == null || emailsList.size() == 0) {
        RestApiUtil.handleBadRequest("Email list cannot be empty", log);
    }
    // Validate for empty list of alerts
    List<AlertTypeDTO> subscribingAlertDTOs = body.getAlerts();
    if (subscribingAlertDTOs == null || subscribingAlertDTOs.size() == 0) {
        RestApiUtil.handleBadRequest("Alert list should not be empty", log);
    }
    String fullyQualifiedUsername = getFullyQualifiedUsername(RestApiCommonUtil.getLoggedInUsername());
    try {
        AdminAlertConfigurator adminAlertConfigurator = (AdminAlertConfigurator) AlertConfigManager.getInstance().getAlertConfigurator(AlertMgtConstants.ADMIN_DASHBOARD_AGENT);
        // Retrieve the supported alert types
        List<org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO> supportedAlertTypes = adminAlertConfigurator.getSupportedAlertTypes();
        Map<String, org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO> supportedAlertTypesMap = supportedAlertTypes.stream().collect(Collectors.toMap(org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO::getName, alertType -> alertType));
        List<org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO> alertTypesToSubscribe = new ArrayList<>();
        // Validate the request alerts against supported alert types
        for (AlertTypeDTO subscribingAlertDTO : subscribingAlertDTOs) {
            if (supportedAlertTypesMap.containsKey(subscribingAlertDTO.getName())) {
                alertTypesToSubscribe.add(supportedAlertTypesMap.get(subscribingAlertDTO.getName()));
            } else {
                RestApiUtil.handleBadRequest("Unsupported alert type : " + subscribingAlertDTO.getName() + " is provided.", log);
                return null;
            }
        }
        adminAlertConfigurator.subscribe(fullyQualifiedUsername, emailsList, alertTypesToSubscribe);
        AlertsSubscriptionDTO subscribedAlerts = new AlertsSubscriptionDTO();
        subscribedAlerts.setAlerts(AlertsMappingUtil.fromAlertTypesListToAlertTypeDTOList(alertTypesToSubscribe));
        subscribedAlerts.setEmailList(emailsList);
        return Response.status(Response.Status.OK).entity(subscribedAlerts).build();
    } catch (AlertManagementException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity("API Manager analytics is not Enabled").build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while subscribing to alert types", e, log);
    }
    return null;
}
Also used : MultitenantConstants(org.wso2.carbon.utils.multitenancy.MultitenantConstants) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) AlertMgtConstants(org.wso2.carbon.apimgt.impl.alertmgt.AlertMgtConstants) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) AlertsSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertsSubscriptionDTO) RestApiCommonUtil(org.wso2.carbon.apimgt.rest.api.common.RestApiCommonUtil) AlertsMappingUtil(org.wso2.carbon.apimgt.rest.api.admin.v1.utils.mappings.AlertsMappingUtil) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) AlertConfigManager(org.wso2.carbon.apimgt.impl.alertmgt.AlertConfigManager) Map(java.util.Map) AlertManagementException(org.wso2.carbon.apimgt.impl.alertmgt.exception.AlertManagementException) AdminAlertConfigurator(org.wso2.carbon.apimgt.impl.alertmgt.AdminAlertConfigurator) ExceptionCodes(org.wso2.carbon.apimgt.api.ExceptionCodes) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) RestApiUtil(org.wso2.carbon.apimgt.rest.api.util.utils.RestApiUtil) Collectors(java.util.stream.Collectors) AlertSubscriptionsApiService(org.wso2.carbon.apimgt.rest.api.admin.v1.AlertSubscriptionsApiService) BotDetectionAlertSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionDTO) List(java.util.List) BotDetectionAlertSubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BotDetectionAlertSubscriptionListDTO) Response(javax.ws.rs.core.Response) AlertTypeDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertTypeDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) BotDetectionMappingUtil(org.wso2.carbon.apimgt.rest.api.admin.v1.utils.mappings.BotDetectionMappingUtil) AlertsSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertsSubscriptionDTO) ArrayList(java.util.ArrayList) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) AlertManagementException(org.wso2.carbon.apimgt.impl.alertmgt.exception.AlertManagementException) AlertTypeDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertTypeDTO) AdminAlertConfigurator(org.wso2.carbon.apimgt.impl.alertmgt.AdminAlertConfigurator)

Example 5 with AlertTypeDTO

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

the class AlertsMappingUtil method fromAlertTypesListToAlertTypeListDTO.

/**
 * Map AlertTypeDTO list to AlertTypesListDTO
 *
 * @param alertTypes
 * @return
 */
public static AlertTypesListDTO fromAlertTypesListToAlertTypeListDTO(List<org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO> alertTypes) {
    AlertTypesListDTO alertTypesListDTO = new AlertTypesListDTO();
    List<AlertTypeDTO> alertTypeDTOList = fromAlertTypesListToAlertTypeDTOList(alertTypes);
    alertTypesListDTO.setAlerts(alertTypeDTOList);
    alertTypesListDTO.setCount(alertTypeDTOList.size());
    return alertTypesListDTO;
}
Also used : AlertTypeDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertTypeDTO) AlertTypesListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertTypesListDTO)

Aggregations

ArrayList (java.util.ArrayList)3 AlertTypeDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AlertTypeDTO)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AlertTypeDTO (org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Response (javax.ws.rs.core.Response)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)1 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 ExceptionCodes (org.wso2.carbon.apimgt.api.ExceptionCodes)1 BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)1 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)1 AdminAlertConfigurator (org.wso2.carbon.apimgt.impl.alertmgt.AdminAlertConfigurator)1 AlertConfigManager (org.wso2.carbon.apimgt.impl.alertmgt.AlertConfigManager)1 AlertMgtConstants (org.wso2.carbon.apimgt.impl.alertmgt.AlertMgtConstants)1