Search in sources :

Example 1 with OperationPolicyDataListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataListDTO in project carbon-apimgt by wso2.

the class OperationPolicyMappingUtil method fromOperationPolicyDataListToDTO.

public static OperationPolicyDataListDTO fromOperationPolicyDataListToDTO(List<OperationPolicyData> policyDataList, int offset, int limit) {
    List<OperationPolicyDataDTO> operationPolicyList = new ArrayList<>();
    if (policyDataList == null) {
        policyDataList = new ArrayList<>();
    }
    int size = policyDataList.size();
    int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = Math.min(offset + limit - 1, size - 1);
    for (int i = start; i <= end; i++) {
        operationPolicyList.add(fromOperationPolicyDataToDTO(policyDataList.get(i)));
    }
    PaginationDTO paginationDTO = new PaginationDTO();
    paginationDTO.setLimit(limit);
    paginationDTO.setOffset(offset);
    paginationDTO.setTotal(size);
    OperationPolicyDataListDTO dataListDTO = new OperationPolicyDataListDTO();
    dataListDTO.setList(operationPolicyList);
    dataListDTO.setCount(operationPolicyList.size());
    dataListDTO.setPagination(paginationDTO);
    return dataListDTO;
}
Also used : OperationPolicyDataListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataListDTO) ArrayList(java.util.ArrayList) PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO) OperationPolicyDataDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataDTO)

Example 2 with OperationPolicyDataListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataListDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method getAllAPISpecificOperationPolicies.

/**
 * Get the list of all API specific operation policies for a given API
 *
 * @param apiId          API UUID
 * @param limit          max number of records returned
 * @param offset         starting index
 * @param messageContext message context
 * @return A list of operation policies available for the API
 */
@Override
public Response getAllAPISpecificOperationPolicies(String apiId, Integer limit, Integer offset, String query, MessageContext messageContext) {
    try {
        validateAPIExistence(apiId);
        limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
        offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        // Lightweight API specific operation policy includes the policy ID and the policy specification.
        // Since policy definition is bit bulky, we don't query the definition unnecessarily.
        List<OperationPolicyData> sharedOperationPolicyLIst = apiProvider.getAllAPISpecificOperationPolicies(apiId, organization);
        OperationPolicyDataListDTO policyListDTO = OperationPolicyMappingUtil.fromOperationPolicyDataListToDTO(sharedOperationPolicyLIst, offset, limit);
        return Response.ok().entity(policyListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving the list of all API specific operation policies." + e.getMessage();
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    } catch (Exception e) {
        RestApiUtil.handleInternalServerError("An error has occurred while getting the list of API specific " + " operation policies", e, log);
    }
    return null;
}
Also used : OperationPolicyData(org.wso2.carbon.apimgt.api.model.OperationPolicyData) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) OperationPolicyDataListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataListDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) JSONException(org.json.JSONException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SdkClientException(com.amazonaws.SdkClientException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) URISyntaxException(java.net.URISyntaxException) BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException) CryptoException(org.wso2.carbon.core.util.CryptoException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) MonetizationException(org.wso2.carbon.apimgt.api.MonetizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(org.json.simple.parser.ParseException) MalformedURLException(java.net.MalformedURLException)

Example 3 with OperationPolicyDataListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataListDTO in project carbon-apimgt by wso2.

the class OperationPoliciesApiServiceImpl method getAllCommonOperationPolicies.

/**
 * Get the list of all common operation policies for a given organization
 *
 * @param limit          max number of records returned
 * @param offset         starting index
 * @param messageContext message context
 * @return A list of operation policies available for the API
 */
@Override
public Response getAllCommonOperationPolicies(Integer limit, Integer offset, String query, MessageContext messageContext) throws APIManagementException {
    try {
        limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
        offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        // Since policy definition is bit bulky, we don't query the definition unnecessarily.
        List<OperationPolicyData> commonOperationPolicyLIst = apiProvider.getAllCommonOperationPolicies(organization);
        OperationPolicyDataListDTO policyListDTO = OperationPolicyMappingUtil.fromOperationPolicyDataListToDTO(commonOperationPolicyLIst, offset, limit);
        return Response.ok().entity(policyListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving the list of all common operation policies." + e.getMessage();
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    } catch (Exception e) {
        RestApiUtil.handleInternalServerError("An error has occurred while getting the list of all common " + " operation policies", e, log);
    }
    return null;
}
Also used : OperationPolicyData(org.wso2.carbon.apimgt.api.model.OperationPolicyData) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) OperationPolicyDataListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataListDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Aggregations

OperationPolicyDataListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataListDTO)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)2 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 OperationPolicyData (org.wso2.carbon.apimgt.api.model.OperationPolicyData)2 SdkClientException (com.amazonaws.SdkClientException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 ParseException (org.json.simple.parser.ParseException)1 APIMgtResourceAlreadyExistsException (org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException)1 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)1 MonetizationException (org.wso2.carbon.apimgt.api.MonetizationException)1 APIImportExportException (org.wso2.carbon.apimgt.impl.importexport.APIImportExportException)1 OperationPolicyDataDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.OperationPolicyDataDTO)1 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)1