use of org.wso2.carbon.apimgt.api.model.Mediation in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesMediationGet.
/**
* Returns list of global Mediation policies
*
* @param limit maximum number of mediation returns
* @param offset starting index
* @param query search condition
* @param accept accept header value
* @return Matched global mediation policies for given search condition
*/
@Override
public Response policiesMediationGet(Integer limit, Integer offset, String query, String accept, MessageContext messageContext) {
// pre-processing
// setting default limit and offset values if they are not set
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
List<Mediation> mediationList = apiProvider.getAllGlobalMediationPolicies();
MediationListDTO mediationListDTO = MediationMappingUtil.fromMediationListToDTO(mediationList, offset, limit);
return Response.ok().entity(mediationListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving all global mediation policies";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
return null;
}
}
use of org.wso2.carbon.apimgt.api.model.Mediation in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesMediationMediationPolicyIdDelete.
/**
* Deletes an existing global mediation policy
*
* @param mediationPolicyId Uuid of mediation policy resource
* @return 200 response if deleted successfully
*/
@Override
public Response policiesMediationMediationPolicyIdDelete(String mediationPolicyId, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
// Delete given global mediation policy
boolean deleteState = apiProvider.deleteGlobalMediationPolicy(mediationPolicyId);
if (deleteState) {
return Response.ok().build();
} else {
// If registry resource not found
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_POLICY, mediationPolicyId, log);
}
} catch (APIManagementException e) {
String errorMessage = "Error while deleting the global mediation policy with uuid " + mediationPolicyId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Mediation in project carbon-apimgt by wso2.
the class MediationMappingUtil method fromMediationListToDTO.
/**
* Converts a List mediation objects into a DTO
*
* @param mediation a list of mediation objects
* @param limit max number of objects returned
* @param offset starting index
* @return TierListDTO object containing TierDTOs
*/
public static MediationListDTO fromMediationListToDTO(List<Mediation> mediation, int offset, int limit) {
MediationListDTO mediationListDTO = new MediationListDTO();
List<MediationInfoDTO> mediationDTOs = mediationListDTO.getList();
if (mediationDTOs == null) {
mediationDTOs = new ArrayList<>();
mediationListDTO.setList(mediationDTOs);
}
// identifying the proper start and end indexes
int size = mediation.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
mediationDTOs.add(fromMediationInfoToDTO(mediation.get(i)));
}
mediationListDTO.setCount(mediationDTOs.size());
return mediationListDTO;
}
Aggregations