Search in sources :

Example 71 with Condition

use of org.wso2.carbon.identity.configuration.mgt.core.search.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
 * @throws UnsupportedThrottleConditionTypeException
 */
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 : IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) Condition(org.wso2.carbon.apimgt.api.model.policy.Condition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) Pipeline(org.wso2.carbon.apimgt.api.model.policy.Pipeline)

Example 72 with Condition

use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOToQueryParameterCondition.

/**
 * Converts a Query Parameter Condition DTO object into a model object
 *
 * @param dto             Query Parameter Condition DTO object
 * @param invertCondition Invert condition relevant to the DTO
 * @return Query Parameter Condition model object derived from Query Parameter Condition DTO
 */
public static QueryParameterCondition fromDTOToQueryParameterCondition(QueryParameterConditionDTO dto, boolean invertCondition) {
    QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
    queryParameterCondition.setConditionEnabled(Boolean.TRUE.toString());
    queryParameterCondition.setInvertCondition(invertCondition);
    queryParameterCondition.setParameter(dto.getParameterName());
    queryParameterCondition.setValue(dto.getParameterValue());
    return queryParameterCondition;
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)

Example 73 with Condition

use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromHeaderConditionToDTO.

/**
 * Converts a Header Condition model object into a DTO
 *
 * @param headerCondition Header Condition model object
 * @return DTO object that was derived from Header Condition model object
 */
public static HeaderConditionDTO fromHeaderConditionToDTO(HeaderCondition headerCondition) {
    HeaderConditionDTO dto = new HeaderConditionDTO();
    dto.setHeaderName(headerCondition.getHeaderName());
    dto.setHeaderValue(headerCondition.getValue());
    return dto;
}
Also used : HeaderConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.HeaderConditionDTO)

Example 74 with Condition

use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOListToConditionList.

/**
 * Converts a list of Throttle Condition DTOs into a list of Condition model objects
 *
 * @param throttleConditionDTOs list of Throttle Condition DTOs
 * @return Derived list of Condition model objects from Throttle Condition DTOs
 * @throws UnsupportedThrottleConditionTypeException
 */
public static List<Condition> fromDTOListToConditionList(List<ThrottleConditionDTO> throttleConditionDTOs) throws UnsupportedThrottleConditionTypeException {
    List<Condition> conditions = new ArrayList<>();
    String errorMessage;
    if (throttleConditionDTOs != null) {
        for (ThrottleConditionDTO dto : throttleConditionDTOs) {
            ThrottleConditionDTO.TypeEnum conditionType = dto.getType();
            if (conditionType != null) {
                switch(conditionType) {
                    case HEADERCONDITION:
                        {
                            if (dto.getHeaderCondition() != null) {
                                conditions.add(fromDTOToHeaderCondition(dto.getHeaderCondition(), dto.isInvertCondition()));
                            } else {
                                errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.HEADERCONDITION) + dto.toString();
                                throw new UnsupportedThrottleConditionTypeException(errorMessage);
                            }
                            break;
                        }
                    case IPCONDITION:
                        {
                            if (dto.getIpCondition() != null) {
                                conditions.add(fromDTOToIPCondition(dto.getIpCondition(), dto.isInvertCondition()));
                            } else {
                                errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.IPCONDITION) + dto.toString();
                                throw new UnsupportedThrottleConditionTypeException(errorMessage);
                            }
                            break;
                        }
                    case QUERYPARAMETERCONDITION:
                        {
                            if (dto.getQueryParameterCondition() != null) {
                                conditions.add(fromDTOToQueryParameterCondition(dto.getQueryParameterCondition(), dto.isInvertCondition()));
                            } else {
                                errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.QUERYPARAMETERCONDITION) + dto.toString();
                                throw new UnsupportedThrottleConditionTypeException(errorMessage);
                            }
                            break;
                        }
                    case JWTCLAIMSCONDITION:
                        {
                            if (dto.getJwtClaimsCondition() != null) {
                                conditions.add(fromDTOToJWTClaimsCondition(dto.getJwtClaimsCondition(), dto.isInvertCondition()));
                            } else {
                                errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.JWTCLAIMSCONDITION) + dto.toString();
                                throw new UnsupportedThrottleConditionTypeException(errorMessage);
                            }
                            break;
                        }
                    default:
                        return null;
                }
            } else {
                errorMessage = "Condition item 'type' property has not been specified\n" + dto.toString();
                throw new UnsupportedThrottleConditionTypeException(errorMessage);
            }
        }
    }
    return conditions;
}
Also used : IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) Condition(org.wso2.carbon.apimgt.api.model.policy.Condition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) ArrayList(java.util.ArrayList) UnsupportedThrottleConditionTypeException(org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO)

Example 75 with Condition

use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOToIPCondition.

/**
 * Converts a IP Condition DTO object into a model object
 *
 * @param dto             IP Condition DTO object
 * @param invertCondition Invert condition relevant to the DTO
 * @return IP Condition model object derived from DTO
 */
public static IPCondition fromDTOToIPCondition(IPConditionDTO dto, boolean invertCondition) {
    String ipConditionType = mapIPConditionTypeFromDTOToModel(dto.getIpConditionType());
    IPCondition ipCondition = new IPCondition(ipConditionType);
    ipCondition.setConditionEnabled(Boolean.TRUE.toString());
    ipCondition.setInvertCondition(invertCondition);
    ipCondition.setSpecificIP(dto.getSpecificIP());
    ipCondition.setStartingIP(dto.getStartingIP());
    ipCondition.setEndingIP(dto.getEndingIP());
    return ipCondition;
}
Also used : IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition)

Aggregations

ArrayList (java.util.ArrayList)43 HashMap (java.util.HashMap)40 Test (org.testng.annotations.Test)34 Test (org.junit.Test)32 PreparedStatement (java.sql.PreparedStatement)29 List (java.util.List)28 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)26 ConditionDto (org.wso2.carbon.apimgt.impl.dto.ConditionDto)26 MessageContext (org.apache.synapse.MessageContext)25 ResultSet (java.sql.ResultSet)24 Map (java.util.Map)24 SQLException (java.sql.SQLException)22 Connection (java.sql.Connection)21 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)18 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)18 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)15 JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)15 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)15 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)15 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)15