Search in sources :

Example 6 with BlockingConditionListDTO

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

the class BlockingConditionMappingUtil method fromBlockConditionListToListDTO.

/**
 * Converts a List of Block Condition in to REST API LIST DTO Object
 *
 * @param blockConditionList A List of Block Conditions
 * @return REST API List DTO object derived from Block Condition list
 */
public static BlockingConditionListDTO fromBlockConditionListToListDTO(List<BlockConditionsDTO> blockConditionList) throws ParseException {
    BlockingConditionListDTO listDTO = new BlockingConditionListDTO();
    List<BlockingConditionDTO> blockingConditionDTOList = new ArrayList<>();
    if (blockConditionList != null) {
        for (BlockConditionsDTO blockCondition : blockConditionList) {
            BlockingConditionDTO dto = fromBlockingConditionToDTO(blockCondition);
            blockingConditionDTOList.add(dto);
        }
    }
    listDTO.setCount(blockingConditionDTOList.size());
    listDTO.setList(blockingConditionDTOList);
    return listDTO;
}
Also used : BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BlockingConditionListDTO) BlockConditionsDTO(org.wso2.carbon.apimgt.api.model.BlockConditionsDTO) ArrayList(java.util.ArrayList) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BlockingConditionDTO)

Example 7 with BlockingConditionListDTO

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

the class BlacklistApiServiceImpl method blacklistGet.

@Override
public Response blacklistGet(String accept, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        List<BlockConditions> blockConditionsList = apiMgtAdminService.getBlockConditions();
        BlockingConditionListDTO blockingConditionListDTO = MappingUtil.fromBlockConditionListToListDTO(blockConditionsList);
        return Response.ok(blockingConditionListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving block conditions";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(errorDTO).build();
    }
}
Also used : BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Example 8 with BlockingConditionListDTO

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

the class BlockingConditionMappingUtil method fromBlockConditionListToListDTO.

/**
 * Converts a List of Block Condition in to REST API LIST DTO Object.
 *
 * @param blockConditionList A List of Block Conditions
 * @return REST API List DTO object derived from Block Condition list
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static BlockingConditionListDTO fromBlockConditionListToListDTO(List<BlockConditions> blockConditionList) throws UnsupportedThrottleLimitTypeException {
    BlockingConditionListDTO listDTO = new BlockingConditionListDTO();
    List<BlockingConditionDTO> blockingConditionDTOList = new ArrayList<>();
    if (blockConditionList != null) {
        for (BlockConditions blockCondition : blockConditionList) {
            BlockingConditionDTO dto = fromBlockingConditionToDTO(blockCondition);
            blockingConditionDTOList.add(dto);
        }
    }
    listDTO.setCount(blockingConditionDTOList.size());
    listDTO.setList(blockingConditionDTOList);
    return listDTO;
}
Also used : BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionListDTO) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ArrayList(java.util.ArrayList) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)

Example 9 with BlockingConditionListDTO

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

the class ThrottlingApiServiceImpl method throttlingDenyPoliciesGet.

/**
 * Retrieves all Block Conditions
 *
 * @param accept          Accept header value
 * @return All matched block conditions to the given request
 */
@Override
public Response throttlingDenyPoliciesGet(String accept, MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        List<BlockConditionsDTO> blockConditions = apiProvider.getBlockConditions();
        BlockingConditionListDTO listDTO = BlockingConditionMappingUtil.fromBlockConditionListToListDTO(blockConditions);
        return Response.ok().entity(listDTO).build();
    } catch (APIManagementException | ParseException e) {
        String errorMessage = "Error while retrieving Block Conditions";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : BlockConditionsDTO(org.wso2.carbon.apimgt.api.model.BlockConditionsDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ParseException(org.json.simple.parser.ParseException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)7 ArrayList (java.util.ArrayList)6 BlockingConditionListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO)4 Test (org.testng.annotations.Test)2 BlockConditionsDTO (org.wso2.carbon.apimgt.api.model.BlockConditionsDTO)2 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 BlockingConditionListDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionListDTO)2 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)2 Response (javax.ws.rs.core.Response)1 ParseException (org.json.simple.parser.ParseException)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)1 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)1 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)1 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BlockingConditionDTO)1 BlockingConditionListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BlockingConditionListDTO)1