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