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");
}
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();
}
Aggregations