use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationListDTO 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 MediationListDTO object containing MediationInfoDTO
*/
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;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationListDTO in project carbon-apimgt by wso2.
the class MediationPoliciesApiServiceImpl method getAllGlobalMediationPolicies.
/**
* Returns list of global Mediation policies
*
* @param limit maximum number of mediation returns
* @param offset starting index
* @param query search condition
* @param ifNoneMatch If-None-Match header value
* @return Matched global mediation policies for given search condition
*/
@Override
public Response getAllGlobalMediationPolicies(Integer limit, Integer offset, String query, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
// 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 global mediation policies";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
return null;
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationListDTO 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.rest.api.publisher.v1.dto.MediationListDTO 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