use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdPut.
/**
* Updates/adds a new Application throttle policy to the system
*
* @param id Uuid of the policy.
* @param body DTO object including the Policy meta information
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Response object response object with the updated application throttle policy resource
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingApplicationIdPut(String id, ApplicationThrottlePolicyDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.application;
if (log.isDebugEnabled()) {
log.info("Received Application Policy PUT request " + body + " with tierLevel = " + tierLevel);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
ApplicationPolicy applicationPolicy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(body);
applicationPolicy.setUuid(id);
apiMgtAdminService.updateApplicationPolicy(applicationPolicy);
return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(apiMgtAdminService.getApplicationPolicyByUuid(id))).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while updating Application Policy. policy uuid: " + id;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationThrottlePolicyToDTO.
/**
* Converts a single Application Policy model into REST API DTO
*
* @param appPolicy An Application Policy model object
* @return Converted Application policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ApplicationThrottlePolicyDTO fromApplicationThrottlePolicyToDTO(Policy appPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyDTO policyDTO = new ApplicationThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(appPolicy, policyDTO);
if (appPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(appPolicy.getDefaultQuotaPolicy()));
}
return policyDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationPolicyArrayToListDTO.
/**
* Converts an array of Application Policy objects into a List DTO
*
* @param appPolicies Array of Application Policies
* @return A List DTO of converted Application Policies
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(List<ApplicationPolicy> appPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
if (appPolicies != null) {
for (Policy policy : appPolicies) {
ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
appPolicyDTOList.add(dto);
}
}
listDTO.setCount(appPolicyDTOList.size());
listDTO.setList(appPolicyDTOList);
return listDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingApplicationPolicyIdPutTest.
@Test
public void policiesThrottlingApplicationPolicyIdPutTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
String uuid = UUID.randomUUID().toString();
ApplicationThrottlePolicyDTO dto = new ApplicationThrottlePolicyDTO();
ApplicationPolicy policy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(adminService).updateApplicationPolicy(policy);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicyByUuid(uuid);
Response response = policiesApiService.policiesThrottlingApplicationIdPut(uuid, dto, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationThrottlePolicyToDTO.
/**
* Converts a single Application Policy model into REST API DTO
*
* @param appPolicy An Application Policy model object
* @return Converted Application policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException
*/
public static ApplicationThrottlePolicyDTO fromApplicationThrottlePolicyToDTO(ApplicationPolicy appPolicy) throws UnsupportedThrottleLimitTypeException {
ApplicationThrottlePolicyDTO policyDTO = new ApplicationThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(appPolicy, policyDTO);
if (appPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(appPolicy.getDefaultQuotaPolicy()));
}
policyDTO.setType(APPLICATION_THROTTLING_POLICY_TYPE);
return policyDTO;
}
Aggregations