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;
}
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;
}
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;
}
Aggregations