use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingPoliciesApplicationPolicyIdGet.
/**
* Get a specific Application Policy by its uuid
*
* @param policyId uuid of the policy
* @return Matched Application Throttle Policy by the given name
*/
@Override
public Response throttlingPoliciesApplicationPolicyIdGet(String policyId, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String username = RestApiCommonUtil.getLoggedInUsername();
// This will give PolicyNotFoundException if there's no policy exists with UUID
ApplicationPolicy appPolicy = apiProvider.getApplicationPolicyByUUID(policyId);
if (!RestApiAdminUtils.isPolicyAccessibleToUser(username, appPolicy)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_APP_POLICY, policyId, log);
}
ApplicationThrottlePolicyDTO policyDTO = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(appPolicy);
return Response.ok().entity(policyDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APP_POLICY, policyId, e, log);
} else {
String errorMessage = "Error while retrieving Application level policy: " + policyId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
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;
}
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
*/
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(ApplicationPolicy[] appPolicies) throws UnsupportedThrottleLimitTypeException {
ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
if (appPolicies != null) {
for (ApplicationPolicy 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 ApplicationThrottlePolicyMappingUtil method fromApplicationThrottlePolicyDTOToModel.
/**
* Converts a single Application Policy DTO into a model object
*
* @param dto Application Policy DTO Object
* @return Converted Application Policy Model object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ApplicationPolicy fromApplicationThrottlePolicyDTOToModel(ApplicationThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException {
ApplicationPolicy appPolicy = new ApplicationPolicy(dto.getPolicyName());
appPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, appPolicy);
if (dto.getDefaultLimit() != null) {
appPolicy.setDefaultQuotaPolicy(CommonThrottleMappingUtil.fromDTOToQuotaPolicy(dto.getDefaultLimit()));
}
return appPolicy;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdGet.
/**
* Returns a matching Application policy for the given policy id @{policyId}
*
* @param id Uuid of the Application policy
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object Response with matching {@link ApplicationThrottlePolicyDTO} object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingApplicationIdGet(String id, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.info("Received Application Policy Get request. Policy uuid: " + id);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
Policy applicationPolicy = apiMgtAdminService.getApplicationPolicyByUuid(id);
return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(applicationPolicy)).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting Application Policy. policy uuid: " + id;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations