Search in sources :

Example 46 with Condition

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

the class BlockingConditionMappingUtil method fromBlockConditionToIpConditionDTO.

/**
 * Block condition IP range details to IPConditionDTO.
 *
 * @param blockConditions blockCondition to be converted into IPConditionDTO.
 * @return IPConditionDTO Object
 */
private static IPConditionDTO fromBlockConditionToIpConditionDTO(BlockConditions blockConditions) {
    IPConditionDTO ipConditionDTO = new IPConditionDTO();
    ipConditionDTO.setStartingIP(blockConditions.getStartingIP());
    ipConditionDTO.setEndingIP(blockConditions.getEndingIP());
    return ipConditionDTO;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO)

Example 47 with Condition

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

the class CommonThrottleMappingUtil method fromJWTClaimsConditionToDTO.

/**
 * Converts a JWT Claims Condition model object into a DTO
 *
 * @param condition JWT Claims Condition model object
 * @return DTO object that was derived from JWT Claims Condition model object
 */
public static ThrottleConditionDTO fromJWTClaimsConditionToDTO(JWTClaimsCondition condition) {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.JWT_CLAIMS_CONDITION_TYPE);
    throttleConditionDTO.setJwtClaimsCondition(new JWTClaimsConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(condition, throttleConditionDTO);
    throttleConditionDTO.getJwtClaimsCondition().setClaimUrl(condition.getClaimUrl());
    throttleConditionDTO.getJwtClaimsCondition().setAttribute(condition.getAttribute());
    return throttleConditionDTO;
}
Also used : JWTClaimsConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.JWTClaimsConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 48 with Condition

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

the class CommonThrottleMappingUtil method fromDTOToJWTClaimsCondition.

/**
 * Converts a JWT Claims Condition DTO object into a model object
 *
 * @param dto JWT Claims Condition DTO object
 * @return JWT Claims Condition model object derived from JWT Claims Condition DTO
 */
public static JWTClaimsCondition fromDTOToJWTClaimsCondition(ThrottleConditionDTO dto) {
    JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
    jwtClaimsCondition = updateFieldsFromDTOToCondition(dto, jwtClaimsCondition);
    jwtClaimsCondition.setAttribute(dto.getJwtClaimsCondition().getAttribute());
    jwtClaimsCondition.setClaimUrl(dto.getJwtClaimsCondition().getClaimUrl());
    return jwtClaimsCondition;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)

Example 49 with Condition

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

the class CommonThrottleMappingUtil method fromIPConditionToDTO.

/**
 * Converts an IP Condition model object into a DTO
 *
 * @param ipCondition IP Condition model object
 * @return DTO object derived from model object
 */
public static ThrottleConditionDTO fromIPConditionToDTO(IPCondition ipCondition) throws UnsupportedThrottleConditionTypeException {
    String ipConditionType = mapIPConditionTypeFromModelToDTO(ipCondition.getType());
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    throttleConditionDTO.setIpCondition(new IPConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(ipCondition, throttleConditionDTO);
    throttleConditionDTO.getIpCondition().setIpConditionType(ipConditionType);
    throttleConditionDTO.getIpCondition().setSpecificIP(ipCondition.getSpecificIP());
    throttleConditionDTO.getIpCondition().setStartingIP(ipCondition.getStartingIP());
    throttleConditionDTO.getIpCondition().setEndingIP(ipCondition.getEndingIP());
    return throttleConditionDTO;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 50 with Condition

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

the class CommonThrottleMappingUtil method fromConditionalGroupDTOToPipeline.

/**
 * Converts a single Conditional Group DTO into a Pipeline object
 *
 * @param dto Conditional Group DTO
 * @return Derived Pipeline object from Conditional Group DTO
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 * @throws UnsupportedThrottleConditionTypeException - If error occurs
 */
public static Pipeline fromConditionalGroupDTOToPipeline(ConditionalGroupDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    Pipeline pipeline = new Pipeline();
    pipeline.setDescription(dto.getDescription());
    pipeline.setEnabled(true);
    pipeline.setQuotaPolicy(fromDTOToQuotaPolicy(dto.getLimit()));
    List<Condition> conditions = fromDTOListToConditionList(dto.getConditions());
    pipeline.setConditions(conditions);
    return pipeline;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) Condition(org.wso2.carbon.apimgt.core.models.policy.Condition) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline)

Aggregations

BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)18 Test (org.testng.annotations.Test)16 PreparedStatement (java.sql.PreparedStatement)12 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)10 ResultSet (java.sql.ResultSet)9 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)9 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)8 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)8 QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)8 ArrayList (java.util.ArrayList)7 Condition (org.wso2.carbon.apimgt.core.models.policy.Condition)7 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)7 Connection (java.sql.Connection)6 SQLException (java.sql.SQLException)6 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)6 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)6 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)4 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)4