Search in sources :

Example 56 with Condition

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

the class CommonThrottleMappingUtilTestCase method fromSpecificIPConditionDtoToIPConditionModelTest.

@Test(description = "Convert IP specific IPCondition DTO to IPCondition Model object")
public void fromSpecificIPConditionDtoToIPConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    IPConditionDTO ipConditionDTO = new IPConditionDTO();
    ipConditionDTO.setIpConditionType(PolicyConstants.IP_SPECIFIC_TYPE);
    ipConditionDTO.setSpecificIP("10.100.0.168");
    throttleConditionDTO.setIpCondition(ipConditionDTO);
    IPCondition condition = (IPCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    Assert.assertNotNull(condition.getCondition());
    assertEquals(condition.getSpecificIP(), "10.100.0.168");
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) Test(org.testng.annotations.Test)

Example 57 with Condition

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

the class ApisApiServiceImpl method apisGet.

/**
 * Retrieves APIs qualifying under given search condition
 *
 * @param limit       maximum number of APIs returns
 * @param offset      starting index
 * @param labels      Labels of the store for which the apis need to be retrieved
 * @param query       search condition
 * @param ifNoneMatch If-None-Match header value
 * @param request     msf4j request object
 * @return matched APIs for the given search condition
 */
@Override
public Response apisGet(Integer limit, Integer offset, String labels, String query, String ifNoneMatch, Request request) throws NotFoundException {
    List<API> apisResult = null;
    APIListDTO apiListDTO = null;
    try {
        String username = RestApiUtil.getLoggedInUsername(request);
        APIStore apiStore = RestApiUtil.getConsumer(username);
        List<String> labelList = new ArrayList<>();
        if (labels != null) {
            labelList = Arrays.asList(labels.split(","));
        }
        apisResult = apiStore.searchAPIsByStoreLabels(query, offset, limit, labelList);
        // convert API
        apiListDTO = APIMappingUtil.toAPIListDTO(apisResult);
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving APIs ";
        HashMap<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.API_NAME, query);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
    return Response.ok().entity(apiListDTO).build();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore)

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