Search in sources :

Example 56 with Mediation

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;
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) MediationListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationListDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) Mediation(org.wso2.carbon.apimgt.api.model.Mediation)

Example 57 with Mediation

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 58 with Mediation

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;
}
Also used : MediationInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationInfoDTO) MediationListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationListDTO)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)35 Mediation (org.wso2.carbon.apimgt.api.model.Mediation)23 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 IOException (java.io.IOException)21 Resource (org.wso2.carbon.registry.core.Resource)19 XMLStreamException (javax.xml.stream.XMLStreamException)12 QName (javax.xml.namespace.QName)11 OMElement (org.apache.axiom.om.OMElement)11 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)11 MediationPolicyPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.MediationPolicyPersistenceException)11 InputStream (java.io.InputStream)10 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)10 ArrayList (java.util.ArrayList)9 Collection (org.wso2.carbon.registry.core.Collection)9 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)8 OMAttribute (org.apache.axiom.om.OMAttribute)7 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)6 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)6 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)6 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)6