Search in sources :

Example 1 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class AbstractAPIManager method getCustomMediationResourceFromUuid.

/**
 * Returns the mediation policy registry resource correspond to the given identifier
 *
 * @param mediationPolicyId uuid of the mediation resource
 * @return Registry resource of given identifier or null
 * @throws APIManagementException If failed to get the registry resource of given uuid
 */
@Override
public Resource getCustomMediationResourceFromUuid(String mediationPolicyId) throws APIManagementException {
    String resourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
    try {
        Resource resource = registry.get(resourcePath);
        // resource : customsequences
        if (resource instanceof Collection) {
            Collection typeCollection = (Collection) resource;
            String[] typeArray = typeCollection.getChildren();
            for (String type : typeArray) {
                Resource typeResource = registry.get(type);
                // typeResource: in/ out/ fault
                if (typeResource instanceof Collection) {
                    String[] policyArray = ((Collection) typeResource).getChildren();
                    if (policyArray.length > 0) {
                        for (String policy : policyArray) {
                            Resource mediationResource = registry.get(policy);
                            // mediationResource: eg .log_in_msg.xml
                            String resourceId = mediationResource.getUUID();
                            if (resourceId.equals(mediationPolicyId)) {
                                // registry resource
                                return mediationResource;
                            }
                        }
                    }
                }
            }
        }
    } catch (RegistryException e) {
        String msg = "Error while accessing registry objects";
        throw new APIManagementException(msg, e);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 2 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class MediationMappingUtil method fromMediationInfoToDTO.

/**
 * Converts an Mediation object into MediationInfoDTO
 *
 * @param mediation Mediation object
 * @return MediationInfoDTO object corresponding to the given Mediation object
 */
public static MediationInfoDTO fromMediationInfoToDTO(Mediation mediation) {
    MediationInfoDTO mediationInfoDTO = new MediationInfoDTO();
    mediationInfoDTO.setId(mediation.getUuid());
    mediationInfoDTO.setName(mediation.getName());
    mediationInfoDTO.setType(MediationInfoDTO.TypeEnum.valueOf(mediation.getType().toUpperCase()));
    return mediationInfoDTO;
}
Also used : MediationInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationInfoDTO)

Example 3 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class MediationMappingUtil method fromMediationToDTO.

public static MediationDTO fromMediationToDTO(Mediation mediation) {
    MediationDTO mediationDTO = new MediationDTO();
    mediationDTO.setId(mediation.getUuid());
    mediationDTO.setName(mediation.getName());
    mediationDTO.setType(MediationDTO.TypeEnum.valueOf(mediation.getType().toUpperCase()));
    mediationDTO.setConfig(mediation.getConfig());
    return mediationDTO;
}
Also used : MediationDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationDTO)

Example 4 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesMediationMediationPolicyIdGet.

/**
 * Returns a specific global mediation policy by identifier
 *
 * @param mediationPolicyId Mediation policy uuid
 * @param accept            Accept header value
 * @return returns the matched mediation
 */
@Override
public Response policiesMediationMediationPolicyIdGet(String mediationPolicyId, String accept, MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        // Get given global mediation policy
        Mediation mediation = apiProvider.getGlobalMediationPolicy(mediationPolicyId);
        if (mediation != null) {
            MediationDTO mediationDTO = MediationMappingUtil.fromMediationToDTO(mediation);
            return Response.ok().entity(mediationDTO).build();
        } else {
            // If global mediation policy not exists
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_POLICY, mediationPolicyId, log);
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving the global mediation policy with id " + mediationPolicyId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) MediationDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.MediationDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) Mediation(org.wso2.carbon.apimgt.api.model.Mediation)

Example 5 with Mediation

use of org.wso2.carbon.apimgt.persistence.dto.Mediation in project carbon-apimgt by wso2.

the class UserAwareAPIProviderTest method testDeleteApiSpecificMediationPolicy.

/**
 * This method checks the behaviour of Delete API specific mediation policy method for a non-existing mediation
 * policy.
 *
 * @throws APIManagementException API Management Exception.
 */
@Test
public void testDeleteApiSpecificMediationPolicy() throws APIManagementException {
    Identifier identifier = Mockito.mock(Identifier.class);
    Assert.assertFalse(userAwareAPIProvider.deleteApiSpecificMediationPolicy(identifier, "test", "test"));
}
Also used : Identifier(org.wso2.carbon.apimgt.api.model.Identifier) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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