Search in sources :

Example 76 with Condition

use of org.wso2.carbon.user.core.model.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromConditionToDTO.

/**
 * Converts a Throttle Condition model object into a DTO
 *
 * @param condition Throttle condition model object
 * @return Derived DTO object from the model object
 * @throws UnsupportedThrottleConditionTypeException
 */
public static // .................
ThrottleConditionDTO fromConditionToDTO(// .................
Condition condition) throws UnsupportedThrottleConditionTypeException {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setInvertCondition(condition.isInvertCondition());
    if (condition instanceof IPCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.IPCONDITION);
        throttleConditionDTO.setIpCondition(fromIPConditionToDTO((IPCondition) condition));
    } else if (condition instanceof HeaderCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.HEADERCONDITION);
        throttleConditionDTO.setHeaderCondition(fromHeaderConditionToDTO((HeaderCondition) condition));
    } else if (condition instanceof QueryParameterCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.QUERYPARAMETERCONDITION);
        throttleConditionDTO.setQueryParameterCondition(fromQueryParameterConditionToDTO((QueryParameterCondition) condition));
    } else if (condition instanceof JWTClaimsCondition) {
        throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.JWTCLAIMSCONDITION);
        throttleConditionDTO.setJwtClaimsCondition(fromJWTClaimsConditionToDTO((JWTClaimsCondition) condition));
    } else {
        String msg = "Throttle Condition type " + condition.getClass().getName() + " is not supported";
        throw new UnsupportedThrottleConditionTypeException(msg);
    }
    return throttleConditionDTO;
}
Also used : IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) UnsupportedThrottleConditionTypeException(org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)

Example 77 with Condition

use of org.wso2.carbon.user.core.model.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOToHeaderCondition.

/**
 * Converts a Header Condition DTO object into a model object
 *
 * @param dto             Header Condition DTO object
 * @param invertCondition Invert condition relevant to the DTO
 * @return Header Condition model object derived from Header Condition DTO
 */
public static HeaderCondition fromDTOToHeaderCondition(HeaderConditionDTO dto, boolean invertCondition) {
    HeaderCondition headerCondition = new HeaderCondition();
    headerCondition.setConditionEnabled(Boolean.TRUE.toString());
    headerCondition.setInvertCondition(invertCondition);
    headerCondition.setHeader(dto.getHeaderName());
    headerCondition.setValue(dto.getHeaderValue());
    return headerCondition;
}
Also used : HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)

Example 78 with Condition

use of org.wso2.carbon.user.core.model.Condition in project carbon-apimgt by wso2.

the class APIMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a APIProductListDTO object given pagination parameters and url parameters.
 *
 * @param apiProductListDTO a APIProductListDTO object
 * @param query             search condition
 * @param limit             max number of objects returned
 * @param offset            starting index
 * @param size              max offset
 */
public static void setPaginationParams(APIProductListDTO apiProductListDTO, String query, int offset, int limit, int size) {
    // acquiring pagination parameters and setting pagination urls
    Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
    String paginatedPrevious = "";
    String paginatedNext = "";
    if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
        paginatedPrevious = RestApiCommonUtil.getAPIProductPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), query);
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getAPIProductPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
    }
    PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
    apiProductListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)

Example 79 with Condition

use of org.wso2.carbon.user.core.model.Condition in project carbon-apimgt by wso2.

the class APIMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a APIListDTO object given pagination parameters and url parameters.
 *
 * @param apiListDTO a APIListDTO object
 * @param query      search condition
 * @param limit      max number of objects returned
 * @param offset     starting index
 * @param size       max offset
 */
public static void setPaginationParams(Object apiListDTO, String query, int offset, int limit, int size) {
    // acquiring pagination parameters and setting pagination urls
    Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
    String paginatedPrevious = "";
    String paginatedNext = "";
    if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
        paginatedPrevious = RestApiCommonUtil.getAPIPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), query);
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getAPIPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
    }
    PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
    ((APIListDTO) apiListDTO).setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO) APIListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO)

Example 80 with Condition

use of org.wso2.carbon.user.core.model.Condition in project carbon-apimgt by wso2.

the class MediationPoliciesApiServiceImpl method getGlobalMediationPolicyContent.

/**
 * Returns content of a global Mediation policy
 *
 * @param mediationPolicyId       search condition
 * @param ifNoneMatch If-None-Match header value
 * @return Matched global mediation policies for given search condition
 */
@Override
public Response getGlobalMediationPolicyContent(String mediationPolicyId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
    String username = RestApiCommonUtil.getLoggedInUsername();
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
    try {
        // Get registry resource correspond to identifier
        Resource mediationResource = apiProvider.getCustomMediationResourceFromUuid(mediationPolicyId);
        if (mediationResource != null) {
            // get the registry resource path
            String resource = mediationResource.getPath();
            resource = RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + resource;
            Map<String, Object> mediationPolicyResourceMap = APIUtil.getDocument(username, resource, tenantDomain);
            Object fileDataStream = mediationPolicyResourceMap.get(APIConstants.DOCUMENTATION_RESOURCE_MAP_DATA);
            Object contentType = mediationPolicyResourceMap.get(APIConstants.DOCUMENTATION_RESOURCE_MAP_CONTENT_TYPE);
            contentType = contentType == null ? RestApiConstants.APPLICATION_OCTET_STREAM : contentType;
            String name = mediationPolicyResourceMap.get(APIConstants.DOCUMENTATION_RESOURCE_MAP_NAME).toString();
            return Response.ok(fileDataStream).header(RestApiConstants.HEADER_CONTENT_TYPE, contentType).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=\"" + name + "\"").build();
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving global mediation policies";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
        return null;
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.api.Resource) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

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