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