Search in sources :

Example 41 with BlockConditions

use of org.wso2.carbon.apimgt.core.models.BlockConditions in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImpl method addBlockCondition.

@Override
public String addBlockCondition(BlockConditions blockConditions) throws APIManagementException {
    try {
        if (StringUtils.isEmpty(blockConditions.getUuid())) {
            blockConditions.setUuid(UUID.randomUUID().toString());
        }
        policyDAO.addBlockConditions(blockConditions);
        apiGateway.addBlockCondition(blockConditions);
        return blockConditions.getUuid();
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't add block condition with condition type: " + blockConditions.getConditionType() + ", condition value: " + blockConditions.getConditionValue();
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Aggregations

BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)32 Test (org.testng.annotations.Test)14 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)12 ArrayList (java.util.ArrayList)8 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)7 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)7 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)5 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)5 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 BlacklistApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl)4 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO)4 BlockingConditionListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO)4 ResultSet (java.sql.ResultSet)3